Fix allocation show / unset with empty allocation
Add a guards for empty allocations in the allocation parsing code of allocation show and allocation unset. Closes-Bug: #1942740 Change-Id: Ic0e6e981d6602a76935f6bc6d9ffb0a707a5b1a9
This commit is contained in:
parent
087dd64dd2
commit
0ea8f1b05d
@ -291,7 +291,7 @@ class UnsetAllocation(command.Lister, version.CheckerMixin):
|
||||
'project_id', 'user_id')
|
||||
if self.compare_version(version.ge('1.38')):
|
||||
fields += ('consumer_type',)
|
||||
props['consumer_type'] = resp['consumer_type']
|
||||
props['consumer_type'] = resp.get('consumer_type')
|
||||
allocs = [dict(project_id=resp['project_id'], user_id=resp['user_id'],
|
||||
resource_provider=k, **props, **v)
|
||||
for k, v in per_provider]
|
||||
@ -332,11 +332,11 @@ class ShowAllocation(command.Lister, version.CheckerMixin):
|
||||
fields = ('resource_provider', 'generation', 'resources')
|
||||
if self.compare_version(version.ge('1.12')):
|
||||
fields += ('project_id', 'user_id')
|
||||
props['project_id'] = resp['project_id']
|
||||
props['user_id'] = resp['user_id']
|
||||
props['project_id'] = resp.get('project_id')
|
||||
props['user_id'] = resp.get('user_id')
|
||||
if self.compare_version(version.ge('1.38')):
|
||||
fields += ('consumer_type',)
|
||||
props['consumer_type'] = resp['consumer_type']
|
||||
props['consumer_type'] = resp.get('consumer_type')
|
||||
|
||||
allocs = [dict(resource_provider=k, **props, **v)
|
||||
for k, v in per_provider]
|
||||
|
@ -198,19 +198,9 @@ class TestAllocation112(base.BaseTestCase):
|
||||
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)
|
||||
alloc = self.resource_allocation_show(
|
||||
str(uuid.uuid4()), columns=('resources',))
|
||||
self.assertEqual([], alloc)
|
||||
|
||||
|
||||
class TestAllocation128(TestAllocation112):
|
||||
@ -317,19 +307,9 @@ class TestAllocation138(TestAllocation128):
|
||||
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)
|
||||
result = self.resource_allocation_unset(
|
||||
consumer_uuid, columns=('resources', 'consumer_type'))
|
||||
self.assertEqual([], result)
|
||||
|
||||
|
||||
class TestAllocationUnsetOldVersion(base.BaseTestCase):
|
||||
|
Loading…
Reference in New Issue
Block a user