From 3d038f5ccc1202085f27ee59be5ad69f5d5e6c54 Mon Sep 17 00:00:00 2001 From: Chris Dent Date: Tue, 11 Dec 2018 11:48:09 +0000 Subject: [PATCH] Sync STANDARDS with placement/nova rc_fields Two new standard resource classes were added in the time between when os-resource-classes was first created and now. This change adds the missing classes and adds a rather tedious sanity check to make sure that tests are updated when adding new classes. Change-Id: I00158c3167430e180040c71cd6e2d646f64372fa --- os_resource_classes/__init__.py | 6 ++++++ .../tests/test_os_resource_classes.py | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/os_resource_classes/__init__.py b/os_resource_classes/__init__.py index b3cbc08..0586c83 100644 --- a/os_resource_classes/__init__.py +++ b/os_resource_classes/__init__.py @@ -53,6 +53,12 @@ STANDARDS = [ 'IPV4_ADDRESS', 'VGPU', 'VGPU_DISPLAY_HEAD', + # Standard resource class for network bandwidth egress measured in + # kilobits per second. + 'NET_BW_EGR_KILOBIT_PER_SEC', + # Standard resource class for network bandwidth ingress measured in + # kilobits per second. + 'NET_BW_IGR_KILOBIT_PER_SEC', ] # Namespace used for custom resource classes diff --git a/os_resource_classes/tests/test_os_resource_classes.py b/os_resource_classes/tests/test_os_resource_classes.py index f2baa46..65f4d69 100644 --- a/os_resource_classes/tests/test_os_resource_classes.py +++ b/os_resource_classes/tests/test_os_resource_classes.py @@ -30,3 +30,21 @@ class TestOs_resource_classes(base.TestCase): def test_id_mapping_symbols(self): self.assertEqual(rc.VCPU, rc.STANDARDS[0]) self.assertEqual(rc.DISK_GB, rc.STANDARDS[2]) + + def test_standards_tail(self): + """A sanity check that developers are paying attention. + + When one or more standard classes are added, change the expected + last class to the last one added and the length to the new length + of rc.STANDARDS. + + If you arrive here because you've run the tests and they've failed + it's possible you've added some standard classes and not thought + about their order. You _must_ add new standard classs at the end + of the STANDARDS list, otherwise database ids will get confused + in the placement service. + """ + expected_last_class = rc.NET_BW_IGR_KILOBIT_PER_SEC + expected_length = 14 + self.assertEqual(expected_last_class, rc.STANDARDS[-1]) + self.assertEqual(expected_length, len(rc.STANDARDS))