From 3b11e7cd3123cdffa2ed870df8c9f230dafca894 Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Mon, 20 Nov 2017 11:31:59 -0500 Subject: [PATCH] Address comments from original inventory patch This addresses some comments from change Ie46b6217fda65cb5d0f1379d0b4a986b4c30a3eb: 1. Fixes a typo in the resource class help. 2. Makes the 'total' inventory field required to avoid ugly error output if total is not specified with "openstack resource provider inventory class set". 3. Adds more wording to the "openstack resource provider inventory set" CLI description about how inventory fields are parsed and that it is a full replacement of the inventory, not just amending existing inventory. Part of blueprint placement-osc-plugin Change-Id: I8c6f3387dba891d5c6aea617594a6ef682ada62d --- osc_placement/resources/inventory.py | 12 ++++++++++-- osc_placement/tests/functional/test_inventory.py | 9 ++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/osc_placement/resources/inventory.py b/osc_placement/resources/inventory.py index 70f0905..b2a284d 100644 --- a/osc_placement/resources/inventory.py +++ b/osc_placement/resources/inventory.py @@ -57,13 +57,13 @@ INVENTORY_FIELDS = { }, 'total': { 'type': int, - 'required': False, + 'required': True, 'help': ('The actual amount of the resource that the provider ' 'can accommodate.') } } FIELDS = tuple(INVENTORY_FIELDS.keys()) -RC_HELP = (' is entity that indicates standard or ' +RC_HELP = (' is an entity that indicates standard or ' 'deployer-specific resources that can be provided by a resource ' 'provider. For example, VCPU, MEMORY_MB, DISK_GB.') @@ -94,6 +94,14 @@ class SetInventory(command.Lister): """Replaces the set of inventory records for the resource provider. + Note that this is a full replacement of the existing inventory. If you + want to retain the existing inventory and add a new resource class + inventory, you must specify all resource class inventory, old and new. + + If a specific inventory field is not specified for a given resource class, + it is assumed to be the total, i.e. --resource VCPU=16 is equivalent to + --resource VCPU:total=16. + Example: openstack resource provider inventory set \ --resource VCPU=16 \ --resource MEMORY_MB=2048 \ diff --git a/osc_placement/tests/functional/test_inventory.py b/osc_placement/tests/functional/test_inventory.py index 82ffdcb..332f257 100644 --- a/osc_placement/tests/functional/test_inventory.py +++ b/osc_placement/tests/functional/test_inventory.py @@ -174,8 +174,15 @@ class TestSetInventory(base.BaseTestCase): subprocess.CalledProcessError, self.openstack, ('resource provider inventory class set ' - 'fake_uuid fake_class --totals 5')) + 'fake_uuid fake_class --total 5 --unknown 1')) self.assertIn('unrecognized arguments', exc.output.decode('utf-8')) + # Valid RP UUID and resource class, but no inventory field. + rp = self.resource_provider_create() + exc = self.assertRaises( + subprocess.CalledProcessError, self.openstack, + 'resource provider inventory class set %s VCPU' % rp['uuid']) + self.assertIn('argument --total is required', + exc.output.decode('utf-8')) def test_set_inventory_for_resource_class(self): rp = self.resource_provider_create()