github.com/openshift/installer@v1.4.17/scripts/openstack/manifest-tests/nova-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 = ["masterzone", "masterztwo", "masterzthree"]
    14  
    15  class ControlPlaneMachineSet(unittest.TestCase):
    16      def setUp(self):
    17          """Parse the CPMS into a Python data structure."""
    18          with open(f'{ASSETS_DIR}/openshift/99_openshift-machine-api_master-control-plane-machine-set.yaml') as f:
    19              self.cpms = yaml.load(f, Loader=yaml.FullLoader)
    20  
    21      def test_providerspec_failuredomain_fields(self):
    22          """Assert that the failure-domain-managed fields in the CPMS providerSpec are omitted."""
    23          provider_spec = self.cpms["spec"]["template"]["machines_v1beta1_machine_openshift_io"]["spec"]["providerSpec"]["value"]
    24          self.assertNotIn("availabilityZone", provider_spec)
    25  
    26      def test_compute_zones(self):
    27          """Assert that the CPMS failure domain zones match the expected machine-pool zones."""
    28          self.assertIn("failureDomains", self.cpms["spec"]["template"]["machines_v1beta1_machine_openshift_io"])
    29          failure_domains = self.cpms["spec"]["template"]["machines_v1beta1_machine_openshift_io"]["failureDomains"]["openstack"]
    30  
    31          compute_zones = []
    32          for failure_domain in failure_domains:
    33              zone = failure_domain["availabilityZone"]
    34              compute_zones.append(zone)
    35              self.assertIn(zone, EXPECTED_MASTER_ZONE_NAMES)
    36  
    37          for expected_zone in EXPECTED_MASTER_ZONE_NAMES:
    38              self.assertIn(expected_zone, compute_zones)
    39  
    40  
    41  if __name__ == '__main__':
    42      ASSETS_DIR = sys.argv.pop()
    43      with open(os.environ.get('JUNIT_FILE', '/dev/null'), 'wb') as output:
    44          unittest.main(testRunner=xmlrunner.XMLTestRunner(output=output), failfast=False, buffer=False, catchbreak=False, verbosity=2)