Skip to content

Commit

Permalink
Added better debug options:
Browse files Browse the repository at this point in the history
- Added verbosity levels for Terraform and Ansible (hitachienergy#987)
- Added vim to Epicli container and devcontainer (hitachienergy#986)
  • Loading branch information
seriva committed Mar 10, 2020
1 parent 571634b commit a901f66
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 13 deletions.
2 changes: 1 addition & 1 deletion core/src/epicli/.devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ RUN chmod +x /config-pre.sh \
&& apt-get update \
&& apt-get -y install --no-install-recommends apt-utils dialog 2>&1 \

&& apt-get -y install git procps lsb-release gcc make musl-dev libffi-dev tar unzip \
&& apt-get -y install git procps lsb-release gcc make musl-dev libffi-dev tar unzip vim \

&& apt-get -y install ruby-full \

Expand Down
2 changes: 1 addition & 1 deletion core/src/epicli/Dockerfile-debian
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ COPY /dist/ /epicli
WORKDIR /epicli

RUN apt-get update \
&& apt-get -y install gcc make musl-dev libffi-dev tar unzip openssh-client
&& apt-get -y install gcc make musl-dev libffi-dev tar unzip openssh-client vim

RUN pip install epicli-${EPICLI_VERSION}-py3-none-any.whl

Expand Down
5 changes: 3 additions & 2 deletions core/src/epicli/cli/engine/ansible/AnsibleCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from cli.helpers.Config import Config
import time

ansible_verbosity = ['NONE','-v','-vv','-vvv','-vvvv']

class AnsibleCommand:

Expand Down Expand Up @@ -62,8 +63,8 @@ def run_playbook(self, inventory, playbook_path, vault_file=None):

cmd.append(playbook_path)

if Config().debug:
cmd.append('-vvv')
if Config().debug > 0:
cmd.append(ansible_verbosity[Config().debug])

self.logger.info('Running: "' + ' '.join(playbook_path) + '"')

Expand Down
5 changes: 3 additions & 2 deletions core/src/epicli/cli/engine/terraform/TerraformCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from cli.helpers.Log import LogPipe, Log
from cli.helpers.Config import Config

terraform_verbosity = ['ERROR','WARN','INFO','DEBUG','TRACE']

class TerraformCommand:

Expand Down Expand Up @@ -41,8 +42,8 @@ def run(self, command, env, auto_approve=False):
cmd = ' '.join(cmd)
self.logger.info(f'Running: "{cmd}"')

if Config().debug:
env['TF_LOG'] = 'TRACE'
if Config().debug > 0:
env['TF_LOG'] = terraform_verbosity[Config().debug]

logpipe = LogPipe(__name__)
with subprocess.Popen(cmd, stdout=logpipe, stderr=logpipe, env=env, shell=True) as sp:
Expand Down
32 changes: 26 additions & 6 deletions core/src/epicli/cli/epicli.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def main():
parser = argparse.ArgumentParser(
description=__doc__,
usage='''epicli <command> [<args>]''',
formatter_class=argparse.RawDescriptionHelpFormatter)
formatter_class=argparse.RawTextHelpFormatter)

# setup some root arguments
parser.add_argument('--version', action='version', help='Shows the CLI version', version=VERSION)
Expand All @@ -45,12 +45,32 @@ def main():
parser.add_argument('--validate-certs', choices=['true', 'false'], default='true', action='store',
dest='validate_certs',
help='''[Experimental]: Disables certificate checks for certain Ansible operations
which might have issues behind proxies (https://github.com/ansible/ansible/issues/32750).
Should NOT be used in production for security reasons.''')
parser.add_argument('--debug', dest='debug', action="store_true",
help='Set this to output extensive debug information. Carries over to Ansible and Terraform.')
which might have issues behind proxies (https://github.com/ansible/ansible/issues/32750).
Should NOT be used in production for security reasons.''')
parser.add_argument('--auto-approve', dest='auto_approve', action="store_true",
help='Auto approve any user input queries asked by Epicli')

# set debug verbosity level.
def debug_level(x):
x = int(x)
if x < 0 or x > 4:
raise argparse.ArgumentTypeError("--debug value should be between 0 and 4")
return x
parser.add_argument('--debug', dest='debug', type=debug_level,
help='''Set this flag (0..4) to enable debug output where 0 is no
debug output and 1..4 is debug output with different verbosity levels:
Python : Anything heigher then 0 enables printing of Python stacktraces
Ansible : 1..4 map to following Ansible verbosity levels:
1: -v
2: -vv
3: -vvv
4: -vvvv
Terraform : 1..4 map to the following Terraform verbosity levels:
1: WARN
2: INFO
3: DEBUG
4: TRACE''')

# some arguments we don't want available when running from the docker image.
if not config.docker_cli:
parser.add_argument('-o', '--output', dest='output_dir', type=str,
Expand Down Expand Up @@ -95,7 +115,7 @@ def main():
return args.func(args)
except Exception as e:
logger = Log('epicli')
logger.error(e, exc_info=config.debug)
logger.error(e, exc_info=(config.debug > 0))
return 1


Expand Down
2 changes: 1 addition & 1 deletion core/src/epicli/cli/helpers/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self):
self._log_type = 'plain'

self._validate_certs = True
self._debug = False
self._debug = 0
self._auto_approve = False
self._offline_requirements = ''
self._wait_for_pods = False
Expand Down

0 comments on commit a901f66

Please sign in to comment.