1
0
mirror of https://github.com/openshift/installer.git synced 2026-02-05 06:46:36 +01:00

openstack-manifests: Refactor

This commit is contained in:
Pierre Prinetti
2023-03-12 17:39:56 +01:00
parent 1fe95cf661
commit 34b53ca9d3
16 changed files with 123 additions and 169 deletions

View File

@@ -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}"

View File

@@ -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)

View File

@@ -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)

View File

@@ -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 = []

View File

@@ -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 = []

View File

@@ -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 = []

View File

@@ -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"])

View File

@@ -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"])

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)