diff --git a/osc_placement/tests/functional/base.py b/osc_placement/tests/functional/base.py index 011d994..af4aed9 100644 --- a/osc_placement/tests/functional/base.py +++ b/osc_placement/tests/functional/base.py @@ -228,11 +228,10 @@ class BaseTestCase(base.BaseTestCase): def resource_provider_delete(self, uuid): return self.openstack('resource provider delete ' + uuid) - def resource_allocation_show(self, consumer_uuid): - return self.openstack( - 'resource provider allocation show ' + consumer_uuid, - use_json=True - ) + def resource_allocation_show(self, consumer_uuid, columns=()): + cmd = 'resource provider allocation show ' + consumer_uuid + cmd += ' '.join(' --column %s' % c for c in columns) + return self.openstack(cmd, use_json=True) def resource_allocation_set(self, consumer_uuid, allocations, project_id=None, user_id=None, @@ -262,8 +261,10 @@ class BaseTestCase(base.BaseTestCase): return result - def resource_allocation_unset(self, consumer_uuid, provider=None, - resource_class=None, use_json=True): + def resource_allocation_unset( + self, consumer_uuid, provider=None, resource_class=None, use_json=True, + columns=(), + ): cmd = 'resource provider allocation unset %s' % consumer_uuid if resource_class: cmd += ' ' + ' '.join( @@ -275,6 +276,9 @@ class BaseTestCase(base.BaseTestCase): provider = [provider] cmd += ' ' + ' '.join( '--provider %s' % rp_uuid for rp_uuid in provider) + + cmd += ' '.join(' --column %s' % c for c in columns) + result = self.openstack(cmd, use_json=use_json) def cleanup(uuid): diff --git a/osc_placement/tests/functional/test_allocation.py b/osc_placement/tests/functional/test_allocation.py index ed8ad94..fee126e 100644 --- a/osc_placement/tests/functional/test_allocation.py +++ b/osc_placement/tests/functional/test_allocation.py @@ -180,6 +180,38 @@ class TestAllocation112(base.BaseTestCase): self.assertEqual(expected, created_alloc) self.assertEqual(expected, retrieved_alloc) + def test_allocation_update_to_empty(self): + consumer_uuid = str(uuid.uuid4()) + project_uuid = str(uuid.uuid4()) + user_uuid = str(uuid.uuid4()) + + self.resource_allocation_set( + consumer_uuid, + ['rp={},VCPU=2'.format(self.rp1['uuid'])], + project_id=project_uuid, + user_id=user_uuid, + ) + + result = self.resource_allocation_unset( + consumer_uuid, columns=("resources",)) + + self.assertEqual([], result) + + def test_allocation_show_empty(self): + # FIXME(gibi): this is bug https://bugs.launchpad.net/nova/+bug/1942740 + # the command fails with KeyError on project_id when the allocation is + # empty + self.assertCommandFailed( + 'project_id', + self.resource_allocation_show, + str(uuid.uuid4()), + columns=("resources",), + ) + # it should be + # alloc = self.resource_allocation_show( + # str(uuid.uuid4()), columns=("resources",)) + # self.assertEqual([], alloc) + class TestAllocation128(TestAllocation112): """Tests allocation set command with --os-placement-api-version 1.28. @@ -272,6 +304,33 @@ class TestAllocation138(TestAllocation128): }) self.assertEqual(expected, updated_alloc) + def test_allocation_update_to_empty(self): + consumer_uuid = str(uuid.uuid4()) + project_uuid = str(uuid.uuid4()) + user_uuid = str(uuid.uuid4()) + + self.resource_allocation_set( + consumer_uuid, + ['rp={},VCPU=2'.format(self.rp1['uuid'])], + project_id=project_uuid, + user_id=user_uuid, + consumer_type="INSTANCE", + ) + + # FIXME(gibi): This is bug https://bugs.launchpad.net/nova/+bug/1942740 + # The command fails with a KeyError as it tries to parse the + # consumer_type out from and empty allocation + self.assertCommandFailed( + "consumer_type", + self.resource_allocation_unset, + consumer_uuid, + columns=('resources', 'consumer_type') + ) + # it should be + # result = self.resource_allocation_unset( + # consumer_uuid, columns=('resources', 'consumer_type')) + # self.assertEqual([], result) + class TestAllocationUnsetOldVersion(base.BaseTestCase):