From 34b53ca9d3276a609ecd8dd40e1c29bcb40ddcc2 Mon Sep 17 00:00:00 2001 From: Pierre Prinetti Date: Sun, 12 Mar 2023 17:39:56 +0100 Subject: [PATCH] openstack-manifests: Refactor --- hack/openstack/test-manifests.sh | 2 +- .../test_machines.py | 50 +++++++++++++++- .../test_machinesets.py | 59 ------------------- .../failure-domains/test_machines.py | 4 +- .../install-config.yaml | 0 .../test_cluster-infra.py | 2 +- .../install-config.yaml | 0 .../test_cluster-infra.py | 2 +- .../install-config.yaml | 0 .../test_cluster-infra.py | 4 +- .../install-config.yaml | 0 .../test_cluster-infra.py | 4 +- .../nova-availability-zones/test_machines.py | 51 ++++++++++++++-- .../test_machinesets.py | 57 ------------------ .../server-groups/test_machines.py | 22 ++++++- .../server-groups/test_machinesets.py | 35 ----------- 16 files changed, 123 insertions(+), 169 deletions(-) delete mode 100755 scripts/openstack/manifest-tests/cinder-availability-zones/test_machinesets.py rename scripts/openstack/manifest-tests/{default-stable-lb => lb-default-stable}/install-config.yaml (100%) rename scripts/openstack/manifest-tests/{default-stable-lb => lb-default-stable}/test_cluster-infra.py (91%) rename scripts/openstack/manifest-tests/{default-techpreview-lb => lb-default-techpreview}/install-config.yaml (100%) rename scripts/openstack/manifest-tests/{default-techpreview-lb => lb-default-techpreview}/test_cluster-infra.py (91%) rename scripts/openstack/manifest-tests/{openshift-managed-lb => lb-managed}/install-config.yaml (100%) rename scripts/openstack/manifest-tests/{openshift-managed-lb => lb-managed}/test_cluster-infra.py (91%) rename scripts/openstack/manifest-tests/{user-managed-lb => lb-unmanaged}/install-config.yaml (100%) rename scripts/openstack/manifest-tests/{user-managed-lb => lb-unmanaged}/test_cluster-infra.py (91%) delete mode 100755 scripts/openstack/manifest-tests/nova-availability-zones/test_machinesets.py delete mode 100755 scripts/openstack/manifest-tests/server-groups/test_machinesets.py diff --git a/hack/openstack/test-manifests.sh b/hack/openstack/test-manifests.sh index e35ec60879..5c2c821a4c 100755 --- a/hack/openstack/test-manifests.sh +++ b/hack/openstack/test-manifests.sh @@ -107,7 +107,7 @@ declare result='PASS' for testcase in "${tests_dir}"/* ; do if [ -d "$testcase" ] && [[ "$testcase" =~ $run ]]; then echo - echo "*** TEST CASE: $(basename "${testcase}")" + echo "*** TEST CASE: $(basename -- "$testcase")" assets_dir="$(mktemp -d)" if [[ "$persist" != 'NO' ]]; then echo "Generated assets for this test can be found in ${assets_dir}" diff --git a/scripts/openstack/manifest-tests/cinder-availability-zones/test_machines.py b/scripts/openstack/manifest-tests/cinder-availability-zones/test_machines.py index 8ac3defaa5..fa06ae6609 100755 --- a/scripts/openstack/manifest-tests/cinder-availability-zones/test_machines.py +++ b/scripts/openstack/manifest-tests/cinder-availability-zones/test_machines.py @@ -9,12 +9,16 @@ import yaml ASSETS_DIR = "" -EXPECTED_MACHINES_NUMBER = 10 +EXPECTED_MASTER_REPLICAS = 10 +EXPECTED_WORKER_REPLICAS = 1000 + EXPECTED_MASTER_ZONE_NAMES = ["MasterAZ1", "MasterAZ2", "MasterAZ3"] +EXPECTED_WORKER_ZONE_NAMES = ["ComputeAZ1", "ComputeAZ2", "ComputeAZ3"] + EXPECTED_VOLUME_ZONE_NAMES = ["VolumeAZ1", "VolumeAZ2", "VolumeAZ3"] -class TestVolumeAZMachines(unittest.TestCase): +class CinderAvailabilityZonesMachines(unittest.TestCase): def setUp(self): """Parse the Machines into a Python data structure.""" self.machines = [] @@ -35,7 +39,7 @@ class TestVolumeAZMachines(unittest.TestCase): def test_total_instance_number(self): """Assert that there are as many Machines as required ControlPlane replicas.""" - self.assertEqual(len(self.machines), EXPECTED_MACHINES_NUMBER) + self.assertEqual(len(self.machines), EXPECTED_MASTER_REPLICAS) def test_replica_distribution(self): """Assert that machines are evenly distributed across volume azs.""" @@ -52,6 +56,46 @@ class TestVolumeAZMachines(unittest.TestCase): self.assertTrue(-2 < replicas - setpoint < 2) +class CinderAvailabilityZonesMachinesets(unittest.TestCase): + def setUp(self): + """Parse the MachineSets into a Python data structure.""" + self.machinesets = [] + for machineset_path in glob.glob( + f'{ASSETS_DIR}/openshift/99_openshift-cluster-api_worker-machineset-*.yaml' + ): + with open(machineset_path) as f: + self.machinesets.append(yaml.load(f, Loader=yaml.FullLoader)) + + def test_machineset_zone_name(self): + """Assert that there is exactly one MachineSet per volume availability zone.""" + found = [] + for machineset in self.machinesets: + master_zone = machineset["spec"]["template"]["spec"]["providerSpec"]["value"]["availabilityZone"] + volume_zone = machineset["spec"]["template"]["spec"]["providerSpec"]["value"]["rootVolume"]["availabilityZone"] + self.assertIn(volume_zone, EXPECTED_VOLUME_ZONE_NAMES) + self.assertNotIn(volume_zone, found) + self.assertEqual(master_zone[-3:], volume_zone[-3:]) + found.append(volume_zone) + self.assertEqual(len(self.machinesets), len(EXPECTED_VOLUME_ZONE_NAMES)) + + def test_total_replica_number(self): + """Assert that replicas spread across the MachineSets add up to the expected number.""" + total_found = 0 + for machineset in self.machinesets: + total_found += machineset["spec"]["replicas"] + self.assertEqual(total_found, EXPECTED_WORKER_REPLICAS) + + def test_replica_distribution(self): + """Assert that replicas are evenly distributed across machinesets.""" + setpoint = 0 + for machineset in self.machinesets: + replicas = machineset["spec"]["replicas"] + if setpoint == 0: + setpoint = replicas + else: + self.assertTrue(-2 < replicas - setpoint < 2) + + if __name__ == '__main__': ASSETS_DIR = sys.argv.pop() unittest.main(verbosity=2) diff --git a/scripts/openstack/manifest-tests/cinder-availability-zones/test_machinesets.py b/scripts/openstack/manifest-tests/cinder-availability-zones/test_machinesets.py deleted file mode 100755 index d2f63f95f0..0000000000 --- a/scripts/openstack/manifest-tests/cinder-availability-zones/test_machinesets.py +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import unittest - -import sys -import glob -import yaml - -ASSETS_DIR = "" - -EXPECTED_MACHINES_NUMBER = 1000 -EXPECTED_COMPUTE_ZONE_NAMES = ["ComputeAZ1", "ComputeAZ2", "ComputeAZ3"] -EXPECTED_VOLUME_ZONE_NAMES = ["VolumeAZ1", "VolumeAZ2", "VolumeAZ3"] - - -class TestVolumeAZMachinesets(unittest.TestCase): - def setUp(self): - """Parse the MachineSets into a Python data structure.""" - self.machinesets = [] - for machineset_path in glob.glob( - f'{ASSETS_DIR}/openshift/99_openshift-cluster-api_worker-machineset-*.yaml' - ): - with open(machineset_path) as f: - self.machinesets.append(yaml.load(f, Loader=yaml.FullLoader)) - - def test_machineset_zone_name(self): - """Assert that there is exactly one MachineSet per volume availability zone.""" - found = [] - for machineset in self.machinesets: - master_zone = machineset["spec"]["template"]["spec"]["providerSpec"]["value"]["availabilityZone"] - volume_zone = machineset["spec"]["template"]["spec"]["providerSpec"]["value"]["rootVolume"]["availabilityZone"] - self.assertIn(volume_zone, EXPECTED_VOLUME_ZONE_NAMES) - self.assertNotIn(volume_zone, found) - self.assertEqual(master_zone[-3:], volume_zone[-3:]) - found.append(volume_zone) - self.assertEqual(len(self.machinesets), len(EXPECTED_VOLUME_ZONE_NAMES)) - - def test_total_replica_number(self): - """Assert that replicas spread across the MachineSets add up to the expected number.""" - total_found = 0 - for machineset in self.machinesets: - total_found += machineset["spec"]["replicas"] - self.assertEqual(total_found, EXPECTED_MACHINES_NUMBER) - - def test_replica_distribution(self): - """Assert that replicas are evenly distributed across machinesets.""" - setpoint = 0 - for machineset in self.machinesets: - replicas = machineset["spec"]["replicas"] - if setpoint == 0: - setpoint = replicas - else: - self.assertTrue(-2 < replicas - setpoint < 2) - - -if __name__ == '__main__': - ASSETS_DIR = sys.argv.pop() - unittest.main(verbosity=2) diff --git a/scripts/openstack/manifest-tests/failure-domains/test_machines.py b/scripts/openstack/manifest-tests/failure-domains/test_machines.py index 72f5bd6247..f6b7ca237a 100755 --- a/scripts/openstack/manifest-tests/failure-domains/test_machines.py +++ b/scripts/openstack/manifest-tests/failure-domains/test_machines.py @@ -9,10 +9,10 @@ import glob import yaml ASSETS_DIR = "" -INSTALLCONFIG_PATH = "" +INSTALLCONFIG_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'install-config.yaml') -class TestMachines(unittest.TestCase): +class FailureDomainsMachines(unittest.TestCase): def setUp(self): """Parse the expected values from install-config and collect Machine resources.""" self.machines = [] diff --git a/scripts/openstack/manifest-tests/default-stable-lb/install-config.yaml b/scripts/openstack/manifest-tests/lb-default-stable/install-config.yaml similarity index 100% rename from scripts/openstack/manifest-tests/default-stable-lb/install-config.yaml rename to scripts/openstack/manifest-tests/lb-default-stable/install-config.yaml diff --git a/scripts/openstack/manifest-tests/default-stable-lb/test_cluster-infra.py b/scripts/openstack/manifest-tests/lb-default-stable/test_cluster-infra.py similarity index 91% rename from scripts/openstack/manifest-tests/default-stable-lb/test_cluster-infra.py rename to scripts/openstack/manifest-tests/lb-default-stable/test_cluster-infra.py index 147254663b..fa168f35b7 100755 --- a/scripts/openstack/manifest-tests/default-stable-lb/test_cluster-infra.py +++ b/scripts/openstack/manifest-tests/lb-default-stable/test_cluster-infra.py @@ -9,7 +9,7 @@ import yaml ASSETS_DIR = "" -class TestClusterInfraObject(unittest.TestCase): +class DefaultStableLoadBalancerClusterInfraObject(unittest.TestCase): def setUp(self): """Parse the Cluster Infrastructure object into a Python data structure.""" self.machines = [] diff --git a/scripts/openstack/manifest-tests/default-techpreview-lb/install-config.yaml b/scripts/openstack/manifest-tests/lb-default-techpreview/install-config.yaml similarity index 100% rename from scripts/openstack/manifest-tests/default-techpreview-lb/install-config.yaml rename to scripts/openstack/manifest-tests/lb-default-techpreview/install-config.yaml diff --git a/scripts/openstack/manifest-tests/default-techpreview-lb/test_cluster-infra.py b/scripts/openstack/manifest-tests/lb-default-techpreview/test_cluster-infra.py similarity index 91% rename from scripts/openstack/manifest-tests/default-techpreview-lb/test_cluster-infra.py rename to scripts/openstack/manifest-tests/lb-default-techpreview/test_cluster-infra.py index 147254663b..e924bc78c4 100755 --- a/scripts/openstack/manifest-tests/default-techpreview-lb/test_cluster-infra.py +++ b/scripts/openstack/manifest-tests/lb-default-techpreview/test_cluster-infra.py @@ -9,7 +9,7 @@ import yaml ASSETS_DIR = "" -class TestClusterInfraObject(unittest.TestCase): +class DefaultTechPreviewLoadBalancerClusterInfraObject(unittest.TestCase): def setUp(self): """Parse the Cluster Infrastructure object into a Python data structure.""" self.machines = [] diff --git a/scripts/openstack/manifest-tests/openshift-managed-lb/install-config.yaml b/scripts/openstack/manifest-tests/lb-managed/install-config.yaml similarity index 100% rename from scripts/openstack/manifest-tests/openshift-managed-lb/install-config.yaml rename to scripts/openstack/manifest-tests/lb-managed/install-config.yaml diff --git a/scripts/openstack/manifest-tests/openshift-managed-lb/test_cluster-infra.py b/scripts/openstack/manifest-tests/lb-managed/test_cluster-infra.py similarity index 91% rename from scripts/openstack/manifest-tests/openshift-managed-lb/test_cluster-infra.py rename to scripts/openstack/manifest-tests/lb-managed/test_cluster-infra.py index f337450542..981114a89b 100755 --- a/scripts/openstack/manifest-tests/openshift-managed-lb/test_cluster-infra.py +++ b/scripts/openstack/manifest-tests/lb-managed/test_cluster-infra.py @@ -9,7 +9,7 @@ import yaml ASSETS_DIR = "" -class TestClusterInfraObject(unittest.TestCase): +class ManagedLoadBalancer(unittest.TestCase): def setUp(self): """Parse the Cluster Infrastructure object into a Python data structure.""" self.machines = [] @@ -17,7 +17,7 @@ class TestClusterInfraObject(unittest.TestCase): with open(cluster_infra) as f: self.cluster_infra = yaml.load(f, Loader=yaml.FullLoader) - def test_load_balancer(self): + def test_cluster_infra_object(self): """Assert that the Cluster infrastructure object contains the LoadBalancer configuration.""" self.assertIn("loadBalancer", self.cluster_infra["status"]["platformStatus"]["openstack"]) diff --git a/scripts/openstack/manifest-tests/user-managed-lb/install-config.yaml b/scripts/openstack/manifest-tests/lb-unmanaged/install-config.yaml similarity index 100% rename from scripts/openstack/manifest-tests/user-managed-lb/install-config.yaml rename to scripts/openstack/manifest-tests/lb-unmanaged/install-config.yaml diff --git a/scripts/openstack/manifest-tests/user-managed-lb/test_cluster-infra.py b/scripts/openstack/manifest-tests/lb-unmanaged/test_cluster-infra.py similarity index 91% rename from scripts/openstack/manifest-tests/user-managed-lb/test_cluster-infra.py rename to scripts/openstack/manifest-tests/lb-unmanaged/test_cluster-infra.py index 56db471a38..e6635f896b 100755 --- a/scripts/openstack/manifest-tests/user-managed-lb/test_cluster-infra.py +++ b/scripts/openstack/manifest-tests/lb-unmanaged/test_cluster-infra.py @@ -9,7 +9,7 @@ import yaml ASSETS_DIR = "" -class TestClusterInfraObject(unittest.TestCase): +class UnmanagedLoadBalancer(unittest.TestCase): def setUp(self): """Parse the Cluster Infrastructure object into a Python data structure.""" self.machines = [] @@ -17,7 +17,7 @@ class TestClusterInfraObject(unittest.TestCase): with open(cluster_infra) as f: self.cluster_infra = yaml.load(f, Loader=yaml.FullLoader) - def test_load_balancer(self): + def test_cluster_infra_object(self): """Assert that the Cluster infrastructure object contains the LoadBalancer configuration.""" self.assertIn("loadBalancer", self.cluster_infra["status"]["platformStatus"]["openstack"]) diff --git a/scripts/openstack/manifest-tests/nova-availability-zones/test_machines.py b/scripts/openstack/manifest-tests/nova-availability-zones/test_machines.py index e683716044..b90982e397 100755 --- a/scripts/openstack/manifest-tests/nova-availability-zones/test_machines.py +++ b/scripts/openstack/manifest-tests/nova-availability-zones/test_machines.py @@ -9,11 +9,13 @@ import yaml ASSETS_DIR = "" -EXPECTED_MACHINES_NUMBER = 10 -EXPECTED_ZONE_NAMES = ["masterzone", "masterztwo", "masterzthree"] +EXPECTED_MASTER_REPLICAS = 10 +EXPECTED_MASTER_ZONE_NAMES = ["masterzone", "masterztwo", "masterzthree"] +EXPECTED_WORKER_REPLICAS = 1000 +EXPECTED_WORKER_ZONE_NAMES = ["zone", "ztwo", "zthree"] -class TestAZMachines(unittest.TestCase): +class NovaAvailabilityZonesMachines(unittest.TestCase): def setUp(self): """Parse the Machines into a Python data structure.""" self.machines = [] @@ -27,11 +29,11 @@ class TestAZMachines(unittest.TestCase): """Assert that all machines have one valid availability zone.""" for machine in self.machines: zone = machine["spec"]["providerSpec"]["value"]["availabilityZone"] - self.assertIn(zone, EXPECTED_ZONE_NAMES) + self.assertIn(zone, EXPECTED_MASTER_ZONE_NAMES) def test_total_instance_number(self): """Assert that there are as many Machines as required ControlPlane replicas.""" - self.assertEqual(len(self.machines), EXPECTED_MACHINES_NUMBER) + self.assertEqual(len(self.machines), EXPECTED_MASTER_REPLICAS) def test_replica_distribution(self): """Assert that machines are evenly distributed across zones.""" @@ -48,6 +50,45 @@ class TestAZMachines(unittest.TestCase): self.assertTrue(-2 < replicas - setpoint < 2) +class NovaAvailabilityZonesMachinesets(unittest.TestCase): + def setUp(self): + """Parse the MachineSets into a Python data structure.""" + self.machinesets = [] + for machineset_path in glob.glob( + f'{ASSETS_DIR}/openshift/99_openshift-cluster-api_worker-machineset-*.yaml' + ): + with open(machineset_path) as f: + self.machinesets.append(yaml.load(f, Loader=yaml.FullLoader)) + + def test_machineset_zone_name(self): + """Assert that there is exactly one MachineSet per availability zone.""" + found = [] + for machineset in self.machinesets: + zone = machineset["spec"]["template"]["spec"]["providerSpec"][ + "value"]["availabilityZone"] + self.assertIn(zone, EXPECTED_WORKER_ZONE_NAMES) + self.assertNotIn(zone, found) + found.append(zone) + self.assertEqual(len(self.machinesets), len(EXPECTED_WORKER_ZONE_NAMES)) + + def test_total_replica_number(self): + """Assert that replicas spread across the MachineSets add up to the expected number.""" + total_found = 0 + for machineset in self.machinesets: + total_found += machineset["spec"]["replicas"] + self.assertEqual(total_found, EXPECTED_WORKER_REPLICAS) + + def test_replica_distribution(self): + """Assert that replicas are evenly distributed across machinesets.""" + setpoint = 0 + for machineset in self.machinesets: + replicas = machineset["spec"]["replicas"] + if setpoint == 0: + setpoint = replicas + else: + self.assertTrue(-2 < replicas - setpoint < 2) + + if __name__ == '__main__': ASSETS_DIR = sys.argv.pop() unittest.main(verbosity=2) diff --git a/scripts/openstack/manifest-tests/nova-availability-zones/test_machinesets.py b/scripts/openstack/manifest-tests/nova-availability-zones/test_machinesets.py deleted file mode 100755 index fede338c18..0000000000 --- a/scripts/openstack/manifest-tests/nova-availability-zones/test_machinesets.py +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import unittest - -import sys -import glob -import yaml - -ASSETS_DIR = "" - -EXPECTED_MACHINES_NUMBER = 1000 -EXPECTED_ZONE_NAMES = ["zone", "ztwo", "zthree"] - - -class TestAZMachinesets(unittest.TestCase): - def setUp(self): - """Parse the MachineSets into a Python data structure.""" - self.machinesets = [] - for machineset_path in glob.glob( - f'{ASSETS_DIR}/openshift/99_openshift-cluster-api_worker-machineset-*.yaml' - ): - with open(machineset_path) as f: - self.machinesets.append(yaml.load(f, Loader=yaml.FullLoader)) - - def test_machineset_zone_name(self): - """Assert that there is exactly one MachineSet per availability zone.""" - found = [] - for machineset in self.machinesets: - zone = machineset["spec"]["template"]["spec"]["providerSpec"][ - "value"]["availabilityZone"] - self.assertIn(zone, EXPECTED_ZONE_NAMES) - self.assertNotIn(zone, found) - found.append(zone) - self.assertEqual(len(self.machinesets), len(EXPECTED_ZONE_NAMES)) - - def test_total_replica_number(self): - """Assert that replicas spread across the MachineSets add up to the expected number.""" - total_found = 0 - for machineset in self.machinesets: - total_found += machineset["spec"]["replicas"] - self.assertEqual(total_found, EXPECTED_MACHINES_NUMBER) - - def test_replica_distribution(self): - """Assert that replicas are evenly distributed across machinesets.""" - setpoint = 0 - for machineset in self.machinesets: - replicas = machineset["spec"]["replicas"] - if setpoint == 0: - setpoint = replicas - else: - self.assertTrue(-2 < replicas - setpoint < 2) - - -if __name__ == '__main__': - ASSETS_DIR = sys.argv.pop() - unittest.main(verbosity=2) diff --git a/scripts/openstack/manifest-tests/server-groups/test_machines.py b/scripts/openstack/manifest-tests/server-groups/test_machines.py index c420351bb9..266ee4ddca 100755 --- a/scripts/openstack/manifest-tests/server-groups/test_machines.py +++ b/scripts/openstack/manifest-tests/server-groups/test_machines.py @@ -10,7 +10,7 @@ import yaml ASSETS_DIR = "" -class TestMachinesServerGroup(unittest.TestCase): +class ServerGroupMachines(unittest.TestCase): def setUp(self): """Parse the Machines into a Python data structure.""" self.machines = [] @@ -31,6 +31,26 @@ class TestMachinesServerGroup(unittest.TestCase): self.assertEqual(name, group_name) +class ServerGroupMachinesets(unittest.TestCase): + def setUp(self): + """Parse the MachineSets into a Python data structure.""" + self.machinesets = [] + for machineset_path in glob.glob( + f'{ASSETS_DIR}/openshift/99_openshift-cluster-api_worker-machineset-*.yaml' + ): + with open(machineset_path) as f: + self.machinesets.append(yaml.load(f, Loader=yaml.FullLoader)) + + def test_consistent_group_names(self): + """Assert that server group names are unique across machinesets.""" + found = [] + for machineset in self.machinesets: + name = machineset["spec"]["template"]["spec"]["providerSpec"][ + "value"]["serverGroupName"] + self.assertNotIn(name, found) + found.append(name) + + if __name__ == '__main__': ASSETS_DIR = sys.argv.pop() unittest.main(verbosity=2) diff --git a/scripts/openstack/manifest-tests/server-groups/test_machinesets.py b/scripts/openstack/manifest-tests/server-groups/test_machinesets.py deleted file mode 100755 index e174345475..0000000000 --- a/scripts/openstack/manifest-tests/server-groups/test_machinesets.py +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import unittest - -import sys -import glob -import yaml - -ASSETS_DIR = "" - - -class TestMachinesetsServerGroup(unittest.TestCase): - def setUp(self): - """Parse the MachineSets into a Python data structure.""" - self.machinesets = [] - for machineset_path in glob.glob( - f'{ASSETS_DIR}/openshift/99_openshift-cluster-api_worker-machineset-*.yaml' - ): - with open(machineset_path) as f: - self.machinesets.append(yaml.load(f, Loader=yaml.FullLoader)) - - def test_consistent_group_names(self): - """Assert that server group names are unique across machinesets.""" - found = [] - for machineset in self.machinesets: - name = machineset["spec"]["template"]["spec"]["providerSpec"][ - "value"]["serverGroupName"] - self.assertNotIn(name, found) - found.append(name) - - -if __name__ == '__main__': - ASSETS_DIR = sys.argv.pop() - unittest.main(verbosity=2)