summaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-rw-r--r--utils/.coveragerc18
l---------utils/.pylintrc1
-rw-r--r--utils/Makefile110
-rw-r--r--utils/README.md61
-rw-r--r--utils/setup.cfg27
-rw-r--r--utils/setup.py11
-rw-r--r--utils/test-requirements.txt15
-rw-r--r--utils/test/cli_installer_tests.py102
-rw-r--r--utils/test/fixture.py13
-rw-r--r--utils/test/oo_config_tests.py39
-rw-r--r--utils/test/openshift_ansible_tests.py26
-rw-r--r--utils/test/test_utils.py8
-rw-r--r--utils/tox.ini19
13 files changed, 28 insertions, 422 deletions
diff --git a/utils/.coveragerc b/utils/.coveragerc
deleted file mode 100644
index 551e13192..000000000
--- a/utils/.coveragerc
+++ /dev/null
@@ -1,18 +0,0 @@
-[run]
-branch = True
-omit =
- */lib/python*/site-packages/*
- */lib/python*/*
- /usr/*
- setup.py
- # TODO(rhcarvalho): this is used to ignore test files from coverage report.
- # We can make this less generic when we stick with a single test pattern in
- # the repo.
- test_*.py
- *_tests.py
-
-[report]
-fail_under = 73
-
-[html]
-directory = cover
diff --git a/utils/.pylintrc b/utils/.pylintrc
deleted file mode 120000
index 30b33b524..000000000
--- a/utils/.pylintrc
+++ /dev/null
@@ -1 +0,0 @@
-../.pylintrc \ No newline at end of file
diff --git a/utils/Makefile b/utils/Makefile
deleted file mode 100644
index 038c31fcf..000000000
--- a/utils/Makefile
+++ /dev/null
@@ -1,110 +0,0 @@
-########################################################
-
-# Makefile for OpenShift: Atomic Quick Installer
-#
-# useful targets (not all implemented yet!):
-# make clean -- Clean up garbage
-# make ci ------------------- Execute CI steps (for travis or jenkins)
-
-########################################################
-
-# > VARIABLE = value
-#
-# Normal setting of a variable - values within it are recursively
-# expanded when the variable is USED, not when it's declared.
-#
-# > VARIABLE := value
-#
-# Setting of a variable with simple expansion of the values inside -
-# values within it are expanded at DECLARATION time.
-
-########################################################
-
-
-NAME := oo-install
-VENV := $(NAME)env
-TESTPACKAGE := oo-install
-SHORTNAME := ooinstall
-
-# This doesn't evaluate until it's called. The -D argument is the
-# directory of the target file ($@), kinda like `dirname`.
-ASCII2MAN = a2x -D $(dir $@) -d manpage -f manpage $<
-MANPAGES := docs/man/man1/atomic-openshift-installer.1
-# slipped into the manpage template before a2x processing
-VERSION := 1.4
-
-# YAMLFILES: Skipping all '/files/' folders due to conflicting yaml file definitions
-YAMLFILES = $(shell find ../ -name $(VENV) -prune -o -name .tox -prune -o \( -name '*.yml' -o -name '*.yaml' \) ! -path "*/files/*" -print 2>&1)
-PYFILES = $(shell find ../ -name $(VENV) -prune -o -name ooinstall.egg-info -prune -o -name test -prune -o -name .tox -prune -o -name "*.py" -print)
-
-sdist: clean
- python setup.py sdist
- rm -fR $(SHORTNAME).egg-info
-
-clean:
- @find . -type f -regex ".*\.py[co]$$" -delete
- @find . -type f \( -name "*~" -or -name "#*" \) -delete
- @rm -fR build dist rpm-build MANIFEST htmlcov .coverage cover ooinstall.egg-info oo-install
- @rm -fR $(VENV)
- @rm -fR .tox
-
-# To force a rebuild of the docs run 'touch' on any *.in file under
-# docs/man/man1/
-docs: $(MANPAGES)
-
-# Regenerate %.1.asciidoc if %.1.asciidoc.in has been modified more
-# recently than %.1.asciidoc.
-%.1.asciidoc: %.1.asciidoc.in
- sed "s/%VERSION%/$(VERSION)/" $< > $@
-
-# Regenerate %.1 if %.1.asciidoc or VERSION has been modified more
-# recently than %.1. (Implicitly runs the %.1.asciidoc recipe)
-%.1: %.1.asciidoc
- $(ASCII2MAN)
-
-viewcover:
- xdg-open cover/index.html
-
-# Conditional virtualenv building strategy taken from this great post
-# by Marcel Hellkamp:
-# http://blog.bottlepy.org/2012/07/16/virtualenv-and-makefiles.html
-$(VENV): $(VENV)/bin/activate
-$(VENV)/bin/activate: test-requirements.txt
- @echo "#############################################"
- @echo "# Creating a virtualenv"
- @echo "#############################################"
- test -d $(VENV) || virtualenv $(VENV)
- . $(VENV)/bin/activate && pip install setuptools==17.1.1
- . $(VENV)/bin/activate && pip install -r test-requirements.txt
- touch $(VENV)/bin/activate
-# If there are any special things to install do it here
-# . $(VENV)/bin/activate && INSTALL STUFF
-
-ci-unittests: $(VENV)
- @echo "#############################################"
- @echo "# Running Unit Tests in virtualenv"
- @echo "#############################################"
- . $(VENV)/bin/activate && detox -e py27-unit,py35-unit
- @echo "VIEW CODE COVERAGE REPORT WITH 'xdg-open cover/index.html' or run 'make viewcover'"
-
-ci-pylint: $(VENV)
- @echo "#############################################"
- @echo "# Running PyLint Tests in virtualenv"
- @echo "#############################################"
- . $(VENV)/bin/activate && detox -e py27-pylint,py35-pylint
-
-ci-flake8: $(VENV)
- @echo "#############################################"
- @echo "# Running Flake8 Compliance Tests in virtualenv"
- @echo "#############################################"
- . $(VENV)/bin/activate && detox -e py27-flake8,py35-flake8
-
-ci-tox: $(VENV)
- . $(VENV)/bin/activate && detox
-
-ci: ci-tox
- @echo
- @echo "##################################################################################"
- @echo "VIEW CODE COVERAGE REPORT WITH 'xdg-open cover/index.html' or run 'make viewcover'"
- @echo "To clean your test environment run 'make clean'"
- @echo "Other targets you may run with 'make': 'ci-pylint', 'ci-tox', 'ci-unittests', 'ci-flake8'"
diff --git a/utils/README.md b/utils/README.md
index 7aa045ae4..79ea3fa9f 100644
--- a/utils/README.md
+++ b/utils/README.md
@@ -1,69 +1,14 @@
# Running Tests
-Run the command:
-
- make ci
-
-to run tests and linting tools.
-
-Underneath the covers, we use [tox](http://readthedocs.org/docs/tox/) to manage virtualenvs and run
-tests. Alternatively, tests can be run using [detox](https://pypi.python.org/pypi/detox/) which allows
-for running tests in parallel.
-
-```
-pip install tox detox
-```
-
-List the test environments available:
-
-```
-tox -l
-```
-
-Run all of the tests with:
-
-```
-tox
-```
-
-Run all of the tests in parallel with detox:
-
-```
-detox
-```
-
-Run a particular test environment:
-
-```
-tox -e py27-flake8
-```
-
-Run a particular test environment in a clean virtualenv:
-
-```
-tox -r -e py35-pylint
-```
-
-If you want to enter the virtualenv created by tox to do additional
-testing/debugging:
-
-```
-source .tox/py27-flake8/bin/activate
-```
-
-You will get errors if the log files already exist and can not be
-written to by the current user (`/tmp/ansible.log` and
-`/tmp/installer.txt`). *We're working on it.*
-
+All tests can be run by running `tox`. See [running tests](..//CONTRIBUTING.md#running-tests) for more information.
# Running From Source
You will need to setup a **virtualenv** to run from source:
$ virtualenv oo-install
- $ source ./oo-install/bin/activate
- $ virtualenv --relocatable ./oo-install/
- $ python setup.py install
+ $ source oo-install/bin/activate
+ $ python setup.py develop
The virtualenv `bin` directory should now be at the start of your
`$PATH`, and `oo-install` is ready to use from your shell.
diff --git a/utils/setup.cfg b/utils/setup.cfg
index d730cd3b4..79bc67848 100644
--- a/utils/setup.cfg
+++ b/utils/setup.cfg
@@ -3,30 +3,3 @@
# 3. If at all possible, it is good practice to do this. If you cannot, you
# will need to generate wheels for each Python version that you support.
universal=1
-
-[aliases]
-test=pytest
-
-[flake8]
-max-line-length=120
-exclude=test/*,setup.py,oo-installenv
-ignore=E501
-
-[lint]
-lint_disable=fixme,locally-disabled,file-ignored,duplicate-code
-
-[tool:pytest]
-testpaths = test
-norecursedirs =
- .*
- __pycache__
-python_files =
- # TODO(rhcarvalho): rename test files to follow a single pattern. "test*.py"
- # is Python unittest's default, while pytest discovers both "test_*.py" and
- # "*_test.py" by default.
- test_*.py
- *_tests.py
-addopts =
- --cov=.
- --cov-report=term
- --cov-report=html
diff --git a/utils/setup.py b/utils/setup.py
index 629d39206..6fec7b173 100644
--- a/utils/setup.py
+++ b/utils/setup.py
@@ -38,26 +38,15 @@ setup(
# You can just specify the packages manually here if your project is
# simple. Or you can use find_packages().
- #packages=find_packages(exclude=['contrib', 'docs', 'tests*']),
packages=['ooinstall'],
package_dir={'': 'src'},
-
# List run-time dependencies here. These will be installed by pip when
# your project is installed. For an analysis of "install_requires" vs pip's
# requirements files see:
# https://packaging.python.org/en/latest/requirements.html
install_requires=['click', 'PyYAML', 'ansible'],
- # List additional groups of dependencies here (e.g. development
- # dependencies). You can install these using the following syntax,
- # for example:
- # $ pip install -e .[dev,test]
- #extras_require={
- # 'dev': ['check-manifest'],
- # 'test': ['coverage'],
- #},
-
# If there are data files included in your packages that need to be
# installed, specify them here. If using Python 2.6 or less, then these
# have to be included in MANIFEST.in as well.
diff --git a/utils/test-requirements.txt b/utils/test-requirements.txt
deleted file mode 100644
index b26e22a7e..000000000
--- a/utils/test-requirements.txt
+++ /dev/null
@@ -1,15 +0,0 @@
-ansible
-# flake8 moved to before setuptools-lint to satisfy mccabe dependency issue
-flake8
-setuptools-lint
-coverage
-mock
-PyYAML
-click
-backports.functools_lru_cache
-pyOpenSSL
-yamllint
-tox
-detox
-pytest
-pytest-cov
diff --git a/utils/test/cli_installer_tests.py b/utils/test/cli_installer_tests.py
index 0cb37eaff..673997c42 100644
--- a/utils/test/cli_installer_tests.py
+++ b/utils/test/cli_installer_tests.py
@@ -409,8 +409,7 @@ class UnattendedCliTests(OOCliFixture):
result = self.runner.invoke(cli.cli, self.cli_args)
if result.exception is None or result.exit_code != 1:
- print("Exit code: %s" % result.exit_code)
- self.fail("Unexpected CLI return")
+ self.fail("Unexpected CLI return. Exit code: %s" % result.exit_code)
# unattended with config file and all installed hosts (with --force)
@patch('ooinstall.openshift_ansible.run_main_playbook')
@@ -600,97 +599,6 @@ class UnattendedCliTests(OOCliFixture):
self.assertEquals('openshift-enterprise',
inventory.get('OSEv3:vars', 'deployment_type'))
- # 2016-09-26 - tbielawa - COMMENTING OUT these tests FOR NOW while
- # we wait to see if anyone notices that we took away their ability
- # to set the ansible_config parameter in the command line options
- # and in the installer config file.
- #
- # We have removed the ability to set the ansible config file
- # manually so that our new quieter output mode is the default and
- # only output mode.
- #
- # RE: https://trello.com/c/DSwwizwP - atomic-openshift-install
- # should only output relevant information.
-
- # @patch('ooinstall.openshift_ansible.run_ansible')
- # @patch('ooinstall.openshift_ansible.load_system_facts')
- # def test_no_ansible_config_specified(self, load_facts_mock, run_ansible_mock):
- # load_facts_mock.return_value = (MOCK_FACTS, 0)
- # run_ansible_mock.return_value = 0
-
- # config = SAMPLE_CONFIG % 'openshift-enterprise'
-
- # self._ansible_config_test(load_facts_mock, run_ansible_mock,
- # config, None, None)
-
- # @patch('ooinstall.openshift_ansible.run_ansible')
- # @patch('ooinstall.openshift_ansible.load_system_facts')
- # def test_ansible_config_specified_cli(self, load_facts_mock, run_ansible_mock):
- # load_facts_mock.return_value = (MOCK_FACTS, 0)
- # run_ansible_mock.return_value = 0
-
- # config = SAMPLE_CONFIG % 'openshift-enterprise'
- # ansible_config = os.path.join(self.work_dir, 'ansible.cfg')
-
- # self._ansible_config_test(load_facts_mock, run_ansible_mock,
- # config, ansible_config, ansible_config)
-
- # @patch('ooinstall.openshift_ansible.run_ansible')
- # @patch('ooinstall.openshift_ansible.load_system_facts')
- # def test_ansible_config_specified_in_installer_config(self,
- # load_facts_mock, run_ansible_mock):
-
- # load_facts_mock.return_value = (MOCK_FACTS, 0)
- # run_ansible_mock.return_value = 0
-
- # ansible_config = os.path.join(self.work_dir, 'ansible.cfg')
- # config = SAMPLE_CONFIG % 'openshift-enterprise'
- # config = "%s\nansible_config: %s" % (config, ansible_config)
- # self._ansible_config_test(load_facts_mock, run_ansible_mock,
- # config, None, ansible_config)
-
- # #pylint: disable=too-many-arguments
- # # This method allows for drastically simpler tests to write, and the args
- # # are all useful.
- # def _ansible_config_test(self, load_facts_mock, run_ansible_mock,
- # installer_config, ansible_config_cli=None, expected_result=None):
- # """
- # Utility method for testing the ways you can specify the ansible config.
- # """
-
- # load_facts_mock.return_value = (MOCK_FACTS, 0)
- # run_ansible_mock.return_value = 0
-
- # config_file = self.write_config(os.path.join(self.work_dir,
- # 'ooinstall.conf'), installer_config)
-
- # self.cli_args.extend(["-c", config_file])
- # if ansible_config_cli:
- # self.cli_args.extend(["--ansible-config", ansible_config_cli])
- # self.cli_args.append("install")
- # result = self.runner.invoke(cli.cli, self.cli_args)
- # self.assert_result(result, 0)
-
- # # Test the env vars for facts playbook:
- # facts_env_vars = load_facts_mock.call_args[0][2]
- # if expected_result:
- # self.assertEquals(expected_result, facts_env_vars['ANSIBLE_CONFIG'])
- # else:
- # # If user running test has rpm installed, this might be set to default:
- # self.assertTrue('ANSIBLE_CONFIG' not in facts_env_vars or
- # facts_env_vars['ANSIBLE_CONFIG'] == cli.DEFAULT_ANSIBLE_CONFIG)
-
- # # Test the env vars for main playbook:
- # env_vars = run_ansible_mock.call_args[0][2]
- # if expected_result:
- # self.assertEquals(expected_result, env_vars['ANSIBLE_CONFIG'])
- # else:
- # # If user running test has rpm installed, this might be set to default:
- # #
- # # By default we will use the quiet config
- # self.assertTrue('ANSIBLE_CONFIG' not in env_vars or
- # env_vars['ANSIBLE_CONFIG'] == cli.QUIET_ANSIBLE_CONFIG)
-
# unattended with bad config file and no installed hosts (without --force)
@patch('ooinstall.openshift_ansible.run_main_playbook')
@patch('ooinstall.openshift_ansible.load_system_facts')
@@ -1011,13 +919,7 @@ class AttendedCliTests(OOCliFixture):
full_line = "%s=%s" % (a, b)
tokens = full_line.split()
if tokens[0] == host:
- found = False
- for token in tokens:
- if token == variable:
- found = True
- continue
- self.assertTrue("Unable to find %s in line: %s" %
- (variable, full_line), found)
+ self.assertTrue(variable in tokens[1:], "Unable to find %s in line: %s" % (variable, full_line))
return
self.fail("unable to find host %s in inventory" % host)
diff --git a/utils/test/fixture.py b/utils/test/fixture.py
index 5200d275d..873ac4a27 100644
--- a/utils/test/fixture.py
+++ b/utils/test/fixture.py
@@ -65,14 +65,13 @@ class OOCliFixture(OOInstallFixture):
def assert_result(self, result, exit_code):
if result.exit_code != exit_code:
- print("Unexpected result from CLI execution")
- print("Exit code: %s" % result.exit_code)
- print("Exception: %s" % result.exception)
- print(result.exc_info)
+ msg = ["Unexpected result from CLI execution\n"]
+ msg.append("Exit code: %s\n" % result.exit_code)
+ msg.append("Exception: %s\n" % result.exception)
import traceback
- traceback.print_exception(*result.exc_info)
- print("Output:\n%s" % result.output)
- self.fail("Exception during CLI execution")
+ msg.extend(traceback.format_exception(*result.exc_info))
+ msg.append("Output:\n%s" % result.output)
+ self.fail("".join(msg))
def _verify_load_facts(self, load_facts_mock):
""" Check that we ran load facts with expected inputs. """
diff --git a/utils/test/oo_config_tests.py b/utils/test/oo_config_tests.py
index 2b4fce512..5651e6e7a 100644
--- a/utils/test/oo_config_tests.py
+++ b/utils/test/oo_config_tests.py
@@ -266,42 +266,3 @@ class HostTests(OOInstallFixture):
self.assertIn(node_labels_expected, legacy_inventory_line)
# An unquoted version is not present
self.assertNotIn(node_labels_bad, legacy_inventory_line)
-
-
- # def test_new_write_inventory_same_as_legacy(self):
- # """Verify the original write_host function produces the same output as the new method"""
- # yaml_props = {
- # 'ip': '192.168.0.1',
- # 'hostname': 'a.example.com',
- # 'connect_to': 'a-private.example.com',
- # 'public_ip': '192.168.0.1',
- # 'public_hostname': 'a.example.com',
- # 'new_host': True,
- # 'roles': ['node'],
- # 'other_variables': {
- # 'zzz': 'last',
- # 'foo': 'bar',
- # 'aaa': 'first',
- # },
- # }
-
- # new_node = Host(**yaml_props)
- # inventory = cStringIO()
-
- # # This is what the original 'write_host' function will
- # # generate. write_host has no return value, it just writes
- # # directly to the file 'inventory' which in this test-case is
- # # a StringIO object
- # ooinstall.openshift_ansible.write_host(
- # new_node,
- # 'node',
- # inventory,
- # schedulable=True)
- # legacy_inventory_line = inventory.getvalue()
-
- # # This is what the new method in the Host class generates
- # new_inventory_line = new_node.inventory_string('node', schedulable=True)
-
- # self.assertEqual(
- # legacy_inventory_line,
- # new_inventory_line)
diff --git a/utils/test/openshift_ansible_tests.py b/utils/test/openshift_ansible_tests.py
index 5847fe37b..02a9754db 100644
--- a/utils/test/openshift_ansible_tests.py
+++ b/utils/test/openshift_ansible_tests.py
@@ -2,7 +2,6 @@ import os
import unittest
import tempfile
import shutil
-import yaml
from six.moves import configparser
@@ -40,17 +39,10 @@ class TestOpenShiftAnsible(unittest.TestCase):
def tearDown(self):
shutil.rmtree(self.work_dir)
- def generate_hosts(self, num_hosts, name_prefix, roles=None, new_host=False):
- hosts = []
- for num in range(1, num_hosts + 1):
- hosts.append(Host(connect_to=name_prefix + str(num),
- roles=roles, new_host=new_host))
- return hosts
-
def test_generate_inventory_new_nodes(self):
- hosts = self.generate_hosts(1, 'master', roles=(['master', 'etcd']))
- hosts.extend(self.generate_hosts(1, 'node', roles=['node']))
- hosts.extend(self.generate_hosts(1, 'new_node', roles=['node'], new_host=True))
+ hosts = generate_hosts(1, 'master', roles=(['master', 'etcd']))
+ hosts.extend(generate_hosts(1, 'node', roles=['node']))
+ hosts.extend(generate_hosts(1, 'new_node', roles=['node'], new_host=True))
openshift_ansible.generate_inventory(hosts)
inventory = configparser.ConfigParser(allow_no_value=True)
inventory.read(self.inventory)
@@ -59,8 +51,8 @@ class TestOpenShiftAnsible(unittest.TestCase):
def test_write_inventory_vars_role_vars(self):
with open(self.inventory, 'w') as inv:
- openshift_ansible.CFG.deployment.roles['master'].variables={'color': 'blue'}
- openshift_ansible.CFG.deployment.roles['node'].variables={'color': 'green'}
+ openshift_ansible.CFG.deployment.roles['master'].variables = {'color': 'blue'}
+ openshift_ansible.CFG.deployment.roles['node'].variables = {'color': 'green'}
openshift_ansible.write_inventory_vars(inv, None)
inventory = configparser.ConfigParser(allow_no_value=True)
@@ -69,3 +61,11 @@ class TestOpenShiftAnsible(unittest.TestCase):
self.assertEquals('blue', inventory.get('masters:vars', 'color'))
self.assertTrue(inventory.has_section('nodes:vars'))
self.assertEquals('green', inventory.get('nodes:vars', 'color'))
+
+
+def generate_hosts(num_hosts, name_prefix, roles=None, new_host=False):
+ hosts = []
+ for num in range(1, num_hosts + 1):
+ hosts.append(Host(connect_to=name_prefix + str(num),
+ roles=roles, new_host=new_host))
+ return hosts
diff --git a/utils/test/test_utils.py b/utils/test/test_utils.py
index cbce64f7e..cabeaee34 100644
--- a/utils/test/test_utils.py
+++ b/utils/test/test_utils.py
@@ -2,14 +2,14 @@
Unittests for ooinstall utils.
"""
-import six
import unittest
-import logging
-import sys
import copy
-from ooinstall.utils import debug_env, is_valid_hostname
import mock
+import six
+
+from ooinstall.utils import debug_env, is_valid_hostname
+
class TestUtils(unittest.TestCase):
"""
diff --git a/utils/tox.ini b/utils/tox.ini
deleted file mode 100644
index 2524923cb..000000000
--- a/utils/tox.ini
+++ /dev/null
@@ -1,19 +0,0 @@
-[tox]
-minversion=2.3.1
-envlist =
- py{27,35}-{flake8,unit,pylint}
-skipsdist=True
-skip_missing_interpreters=True
-
-[testenv]
-usedevelop=True
-deps =
- -rtest-requirements.txt
- py35-flake8: flake8-bugbear
-commands =
- # Needed to make detox work, since it ignores usedevelop
- # https://github.com/tox-dev/tox/issues/180
- unit: pip install -e .
- unit: pytest {posargs}
- flake8: python setup.py flake8
- pylint: python setup.py lint