From 39befda0d70fe51d75fdece30270fd23b68e0433 Mon Sep 17 00:00:00 2001 From: Tetsuro Nakamura Date: Wed, 4 Sep 2019 11:58:48 +0000 Subject: [PATCH] Verify result for inventory set --dry-run There were tests to verify that 'resource provider inventory set' command with --dry-run and --aggregate option changes nothing on the server side but there was no test to verify the result of that command. This patch adds the test. Change-Id: I8d2c25a654928d8d46d5e1d0ee203600c9a72600 --- .../tests/functional/test_inventory.py | 36 +++++++++++++++---- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/osc_placement/tests/functional/test_inventory.py b/osc_placement/tests/functional/test_inventory.py index 1f372de..def1864 100644 --- a/osc_placement/tests/functional/test_inventory.py +++ b/osc_placement/tests/functional/test_inventory.py @@ -337,12 +337,36 @@ class TestAggregateInventory(base.BaseTestCase): VERSION = '1.3' def _test_dry_run(self, agg, rps, old_inventories, amend=False): - self.resource_inventory_set( - agg, - 'VCPU:allocation_ratio=5.0', - 'MEMORY_MB:allocation_ratio=6.0', - 'DISK_GB:allocation_ratio=7.0', - aggregate=True, amend=amend, dry_run=True) + new_resources = ['VCPU:allocation_ratio=5.0', + 'MEMORY_MB:allocation_ratio=6.0', + 'DISK_GB:allocation_ratio=7.0'] + resp = self.resource_inventory_set( + agg, *new_resources, aggregate=True, amend=amend, dry_run=True) + # Use empty dict to get expected values for full replacement + inventories = old_inventories if amend else [{}] * len(old_inventories) + # A list of dict keyed by resource class of dict of inventories + # Each list element corresponds to one resource provider + new_inventories = self._get_expected_inventories( + inventories, new_resources) + # To compare with actual result, reformat new_inventories to + # a dict, keyed by resource provider uuid, of dict of inventories + # keyed by resource class + expected = {} + for rp, inventory in zip(rps, new_inventories): + for rc, inv in inventory.items(): + inv['resource_provider'] = rp['uuid'] + # For full replacement (not amend) case these values should + # be set to empty string. + for key in ('max_unit', 'min_unit', 'reserved', 'step_size', + 'total', 'reserved', 'step_size'): + if key not in inv: + inv[key] = '' + expected[rp['uuid']] = inventory + # Reformat raw response (list of inventories) as well + resp_dict = collections.defaultdict(dict) + for row in resp: + resp_dict[row['resource_provider']][row['resource_class']] = row + self.assertEqual(expected, resp_dict) # Verify the inventories weren't changed (--dry-run) for i, rp in enumerate(rps): resp = self.resource_inventory_list(rp['uuid'])