Skip to content

Commit 9b19a35

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add --enable/disable-port-security option to port set and port create"
2 parents 3a509be + 246f60a commit 9b19a35

4 files changed

Lines changed: 136 additions & 0 deletions

File tree

doc/source/command-objects/port.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Create new port
2929
[--mac-address <mac-address>]
3030
[--security-group <security-group> | --no-security-group]
3131
[--project <project> [--project-domain <project-domain>]]
32+
[--enable-port-security | --disable-port-security]
3233
<name>
3334
3435
.. option:: --network <network>
@@ -99,6 +100,14 @@ Create new port
99100
Domain the project belongs to (name or ID).
100101
This can be used in case collisions between project names exist.
101102
103+
.. option:: --enable-port-security
104+
105+
Enable port security for this port (Default)
106+
107+
.. option:: --disable-port-security
108+
109+
Disable port security for this port
110+
102111
.. _port_create-name:
103112
.. describe:: <name>
104113
@@ -182,6 +191,7 @@ Set port properties
182191
[--name <name>]
183192
[--security-group <security-group>]
184193
[--no-security-group]
194+
[--enable-port-security | --disable-port-security]
185195
<port>
186196
187197
.. option:: --description <description>
@@ -251,6 +261,14 @@ Set port properties
251261
252262
Clear existing security groups associated with this port
253263
264+
.. option:: --enable-port-security
265+
266+
Enable port security for this port
267+
268+
.. option:: --disable-port-security
269+
270+
Disable port security for this port
271+
254272
.. _port_set-port:
255273
.. describe:: <port>
256274

openstackclient/network/v2/port.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ def _get_attrs(client_manager, parsed_args):
148148
).id
149149
attrs['tenant_id'] = project_id
150150

151+
if parsed_args.disable_port_security:
152+
attrs['port_security_enabled'] = False
153+
154+
if parsed_args.enable_port_security:
155+
attrs['port_security_enabled'] = True
156+
151157
return attrs
152158

153159

@@ -304,6 +310,17 @@ def get_parser(self, prog_name):
304310
action='store_true',
305311
help=_("Associate no security groups with this port")
306312
)
313+
port_security = parser.add_mutually_exclusive_group()
314+
port_security.add_argument(
315+
'--enable-port-security',
316+
action='store_true',
317+
help=_("Enable port security for this port (Default)")
318+
)
319+
port_security.add_argument(
320+
'--disable-port-security',
321+
action='store_true',
322+
help=_("Disable port security for this port")
323+
)
307324

308325
return parser
309326

@@ -526,6 +543,17 @@ def get_parser(self, prog_name):
526543
action='store_true',
527544
help=_("Clear existing security groups associated with this port")
528545
)
546+
port_security = parser.add_mutually_exclusive_group()
547+
port_security.add_argument(
548+
'--enable-port-security',
549+
action='store_true',
550+
help=_("Enable port security for this port")
551+
)
552+
port_security.add_argument(
553+
'--disable-port-security',
554+
action='store_true',
555+
help=_("Disable port security for this port")
556+
)
529557

530558
return parser
531559

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

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,54 @@ def test_create_with_no_secuirty_groups(self):
320320
self.assertEqual(ref_columns, columns)
321321
self.assertEqual(ref_data, data)
322322

323+
def test_create_port_security_enabled(self):
324+
arglist = [
325+
'--network', self._port.network_id,
326+
'--enable-port-security',
327+
'test-port',
328+
]
329+
verifylist = [
330+
('network', self._port.network_id,),
331+
('enable', True),
332+
('enable_port_security', True),
333+
('name', 'test-port'),
334+
]
335+
336+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
337+
338+
self.cmd.take_action(parsed_args)
339+
340+
self.network.create_port.assert_called_once_with(**{
341+
'admin_state_up': True,
342+
'network_id': self._port.network_id,
343+
'port_security_enabled': True,
344+
'name': 'test-port',
345+
})
346+
347+
def test_create_port_security_disabled(self):
348+
arglist = [
349+
'--network', self._port.network_id,
350+
'--disable-port-security',
351+
'test-port',
352+
]
353+
verifylist = [
354+
('network', self._port.network_id,),
355+
('enable', True),
356+
('disable_port_security', True),
357+
('name', 'test-port'),
358+
]
359+
360+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
361+
362+
self.cmd.take_action(parsed_args)
363+
364+
self.network.create_port.assert_called_once_with(**{
365+
'admin_state_up': True,
366+
'network_id': self._port.network_id,
367+
'port_security_enabled': False,
368+
'name': 'test-port',
369+
})
370+
323371

324372
class TestDeletePort(TestPort):
325373

@@ -898,6 +946,42 @@ def test_overwrite_security_group(self):
898946
self.network.update_port.assert_called_once_with(_testport, **attrs)
899947
self.assertIsNone(result)
900948

949+
def test_port_security_enabled(self):
950+
arglist = [
951+
'--enable-port-security',
952+
self._port.id,
953+
]
954+
verifylist = [
955+
('enable_port_security', True),
956+
('port', self._port.id,)
957+
]
958+
959+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
960+
961+
self.cmd.take_action(parsed_args)
962+
963+
self.network.update_port.assert_called_once_with(self._port, **{
964+
'port_security_enabled': True,
965+
})
966+
967+
def test_port_security_disabled(self):
968+
arglist = [
969+
'--disable-port-security',
970+
self._port.id,
971+
]
972+
verifylist = [
973+
('disable_port_security', True),
974+
('port', self._port.id,)
975+
]
976+
977+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
978+
979+
self.cmd.take_action(parsed_args)
980+
981+
self.network.update_port.assert_called_once_with(self._port, **{
982+
'port_security_enabled': False,
983+
})
984+
901985

902986
class TestShowPort(TestPort):
903987

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
features:
3+
- |
4+
Added ``--enable-port-security`` and ``--disable-port-security``
5+
options to ``port set`` and ``port create`` commands.
6+
[Blueprint :oscbp:`network-commands-options`]

0 commit comments

Comments
 (0)