Fix display of chassis UUID field if empty

When calling OSC commands "openstack baremetal node create" or
"openstack baremetal node show" the field "chassis_uuid" should be
displayed even if it is empty.

This patch also updated the test schema for the ironic --json node-*
command as chassis_uuid will now appear as 'null' when the node isn't
associated with a chassis.

Change-Id: Ic10eb9ef908c12d5c71c1df407bfb66079a25703
Closes-Bug: #1620749
This commit is contained in:
Vadim Hmyrov 2016-09-15 08:30:19 -04:00 committed by Vladyslav Drok
parent 77f02f317d
commit d35a75cbb0
6 changed files with 50 additions and 29 deletions

View File

@ -323,6 +323,8 @@ class CreateBaremetalNode(command.ShowOne):
node.pop('links', None)
node.pop('ports', None)
node.setdefault('chassis_uuid', '')
return self.dict2columns(node)
@ -950,7 +952,9 @@ class ShowBaremetalNode(command.ShowOne):
node.pop("links", None)
node.pop("ports", None)
return zip(*sorted(node.items()))
node.setdefault('chassis_uuid', '')
return self.dict2columns(node)
class ShowBaremetal(ShowBaremetalNode):

View File

@ -67,7 +67,7 @@ class TestNodeJsonResponse(base.FunctionalTestBase):
"driver_info": {"type": "object"},
"created_at": {"type": "string"},
"driver_internal_info": {"type": "object"},
"chassis_uuid": {"type": "string"},
"chassis_uuid": {"type": ["string", "null"]},
"instance_info": {"type": "object"}
}
}
@ -144,7 +144,7 @@ class TestNodeJsonResponse(base.FunctionalTestBase):
"driver_info": {"type": "object"},
"extra": {"type": "object"},
"driver": {"type": "string"},
"chassis_uuid": {"type": "string"},
"chassis_uuid": {"type": ["string", "null"]},
"properties": {"type": "object"},
"name": {"type": ["string", "null"]},
}

View File

@ -20,6 +20,8 @@ from osc_lib.tests import utils
from ironicclient.tests.unit.osc import fakes
baremetal_chassis_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'
baremetal_chassis_uuid_empty = ''
baremetal_properties_empty = ''
baremetal_chassis_description = 'chassis description'
baremetal_chassis_extra = {}
BAREMETAL_CHASSIS = {

View File

@ -42,14 +42,22 @@ class TestBaremetalCreate(baremetal_fakes.TestBaremetal):
# DisplayCommandBase.take_action() returns two tuples
columns, data = self.cmd.take_action(parsed_args)
self.assertEqual(('instance_uuid', 'maintenance', 'name',
'power_state', 'provision_state', 'uuid'), columns)
self.assertEqual(('yyy-yyyyyy-yyyy',
baremetal_fakes.baremetal_maintenance,
baremetal_fakes.baremetal_name,
baremetal_fakes.baremetal_power_state,
baremetal_fakes.baremetal_provision_state,
baremetal_fakes.baremetal_uuid), tuple(data))
self.assertEqual(('chassis_uuid',
'instance_uuid',
'maintenance',
'name',
'power_state',
'provision_state',
'uuid'), columns)
self.assertEqual(
(baremetal_fakes.baremetal_chassis_uuid_empty,
baremetal_fakes.baremetal_instance_uuid,
baremetal_fakes.baremetal_maintenance,
baremetal_fakes.baremetal_name,
baremetal_fakes.baremetal_power_state,
baremetal_fakes.baremetal_provision_state,
baremetal_fakes.baremetal_uuid), tuple(data))
self.baremetal_mock.node.create.assert_called_once_with(
driver='fake_driver')

View File

@ -219,16 +219,17 @@ class TestBaremetalCreate(TestBaremetal):
self.cmd = baremetal_node.CreateBaremetalNode(self.app, None)
self.arglist = ['--driver', 'fake_driver']
self.verifylist = [('driver', 'fake_driver')]
self.collist = (
'instance_uuid',
'maintenance',
'name',
'power_state',
'provision_state',
'uuid'
)
self.collist = ('chassis_uuid',
'instance_uuid',
'maintenance',
'name',
'power_state',
'provision_state',
'uuid'
)
self.datalist = (
'yyy-yyyyyy-yyyy',
baremetal_fakes.baremetal_chassis_uuid_empty,
baremetal_fakes.baremetal_instance_uuid,
baremetal_fakes.baremetal_maintenance,
baremetal_fakes.baremetal_name,
baremetal_fakes.baremetal_power_state,
@ -1329,18 +1330,19 @@ class TestBaremetalShow(TestBaremetal):
*args, fields=None
)
collist = (
'instance_uuid',
'maintenance',
'name',
'power_state',
'provision_state',
'uuid'
)
collist = ('chassis_uuid',
'instance_uuid',
'maintenance',
'name',
'power_state',
'provision_state',
'uuid'
)
self.assertEqual(collist, columns)
self.assertNotIn('ports', columns)
datalist = (
'yyy-yyyyyy-yyyy',
baremetal_fakes.baremetal_chassis_uuid_empty,
baremetal_fakes.baremetal_instance_uuid,
baremetal_fakes.baremetal_maintenance,
baremetal_fakes.baremetal_name,
baremetal_fakes.baremetal_power_state,

View File

@ -0,0 +1,5 @@
---
fixes:
- |
If a node does not have ``chassis_uuid`` field in the API response, it
is added to the output of the node commands as an empty string.