Fix port create ignores the name field

The newly added name argument support is not processed
so that create a port with name does not take effect.
Also amend a few unit tests.

Change-Id: I8c05cd03557c01dfe83e0875ad653ff53d7dee42
This commit is contained in:
Kaifeng Wang 2024-07-15 18:44:50 +08:00
parent 85542f0caf
commit a10c3e3923
3 changed files with 60 additions and 1 deletions

View File

@ -132,7 +132,7 @@ class CreateBaremetalPort(command.ShowOne):
field_list = ['address', 'uuid', 'extra', 'node_uuid', 'pxe_enabled',
'local_link_connection', 'portgroup_uuid',
'physical_network']
'physical_network', 'name']
fields = dict((k, v) for (k, v) in vars(parsed_args).items()
if k in field_list and v is not None)
fields = utils.args_array_to_dict(fields, 'extra')

View File

@ -272,6 +272,33 @@ class TestCreateBaremetalPort(TestBaremetalPort):
'is_smartnic': True}
self.baremetal_mock.port.create.assert_called_once_with(**args)
def test_baremetal_port_create_name(self):
arglist = [
baremetal_fakes.baremetal_port_address,
'--node', baremetal_fakes.baremetal_uuid,
'--name', 'portname1'
]
verifylist = [
('node_uuid', baremetal_fakes.baremetal_uuid),
('address', baremetal_fakes.baremetal_port_address),
('name', 'portname1')
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
# DisplayCommandBase.take_action() returns two tuples
self.cmd.take_action(parsed_args)
# Set expected values
args = {
'address': baremetal_fakes.baremetal_port_address,
'node_uuid': baremetal_fakes.baremetal_uuid,
'name': 'portname1'
}
self.baremetal_mock.port.create.assert_called_once_with(**args)
class TestShowBaremetalPort(TestBaremetalPort):
def setUp(self):
@ -427,6 +454,18 @@ class TestBaremetalPortUnset(TestBaremetalPort):
'port',
[{'path': '/is_smartnic', 'op': 'add', 'value': 'False'}])
def test_baremetal_port_unset_name(self):
arglist = ['port', '--name']
verifylist = [('port', 'port'),
('name', True)]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.take_action(parsed_args)
self.baremetal_mock.port.update.assert_called_once_with(
'port',
[{'path': '/name', 'op': 'remove'}])
class TestBaremetalPortSet(TestBaremetalPort):
def setUp(self):
@ -595,6 +634,22 @@ class TestBaremetalPortSet(TestBaremetalPort):
[{'path': '/is_smartnic', 'value': 'True',
'op': 'add'}])
def test_baremetal_port_set_name(self):
arglist = [
baremetal_fakes.baremetal_port_uuid,
'--name', 'portname2']
verifylist = [
('port', baremetal_fakes.baremetal_port_uuid),
('name', 'portname2')]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.take_action(parsed_args)
self.baremetal_mock.port.update.assert_called_once_with(
baremetal_fakes.baremetal_port_uuid,
[{'path': '/name', 'value': 'portname2',
'op': 'add'}])
class TestBaremetalPortDelete(TestBaremetalPort):
def setUp(self):

View File

@ -0,0 +1,4 @@
---
fixes:
- |
Fixes the issue that create port with name does not take effect.