summaryrefslogtreecommitdiffstats
path: root/utils/test
diff options
context:
space:
mode:
authorScott Dodson <sdodson@redhat.com>2017-01-10 16:27:29 -0500
committerGitHub <noreply@github.com>2017-01-10 16:27:29 -0500
commit393eccd3a5347a13eda5d627f3cc35aeeb42f1cc (patch)
tree668806139fc108ce6763cc95a640aedffa8a4ecf /utils/test
parent706c582b2482d5cc3a4fb28b348ce5b856fc9c26 (diff)
parent33da32dbcdc5e93e26bccf59d0781a60386b6b04 (diff)
downloadopenshift-393eccd3a5347a13eda5d627f3cc35aeeb42f1cc.tar.gz
openshift-393eccd3a5347a13eda5d627f3cc35aeeb42f1cc.tar.bz2
openshift-393eccd3a5347a13eda5d627f3cc35aeeb42f1cc.tar.xz
openshift-393eccd3a5347a13eda5d627f3cc35aeeb42f1cc.zip
Merge pull request #3007 from detiber/toxification
More Toxification
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..f6fa1b916
--- /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: 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):
+ 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'))