github.com/openshift/installer@v1.4.17/scripts/openstack/manifest-tests/server-groups/test_machines.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 glob
    10  import yaml
    11  
    12  ASSETS_DIR = ""
    13  
    14  
    15  class ServerGroupMachines(unittest.TestCase):
    16      def setUp(self):
    17          """Parse the Machines into a Python data structure."""
    18          self.machines = []
    19          for machine_path in glob.glob(
    20                  f'{ASSETS_DIR}/openshift/99_openshift-cluster-api_master-machines-*.yaml'
    21          ):
    22              with open(machine_path) as f:
    23                  self.machines.append(yaml.load(f, Loader=yaml.FullLoader))
    24  
    25      def test_consistent_group_name(self):
    26          """Assert that all machines bear the same server group name."""
    27          group_name = None
    28          for machine in self.machines:
    29              name = machine["spec"]["providerSpec"]["value"]["serverGroupName"]
    30              if group_name is None:
    31                  group_name = name
    32  
    33              self.assertEqual(name, group_name)
    34  
    35  
    36  class ServerGroupMachinesets(unittest.TestCase):
    37      def setUp(self):
    38          """Parse the MachineSets into a Python data structure."""
    39          self.machinesets = []
    40          for machineset_path in glob.glob(
    41                  f'{ASSETS_DIR}/openshift/99_openshift-cluster-api_worker-machineset-*.yaml'
    42          ):
    43              with open(machineset_path) as f:
    44                  self.machinesets.append(yaml.load(f, Loader=yaml.FullLoader))
    45  
    46      def test_consistent_group_names(self):
    47          """Assert that server group names are unique across machinesets."""
    48          found = []
    49          for machineset in self.machinesets:
    50              name = machineset["spec"]["template"]["spec"]["providerSpec"][
    51                  "value"]["serverGroupName"]
    52              self.assertNotIn(name, found)
    53              found.append(name)
    54  
    55  
    56  if __name__ == '__main__':
    57      ASSETS_DIR = sys.argv.pop()
    58      with open(os.environ.get('JUNIT_FILE', '/dev/null'), 'wb') as output:
    59          unittest.main(testRunner=xmlrunner.XMLTestRunner(output=output), failfast=False, buffer=False, catchbreak=False, verbosity=2)