summaryrefslogtreecommitdiffstats
path: root/utils/test
diff options
context:
space:
mode:
Diffstat (limited to 'utils/test')
-rw-r--r--utils/test/cli_installer_tests.py21
-rw-r--r--utils/test/fixture.py10
-rw-r--r--utils/test/oo_config_tests.py7
-rw-r--r--utils/test/openshift_ansible_tests.py71
-rw-r--r--utils/test/test_utils.py11
5 files changed, 96 insertions, 24 deletions
diff --git a/utils/test/cli_installer_tests.py b/utils/test/cli_installer_tests.py
index 36dc18034..0cb37eaff 100644
--- a/utils/test/cli_installer_tests.py
+++ b/utils/test/cli_installer_tests.py
@@ -4,7 +4,8 @@
import copy
import os
-import ConfigParser
+
+from six.moves import configparser
import ooinstall.cli_installer as cli
@@ -408,7 +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
+ print("Exit code: %s" % result.exit_code)
self.fail("Unexpected CLI return")
# unattended with config file and all installed hosts (with --force)
@@ -523,7 +524,7 @@ class UnattendedCliTests(OOCliFixture):
self.assert_result(result, 0)
# Check the inventory file looks as we would expect:
- inventory = ConfigParser.ConfigParser(allow_no_value=True)
+ inventory = configparser.ConfigParser(allow_no_value=True)
inventory.read(os.path.join(self.work_dir, 'hosts'))
self.assertEquals('root',
inventory.get('OSEv3:vars', 'ansible_ssh_user'))
@@ -566,7 +567,7 @@ class UnattendedCliTests(OOCliFixture):
self.assertEquals('3.3', written_config['variant_version'])
# Make sure the correct value was passed to ansible:
- inventory = ConfigParser.ConfigParser(allow_no_value=True)
+ inventory = configparser.ConfigParser(allow_no_value=True)
inventory.read(os.path.join(self.work_dir, 'hosts'))
self.assertEquals('openshift-enterprise',
inventory.get('OSEv3:vars', 'deployment_type'))
@@ -594,7 +595,7 @@ class UnattendedCliTests(OOCliFixture):
# and written to disk:
self.assertEquals('3.3', written_config['variant_version'])
- inventory = ConfigParser.ConfigParser(allow_no_value=True)
+ inventory = configparser.ConfigParser(allow_no_value=True)
inventory.read(os.path.join(self.work_dir, 'hosts'))
self.assertEquals('openshift-enterprise',
inventory.get('OSEv3:vars', 'deployment_type'))
@@ -830,7 +831,7 @@ class AttendedCliTests(OOCliFixture):
written_config = read_yaml(self.config_file)
self._verify_config_hosts(written_config, 4)
- inventory = ConfigParser.ConfigParser(allow_no_value=True)
+ inventory = configparser.ConfigParser(allow_no_value=True)
inventory.read(os.path.join(self.work_dir, 'hosts'))
self.assert_inventory_host_var(inventory, 'nodes', '10.0.0.1',
'openshift_schedulable=False')
@@ -949,7 +950,7 @@ class AttendedCliTests(OOCliFixture):
written_config = read_yaml(self.config_file)
self._verify_config_hosts(written_config, 6)
- inventory = ConfigParser.ConfigParser(allow_no_value=True)
+ inventory = configparser.ConfigParser(allow_no_value=True)
inventory.read(os.path.join(self.work_dir, 'hosts'))
self.assert_inventory_host_var(inventory, 'nodes', '10.0.0.1',
'openshift_schedulable=False')
@@ -990,7 +991,7 @@ class AttendedCliTests(OOCliFixture):
written_config = read_yaml(self.config_file)
self._verify_config_hosts(written_config, 5)
- inventory = ConfigParser.ConfigParser(allow_no_value=True)
+ inventory = configparser.ConfigParser(allow_no_value=True)
inventory.read(os.path.join(self.work_dir, 'hosts'))
self.assert_inventory_host_var(inventory, 'nodes', '10.0.0.1',
'openshift_schedulable=True')
@@ -1082,7 +1083,7 @@ class AttendedCliTests(OOCliFixture):
written_config = read_yaml(self.config_file)
self._verify_config_hosts(written_config, 1)
- inventory = ConfigParser.ConfigParser(allow_no_value=True)
+ inventory = configparser.ConfigParser(allow_no_value=True)
inventory.read(os.path.join(self.work_dir, 'hosts'))
self.assert_inventory_host_var(inventory, 'nodes', '10.0.0.1',
'openshift_schedulable=True')
@@ -1116,7 +1117,7 @@ class AttendedCliTests(OOCliFixture):
written_config = read_yaml(self.config_file)
self._verify_config_hosts(written_config, 4)
- inventory = ConfigParser.ConfigParser(allow_no_value=True)
+ inventory = configparser.ConfigParser(allow_no_value=True)
inventory.read(os.path.join(self.work_dir, 'hosts'))
self.assert_inventory_host_var(inventory, 'nodes', '10.0.0.1',
'openshift_schedulable=False')
diff --git a/utils/test/fixture.py b/utils/test/fixture.py
index 62135c761..5200d275d 100644
--- a/utils/test/fixture.py
+++ b/utils/test/fixture.py
@@ -65,13 +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
+ print("Unexpected result from CLI execution")
+ print("Exit code: %s" % result.exit_code)
+ print("Exception: %s" % result.exception)
+ print(result.exc_info)
import traceback
traceback.print_exception(*result.exc_info)
- print "Output:\n%s" % result.output
+ print("Output:\n%s" % result.output)
self.fail("Exception during CLI execution")
def _verify_load_facts(self, load_facts_mock):
diff --git a/utils/test/oo_config_tests.py b/utils/test/oo_config_tests.py
index 56fd82408..2b4fce512 100644
--- a/utils/test/oo_config_tests.py
+++ b/utils/test/oo_config_tests.py
@@ -2,13 +2,14 @@
# repo. We will work on these over time.
# pylint: disable=bad-continuation,missing-docstring,no-self-use,invalid-name
-import cStringIO
import os
import unittest
import tempfile
import shutil
import yaml
+from six.moves import cStringIO
+
from ooinstall.oo_config import OOConfig, Host, OOConfigInvalidHostError
import ooinstall.openshift_ansible
@@ -244,7 +245,7 @@ class HostTests(OOInstallFixture):
}
new_node = Host(**yaml_props)
- inventory = cStringIO.StringIO()
+ inventory = cStringIO()
# This is what the 'write_host' function generates. write_host
# has no return value, it just writes directly to the file
# 'inventory' which in this test-case is a StringIO object
@@ -285,7 +286,7 @@ class HostTests(OOInstallFixture):
# }
# new_node = Host(**yaml_props)
- # inventory = cStringIO.StringIO()
+ # inventory = cStringIO()
# # This is what the original 'write_host' function will
# # generate. write_host has no return value, it just writes
diff --git a/utils/test/openshift_ansible_tests.py b/utils/test/openshift_ansible_tests.py
new file mode 100644
index 000000000..5847fe37b
--- /dev/null
+++ b/utils/test/openshift_ansible_tests.py
@@ -0,0 +1,71 @@
+import os
+import unittest
+import tempfile
+import shutil
+import yaml
+
+from six.moves import configparser
+
+from ooinstall import openshift_ansible
+from ooinstall.oo_config import Host, OOConfig
+
+
+BASE_CONFIG = """
+---
+variant: openshift-enterprise
+variant_version: 3.3
+version: v2
+deployment:
+ ansible_ssh_user: cloud-user
+ hosts: []
+ roles:
+ master:
+ node:
+"""
+
+
+class TestOpenShiftAnsible(unittest.TestCase):
+
+ def setUp(self):
+ self.tempfiles = []
+ self.work_dir = tempfile.mkdtemp(prefix='openshift_ansible_tests')
+ self.configfile = os.path.join(self.work_dir, 'ooinstall.config')
+ with open(self.configfile, 'w') as config_file:
+ config_file.write(BASE_CONFIG)
+ self.inventory = os.path.join(self.work_dir, 'hosts')
+ config = OOConfig(self.configfile)
+ config.settings['ansible_inventory_path'] = self.inventory
+ openshift_ansible.set_config(config)
+
+ 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))
+ openshift_ansible.generate_inventory(hosts)
+ inventory = configparser.ConfigParser(allow_no_value=True)
+ inventory.read(self.inventory)
+ self.assertTrue(inventory.has_section('new_nodes'))
+ self.assertTrue(inventory.has_option('new_nodes', 'new_node1'))
+
+ 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.write_inventory_vars(inv, None)
+
+ inventory = configparser.ConfigParser(allow_no_value=True)
+ inventory.read(self.inventory)
+ self.assertTrue(inventory.has_section('masters:vars'))
+ self.assertEquals('blue', inventory.get('masters:vars', 'color'))
+ self.assertTrue(inventory.has_section('nodes:vars'))
+ self.assertEquals('green', inventory.get('nodes:vars', 'color'))
diff --git a/utils/test/test_utils.py b/utils/test/test_utils.py
index 2e59d86f2..cbce64f7e 100644
--- a/utils/test/test_utils.py
+++ b/utils/test/test_utils.py
@@ -2,6 +2,7 @@
Unittests for ooinstall utils.
"""
+import six
import unittest
import logging
import sys
@@ -28,9 +29,6 @@ class TestUtils(unittest.TestCase):
mock.call('OO_FOO: bar'),
]
- # python 2.x has assertItemsEqual, python 3.x has assertCountEqual
- if sys.version_info.major > 3:
- self.assertItemsEqual = self.assertCountEqual
######################################################################
# Validate ooinstall.utils.debug_env functionality
@@ -40,7 +38,6 @@ class TestUtils(unittest.TestCase):
with mock.patch('ooinstall.utils.installer_log') as _il:
debug_env(self.debug_all_params)
- print _il.debug.call_args_list
# Debug was called for each item we expect
self.assertEqual(
@@ -48,7 +45,8 @@ class TestUtils(unittest.TestCase):
_il.debug.call_count)
# Each item we expect was logged
- self.assertItemsEqual(
+ six.assertCountEqual(
+ self,
self.expected,
_il.debug.call_args_list)
@@ -67,7 +65,8 @@ class TestUtils(unittest.TestCase):
_il.debug.call_count,
len(debug_some_params))
- self.assertItemsEqual(
+ six.assertCountEqual(
+ self,
self.expected,
_il.debug.call_args_list)