Merge "Add device ID and device owner to port unset"

This commit is contained in:
Zuul
2025-08-15 03:29:28 +00:00
committed by Gerrit Code Review
3 changed files with 61 additions and 0 deletions

View File

@@ -1316,6 +1316,18 @@ class UnsetPort(common.NeutronUnsetCommandWithExtraArgs):
default=False,
help=_("Clear hints for the port"),
)
parser.add_argument(
'--device',
action='store_true',
default=False,
help=_("Clear device ID for the port."),
)
parser.add_argument(
'--device-owner',
action='store_true',
default=False,
help=_("Clear device owner for the port."),
)
_tag.add_tag_option_to_parser_for_unset(parser, _('port'))
parser.add_argument(
'port',
@@ -1382,6 +1394,10 @@ class UnsetPort(common.NeutronUnsetCommandWithExtraArgs):
attrs['binding:host_id'] = None
if parsed_args.hints:
attrs['hints'] = None
if parsed_args.device:
attrs['device_id'] = ''
if parsed_args.device_owner:
attrs['device_owner'] = ''
attrs.update(
self._parse_extra_properties(parsed_args.extra_properties)

View File

@@ -3014,3 +3014,43 @@ class TestUnsetPort(TestPort):
**{'hints': None},
)
self.assertIsNone(result)
def test_unset_device(self):
testport = network_fakes.create_one_port()
self.network_client.find_port = mock.Mock(return_value=testport)
arglist = [
'--device',
testport.name,
]
verifylist = [
('device', True),
('port', testport.name),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
self.network_client.update_port.assert_called_once_with(
testport,
**{'device_id': ''},
)
self.assertIsNone(result)
def test_unset_device_owner(self):
testport = network_fakes.create_one_port()
self.network_client.find_port = mock.Mock(return_value=testport)
arglist = [
'--device-owner',
testport.name,
]
verifylist = [
('device_owner', True),
('port', testport.name),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
self.network_client.update_port.assert_called_once_with(
testport,
**{'device_owner': ''},
)
self.assertIsNone(result)

View File

@@ -0,0 +1,5 @@
---
features:
- |
Added ``--device`` and ``--device-owner`` parameter to the
``port unset`` command.