Add QoS support to Network object.

Added "qos_policy" parameter to Network class.

Change-Id: Idc00f2792eef5b1f0910084d95cf9a8e83fe818c
Closes-Bug: 1627069
This commit is contained in:
Rodolfo Alonso Hernandez 2016-09-26 11:12:07 +01:00
parent f4536e708d
commit 4132392c2f
5 changed files with 69 additions and 0 deletions

View File

@ -30,6 +30,7 @@ Create new network
[--provider-network-type <provider-network-type>]
[--provider-physical-network <provider-physical-network>]
[--provider-segment <provider-segment>]
[--qos-policy <qos-policy>]
[--transparent-vlan | --no-transparent-vlan]
<name>
@ -144,6 +145,12 @@ Create new network
*Network version 2 only*
.. option:: --qos-policy <qos-policy>
QoS policy to attach to this network (name or ID)
*Network version 2 only*
.. option:: --transparent-vlan
Make the network VLAN transparent
@ -303,6 +310,7 @@ Set network properties
[--provider-network-type <provider-network-type>]
[--provider-physical-network <provider-physical-network>]
[--provider-segment <provider-segment>]
[--qos-policy <qos-policy> | --no-qos-policy]
[--transparent-vlan | --no-transparent-vlan]
<network>
@ -370,6 +378,14 @@ Set network properties
VLAN ID for VLAN networks or Tunnel ID for GRE/VXLAN networks
.. option:: --qos-policy <qos-policy>
QoS policy to attach to this network (name or ID)
.. option:: --no-qos-policy
Remove the QoS policy attached to this network
.. option:: --transparent-vlan
Make the network VLAN transparent

View File

@ -99,6 +99,13 @@ def _get_attrs(client_manager, parsed_args):
attrs['provider:physical_network'] = parsed_args.physical_network
if parsed_args.segmentation_id:
attrs['provider:segmentation_id'] = parsed_args.segmentation_id
if parsed_args.qos_policy is not None:
network_client = client_manager.network
_qos_policy = network_client.find_qos_policy(parsed_args.qos_policy,
ignore_missing=False)
attrs['qos_policy_id'] = _qos_policy.id
if 'no_qos_policy' in parsed_args and parsed_args.no_qos_policy:
attrs['qos_policy_id'] = None
# Update VLAN Transparency for networks
if parsed_args.transparent_vlan:
attrs['vlan_transparent'] = True
@ -249,6 +256,11 @@ class CreateNetwork(common.NetworkAndComputeShowOne):
help=_("Do not use the network as the default external network "
"(default)")
)
parser.add_argument(
'--qos-policy',
metavar='<qos-policy>',
help=_("QoS policy to attach to this network (name or ID)")
)
_add_additional_network_options(parser)
return parser
@ -572,6 +584,17 @@ class SetNetwork(command.Command):
action='store_true',
help=_("Do not use the network as the default external network")
)
qos_group = parser.add_mutually_exclusive_group()
qos_group.add_argument(
'--qos-policy',
metavar='<qos-policy>',
help=_("QoS policy to attach to this network (name or ID)")
)
qos_group.add_argument(
'--no-qos-policy',
action='store_true',
help=_("Remove the QoS policy attached to this network")
)
_add_additional_network_options(parser)
return parser

View File

@ -299,6 +299,7 @@ class FakeNetwork(object):
'availability_zone_hints': [],
'is_default': False,
'port_security_enabled': True,
'qos_policy_id': 'qos-policy-id-' + uuid.uuid4().hex,
}
# Overwrite default attributes.

View File

