Skip to content

Commit 8983373

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add "qos-policy" option to "port create" & "port set""
2 parents 27f96a3 + 5ff2cfd commit 8983373

5 files changed

Lines changed: 112 additions & 3 deletions

File tree

doc/source/command-objects/port.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Create new port
3030
[--security-group <security-group> | --no-security-group]
3131
[--dns-name <dns-name>]
3232
[--allowed-address ip-address=<ip-address>[,mac-address=<mac-address>]]
33+
[--qos-policy <qos-policy>]
3334
[--project <project> [--project-domain <project-domain>]]
3435
[--enable-port-security | --disable-port-security]
3536
<name>
@@ -104,6 +105,10 @@ Create new port
104105
ip-address=<ip-address>[,mac-address=<mac-address>]
105106
(repeat option to set multiple allowed-address pairs)
106107
108+
.. option:: --qos-policy <qos-policy>
109+
110+
Attach QoS policy to this port (name or ID)
111+
107112
.. option:: --project <project>
108113
109114
Owner's project (name or ID)
@@ -217,6 +222,7 @@ Set port properties
217222
[--binding-profile <binding-profile>]
218223
[--no-binding-profile]
219224
[--host <host-id>]
225+
[--qos-policy <qos-policy>]
220226
[--enable | --disable]
221227
[--name <name>]
222228
[--mac-address <mac-address>]
@@ -274,6 +280,10 @@ Set port properties
274280
275281
Allocate port on host ``<host-id>`` (ID only)
276282
283+
.. option:: --qos-policy <qos-policy>
284+
285+
Attach QoS policy to this port (name or ID)
286+
277287
.. option:: --enable
278288
279289
Enable port
@@ -359,6 +369,7 @@ Unset port properties
359369
[--binding-profile <binding-profile-key> [...]]
360370
[--security-group <security-group> [...]]
361371
[--allowed-address ip-address=<ip-address>[,mac-address=<mac-address>] [...]]
372+
[--qos-policy]
362373
<port>
363374
364375
.. option:: --fixed-ip subnet=<subnet>,ip-address=<ip-address>
@@ -383,6 +394,10 @@ Unset port properties
383394
ip-address=<ip-address>[,mac-address=<mac-address>]
384395
(repeat option to unset multiple allowed-address pairs)
385396
397+
.. option:: --qos-policy
398+
399+
Remove the QoS policy attached to the port
400+
386401
.. _port_unset-port:
387402
.. describe:: <port>
388403

openstackclient/network/v2/port.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,13 @@ def _get_attrs(client_manager, parsed_args):
155155
if parsed_args.enable_port_security:
156156
attrs['port_security_enabled'] = True
157157

158+
if 'no_qos_policy' in parsed_args and parsed_args.no_qos_policy:
159+
attrs['qos_policy_id'] = None
160+
161+
if parsed_args.qos_policy:
162+
attrs['qos_policy_id'] = client_manager.network.find_qos_policy(
163+
parsed_args.qos_policy, ignore_missing=False).id
164+
158165
return attrs
159166

160167

