github.com/openshift/installer@v1.4.17/scripts/openstack/manifest-tests/zero-workers/test_machines.py (about) 1 #!/usr/bin/env python 2 # -*- coding: utf-8 -*- 3 4 import unittest 5 import xmlrunner 6 7 import os 8 import sys 9 import glob 10 import yaml 11 12 ASSETS_DIR = "" 13 14 EXPECTED_MASTER_REPLICAS = 3 15 EXPECTED_WORKER_REPLICAS = 0 16 17 18 class Machines(unittest.TestCase): 19 def setUp(self): 20 """Parse the Machines into a Python data structure.""" 21 self.machines = [] 22 for machine_path in glob.glob( 23 f'{ASSETS_DIR}/openshift/99_openshift-cluster-api_master-machines-*.yaml' 24 ): 25 with open(machine_path) as f: 26 self.machines.append(yaml.load(f, Loader=yaml.FullLoader)) 27 28 def test_total_instance_number(self): 29 """Assert that there are as many Machines as required ControlPlane replicas.""" 30 self.assertEqual(len(self.machines), EXPECTED_MASTER_REPLICAS) 31 32 33 class Machinesets(unittest.TestCase): 34 def setUp(self): 35 """Parse the MachineSets into a Python data structure.""" 36 self.machinesets = [] 37 for machineset_path in glob.glob( 38 f'{ASSETS_DIR}/openshift/99_openshift-cluster-api_worker-machineset-*.yaml' 39 ): 40 with open(machineset_path) as f: 41 self.machinesets.append(yaml.load(f, Loader=yaml.FullLoader)) 42 43 def test_total_replica_number(self): 44 """Assert that there is at least one MachineSet.""" 45 self.assertGreater(len(self.machinesets), 0) 46 47 def test_total_replica_number(self): 48 """Assert that replicas spread across the MachineSets add up to the expected number.""" 49 total_found = 0 50 for machineset in self.machinesets: 51 total_found += machineset["spec"]["replicas"] 52 self.assertEqual(total_found, EXPECTED_WORKER_REPLICAS) 53 54 55 if __name__ == '__main__': 56 ASSETS_DIR = sys.argv.pop() 57 with open(os.environ.get('JUNIT_FILE', '/dev/null'), 'wb') as output: 58 unittest.main(testRunner=xmlrunner.XMLTestRunner(output=output), failfast=False, buffer=False, catchbreak=False, verbosity=2)