@ -53,6 +53,8 @@ class TestCreateNetworkIdentityV3(TestNetwork):
'availability_zone_hints': ["nova"],
}
)
qos_policy = (network_fakes.FakeNetworkQosPolicy.
create_one_qos_policy(attrs={'id': _network.qos_policy_id}))
columns = (
'admin_state_up',
@ -67,6 +69,7 @@ class TestCreateNetworkIdentityV3(TestNetwork):
'provider_network_type',
'provider_physical_network',
'provider_segmentation_id',
'qos_policy_id',
'router:external',
'shared',
'status',
@ -86,6 +89,7 @@ class TestCreateNetworkIdentityV3(TestNetwork):
_network.provider_network_type,
_network.provider_physical_network,
_network.provider_segmentation_id,
_network.qos_policy_id,
network._format_router_external(_network.is_router_external),
_network.shared,
_network.status,
@ -102,6 +106,7 @@ class TestCreateNetworkIdentityV3(TestNetwork):
self.projects_mock.get.return_value = self.project
self.domains_mock.get.return_value = self.domain
self.network.find_qos_policy = mock.Mock(return_value=self.qos_policy)
def test_create_no_options(self):
arglist = []
@ -144,6 +149,7 @@ class TestCreateNetworkIdentityV3(TestNetwork):
"--provider-network-type", "vlan",
"--provider-physical-network", "physnet1",
"--provider-segment", "400",
"--qos-policy", self.qos_policy.id,
"--transparent-vlan",
"--enable-port-security",
self._network.name,
@ -160,6 +166,7 @@ class TestCreateNetworkIdentityV3(TestNetwork):
('provider_network_type', 'vlan'),
('physical_network', 'physnet1'),
('segmentation_id', '400'),
('qos_policy', self.qos_policy.id),
('transparent_vlan', True),
('enable_port_security', True),
('name', self._network.name),
@ -180,6 +187,7 @@ class TestCreateNetworkIdentityV3(TestNetwork):
'provider:network_type': 'vlan',
'provider:physical_network': 'physnet1',
'provider:segmentation_id': '400',
'qos_policy_id': self.qos_policy.id,
'vlan_transparent': True,
'port_security_enabled': True,
})
@ -235,6 +243,7 @@ class TestCreateNetworkIdentityV2(TestNetwork):
'provider_network_type',
'provider_physical_network',
'provider_segmentation_id',
'qos_policy_id',
'router:external',
'shared',
'status',
@ -254,6 +263,7 @@ class TestCreateNetworkIdentityV2(TestNetwork):
_network.provider_network_type,
_network.provider_physical_network,
_network.provider_segmentation_id,
_network.qos_policy_id,
network._format_router_external(_network.is_router_external),
_network.shared,
_network.status,
@ -745,6 +755,8 @@ class TestSetNetwork(TestNetwork):
# The network to set.
_network = network_fakes.FakeNetwork.create_one_network()
qos_policy = (network_fakes.FakeNetworkQosPolicy.
create_one_qos_policy(attrs={'id': _network.qos_policy_id}))
def setUp(self):
super(TestSetNetwork, self).setUp()
@ -752,6 +764,7 @@ class TestSetNetwork(TestNetwork):
self.network.update_network = mock.Mock(return_value=None)
self.network.find_network = mock.Mock(return_value=self._network)
self.network.find_qos_policy = mock.Mock(return_value=self.qos_policy)
# Get the command object to test
self.cmd = network.SetNetwork(self.app, self.namespace)
@ -770,6 +783,7 @@ class TestSetNetwork(TestNetwork):
'--provider-segment', '400',
'--no-transparent-vlan',
'--enable-port-security',
'--qos-policy', self.qos_policy.name,
]
verifylist = [
('network', self._network.name),
@ -784,6 +798,7 @@ class TestSetNetwork(TestNetwork):
('segmentation_id', '400'),
('no_transparent_vlan', True),
('enable_port_security', True),
('qos_policy', self.qos_policy.name),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -801,6 +816,7 @@ class TestSetNetwork(TestNetwork):
'provider:segmentation_id': '400',
'vlan_transparent': False,
'port_security_enabled': True,
'qos_policy_id': self.qos_policy.id,
}
self.network.update_network.assert_called_once_with(
self._network, **attrs)
@ -813,6 +829,7 @@ class TestSetNetwork(TestNetwork):
'--no-share',
'--internal',
'--disable-port-security',
'--no-qos-policy',
]
verifylist = [
('network', self._network.name),
@ -820,6 +837,7 @@ class TestSetNetwork(TestNetwork):
('no_share', True),
('internal', True),
('disable_port_security', True),
('no_qos_policy', True),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -830,6 +848,7 @@ class TestSetNetwork(TestNetwork):
'shared': False,
'router:external': False,
'port_security_enabled': False,
'qos_policy_id': None,
}
self.network.update_network.assert_called_once_with(
self._network, **attrs)
@ -866,6 +885,7 @@ class TestShowNetwork(TestNetwork):
'provider_network_type',
'provider_physical_network',
'provider_segmentation_id',
'qos_policy_id',
'router:external',
'shared',
'status',
@ -885,6 +905,7 @@ class TestShowNetwork(TestNetwork):
_network.provider_network_type,
_network.provider_physical_network,
_network.provider_segmentation_id,
_network.qos_policy_id,
network._format_router_external(_network.is_router_external),
_network.shared,
_network.status,

View File

@ -0,0 +1,8 @@
---
features:
- |
Add QoS support for Network commands.
The new parameter ``qos-policy`` is added to ``network create`` and
``network set`` commands. This parameter is the name or the ID of the
network QoS policy to attach to this network.
[Bug `1627069 <https://bugs.launchpad.net/python-openstackclient/+bug/1627069>`_]