@@ -337,7 +344,7 @@ def get_parser(self, prog_name):
337344
help=_("Name of this port")
338345
)
339346
# TODO(singhj): Add support for extended options:
340-
# qos,dhcp
347+
# dhcp
341348
secgroups = parser.add_mutually_exclusive_group()
342349
secgroups.add_argument(
343350
'--security-group',
@@ -353,6 +360,11 @@ def get_parser(self, prog_name):
353360
action='store_true',
354361
help=_("Associate no security groups with this port")
355362
)
363+
parser.add_argument(
364+
'--qos-policy',
365+
metavar='<qos-policy>',
366+
help=_("Attach QoS policy to this port (name or ID)")
367+
)
356368
port_security = parser.add_mutually_exclusive_group()
357369
port_security.add_argument(
358370
'--enable-port-security',
@@ -403,6 +415,9 @@ def take_action(self, parsed_args):
403415
attrs['allowed_address_pairs'] = (
404416
_convert_address_pairs(parsed_args))
405417

418+
if parsed_args.qos_policy:
419+
attrs['qos_policy_id'] = client.find_qos_policy(
420+
parsed_args.qos_policy, ignore_missing=False).id
406421
obj = client.create_port(**attrs)
407422
display_columns, columns = _get_columns(obj)
408423
data = utils.get_item_properties(obj, columns, formatters=_formatters)
@@ -619,6 +634,11 @@ def get_parser(self, prog_name):
619634
"Specify both --binding-profile and --no-binding-profile "
620635
"to overwrite the current binding:profile information.")
621636
)
637+
parser.add_argument(
638+
'--qos-policy',
639+
metavar='<qos-policy>',
640+
help=_("Attach QoS policy to this port (name or ID)")
641+
)
622642
parser.add_argument(
623643
'port',
624644
metavar="<port>",
@@ -675,8 +695,8 @@ def take_action(self, parsed_args):
675695
client = self.app.client_manager.network
676696

677697
_prepare_fixed_ips(self.app.client_manager, parsed_args)
678-
attrs = _get_attrs(self.app.client_manager, parsed_args)
679698
obj = client.find_port(parsed_args.port, ignore_missing=False)
699+
attrs = _get_attrs(self.app.client_manager, parsed_args)
680700

681701
if parsed_args.no_binding_profile:
682702
attrs['binding:profile'] = {}
@@ -794,6 +814,12 @@ def get_parser(self, prog_name):
794814
"[,mac-address=<mac-address>] (repeat option to set "
795815
"multiple allowed-address pairs)")
796816
)
817+
parser.add_argument(
818+
'--qos-policy',
819+
action='store_true',
820+
default=False,
821+
help=_("Remove the QoS policy attached to the port")
822+
)
797823

798824
return parser
799825

@@ -843,6 +869,8 @@ def take_action(self, parsed_args):
843869
msg = _("Port does not contain allowed-address-pair %s") % addr
844870
raise exceptions.CommandError(msg)
845871
attrs['allowed_address_pairs'] = tmp_addr_pairs
872+
if parsed_args.qos_policy:
873+
attrs['qos_policy_id'] = None
846874

847875
if attrs:
848876
client.update_port(obj, **attrs)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,7 @@ def create_one_port(attrs=None):
572572
'security_group_ids': [],
573573
'status': 'ACTIVE',
574574
'tenant_id': 'project-id-' + uuid.uuid4().hex,
575+
'qos_policy_id': 'qos-policy-id-' + uuid.uuid4().hex,
575576
}
576577

577578
# Overwrite default attributes.
@@ -590,6 +591,7 @@ def create_one_port(attrs=None):
590591
port.is_port_security_enabled = port_attrs['port_security_enabled']
591592
port.project_id = port_attrs['tenant_id']
592593
port.security_group_ids = port_attrs['security_group_ids']
594+
port.qos_policy_id = port_attrs['qos_policy_id']
593595

594596
return port
595597

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

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def _get_common_cols_data(self, fake_port):
5757
'network_id',
5858
'port_security_enabled',
5959
'project_id',
60+
'qos_policy_id',
6061
'security_group_ids',
6162
'status',
6263
)
@@ -82,6 +83,7 @@ def _get_common_cols_data(self, fake_port):
8283
fake_port.network_id,
8384
fake_port.port_security_enabled,
8485
fake_port.project_id,
86+
fake_port.qos_policy_id,
8587
utils.format_list(fake_port.security_group_ids),
8688
fake_port.status,
8789
)
@@ -422,6 +424,35 @@ def test_create_port_with_allowed_address_pair(self):
422424
self.assertEqual(ref_columns, columns)
423425
self.assertEqual(ref_data, data)
424426

