summaryrefslogtreecommitdiffstats
path: root/utils/test
diff options
context:
space:
mode:
authorJason DeTiberus <jdetiber@redhat.com>2016-12-22 12:20:12 -0500
committerJason DeTiberus <jdetiber@redhat.com>2017-01-10 11:44:30 -0500
commit9d316d3091b28820e3840c535fc9bc4b6603ed72 (patch)
tree72134b1c99a84ead5966a770c1cf81e525598aa4 /utils/test
parent30a31899af8a553385c28956a1dbec071f249c55 (diff)
downloadopenshift-9d316d3091b28820e3840c535fc9bc4b6603ed72.tar.gz
openshift-9d316d3091b28820e3840c535fc9bc4b6603ed72.tar.bz2
openshift-9d316d3091b28820e3840c535fc9bc4b6603ed72.tar.xz
openshift-9d316d3091b28820e3840c535fc9bc4b6603ed72.zip
add test for utils to bump coverage
Diffstat (limited to 'utils/test')
-rw-r--r--utils/test/openshift_ansible_tests.py73
1 files changed, 73 insertions, 0 deletions
diff --git a/utils/test/openshift_ansible_tests.py b/utils/test/openshift_ansible_tests.py
new file mode 100644
index 000000000..21ac6aefe
--- /dev/null
+++ b/utils/test/openshift_ansible_tests.py
@@ -0,0 +1,73 @@
+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: root
+ 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):
+ print(yaml.dump(openshift_ansible.CFG.deployment.roles))
+ 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)
+ print(inventory.sections())
+ 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'))