Browse Source

Merge "Display Network QoS rule type details"

tags/3.13.0
Zuul 1 year ago
parent
commit
e8a87e1478

+ 15
- 0
doc/source/cli/command-objects/network-qos-rule-type.rst View File

@@ -16,3 +16,18 @@ List Network QoS rule types
16 16
 .. code:: bash
17 17
 
18 18
     openstack network qos rule type list
19
+
20
+network qos rule type show
21
+--------------------------
22
+
23
+Display Network QoS rule type details
24
+
25
+.. program:: network qos rule type show
26
+.. code:: bash
27
+
28
+    openstack network qos rule type show
29
+        <rule-type-name>
30
+
31
+.. describe:: <rule-type-name>
32
+
33
+    Name of QoS rule type (minimum-bandwidth, dscp-marking, bandwidth-limit)

+ 31
- 0
openstackclient/network/v2/network_qos_rule_type.py View File

@@ -17,6 +17,17 @@ from osc_lib.command import command
17 17
 from osc_lib import utils
18 18
 
19 19
 from openstackclient.i18n import _
20
+from openstackclient.network import sdk_utils
21
+
22
+
23
+def _get_columns(item):
24
+    column_map = {
25
+        "type": "rule_type_name",
26
+        "drivers": "drivers",
27
+    }
28
+    invisible_columns = ["id", "name"]
29
+    return sdk_utils.get_osc_show_columns_for_sdk_resource(
30
+        item, column_map, invisible_columns)
20 31
 
21 32
 
22 33
 class ListNetworkQosRuleType(command.Lister):
@@ -36,3 +47,23 @@ class ListNetworkQosRuleType(command.Lister):
36 47
                 (utils.get_item_properties(
37 48
                     s, columns, formatters={},
38 49
                 ) for s in data))
50
+
51
+
52
+class ShowNetworkQosRuleType(command.ShowOne):
53
+    _description = _("Show details about supported QoS rule type")
54
+
55
+    def get_parser(self, prog_name):
56
+        parser = super(ShowNetworkQosRuleType, self).get_parser(prog_name)
57
+        parser.add_argument(
58
+            'rule_type',
59
+            metavar="<qos-rule-type-name>",
60
+            help=_("Name of QoS rule type")
61
+        )
62
+        return parser
63
+
64
+    def take_action(self, parsed_args):
65
+        client = self.app.client_manager.network
66
+        obj = client.get_qos_rule_type(parsed_args.rule_type)
67
+        display_columns, columns = _get_columns(obj)
68
+        data = utils.get_item_properties(obj, columns)
69
+        return display_columns, data

+ 7
- 0
openstackclient/tests/functional/network/v2/test_network_qos_rule_type.py View File

@@ -35,3 +35,10 @@ class NetworkQosRuleTypeTests(common.NetworkTests):
35 35
             'network qos rule type list -f json'))
36 36
         for rule_type in self.AVAILABLE_RULE_TYPES:
37 37
             self.assertIn(rule_type, [x['Type'] for x in cmd_output])
38
+
39
+    def test_qos_rule_type_details(self):
40
+        for rule_type in self.AVAILABLE_RULE_TYPES:
41
+            cmd_output = json.loads(self.openstack(
42
+                'network qos rule type show %s -f json' % rule_type))
43
+            self.assertEqual(rule_type, cmd_output['rule_type_name'])
44
+            self.assertIn("drivers", cmd_output.keys())

+ 55
- 0
openstackclient/tests/unit/network/v2/test_network_qos_rule_type.py View File

@@ -17,6 +17,7 @@ import mock
17 17
 
18 18
 from openstackclient.network.v2 import network_qos_rule_type as _qos_rule_type
19 19
 from openstackclient.tests.unit.network.v2 import fakes as network_fakes
20
+from openstackclient.tests.unit import utils as tests_utils
20 21
 
21 22
 
22 23
 class TestNetworkQosRuleType(network_fakes.TestNetworkV2):
@@ -27,6 +28,60 @@ class TestNetworkQosRuleType(network_fakes.TestNetworkV2):
27 28
         self.network = self.app.client_manager.network
28 29
 
29 30
 
31
+class TestShowNetworkQosRuleType(TestNetworkQosRuleType):
32
+
33
+    attrs = {
34
+        'drivers': [{
35
+            'name': 'driver 1',
36
+            'supported_parameters': []
37
+        }]
38
+    }
39
+    # The QoS policies to show.
40
+    qos_rule_type = (
41
+        network_fakes.FakeNetworkQosRuleType.create_one_qos_rule_type(attrs))
42
+    columns = (
43
+        'drivers',
44
+        'rule_type_name'
45
+    )
46
+    data = [
47
+        qos_rule_type.drivers,
48
+        qos_rule_type.type
49
+    ]
50
+
51
+    def setUp(self):
52
+        super(TestShowNetworkQosRuleType, self).setUp()
53
+        self.network.get_qos_rule_type = mock.Mock(
54
+            return_value=self.qos_rule_type)
55
+
56
+        # Get the command object to test
57
+        self.cmd = _qos_rule_type.ShowNetworkQosRuleType(self.app,
58
+                                                         self.namespace)
59
+
60
+    def test_show_no_options(self):
61
+        arglist = []
62
+        verifylist = []
63
+
64
+        # Missing required args should bail here
65
+        self.assertRaises(tests_utils.ParserException, self.check_parser,
66
+                          self.cmd, arglist, verifylist)
67
+
68
+    def test_show_all_options(self):
69
+        arglist = [
70
+            self.qos_rule_type.type,
71
+        ]
72
+        verifylist = [
73
+            ('rule_type', self.qos_rule_type.type),
74
+        ]
75
+
76
+        parsed_args = self.check_parser(self.cmd, arglist, verifylist)
77
+        columns, data = self.cmd.take_action(parsed_args)
78
+
79
+        self.network.get_qos_rule_type.assert_called_once_with(
80
+            self.qos_rule_type.type)
81
+        self.assertEqual(self.columns, columns)
82
+        self.assertEqual(list(self.data), list(data))
83
+
84
+
30 85
 class TestListNetworkQosRuleType(TestNetworkQosRuleType):
31 86
 
32 87
     # The QoS policies to list up.

+ 4
- 0
releasenotes/notes/add-network-qos-rule-type-show-57a714a1d428726e.yaml View File

@@ -0,0 +1,4 @@
1
+---
2
+features:
3
+  - |
4
+    Add ``network qos rule type show`` command.

+ 1
- 0
setup.cfg View File

@@ -425,6 +425,7 @@ openstack.network.v2 =
425 425
     network_qos_rule_show = openstackclient.network.v2.network_qos_rule:ShowNetworkQosRule
426 426
 
427 427
     network_qos_rule_type_list = openstackclient.network.v2.network_qos_rule_type:ListNetworkQosRuleType
428
+    network_qos_rule_type_show = openstackclient.network.v2.network_qos_rule_type:ShowNetworkQosRuleType
428 429
 
429 430
     network_rbac_create = openstackclient.network.v2.network_rbac:CreateNetworkRBAC
430 431
     network_rbac_delete = openstackclient.network.v2.network_rbac:DeleteNetworkRBAC

Loading…
Cancel
Save