From bfab0199bebf139be5a948fdf8ced868b3e942de Mon Sep 17 00:00:00 2001 From: Rodolfo Alonso Hernandez Date: Wed, 2 Feb 2022 19:44:37 +0000 Subject: [PATCH] Add qos rule type filtering Added two new filter flags to ``openstack network qos rule type list``: - "--all-supported", to return any QoS rule type supported by at least one loaded driver. - "--all-rules", to return all QoS rule types supported by the current version of Neutron server, regardless of the loaded drivers. Depends-On: https://review.opendev.org/c/openstack/openstacksdk/+/827671 Depends-On: https://review.opendev.org/c/openstack/neutron/+/827683 Related-Bug: #1959749 Change-Id: Ie0622e79ecf7dadd6560fea142352f5a2ed66b74 --- .../network/v2/network_qos_rule_type.py | 25 +++++++++++++- .../network/v2/test_network_qos_rule_type.py | 29 ++++++++++++++++ .../network/v2/test_network_qos_rule_type.py | 34 +++++++++++++++++++ ...os-rule-type-filters-47f4911a02011501.yaml | 8 +++++ 4 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/network-qos-rule-type-filters-47f4911a02011501.yaml diff --git a/openstackclient/network/v2/network_qos_rule_type.py b/openstackclient/network/v2/network_qos_rule_type.py index 9af228760d..3f4f6a198b 100644 --- a/openstackclient/network/v2/network_qos_rule_type.py +++ b/openstackclient/network/v2/network_qos_rule_type.py @@ -32,6 +32,23 @@ def _get_columns(item): class ListNetworkQosRuleType(command.Lister): _description = _("List QoS rule types") + def get_parser(self, prog_name): + parser = super().get_parser(prog_name) + supported = parser.add_mutually_exclusive_group() + supported.add_argument( + '--all-supported', + action='store_true', + help=_("List all the QoS rule types supported by any loaded " + "mechanism drivers (the union of all sets of supported " + "rules)") + ) + supported.add_argument( + '--all-rules', + action='store_true', + help=_("List all QoS rule types implemented in Neutron QoS driver") + ) + return parser + def take_action(self, parsed_args): client = self.app.client_manager.network columns = ( @@ -40,7 +57,13 @@ class ListNetworkQosRuleType(command.Lister): column_headers = ( 'Type', ) - data = client.qos_rule_types() + + args = {} + if parsed_args.all_supported: + args['all_supported'] = True + elif parsed_args.all_rules: + args['all_rules'] = True + data = client.qos_rule_types(**args) return (column_headers, (utils.get_item_properties( 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 6b719cbe48..4ead65cc29 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 @@ -21,6 +21,13 @@ class NetworkQosRuleTypeTests(common.NetworkTests): AVAILABLE_RULE_TYPES = ['dscp_marking', 'bandwidth_limit'] + # NOTE(ralonsoh): this list was updated in Yoga (February 2022) + ALL_AVAILABLE_RULE_TYPES = ['dscp_marking', + 'bandwidth_limit', + 'minimum_bandwidth', + 'packet_rate_limit', + 'minimum_packet_rate', + ] def setUp(self): super(NetworkQosRuleTypeTests, self).setUp() @@ -36,6 +43,28 @@ class NetworkQosRuleTypeTests(common.NetworkTests): for rule_type in self.AVAILABLE_RULE_TYPES: self.assertIn(rule_type, [x['Type'] for x in cmd_output]) + def test_qos_rule_type_list_all_supported(self): + if not self.is_extension_enabled('qos-rule-type-filter'): + self.skipTest('No "qos-rule-type-filter" extension present') + + cmd_output = self.openstack( + 'network qos rule type list --all-supported -f json', + parse_output=True + ) + for rule_type in self.AVAILABLE_RULE_TYPES: + self.assertIn(rule_type, [x['Type'] for x in cmd_output]) + + def test_qos_rule_type_list_all_rules(self): + if not self.is_extension_enabled('qos-rule-type-filter'): + self.skipTest('No "qos-rule-type-filter" extension present') + + cmd_output = self.openstack( + 'network qos rule type list --all-rules -f json', + parse_output=True + ) + for rule_type in self.ALL_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 = self.openstack( 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 08a83fabda..3aae822e61 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 @@ -115,3 +115,37 @@ class TestListNetworkQosRuleType(TestNetworkQosRuleType): self.network.qos_rule_types.assert_called_once_with(**{}) self.assertEqual(self.columns, columns) self.assertEqual(self.data, list(data)) + + def test_qos_rule_type_list_all_supported(self): + arglist = [ + '--all-supported' + ] + verifylist = [ + ('all_supported', True), + ] + + 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( + **{'all_supported': True} + ) + self.assertEqual(self.columns, columns) + self.assertEqual(self.data, list(data)) + + def test_qos_rule_type_list_all_rules(self): + arglist = [ + '--all-rules' + ] + verifylist = [ + ('all_rules', True), + ] + + 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( + **{'all_rules': True} + ) + self.assertEqual(self.columns, columns) + self.assertEqual(self.data, list(data)) diff --git a/releasenotes/notes/network-qos-rule-type-filters-47f4911a02011501.yaml b/releasenotes/notes/network-qos-rule-type-filters-47f4911a02011501.yaml new file mode 100644 index 0000000000..d0503f5947 --- /dev/null +++ b/releasenotes/notes/network-qos-rule-type-filters-47f4911a02011501.yaml @@ -0,0 +1,8 @@ +--- +features: + - | + Added two new filter flags to ``openstack network qos rule type list``: + ``--all-supported``, to return any QoS rule type supported by at least + one loaded driver; ``--all-rules``, to return all QoS rule types + supported by the current version of Neutron server, regardless of the + loaded drivers.