From bcd52957e16dca503c70536d448a71f7089f8492 Mon Sep 17 00:00:00 2001 From: Vadim Rutkovsky Date: Sun, 6 Sep 2015 01:35:42 +0200 Subject: [PATCH 1/3] Use Travis CI This also adds pep8/pyflakes checks, but these don't break build --- .travis.yml | 39 +++++++++++++++++++++++++++++++++++++++ circle.yml | 24 ------------------------ 2 files changed, 39 insertions(+), 24 deletions(-) create mode 100644 .travis.yml delete mode 100644 circle.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..34df5ea --- /dev/null +++ b/.travis.yml @@ -0,0 +1,39 @@ +sudo: false + +language: python + +python: + - "2.7" + +env: + - TESTS="pyflakes" + - TESTS="pep8" + - TESTS="behave" + +matrix: + allow_failures: + - env: TESTS="pep8" + - env: TESTS="pyflakes" + +before_install: + - pip install pep8 pyflakes behave PyHamcrest python-coveralls nose --upgrade + - python setup.py -q install + - git clean -fdx + +script: +- case $TESTS in + pep8) pep8 ctf-cli.py ctf_cli/* --ignore=E501,E225,E265,E402 --show-source --show-pep8 ;; + pyflakes) pyflakes ctf-cli.py ctf_cli/* ;; + behave) behave -t ~@xfail ;; + esac + +notifications: + webhooks: + urls: + - https://webhooks.gitter.im/e/92b168ffacdc38a6facd + on_success: change + on_failure: always + on_start: never + +after_success: + coveralls \ No newline at end of file diff --git a/circle.yml b/circle.yml deleted file mode 100644 index 9315b15..0000000 --- a/circle.yml +++ /dev/null @@ -1,24 +0,0 @@ -machine: - services: - - docker - python: - version: 2.7 - environment: - COVERALLS_REPO_TOKEN: RDQpf8yX7quK5FXKN2auJpAxFNlIByLiT - - -dependencies: - pre: - - pip install --use-mirrors behave coverage PyHamcrest python-coveralls nose - override: - - python setup.py -q install - -test: - override: - - mkdir -p $CIRCLE_TEST_REPORTS/junit/ - - behave -t ~@xfail --junit --junit-directory $CIRCLE_TEST_REPORTS/junit/ - - coveralls - -notify: - webhooks: - - url: https://webhooks.gitter.im/e/92b168ffacdc38a6facd From ce192b569f2ddad1ac53419854113e3974e20edf Mon Sep 17 00:00:00 2001 From: Vadim Rutkovsky Date: Thu, 24 Sep 2015 13:51:17 +0200 Subject: [PATCH 2/3] Remove unused e variables and make pyflakes errors important --- .travis.yml | 1 - ctf_cli/behave.py | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 34df5ea..8f31788 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,6 @@ env: matrix: allow_failures: - env: TESTS="pep8" - - env: TESTS="pyflakes" before_install: - pip install pep8 pyflakes behave PyHamcrest python-coveralls nose --upgrade diff --git a/ctf_cli/behave.py b/ctf_cli/behave.py index 906f3a8..cff8536 100644 --- a/ctf_cli/behave.py +++ b/ctf_cli/behave.py @@ -164,9 +164,9 @@ def _create_ansible_config(self): try: script = self._cli_conf.get(CTFCliConfig.ANSIBLE_SECTION_NAME, CTFCliConfig.CONFIG_ANSIBLE_DYNAMIC_SCRIPT) - except NoSectionError as e: + except NoSectionError: raise CTFCliError("No configuration for 'ansible' provided!") - except NoOptionError as e: + except NoOptionError: logger.debug("No dynamic provision script found") script = None @@ -176,13 +176,13 @@ def _create_ansible_config(self): host = self._cli_conf.get(CTFCliConfig.ANSIBLE_SECTION_NAME, CTFCliConfig.CONFIG_ANSIBLE_HOST) user = self._cli_conf.get(CTFCliConfig.ANSIBLE_SECTION_NAME, CTFCliConfig.CONFIG_ANSIBLE_USER) - except NoOptionError as e: + except NoOptionError: logger.debug("No dynamic provision script found") # Optional parameters try: sudo = self._cli_conf.get(CTFCliConfig.ANSIBLE_SECTION_NAME, CTFCliConfig.CONFIG_ANSIBLE_SUDO) - except NoOptionError as e: + except NoOptionError: sudo = False ansible_conf_path = None From d77600e1fb90e529acc19eaa9d6a78707d59a3ab Mon Sep 17 00:00:00 2001 From: Vadim Rutkovsky Date: Thu, 24 Sep 2015 13:57:53 +0200 Subject: [PATCH 3/3] Fix pep8 failures --- ctf-cli.py | 2 +- ctf_cli/__init__.py | 2 +- ctf_cli/application.py | 14 +++++++++----- ctf_cli/arguments_parser.py | 33 ++++++++++++++++++--------------- ctf_cli/behave.py | 28 +++++++++++++++++++--------- ctf_cli/cli_runner.py | 1 + ctf_cli/settings.py | 2 +- 7 files changed, 50 insertions(+), 32 deletions(-) diff --git a/ctf-cli.py b/ctf-cli.py index 92a6b30..b31d3dd 100755 --- a/ctf-cli.py +++ b/ctf-cli.py @@ -19,4 +19,4 @@ from ctf_cli.cli_runner import CliRunner -CliRunner.run() \ No newline at end of file +CliRunner.run() diff --git a/ctf_cli/__init__.py b/ctf_cli/__init__.py index ef15c5f..ac96cad 100644 --- a/ctf_cli/__init__.py +++ b/ctf_cli/__init__.py @@ -14,4 +14,4 @@ # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with this program. If not, see . \ No newline at end of file +# along with this program. If not, see . diff --git a/ctf_cli/application.py b/ctf_cli/application.py index 67e0fb8..5af9d5d 100644 --- a/ctf_cli/application.py +++ b/ctf_cli/application.py @@ -100,7 +100,7 @@ def init(self): with open(steps_py_file, "w") as f: f.write(common_steps_py_content) check_call("git add %s" % steps_py_file, shell=True) - + # Copy sample configuration ctf_conf_file = os.path.join(self._execution_dir_path, "ctf.conf") if os.path.exists(ctf_conf_file): @@ -113,13 +113,15 @@ def init(self): check_call("git add %s" % ctf_conf_file, shell=True) def add_remote(self): - if 'feature' in self._cli_conf.get(CTFCliConfig.GLOBAL_SECTION_NAME, CTFCliConfig.CONFIG_REMOTE_TYPE): + if 'feature' in self._cli_conf.get( + CTFCliConfig.GLOBAL_SECTION_NAME, CTFCliConfig.CONFIG_REMOTE_TYPE): self.add_remote_feature() else: self.add_remote_step() def add_remote_feature(self): - project = self._cli_conf.get(CTFCliConfig.GLOBAL_SECTION_NAME, CTFCliConfig.CONFIG_REMOTE_PROJECT) + project = self._cli_conf.get( + CTFCliConfig.GLOBAL_SECTION_NAME, CTFCliConfig.CONFIG_REMOTE_PROJECT) if project is None: path = "tests/features/" else: @@ -127,7 +129,8 @@ def add_remote_feature(self): self.add_submodule(path) def add_remote_step(self): - project = self._cli_conf.get(CTFCliConfig.GLOBAL_SECTION_NAME, CTFCliConfig.CONFIG_REMOTE_PROJECT) + project = self._cli_conf.get( + CTFCliConfig.GLOBAL_SECTION_NAME, CTFCliConfig.CONFIG_REMOTE_PROJECT) if project is None: path = "tests/steps/" else: @@ -159,7 +162,8 @@ def run(self): check_call("git submodule update --init", shell=True) # TODO: Remove this or rework, once more types are implemented - if self._cli_conf.get(CTFCliConfig.GLOBAL_SECTION_NAME, CTFCliConfig.CONFIG_EXEC_TYPE) != 'ansible': + if self._cli_conf.get( + CTFCliConfig.GLOBAL_SECTION_NAME, CTFCliConfig.CONFIG_EXEC_TYPE) != 'ansible': raise CTFCliError("Wrong ExecType configured. Currently only 'ansible' is supported!") self._working_dir = BehaveWorkingDirectory(self._working_dir_path, self._cli_conf) diff --git a/ctf_cli/arguments_parser.py b/ctf_cli/arguments_parser.py index 5dffe21..b9ce4d3 100644 --- a/ctf_cli/arguments_parser.py +++ b/ctf_cli/arguments_parser.py @@ -24,7 +24,8 @@ class ArgumentsParser(object): def __init__(self, args=None): """ parse arguments """ - self.parser = argparse.ArgumentParser(description='CLI for running Containers Testing Framework') + self.parser = argparse.ArgumentParser( + description='CLI for running Containers Testing Framework') self.subparsers = self.parser.add_subparsers(dest="cli_action") self.add_args() self.add_remote_subparser() @@ -36,14 +37,12 @@ def __init__(self, args=None): def add_remote_add_subparser(self, subparser): subparser.add_argument( dest='remote_type', - choices=['steps', 'features'], - ) + choices=['steps', 'features']) subparser.add_argument( dest='url', - help='module url' - ) - + help='module url') + subparser.add_argument( "--project", dest='project', @@ -51,24 +50,29 @@ def add_remote_add_subparser(self, subparser): def add_remote_remove_subparser(self, subparser): subparser.add_argument( - dest='name' - ) + dest='name') def add_remote_subparser(self): - remote_subparser=self.subparsers.add_parser('remote', help='addidng/removing test suites') - remote_oper_subparser=remote_subparser.add_subparsers(dest='remote_action') - self.add_remote_add_subparser(remote_oper_subparser.add_parser('add', help='add remote repository')) - self.add_remote_remove_subparser(remote_oper_subparser.add_parser('remove', help='remove remote repository')) + remote_subparser = self.subparsers.add_parser( + 'remote', help='addidng/removing test suites') + remote_oper_subparser = remote_subparser.add_subparsers( + dest='remote_action') + self.add_remote_add_subparser(remote_oper_subparser.add_parser( + 'add', help='add remote repository')) + self.add_remote_remove_subparser(remote_oper_subparser.add_parser( + 'remove', help='remove remote repository')) remote_oper_subparser.add_parser('list', help='list remote repositories') def add_run_subparser(self): - run_subparser=self.subparsers.add_parser('run', help="run test suite - default") + run_subparser = self.subparsers.add_parser( + 'run', help="run test suite - default") run_subparser.add_argument( "-c", "--cli-config", default=None, dest='cli_config_path', - help="Path to CLI configuration file (By default use only CLI arguments and default values)" + help="Path to CLI configuration file" + + "(By default use only CLI arguments and default values)" ) run_subparser.add_argument( "-t", @@ -116,7 +120,6 @@ def add_args(self): help="Output is more verbose (recommended)" ) - def __getattr__(self, name): try: return getattr(self.args, name) diff --git a/ctf_cli/behave.py b/ctf_cli/behave.py index cff8536..d24bd20 100644 --- a/ctf_cli/behave.py +++ b/ctf_cli/behave.py @@ -121,7 +121,8 @@ def setup(self): """ self._check_working_dir() - if self._cli_conf.get(CTFCliConfig.GLOBAL_SECTION_NAME, CTFCliConfig.CONFIG_EXEC_TYPE) == 'ansible': + if self._cli_conf.get(CTFCliConfig.GLOBAL_SECTION_NAME, + CTFCliConfig.CONFIG_EXEC_TYPE) == 'ansible': self._create_ansible_config() self._add_project_specific_features() @@ -163,7 +164,8 @@ def _create_ansible_config(self): user = None try: - script = self._cli_conf.get(CTFCliConfig.ANSIBLE_SECTION_NAME, CTFCliConfig.CONFIG_ANSIBLE_DYNAMIC_SCRIPT) + script = self._cli_conf.get(CTFCliConfig.ANSIBLE_SECTION_NAME, + CTFCliConfig.CONFIG_ANSIBLE_DYNAMIC_SCRIPT) except NoSectionError: raise CTFCliError("No configuration for 'ansible' provided!") except NoOptionError: @@ -172,16 +174,20 @@ def _create_ansible_config(self): if not script: try: - method = self._cli_conf.get(CTFCliConfig.ANSIBLE_SECTION_NAME, CTFCliConfig.CONFIG_ANSIBLE_METHOD) - host = self._cli_conf.get(CTFCliConfig.ANSIBLE_SECTION_NAME, CTFCliConfig.CONFIG_ANSIBLE_HOST) - user = self._cli_conf.get(CTFCliConfig.ANSIBLE_SECTION_NAME, CTFCliConfig.CONFIG_ANSIBLE_USER) + method = self._cli_conf.get(CTFCliConfig.ANSIBLE_SECTION_NAME, + CTFCliConfig.CONFIG_ANSIBLE_METHOD) + host = self._cli_conf.get(CTFCliConfig.ANSIBLE_SECTION_NAME, + CTFCliConfig.CONFIG_ANSIBLE_HOST) + user = self._cli_conf.get(CTFCliConfig.ANSIBLE_SECTION_NAME, + CTFCliConfig.CONFIG_ANSIBLE_USER) except NoOptionError: logger.debug("No dynamic provision script found") # Optional parameters try: - sudo = self._cli_conf.get(CTFCliConfig.ANSIBLE_SECTION_NAME, CTFCliConfig.CONFIG_ANSIBLE_SUDO) + sudo = self._cli_conf.get(CTFCliConfig.ANSIBLE_SECTION_NAME, + CTFCliConfig.CONFIG_ANSIBLE_SUDO) except NoOptionError: sudo = False @@ -196,7 +202,8 @@ def _create_ansible_config(self): host=host, method=method, user=user, sudo=sudo ) - logger.debug("Writing ansible configuration to '%s'\n%s", ansible_conf_path, ansible_conf_content) + logger.debug("Writing ansible configuration to '%s'\n%s", + ansible_conf_path, ansible_conf_content) with open(ansible_conf_path, 'w') as f: f.write(ansible_conf_content) @@ -204,7 +211,9 @@ def _create_ansible_config(self): def _check_working_dir(self): """ - Check if working directory exists. Remove it if it exists and then recreate. Create it if it does not exist + Check if working directory exists. + Remove it if it exists and then recreate. + Create it if it does not exist """ if os.path.exists(self._working_dir): logger.debug("Working directory '%s' exists. Removing it!", self._working_dir) @@ -227,7 +236,8 @@ def _add_project_specific_steps(self): shutil.copytree(project_steps_dir, self._steps_dir) else: - logger.warning("Not using project specific Steps. '%s' does not exist!", project_steps_dir) + logger.warning("Not using project specific Steps. '%s' does not exist!", + project_steps_dir) def _add_project_specific_features(self): """ diff --git a/ctf_cli/cli_runner.py b/ctf_cli/cli_runner.py index cd86bc5..3e16309 100644 --- a/ctf_cli/cli_runner.py +++ b/ctf_cli/cli_runner.py @@ -70,5 +70,6 @@ def run(): finally: logger.debug('Exiting...') + def run(): CliRunner.run() diff --git a/ctf_cli/settings.py b/ctf_cli/settings.py index a1813a6..15d39de 100644 --- a/ctf_cli/settings.py +++ b/ctf_cli/settings.py @@ -17,4 +17,4 @@ # along with this program. If not, see . DEFAULT_CONFIG_NAME = 'ctf.conf' -DEBUG_LOG_FILE_NAME = 'ctf-debug.log' \ No newline at end of file +DEBUG_LOG_FILE_NAME = 'ctf-debug.log'