github.com/openshift/installer@v1.4.17/scripts/openstack/manifest-tests/convert/test_convert.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  class ConvertMachine(unittest.TestCase):
    15      def setUp(self):
    16          """Parse the Machines into a Python data structure."""
    17          self.masters = []
    18          for machine_path in glob.glob(
    19                  f'{ASSETS_DIR}/openshift/99_openshift-cluster-api_master-machines-*.yaml'
    20          ):
    21              with open(machine_path) as f:
    22                  self.masters.append(yaml.load(f, Loader=yaml.FullLoader))
    23  
    24          with open(f'{ASSETS_DIR}/manifests/cluster-config.yaml') as f:
    25              cluster_config = yaml.load(f, Loader=yaml.FullLoader)
    26              self.install_config = yaml.load(cluster_config["data"]["install-config"], Loader=yaml.FullLoader)
    27  
    28      def test_flavor(self):
    29          """Assert that all machines take flavor from computeFlavor."""
    30          for machine in self.masters:
    31              master_flavor = machine["spec"]["providerSpec"]["value"]["flavor"]
    32              expected_master_flavor = self.install_config["platform"]["openstack"]["computeFlavor"]
    33              self.assertEqual(master_flavor, expected_master_flavor)
    34  
    35  class ConvertMachineSet(unittest.TestCase):
    36      def setUp(self):
    37          """Parse the MachineSets into a Python data structure."""
    38          self.machinesets = []
    39          for machineset_path in glob.glob(
    40                  f'{ASSETS_DIR}/openshift/99_openshift-cluster-api_worker-machineset-*.yaml'
    41          ):
    42              with open(machineset_path) as f:
    43                  self.machinesets.append(yaml.load(f, Loader=yaml.FullLoader))
    44  
    45          with open(f'{ASSETS_DIR}/manifests/cluster-config.yaml') as f:
    46              cluster_config = yaml.load(f, Loader=yaml.FullLoader)
    47              self.install_config = yaml.load(cluster_config["data"]["install-config"], Loader=yaml.FullLoader)
    48  
    49      def test_flavor(self):
    50          """Assert that worker machinesets take flavor from machinepool."""
    51          for machineset in self.machinesets:
    52              flavor = machineset["spec"]["template"]["spec"]["providerSpec"]["value"]["flavor"]
    53              compute_flavor = self.install_config["platform"]["openstack"]["computeFlavor"]
    54              expected_flavor = self.install_config["compute"][0]["platform"]["openstack"]["type"]
    55              self.assertEqual(flavor, expected_flavor)
    56              self.assertNotEqual(flavor, compute_flavor)
    57  
    58  
    59  if __name__ == '__main__':
    60      ASSETS_DIR = sys.argv.pop()
    61      with open(os.environ.get('JUNIT_FILE', '/dev/null'), 'wb') as output:
    62          unittest.main(testRunner=xmlrunner.XMLTestRunner(output=output), failfast=False, buffer=False, catchbreak=False, verbosity=2)