427+
def test_create_port_with_qos(self):
428+
qos_policy = network_fakes.FakeNetworkQosPolicy.create_one_qos_policy()
429+
self.network.find_qos_policy = mock.Mock(return_value=qos_policy)
430+
arglist = [
431+
'--network', self._port.network_id,
432+
'--qos-policy', qos_policy.id,
433+
'test-port',
434+
]
435+
verifylist = [
436+
('network', self._port.network_id,),
437+
('enable', True),
438+
('qos_policy', qos_policy.id),
439+
('name', 'test-port'),
440+
]
441+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
442+
443+
columns, data = (self.cmd.take_action(parsed_args))
444+
445+
self.network.create_port.assert_called_once_with(**{
446+
'admin_state_up': True,
447+
'network_id': self._port.network_id,
448+
'qos_policy_id': qos_policy.id,
449+
'name': 'test-port',
450+
})
451+
452+
ref_columns, ref_data = self._get_common_cols_data(self._port)
453+
self.assertEqual(ref_columns, columns)
454+
self.assertEqual(ref_data, data)
455+
425456
def test_create_port_security_enabled(self):
426457
arglist = [
427458
'--network', self._port.network_id,
@@ -1316,6 +1347,30 @@ def test_set_port_security_disabled(self):
13161347
'port_security_enabled': False,
13171348
})
13181349

1350+
def test_set_port_with_qos(self):
1351+
qos_policy = network_fakes.FakeNetworkQosPolicy.create_one_qos_policy()
1352+
self.network.find_qos_policy = mock.Mock(return_value=qos_policy)
1353+
_testport = network_fakes.FakePort.create_one_port(
1354+
{'qos_policy_id': None})
1355+
self.network.find_port = mock.Mock(return_value=_testport)
1356+
arglist = [
1357+
'--qos-policy', qos_policy.id,
1358+
_testport.name,
1359+
]
1360+
verifylist = [
1361+
('qos_policy', qos_policy.id),
1362+
('port', _testport.name),
1363+
]
1364+
1365+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1366+
result = self.cmd.take_action(parsed_args)
1367+
1368+
attrs = {
1369+
'qos_policy_id': qos_policy.id,
1370+
}
1371+
self.network.update_port.assert_called_once_with(_testport, **attrs)
1372+
self.assertIsNone(result)
1373+
13191374

13201375
class TestShowPort(TestPort):
13211376

@@ -1379,13 +1434,15 @@ def test_unset_port_parameters(self):
13791434
'--fixed-ip',
13801435
'subnet=042eb10a-3a18-4658-ab-cf47c8d03152,ip-address=1.0.0.0',
13811436
'--binding-profile', 'Superman',
1437+
'--qos-policy',
13821438
self._testport.name,
13831439
]
13841440
verifylist = [
13851441
('fixed_ip', [{
13861442
'subnet': '042eb10a-3a18-4658-ab-cf47c8d03152',
13871443
'ip-address': '1.0.0.0'}]),
13881444
('binding_profile', ['Superman']),
1445+
('qos_policy', True),
13891446
]
13901447

13911448
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@@ -1395,7 +1452,8 @@ def test_unset_port_parameters(self):
13951452
'fixed_ips': [{
13961453
'subnet_id': '042eb10a-3a18-4658-ab-cf47c8d03152',
13971454
'ip_address': '0.0.0.1'}],
1398-
'binding:profile': {'batman': 'Joker'}
1455+
'binding:profile': {'batman': 'Joker'},
1456+
'qos_policy_id': None
13991457
}
14001458
self.network.update_port.assert_called_once_with(
14011459
self._testport, **attrs)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
features:
3+
- |
4+
Add ``--qos-policy`` option to ``port create``, ``port set`` and
5+
``port unset`` commands.
6+
[Bug `1612136 <https://bugs.launchpad.net/python-openstackclient/+bug/1612136>`_]

0 commit comments

Comments
 (0)