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
This commit is contained in:
Matt Riedemann 2017-11-20 11:31:59 -05:00
parent 1fac79d183
commit 3b11e7cd31
2 changed files with 18 additions and 3 deletions

View File

@ -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 = ('<resource_class> is entity that indicates standard or '
RC_HELP = ('<resource_class> 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 <uuid> \
--resource VCPU=16 \
--resource MEMORY_MB=2048 \

View File

@ -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()