Skip to content

Use Travis CI #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
sudo: false

language: python

python:
- "2.7"

env:
- TESTS="pyflakes"
- TESTS="pep8"
- TESTS="behave"

matrix:
allow_failures:
- env: TESTS="pep8"

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
24 changes: 0 additions & 24 deletions circle.yml

This file was deleted.

2 changes: 1 addition & 1 deletion ctf-cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@

from ctf_cli.cli_runner import CliRunner

CliRunner.run()
CliRunner.run()
2 changes: 1 addition & 1 deletion ctf_cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <http://www.gnu.org/licenses/>.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
14 changes: 9 additions & 5 deletions ctf_cli/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -113,21 +113,24 @@ 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:
path = "tests/features/" + project
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:
Expand Down Expand Up @@ -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)
Expand Down
33 changes: 18 additions & 15 deletions ctf_cli/arguments_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -36,39 +37,42 @@ 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',
help="name of test project")

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",
Expand Down Expand Up @@ -116,7 +120,6 @@ def add_args(self):
help="Output is more verbose (recommended)"
)


def __getattr__(self, name):
try:
return getattr(self.args, name)
Expand Down
38 changes: 24 additions & 14 deletions ctf_cli/behave.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -163,26 +164,31 @@ def _create_ansible_config(self):
user = None

try:
script = self._cli_conf.get(CTFCliConfig.ANSIBLE_SECTION_NAME, CTFCliConfig.CONFIG_ANSIBLE_DYNAMIC_SCRIPT)
except NoSectionError as e:
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 as e:
except NoOptionError:
logger.debug("No dynamic provision script found")
script = None

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)

except NoOptionError as e:
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)
except NoOptionError as e:
sudo = self._cli_conf.get(CTFCliConfig.ANSIBLE_SECTION_NAME,
CTFCliConfig.CONFIG_ANSIBLE_SUDO)
except NoOptionError:
sudo = False

ansible_conf_path = None
Expand All @@ -196,15 +202,18 @@ 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)

self._exec_type_conf_path = ansible_conf_path

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)
Expand All @@ -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):
"""
Expand Down
1 change: 1 addition & 0 deletions ctf_cli/cli_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,6 @@ def run():
finally:
logger.debug('Exiting...')


def run():
CliRunner.run()
2 changes: 1 addition & 1 deletion ctf_cli/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

DEFAULT_CONFIG_NAME = 'ctf.conf'
DEBUG_LOG_FILE_NAME = 'ctf-debug.log'
DEBUG_LOG_FILE_NAME = 'ctf-debug.log'