From 07f0c7aa55920d65035124c9e8bfe8452356c811 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=82awek=20Kap=C5=82o=C5=84ski?= Date: Thu, 7 Sep 2017 20:34:15 +0000 Subject: [PATCH] Display Network QoS rule type details Neutron API now supports getting details of supported QoS rule type. This patch adds support for this feature to OpenStack client. Change-Id: I74d16563ce2236a7c899f5994f1dab43ace02138 Depends-On: I448b5d4f8e4ef42eafe50d9d6c63d0be666f98fc Related-Bug: #1686035 --- .../command-objects/network-qos-rule-type.rst | 15 +++++ .../network/v2/network_qos_rule_type.py | 31 +++++++++++ .../network/v2/test_network_qos_rule_type.py | 7 +++ .../network/v2/test_network_qos_rule_type.py | 55 +++++++++++++++++++ ...k-qos-rule-type-show-57a714a1d428726e.yaml | 4 ++ setup.cfg | 1 + 6 files changed, 113 insertions(+) create mode 100644 releasenotes/notes/add-network-qos-rule-type-show-57a714a1d428726e.yaml diff --git a/doc/source/cli/command-objects/network-qos-rule-type.rst b/doc/source/cli/command-objects/network-qos-rule-type.rst index ee53e30b41..de6f2474af 100644 --- a/doc/source/cli/command-objects/network-qos-rule-type.rst +++ b/doc/source/cli/command-objects/network-qos-rule-type.rst @@ -16,3 +16,18 @@ List Network QoS rule types .. code:: bash openstack network qos rule type list + +network qos rule type show +-------------------------- + +Display Network QoS rule type details + +.. program:: network qos rule type show +.. code:: bash + + openstack network qos rule type show + + +.. describe:: + + Name of QoS rule type (minimum-bandwidth, dscp-marking, bandwidth-limit) diff --git a/openstackclient/network/v2/network_qos_rule_type.py b/openstackclient/network/v2/network_qos_rule_type.py index 52f8e23576..7b92c8ad4b 100644 --- a/openstackclient/network/v2/network_qos_rule_type.py +++ b/openstackclient/network/v2/network_qos_rule_type.py @@ -17,6 +17,17 @@ from osc_lib.command import command from osc_lib import utils from openstackclient.i18n import _ +from openstackclient.network import sdk_utils + + +def _get_columns(item): + column_map = { + "type": "rule_type_name", + "drivers": "drivers", + } + invisible_columns = ["id", "name"] + return sdk_utils.get_osc_show_columns_for_sdk_resource( + item, column_map, invisible_columns) class ListNetworkQosRuleType(command.Lister): @@ -36,3 +47,23 @@ class ListNetworkQosRuleType(command.Lister): (utils.get_item_properties( s, columns, formatters={}, ) for s in data)) + + +class ShowNetworkQosRuleType(command.ShowOne): + _description = _("Show details about supported QoS rule type") + + def get_parser(self, prog_name): + parser = super(ShowNetworkQosRuleType, self).get_parser(prog_name) + parser.add_argument( + 'rule_type', + metavar="", + help=_("Name of QoS rule type") + ) + return parser + + def take_action(self, parsed_args): + client = self.app.client_manager.network + obj = client.get_qos_rule_type(parsed_args.rule_type) + display_columns, columns = _get_columns(obj) + data = utils.get_item_properties(obj, columns) + return display_columns, 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 index a6ee3e1006..56cd8920b8 100644 --- a/openstackclient/tests/functional/network/v2/test_network_qos_rule_type.py +++ b/openstackclient/tests/functional/network/v2/test_network_qos_rule_type.py @@ -35,3 +35,10 @@ class NetworkQosRuleTypeTests(common.NetworkTests): 'network qos rule type list -f json')) for rule_type in self.AVAILABLE_RULE_TYPES: self.assertIn(rule_type, [x['Type'] for x in cmd_output]) + + def test_qos_rule_type_details(self): + for rule_type in self.AVAILABLE_RULE_TYPES: + cmd_output = json.loads(self.openstack( + 'network qos rule type show %s -f json' % rule_type)) + self.assertEqual(rule_type, cmd_output['rule_type_name']) + self.assertIn("drivers", cmd_output.keys()) 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 index b93abe8017..80c52bf72e 100644 --- a/openstackclient/tests/unit/network/v2/test_network_qos_rule_type.py +++ b/openstackclient/tests/unit/network/v2/test_network_qos_rule_type.py @@ -17,6 +17,7 @@ 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 +from openstackclient.tests.unit import utils as tests_utils class TestNetworkQosRuleType(network_fakes.TestNetworkV2): @@ -27,6 +28,60 @@ class TestNetworkQosRuleType(network_fakes.TestNetworkV2): self.network = self.app.client_manager.network +class TestShowNetworkQosRuleType(TestNetworkQosRuleType): + + attrs = { + 'drivers': [{ + 'name': 'driver 1', + 'supported_parameters': [] + }] + } + # The QoS policies to show. + qos_rule_type = ( + network_fakes.FakeNetworkQosRuleType.create_one_qos_rule_type(attrs)) + columns = ( + 'drivers', + 'rule_type_name' + ) + data = [ + qos_rule_type.drivers, + qos_rule_type.type + ] + + def setUp(self): + super(TestShowNetworkQosRuleType, self).setUp() + self.network.get_qos_rule_type = mock.Mock( + return_value=self.qos_rule_type) + + # Get the command object to test + self.cmd = _qos_rule_type.ShowNetworkQosRuleType(self.app, + self.namespace) + + def test_show_no_options(self): + arglist = [] + verifylist = [] + + # Missing required args should bail here + self.assertRaises(tests_utils.ParserException, self.check_parser, + self.cmd, arglist, verifylist) + + def test_show_all_options(self): + arglist = [ + self.qos_rule_type.type, + ] + verifylist = [ + ('rule_type', self.qos_rule_type.type), + ] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + columns, data = self.cmd.take_action(parsed_args) + + self.network.get_qos_rule_type.assert_called_once_with( + self.qos_rule_type.type) + self.assertEqual(self.columns, columns) + self.assertEqual(list(self.data), list(data)) + + class TestListNetworkQosRuleType(TestNetworkQosRuleType): # The QoS policies to list up. diff --git a/releasenotes/notes/add-network-qos-rule-type-show-57a714a1d428726e.yaml b/releasenotes/notes/add-network-qos-rule-type-show-57a714a1d428726e.yaml new file mode 100644 index 0000000000..d1fb88cebb --- /dev/null +++ b/releasenotes/notes/add-network-qos-rule-type-show-57a714a1d428726e.yaml @@ -0,0 +1,4 @@ +--- +features: + - | + Add ``network qos rule type show`` command. diff --git a/setup.cfg b/setup.cfg index 2412b6fe02..dcfe767199 100644 --- a/setup.cfg +++ b/setup.cfg @@ -424,6 +424,7 @@ openstack.network.v2 = network_qos_rule_show = openstackclient.network.v2.network_qos_rule:ShowNetworkQosRule network_qos_rule_type_list = openstackclient.network.v2.network_qos_rule_type:ListNetworkQosRuleType + network_qos_rule_type_show = openstackclient.network.v2.network_qos_rule_type:ShowNetworkQosRuleType network_rbac_create = openstackclient.network.v2.network_rbac:CreateNetworkRBAC network_rbac_delete = openstackclient.network.v2.network_rbac:DeleteNetworkRBAC