Skip to content

Commit a8751b0

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Add device ID and device owner to port unset"
2 parents 2a492fb + f1bd417 commit a8751b0

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

openstackclient/network/v2/port.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,6 +1316,18 @@ def get_parser(self, prog_name):
13161316
default=False,
13171317
help=_("Clear hints for the port"),
13181318
)
1319+
parser.add_argument(
1320+
'--device',
1321+
action='store_true',
1322+
default=False,
1323+
help=_("Clear device ID for the port."),
1324+
)
1325+
parser.add_argument(
1326+
'--device-owner',
1327+
action='store_true',
1328+
default=False,
1329+
help=_("Clear device owner for the port."),
1330+
)
13191331
_tag.add_tag_option_to_parser_for_unset(parser, _('port'))
13201332
parser.add_argument(
13211333
'port',
@@ -1382,6 +1394,10 @@ def take_action(self, parsed_args):
13821394
attrs['binding:host_id'] = None
13831395
if parsed_args.hints:
13841396
attrs['hints'] = None
1397+
if parsed_args.device:
1398+
attrs['device_id'] = ''
1399+
if parsed_args.device_owner:
1400+
attrs['device_owner'] = ''
13851401

13861402
attrs.update(
13871403
self._parse_extra_properties(parsed_args.extra_properties)

openstackclient/tests/unit/network/v2/test_port.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3014,3 +3014,43 @@ def test_unset_hints(self):
30143014
**{'hints': None},
30153015
)
30163016
self.assertIsNone(result)
3017+
3018+
def test_unset_device(self):
3019+
testport = network_fakes.create_one_port()
3020+
self.network_client.find_port = mock.Mock(return_value=testport)
3021+
arglist = [
3022+
'--device',
3023+
testport.name,
3024+
]
3025+
verifylist = [
3026+
('device', True),
3027+
('port', testport.name),
3028+
]
3029+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
3030+
result = self.cmd.take_action(parsed_args)
3031+
3032+
self.network_client.update_port.assert_called_once_with(
3033+
testport,
3034+
**{'device_id': ''},
3035+
)
3036+
self.assertIsNone(result)
3037+
3038+
def test_unset_device_owner(self):
3039+
testport = network_fakes.create_one_port()
3040+
self.network_client.find_port = mock.Mock(return_value=testport)
3041+
arglist = [
3042+
'--device-owner',
3043+
testport.name,
3044+
]
3045+
verifylist = [
3046+
('device_owner', True),
3047+
('port', testport.name),
3048+
]
3049+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
3050+
result = self.cmd.take_action(parsed_args)
3051+
3052+
self.network_client.update_port.assert_called_once_with(
3053+
testport,
3054+
**{'device_owner': ''},
3055+
)
3056+
self.assertIsNone(result)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
features:
3+
- |
4+
Added ``--device`` and ``--device-owner`` parameter to the
5+
``port unset`` command.

0 commit comments

Comments
 (0)