Skip to content

Commit 894df67

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add 'data_plane_status' option to Port classes"
2 parents bca8d57 + 1ae904a commit 894df67

5 files changed

Lines changed: 95 additions & 0 deletions

File tree

doc/source/cli/command-objects/port.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ Set port properties
232232
[--dns-name <dns-name>]
233233
[--allowed-address ip-address=<ip-address>[,mac-address=<mac-address>]]
234234
[--no-allowed-address]
235+
[--data-plane-status <status>]
235236
<port>
236237
237238
.. option:: --description <description>
@@ -335,6 +336,12 @@ Set port properties
335336
(Specify both --allowed-address and --no-allowed-address
336337
to overwrite the current allowed-address pairs)
337338
339+
.. option:: --data-plane-status
340+
341+
Set data plane status of this port (ACTIVE | DOWN).
342+
Unset it to None with the 'port unset' command
343+
(requires data plane status extension)
344+
338345
.. _port_set-port:
339346
.. describe:: <port>
340347
@@ -370,6 +377,7 @@ Unset port properties
370377
[--security-group <security-group> [...]]
371378
[--allowed-address ip-address=<ip-address>[,mac-address=<mac-address>] [...]]
372379
[--qos-policy]
380+
[--data-plane-status]
373381
<port>
374382
375383
.. option:: --fixed-ip subnet=<subnet>,ip-address=<ip-address>
@@ -398,6 +406,10 @@ Unset port properties
398406
399407
Remove the QoS policy attached to the port
400408
409+
.. option:: --data-plane-status
410+
411+
Clear existing information of data plane status
412+
401413
.. _port_unset-port:
402414
.. describe:: <port>
403415

openstackclient/network/v2/port.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,15 @@ def get_parser(self, prog_name):
685685
"(Specify both --allowed-address and --no-allowed-address"
686686
"to overwrite the current allowed-address pairs)")
687687
)
688+
parser.add_argument(
689+
'--data-plane-status',
690+
metavar='<status>',
691+
choices=['ACTIVE', 'DOWN'],
692+
help=_("Set data plane status of this port (ACTIVE | DOWN). "
693+
"Unset it to None with the 'port unset' command "
694+
"(requires data plane status extension)")
695+
)
696+
688697
return parser
689698

690699
def take_action(self, parsed_args):
@@ -737,6 +746,8 @@ def take_action(self, parsed_args):
737746
attrs['allowed_address_pairs'].extend(
738747
_convert_address_pairs(parsed_args)
739748
)
749+
if parsed_args.data_plane_status:
750+
attrs['data_plane_status'] = parsed_args.data_plane_status
740751

741752
client.update_port(obj, **attrs)
742753

@@ -816,6 +827,11 @@ def get_parser(self, prog_name):
816827
default=False,
817828
help=_("Remove the QoS policy attached to the port")
818829
)
830+
parser.add_argument(
831+
'--data-plane-status',
832+
action='store_true',
833+
help=_("Clear existing information of data plane status")
834+
)
819835

820836
return parser
821837

@@ -867,6 +883,8 @@ def take_action(self, parsed_args):
867883
attrs['allowed_address_pairs'] = tmp_addr_pairs
868884
if parsed_args.qos_policy:
869885
attrs['qos_policy_id'] = None
886+
if parsed_args.data_plane_status:
887+
attrs['data_plane_status'] = None
870888

871889
if attrs:
872890
client.update_port(obj, **attrs)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,7 @@ def create_one_port(attrs=None):
558558
'binding:vif_details': {},
559559
'binding:vif_type': 'ovs',
560560
'binding:vnic_type': 'normal',
561+
'data_plane_status': None,
561562
'description': 'description-' + uuid.uuid4().hex,
562563
'device_id': 'device-id-' + uuid.uuid4().hex,
563564
'device_owner': 'compute:nova',

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

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def _get_common_cols_data(self, fake_port):
4444
'binding_vif_details',
4545
'binding_vif_type',
4646
'binding_vnic_type',
47+
'data_plane_status',
4748
'description',
4849
'device_id',
4950
'device_owner',
@@ -70,6 +71,7 @@ def _get_common_cols_data(self, fake_port):
7071
utils.format_dict(fake_port.binding_vif_details),
7172
fake_port.binding_vif_type,
7273
fake_port.binding_vnic_type,
74+
fake_port.data_plane_status,
7375
fake_port.description,
7476
fake_port.device_id,
7577
fake_port.device_owner,
@@ -1371,6 +1373,40 @@ def test_set_port_with_qos(self):
13711373
self.network.update_port.assert_called_once_with(_testport, **attrs)
13721374
self.assertIsNone(result)
13731375

1376+
def test_set_port_data_plane_status(self):
1377+
_testport = network_fakes.FakePort.create_one_port(
1378+
{'data_plane_status': None})
1379+
self.network.find_port = mock.Mock(return_value=_testport)
1380+
arglist = [
1381+
'--data-plane-status', 'ACTIVE',
1382+
_testport.name,
1383+
]
1384+
verifylist = [
1385+
('data_plane_status', 'ACTIVE'),
1386+
('port', _testport.name),
1387+
]
1388+
1389+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1390+
result = self.cmd.take_action(parsed_args)
1391+
1392+
attrs = {
1393+
'data_plane_status': 'ACTIVE',
1394+
}
1395+
1396+
self.network.update_port.assert_called_once_with(_testport, **attrs)
1397+
self.assertIsNone(result)
1398+
1399+
def test_set_port_invalid_data_plane_status_value(self):
1400+
arglist = [
1401+
'--data-plane-status', 'Spider-Man',
1402+
'test-port',
1403+
]
1404+
self.assertRaises(tests_utils.ParserException,
1405+
self.check_parser,
1406+
self.cmd,
1407+
arglist,
1408+
None)
1409+
13741410

13751411
class TestShowPort(TestPort):
13761412

@@ -1573,3 +1609,26 @@ def test_unset_port_allowed_address_pair_not_existent(self):
15731609
self.assertRaises(exceptions.CommandError,
15741610
self.cmd.take_action,
15751611
parsed_args)
1612+
1613+
def test_unset_port_data_plane_status(self):
1614+
_fake_port = network_fakes.FakePort.create_one_port(
1615+
{'data_plane_status': 'ACTIVE'})
1616+
self.network.find_port = mock.Mock(return_value=_fake_port)
1617+
arglist = [
1618+
'--data-plane-status',
1619+
_fake_port.name,
1620+
]
1621+
verifylist = [
1622+
('data_plane_status', True),
1623+
('port', _fake_port.name),
1624+
]
1625+
1626+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1627+
result = self.cmd.take_action(parsed_args)
1628+
1629+
attrs = {
1630+
'data_plane_status': None,
1631+
}
1632+
1633+
self.network.update_port.assert_called_once_with(_fake_port, **attrs)
1634+
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+
- Add ``--data-plane-status`` option to ``port set`` and ``port unset``
4+
commands.
5+
[Bug `1684989 <https://bugs.launchpad.net/bugs/1684989>`_]

0 commit comments

Comments
 (0)