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
This commit is contained in:
parent
8efed05e82
commit
07f0c7aa55
@ -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
|
||||
<rule-type-name>
|
||||
|
||||
.. describe:: <rule-type-name>
|
||||
|
||||
Name of QoS rule type (minimum-bandwidth, dscp-marking, bandwidth-limit)
|
||||
|
@ -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="<qos-rule-type-name>",
|
||||
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
|
||||
|
@ -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())
|
||||
|
@ -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.
|
||||
|
@ -0,0 +1,4 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Add ``network qos rule type show`` command.
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user