Skip to content

Commit 34b53ca

Browse files
openstack-manifests: Refactor
1 parent 1fe95cf commit 34b53ca

File tree

16 files changed

+123
-169
lines changed

16 files changed

+123
-169
lines changed

hack/openstack/test-manifests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ declare result='PASS'
107107
for testcase in "${tests_dir}"/* ; do
108108
if [ -d "$testcase" ] && [[ "$testcase" =~ $run ]]; then
109109
echo
110-
echo "*** TEST CASE: $(basename "${testcase}")"
110+
echo "*** TEST CASE: $(basename -- "$testcase")"
111111
assets_dir="$(mktemp -d)"
112112
if [[ "$persist" != 'NO' ]]; then
113113
echo "Generated assets for this test can be found in ${assets_dir}"

scripts/openstack/manifest-tests/cinder-availability-zones/test_machines.py

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@
99

1010
ASSETS_DIR = ""
1111

12-
EXPECTED_MACHINES_NUMBER = 10
12+
EXPECTED_MASTER_REPLICAS = 10
13+
EXPECTED_WORKER_REPLICAS = 1000
14+
1315
EXPECTED_MASTER_ZONE_NAMES = ["MasterAZ1", "MasterAZ2", "MasterAZ3"]
16+
EXPECTED_WORKER_ZONE_NAMES = ["ComputeAZ1", "ComputeAZ2", "ComputeAZ3"]
17+
1418
EXPECTED_VOLUME_ZONE_NAMES = ["VolumeAZ1", "VolumeAZ2", "VolumeAZ3"]
1519

1620

17-
class TestVolumeAZMachines(unittest.TestCase):
21+
class CinderAvailabilityZonesMachines(unittest.TestCase):
1822
def setUp(self):
1923
"""Parse the Machines into a Python data structure."""
2024
self.machines = []
@@ -35,7 +39,7 @@ def test_zone_names(self):
3539

3640
def test_total_instance_number(self):
3741
"""Assert that there are as many Machines as required ControlPlane replicas."""
38-
self.assertEqual(len(self.machines), EXPECTED_MACHINES_NUMBER)
42+
self.assertEqual(len(self.machines), EXPECTED_MASTER_REPLICAS)
3943

4044
def test_replica_distribution(self):
4145
"""Assert that machines are evenly distributed across volume azs."""
@@ -52,6 +56,46 @@ def test_replica_distribution(self):
5256
self.assertTrue(-2 < replicas - setpoint < 2)
5357

5458

59+
class CinderAvailabilityZonesMachinesets(unittest.TestCase):
60+
def setUp(self):
61+
"""Parse the MachineSets into a Python data structure."""
62+
self.machinesets = []
63+
for machineset_path in glob.glob(
64+
f'{ASSETS_DIR}/openshift/99_openshift-cluster-api_worker-machineset-*.yaml'
65+
):
66+
with open(machineset_path) as f:
67+
self.machinesets.append(yaml.load(f, Loader=yaml.FullLoader))
68+
69+
def test_machineset_zone_name(self):
70+
"""Assert that there is exactly one MachineSet per volume availability zone."""
71+
found = []
72+
for machineset in self.machinesets:
73+
master_zone = machineset["spec"]["template"]["spec"]["providerSpec"]["value"]["availabilityZone"]
74+
volume_zone = machineset["spec"]["template"]["spec"]["providerSpec"]["value"]["rootVolume"]["availabilityZone"]
75+
self.assertIn(volume_zone, EXPECTED_VOLUME_ZONE_NAMES)
76+
self.assertNotIn(volume_zone, found)
77+
self.assertEqual(master_zone[-3:], volume_zone[-3:])
78+
found.append(volume_zone)
79+
self.assertEqual(len(self.machinesets), len(EXPECTED_VOLUME_ZONE_NAMES))
80+
81+
def test_total_replica_number(self):
82+
"""Assert that replicas spread across the MachineSets add up to the expected number."""
83+
total_found = 0
84+
for machineset in self.machinesets:
85+
total_found += machineset["spec"]["replicas"]
86+
self.assertEqual(total_found, EXPECTED_WORKER_REPLICAS)
87+
88+
def test_replica_distribution(self):
89+
"""Assert that replicas are evenly distributed across machinesets."""
90+
setpoint = 0
91+
for machineset in self.machinesets:
92+
replicas = machineset["spec"]["replicas"]
93+
if setpoint == 0:
94+
setpoint = replicas
95+
else:
96+
self.assertTrue(-2 < replicas - setpoint < 2)
97+
98+
5599
if __name__ == '__main__':
56100
ASSETS_DIR = sys.argv.pop()
57101
unittest.main(verbosity=2)

scripts/openstack/manifest-tests/cinder-availability-zones/test_machinesets.py

Lines changed: 0 additions & 59 deletions
This file was deleted.

scripts/openstack/manifest-tests/failure-domains/test_machines.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
import yaml
1010

1111
ASSETS_DIR = ""
12-
INSTALLCONFIG_PATH = ""
12+
INSTALLCONFIG_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'install-config.yaml')
1313

1414

15-
class TestMachines(unittest.TestCase):
15+
class FailureDomainsMachines(unittest.TestCase):
1616
def setUp(self):
1717
"""Parse the expected values from install-config and collect Machine resources."""
1818
self.machines = []

scripts/openstack/manifest-tests/default-stable-lb/install-config.yaml renamed to scripts/openstack/manifest-tests/lb-default-stable/install-config.yaml

File renamed without changes.

scripts/openstack/manifest-tests/default-stable-lb/test_cluster-infra.py renamed to scripts/openstack/manifest-tests/lb-default-stable/test_cluster-infra.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
ASSETS_DIR = ""
1111

12-
class TestClusterInfraObject(unittest.TestCase):
12+
class DefaultStableLoadBalancerClusterInfraObject(unittest.TestCase):
1313
def setUp(self):
1414
"""Parse the Cluster Infrastructure object into a Python data structure."""
1515
self.machines = []

scripts/openstack/manifest-tests/default-techpreview-lb/install-config.yaml renamed to scripts/openstack/manifest-tests/lb-default-techpreview/install-config.yaml

File renamed without changes.

scripts/openstack/manifest-tests/default-techpreview-lb/test_cluster-infra.py renamed to scripts/openstack/manifest-tests/lb-default-techpreview/test_cluster-infra.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
ASSETS_DIR = ""
1111

12-
class TestClusterInfraObject(unittest.TestCase):
12+
class DefaultTechPreviewLoadBalancerClusterInfraObject(unittest.TestCase):
1313
def setUp(self):
1414
"""Parse the Cluster Infrastructure object into a Python data structure."""
1515
self.machines = []

scripts/openstack/manifest-tests/openshift-managed-lb/install-config.yaml renamed to scripts/openstack/manifest-tests/lb-managed/install-config.yaml

File renamed without changes.

scripts/openstack/manifest-tests/openshift-managed-lb/test_cluster-infra.py renamed to scripts/openstack/manifest-tests/lb-managed/test_cluster-infra.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99

1010
ASSETS_DIR = ""
1111

12-
class TestClusterInfraObject(unittest.TestCase):
12+
class ManagedLoadBalancer(unittest.TestCase):
1313
def setUp(self):
1414
"""Parse the Cluster Infrastructure object into a Python data structure."""
1515
self.machines = []
1616
cluster_infra = f'{ASSETS_DIR}/manifests/cluster-infrastructure-02-config.yml'
1717
with open(cluster_infra) as f:
1818
self.cluster_infra = yaml.load(f, Loader=yaml.FullLoader)
1919

20-
def test_load_balancer(self):
20+
def test_cluster_infra_object(self):
2121
"""Assert that the Cluster infrastructure object contains the LoadBalancer configuration."""
2222
self.assertIn("loadBalancer", self.cluster_infra["status"]["platformStatus"]["openstack"])
2323

0 commit comments

Comments
 (0)