Skip to content

Commit 9e1e7e1

Browse files
author
Rodolfo Alonso Hernandez
committed
Add support for QoS rule type commands
Added following commands: - network qos rule type list Closes-Bug: 1612194 Depends-On: Iecf7bc7acd244a842aae963993f37a64a26b43b9 Change-Id: I38af823c726ceaba9d0b45488fa48e2d93971c92
1 parent 5084ce1 commit 9e1e7e1

8 files changed

Lines changed: 204 additions & 0 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
=====================
2+
network qos rule type
3+
=====================
4+
5+
A **Network QoS rule type** is a specific Network QoS rule type available to be
6+
used.
7+
8+
Network v2
9+
10+
network qos rule type list
11+
--------------------------
12+
13+
List Network QoS rule types
14+
15+
.. program:: network qos rule type list
16+
.. code:: bash
17+
18+
os network qos rule type list

doc/source/commands.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ referring to both Compute and Volume quotas.
113113
* ``network agent``: (**Network**) - A network agent is an agent that handles various tasks used to implement virtual networks
114114
* ``network rbac``: (**Network**) - an RBAC policy for network resources
115115
* ``network qos policy``: (**Network**) - a QoS policy for network resources
116+
* ``network qos rule type``: (**Network**) - list of QoS available rule types
116117
* ``network segment``: (**Network**) - a segment of a virtual network
117118
* ``network service provider``: (**Network**) - a driver providing a network service
118119
* ``object``: (**Object Storage**) a single file in the Object Storage
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright (c) 2016, Intel Corporation.
2+
# All Rights Reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
5+
# not use this file except in compliance with the License. You may obtain
6+
# a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
# License for the specific language governing permissions and limitations
14+
# under the License.
15+
16+
import logging
17+
18+
from osc_lib.command import command
19+
from osc_lib import utils
20+
21+
22+
LOG = logging.getLogger(__name__)
23+
24+
25+
class ListNetworkQosRuleType(command.Lister):
26+
"""List QoS rule types"""
27+
28+
def take_action(self, parsed_args):
29+
client = self.app.client_manager.network
30+
columns = (
31+
'type',
32+
)
33+
column_headers = (
34+
'Type',
35+
)
36+
data = client.qos_rule_types()
37+
38+
return (column_headers,
39+
(utils.get_item_properties(
40+
s, columns, formatters={},
41+
) for s in data))
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright (c) 2016, Intel Corporation.
2+
# All Rights Reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
5+
# not use this file except in compliance with the License. You may obtain
6+
# a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
# License for the specific language governing permissions and limitations
14+
# under the License.
15+
16+
from openstackclient.tests.functional import base
17+
18+
19+
class NetworkQosRuleTypeTests(base.TestCase):
20+
"""Functional tests for Network QoS rule type. """
21+
22+
AVAILABLE_RULE_TYPES = ['dscp_marking',
23+
'bandwidth_limit',
24+
'minimum_bandwidth']
25+
26+
def test_qos_rule_type_list(self):
27+
raw_output = self.openstack('network qos rule type list')
28+
for rule_type in self.AVAILABLE_RULE_TYPES:
29+
self.assertIn(rule_type, raw_output)

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,51 @@ def get_qos_policies(qos_policies=None, count=2):
813813
return mock.Mock(side_effect=qos_policies)
814814

815815

816+
class FakeNetworkQosRuleType(object):
817+
"""Fake one or more Network QoS rule types."""
818+
819+
@staticmethod
820+
def create_one_qos_rule_type(attrs=None):
821+
"""Create a fake Network QoS rule type.
822+
823+
:param Dictionary attrs:
824+
A dictionary with all attributes
825+
:return:
826+
A FakeResource object with name, id, etc.
827+
"""
828+
attrs = attrs or {}
829+
830+
# Set default attributes.
831+
qos_rule_type_attrs = {
832+
'type': 'rule-type-' + uuid.uuid4().hex,
833+
}
834+
835+
# Overwrite default attributes.
836+
qos_rule_type_attrs.update(attrs)
837+
838+
return fakes.FakeResource(
839+
info=copy.deepcopy(qos_rule_type_attrs),
840+
loaded=True)
841+
842+
@staticmethod
843+
def create_qos_rule_types(attrs=None, count=2):
844+
"""Create multiple fake Network QoS rule types.
845+
846+
:param Dictionary attrs:
847+
A dictionary with all attributes
848+
:param int count:
849+
The number of QoS rule types to fake
850+
:return:
851+
A list of FakeResource objects faking the QoS rule types
852+
"""
853+
qos_rule_types = []
854+
for i in range(0, count):
855+
qos_rule_types.append(
856+
FakeNetworkQosRuleType.create_one_qos_rule_type(attrs))
857+
858+
return qos_rule_types
859+
860+
816861
class FakeRouter(object):
817862
"""Fake one or more routers."""
818863

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Copyright (c) 2016, Intel Corporation.
2+
# All Rights Reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
5+
# not use this file except in compliance with the License. You may obtain
6+
# a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
# License for the specific language governing permissions and limitations
14+
# under the License.
15+
16+
import mock
17+
18+
from openstackclient.network.v2 import network_qos_rule_type as _qos_rule_type
19+
from openstackclient.tests.unit.network.v2 import fakes as network_fakes
20+
21+
22+
class TestNetworkQosRuleType(network_fakes.TestNetworkV2):
23+
24+
def setUp(self):
25+
super(TestNetworkQosRuleType, self).setUp()
26+
# Get a shortcut to the network client
27+
self.network = self.app.client_manager.network
28+
29+
30+
class TestListNetworkQosRuleType(TestNetworkQosRuleType):
31+
32+
# The QoS policies to list up.
33+
qos_rule_types = (
34+
network_fakes.FakeNetworkQosRuleType.create_qos_rule_types(count=3))
35+
columns = (
36+
'Type',
37+
)
38+
data = []
39+
for qos_rule_type in qos_rule_types:
40+
data.append((
41+
qos_rule_type.type,
42+
))
43+
44+
def setUp(self):
45+
super(TestListNetworkQosRuleType, self).setUp()
46+
self.network.qos_rule_types = mock.Mock(
47+
return_value=self.qos_rule_types)
48+
49+
# Get the command object to test
50+
self.cmd = _qos_rule_type.ListNetworkQosRuleType(self.app,
51+
self.namespace)
52+
53+
def test_qos_rule_type_list(self):
54+
arglist = []
55+
verifylist = []
56+
57+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
58+
columns, data = self.cmd.take_action(parsed_args)
59+
60+
self.network.qos_rule_types.assert_called_once_with(**{})
61+
self.assertEqual(self.columns, columns)
62+
self.assertEqual(self.data, list(data))
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
features:
3+
- |
4+
Add support for Network QoS rule type commands:
5+
``network qos rule type list``,
6+
[Bug `1612194 <https://bugs.launchpad.net/bugs/1612194>`_]

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,8 @@ openstack.network.v2 =
372372
network_qos_policy_set = openstackclient.network.v2.network_qos_policy:SetNetworkQosPolicy
373373
network_qos_policy_show = openstackclient.network.v2.network_qos_policy:ShowNetworkQosPolicy
374374

375+
network_qos_rule_type_list = openstackclient.network.v2.network_qos_rule_type:ListNetworkQosRuleType
376+
375377
network_rbac_create = openstackclient.network.v2.network_rbac:CreateNetworkRBAC
376378
network_rbac_delete = openstackclient.network.v2.network_rbac:DeleteNetworkRBAC
377379
network_rbac_list = openstackclient.network.v2.network_rbac:ListNetworkRBAC

0 commit comments

Comments
 (0)