From 9e1e7e1c9fde2e60b2f95f3bd000c599a9e1c72a Mon Sep 17 00:00:00 2001 From: Rodolfo Alonso Hernandez Date: Fri, 12 Aug 2016 16:51:35 +0100 Subject: [PATCH] Add support for QoS rule type commands Added following commands: - network qos rule type list Closes-Bug: 1612194 Depends-On: Iecf7bc7acd244a842aae963993f37a64a26b43b9 Change-Id: I38af823c726ceaba9d0b45488fa48e2d93971c92 --- .../command-objects/network-qos-rule-type.rst | 18 ++++++ doc/source/commands.rst | 1 + .../network/v2/network_qos_rule_type.py | 41 ++++++++++++ .../network/v2/test_network_qos_rule_type.py | 29 +++++++++ .../tests/unit/network/v2/fakes.py | 45 ++++++++++++++ .../network/v2/test_network_qos_rule_type.py | 62 +++++++++++++++++++ ...twork-qos-rule-types-337e464c6e81f29c.yaml | 6 ++ setup.cfg | 2 + 8 files changed, 204 insertions(+) create mode 100644 doc/source/command-objects/network-qos-rule-type.rst create mode 100644 openstackclient/network/v2/network_qos_rule_type.py create mode 100644 openstackclient/tests/functional/network/v2/test_network_qos_rule_type.py create mode 100644 openstackclient/tests/unit/network/v2/test_network_qos_rule_type.py create mode 100644 releasenotes/notes/add-network-qos-rule-types-337e464c6e81f29c.yaml diff --git a/doc/source/command-objects/network-qos-rule-type.rst b/doc/source/command-objects/network-qos-rule-type.rst new file mode 100644 index 0000000000..020a05cd5f --- /dev/null +++ b/doc/source/command-objects/network-qos-rule-type.rst @@ -0,0 +1,18 @@ +===================== +network qos rule type +===================== + +A **Network QoS rule type** is a specific Network QoS rule type available to be +used. + +Network v2 + +network qos rule type list +-------------------------- + +List Network QoS rule types + +.. program:: network qos rule type list +.. code:: bash + + os network qos rule type list diff --git a/doc/source/commands.rst b/doc/source/commands.rst index 206b18af3a..52e05d7e09 100644 --- a/doc/source/commands.rst +++ b/doc/source/commands.rst @@ -113,6 +113,7 @@ referring to both Compute and Volume quotas. * ``network agent``: (**Network**) - A network agent is an agent that handles various tasks used to implement virtual networks * ``network rbac``: (**Network**) - an RBAC policy for network resources * ``network qos policy``: (**Network**) - a QoS policy for network resources +* ``network qos rule type``: (**Network**) - list of QoS available rule types * ``network segment``: (**Network**) - a segment of a virtual network * ``network service provider``: (**Network**) - a driver providing a network service * ``object``: (**Object Storage**) a single file in the Object Storage diff --git a/openstackclient/network/v2/network_qos_rule_type.py b/openstackclient/network/v2/network_qos_rule_type.py new file mode 100644 index 0000000000..82a265b8c9 --- /dev/null +++ b/openstackclient/network/v2/network_qos_rule_type.py @@ -0,0 +1,41 @@ +# Copyright (c) 2016, Intel Corporation. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import logging + +from osc_lib.command import command +from osc_lib import utils + + +LOG = logging.getLogger(__name__) + + +class ListNetworkQosRuleType(command.Lister): + """List QoS rule types""" + + def take_action(self, parsed_args): + client = self.app.client_manager.network + columns = ( + 'type', + ) + column_headers = ( + 'Type', + ) + data = client.qos_rule_types() + + return (column_headers, + (utils.get_item_properties( + s, columns, formatters={}, + ) for s in data)) diff --git a/openstackclient/tests/functional/network/v2/test_network_qos_rule_type.py b/openstackclient/tests/functional/network/v2/test_network_qos_rule_type.py new file mode 100644 index 0000000000..4d0dbab06d --- /dev/null +++ b/openstackclient/tests/functional/network/v2/test_network_qos_rule_type.py @@ -0,0 +1,29 @@ +# Copyright (c) 2016, Intel Corporation. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from openstackclient.tests.functional import base + + +class NetworkQosRuleTypeTests(base.TestCase): + """Functional tests for Network QoS rule type. """ + + AVAILABLE_RULE_TYPES = ['dscp_marking', + 'bandwidth_limit', + 'minimum_bandwidth'] + + def test_qos_rule_type_list(self): + raw_output = self.openstack('network qos rule type list') + for rule_type in self.AVAILABLE_RULE_TYPES: + self.assertIn(rule_type, raw_output) diff --git a/openstackclient/tests/unit/network/v2/fakes.py b/openstackclient/tests/unit/network/v2/fakes.py index 84f145fbe1..88e67f43ff 100644 --- a/openstackclient/tests/unit/network/v2/fakes.py +++ b/openstackclient/tests/unit/network/v2/fakes.py @@ -813,6 +813,51 @@ class FakeNetworkQosPolicy(object): return mock.Mock(side_effect=qos_policies) +class FakeNetworkQosRuleType(object): + """Fake one or more Network QoS rule types.""" + + @staticmethod + def create_one_qos_rule_type(attrs=None): + """Create a fake Network QoS rule type. + + :param Dictionary attrs: + A dictionary with all attributes + :return: + A FakeResource object with name, id, etc. + """ + attrs = attrs or {} + + # Set default attributes. + qos_rule_type_attrs = { + 'type': 'rule-type-' + uuid.uuid4().hex, + } + + # Overwrite default attributes. + qos_rule_type_attrs.update(attrs) + + return fakes.FakeResource( + info=copy.deepcopy(qos_rule_type_attrs), + loaded=True) + + @staticmethod + def create_qos_rule_types(attrs=None, count=2): + """Create multiple fake Network QoS rule types. + + :param Dictionary attrs: + A dictionary with all attributes + :param int count: + The number of QoS rule types to fake + :return: + A list of FakeResource objects faking the QoS rule types + """ + qos_rule_types = [] + for i in range(0, count): + qos_rule_types.append( + FakeNetworkQosRuleType.create_one_qos_rule_type(attrs)) + + return qos_rule_types + + class FakeRouter(object): """Fake one or more routers.""" diff --git a/openstackclient/tests/unit/network/v2/test_network_qos_rule_type.py b/openstackclient/tests/unit/network/v2/test_network_qos_rule_type.py new file mode 100644 index 0000000000..b93abe8017 --- /dev/null +++ b/openstackclient/tests/unit/network/v2/test_network_qos_rule_type.py @@ -0,0 +1,62 @@ +# Copyright (c) 2016, Intel Corporation. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import mock + +from openstackclient.network.v2 import network_qos_rule_type as _qos_rule_type +from openstackclient.tests.unit.network.v2 import fakes as network_fakes + + +class TestNetworkQosRuleType(network_fakes.TestNetworkV2): + + def setUp(self): + super(TestNetworkQosRuleType, self).setUp() + # Get a shortcut to the network client + self.network = self.app.client_manager.network + + +class TestListNetworkQosRuleType(TestNetworkQosRuleType): + + # The QoS policies to list up. + qos_rule_types = ( + network_fakes.FakeNetworkQosRuleType.create_qos_rule_types(count=3)) + columns = ( + 'Type', + ) + data = [] + for qos_rule_type in qos_rule_types: + data.append(( + qos_rule_type.type, + )) + + def setUp(self): + super(TestListNetworkQosRuleType, self).setUp() + self.network.qos_rule_types = mock.Mock( + return_value=self.qos_rule_types) + + # Get the command object to test + self.cmd = _qos_rule_type.ListNetworkQosRuleType(self.app, + self.namespace) + + def test_qos_rule_type_list(self): + arglist = [] + verifylist = [] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + columns, data = self.cmd.take_action(parsed_args) + + self.network.qos_rule_types.assert_called_once_with(**{}) + self.assertEqual(self.columns, columns) + self.assertEqual(self.data, list(data)) diff --git a/releasenotes/notes/add-network-qos-rule-types-337e464c6e81f29c.yaml b/releasenotes/notes/add-network-qos-rule-types-337e464c6e81f29c.yaml new file mode 100644 index 0000000000..2cff599ff5 --- /dev/null +++ b/releasenotes/notes/add-network-qos-rule-types-337e464c6e81f29c.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + Add support for Network QoS rule type commands: + ``network qos rule type list``, + [Bug `1612194 `_] diff --git a/setup.cfg b/setup.cfg index 8c5c663055..7e1bfc1735 100644 --- a/setup.cfg +++ b/setup.cfg @@ -372,6 +372,8 @@ openstack.network.v2 = network_qos_policy_set = openstackclient.network.v2.network_qos_policy:SetNetworkQosPolicy network_qos_policy_show = openstackclient.network.v2.network_qos_policy:ShowNetworkQosPolicy + network_qos_rule_type_list = openstackclient.network.v2.network_qos_rule_type:ListNetworkQosRuleType + network_rbac_create = openstackclient.network.v2.network_rbac:CreateNetworkRBAC network_rbac_delete = openstackclient.network.v2.network_rbac:DeleteNetworkRBAC network_rbac_list = openstackclient.network.v2.network_rbac:ListNetworkRBAC