github.com/openshift/installer@v1.4.17/scripts/openstack/manifest-tests/cinder-availability-zones/test_cpms.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 yaml
    10  
    11  ASSETS_DIR = ""
    12  
    13  EXPECTED_MASTER_ZONE_NAMES = ["MasterAZ1", "MasterAZ2", "MasterAZ3"]
    14  EXPECTED_MASTER_ROOT_VOLUME_ZONE_NAMES = ["VolumeAZ1", "VolumeAZ2", "VolumeAZ3"]
    15  
    16  class ControlPlaneMachineSet(unittest.TestCase):
    17      def setUp(self):
    18          """Parse the CPMS into a Python data structure."""
    19          with open(f'{ASSETS_DIR}/openshift/99_openshift-machine-api_master-control-plane-machine-set.yaml') as f:
    20              self.cpms = yaml.load(f, Loader=yaml.FullLoader)
    21  
    22      def test_providerspec_failuredomain_fields(self):
    23          """Assert that the failure-domain-managed fields in the CPMS providerSpec are omitted."""
    24          provider_spec = self.cpms["spec"]["template"]["machines_v1beta1_machine_openshift_io"]["spec"]["providerSpec"]["value"]
    25          self.assertNotIn("availabilityZone", provider_spec)
    26          self.assertNotIn("availabilityZone", provider_spec["rootVolume"])
    27  
    28      def test_compute_zones(self):
    29          """Assert that the CPMS failure domain zones match the expected machine-pool zones."""
    30          self.assertIn("failureDomains", self.cpms["spec"]["template"]["machines_v1beta1_machine_openshift_io"])
    31          failure_domains = self.cpms["spec"]["template"]["machines_v1beta1_machine_openshift_io"]["failureDomains"]["openstack"]
    32  
    33          compute_zones = []
    34          for failure_domain in failure_domains:
    35              zone = failure_domain["availabilityZone"]
    36              compute_zones.append(zone)
    37              self.assertIn(zone, EXPECTED_MASTER_ZONE_NAMES)
    38  
    39          for expected_zone in EXPECTED_MASTER_ZONE_NAMES:
    40              self.assertIn(expected_zone, compute_zones)
    41  
    42      def test_storage_zones(self):
    43          """Assert that the CPMS failure domain root volume zones match the expected machine-pool zones."""
    44          self.assertIn("failureDomains", self.cpms["spec"]["template"]["machines_v1beta1_machine_openshift_io"])
    45          self.assertIn("openstack", self.cpms["spec"]["template"]["machines_v1beta1_machine_openshift_io"]["failureDomains"])
    46          failure_domains = self.cpms["spec"]["template"]["machines_v1beta1_machine_openshift_io"]["failureDomains"]["openstack"]
    47  
    48          storage_zones = []
    49          for failure_domain in failure_domains:
    50              self.assertIn("rootVolume", failure_domain)
    51              self.assertIn("availabilityZone", failure_domain["rootVolume"])
    52              rootVolumeZone = failure_domain["rootVolume"]["availabilityZone"]
    53              storage_zones.append(rootVolumeZone)
    54              self.assertIn(rootVolumeZone, EXPECTED_MASTER_ROOT_VOLUME_ZONE_NAMES)
    55  
    56          for expected_zone in EXPECTED_MASTER_ROOT_VOLUME_ZONE_NAMES:
    57              self.assertIn(expected_zone, storage_zones)
    58  
    59  
    60  if __name__ == '__main__':
    61      ASSETS_DIR = sys.argv.pop()
    62      with open(os.environ.get('JUNIT_FILE', '/dev/null'), 'wb') as output:
    63          unittest.main(testRunner=xmlrunner.XMLTestRunner(output=output), failfast=False, buffer=False, catchbreak=False, verbosity=2)