From ca3e51356502b6bca86fa5b2c81f2805aecb06f0 Mon Sep 17 00:00:00 2001 From: zahlabut Date: Tue, 20 Jul 2021 20:37:51 +0300 Subject: [PATCH] Add missing tempest client for "QoS Limit Bandwidth" APIs + testing "QoS Limit Bandwidth" APIs must be used in Octavia-Tempest-Plugin to add missing QoS based tests. Note: this patch fixes the "expected status" code for Update Minimum Bandwidth, that was set to default 200 instead of 202. Change-Id: I30d9d823c972e560a0a48e24e44fb16bcc353c5a --- ...andwidth-limit-rules-cc144660fcaa419a.yaml | 11 ++ .../qos_limit_bandwidth_rules_client.py | 74 +++++++++++ .../qos_minimum_bandwidth_rules_client.py | 2 +- .../test_qos_limit_bandwidth_rules_client.py | 124 ++++++++++++++++++ ...test_qos_minimum_bandwidth_rules_client.py | 2 +- 5 files changed, 211 insertions(+), 2 deletions(-) create mode 100644 releasenotes/notes/add-qos-apis-for-bandwidth-limit-rules-cc144660fcaa419a.yaml create mode 100644 tempest/lib/services/network/qos_limit_bandwidth_rules_client.py create mode 100644 tempest/tests/lib/services/network/test_qos_limit_bandwidth_rules_client.py diff --git a/releasenotes/notes/add-qos-apis-for-bandwidth-limit-rules-cc144660fcaa419a.yaml b/releasenotes/notes/add-qos-apis-for-bandwidth-limit-rules-cc144660fcaa419a.yaml new file mode 100644 index 0000000000..da58ba3db6 --- /dev/null +++ b/releasenotes/notes/add-qos-apis-for-bandwidth-limit-rules-cc144660fcaa419a.yaml @@ -0,0 +1,11 @@ +--- +features: + - | + Add "QoS bandwidth limit rules" APIs to: + "tempest/tests/lib/services/network/test_qos_limit_bandwidth_rules_client.py" module. + + * List bandwidth limit rules for QoS policy + * Create bandwidth limit rule + * Show bandwidth limit rule details + * Update bandwidth limit rule + * Delete bandwidth limit rule \ No newline at end of file diff --git a/tempest/lib/services/network/qos_limit_bandwidth_rules_client.py b/tempest/lib/services/network/qos_limit_bandwidth_rules_client.py new file mode 100644 index 0000000000..09483e366e --- /dev/null +++ b/tempest/lib/services/network/qos_limit_bandwidth_rules_client.py @@ -0,0 +1,74 @@ +# Copyright 2021 Red Hat. +# +# 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 tempest.lib.services.network import base + + +class QosLimitBandwidthRulesClient(base.BaseNetworkClient): + + def create_limit_bandwidth_rule(self, qos_policy_id, **kwargs): + """Creates a limit bandwidth rule for a QoS policy. + + For full list of available parameters, please refer to the official + API reference: + https://docs.openstack.org/api-ref/network/v2/index.html#create-bandwidth-limit-rule + """ + uri = '/qos/policies/{}/bandwidth_limit_rules'.format( + qos_policy_id) + post_data = {'bandwidth_limit_rule': kwargs} + return self.create_resource(uri, post_data) + + def update_limit_bandwidth_rule(self, qos_policy_id, rule_id, **kwargs): + """Updates a limit bandwidth rule. + + For full list of available parameters, please refer to the official + API reference: + https://docs.openstack.org/api-ref/network/v2/index.html#update-bandwidth-limit-rule + """ + uri = '/qos/policies/{}/bandwidth_limit_rules{}/'.format( + qos_policy_id, rule_id) + post_data = {'bandwidth_limit_rule': kwargs} + return self.update_resource(uri, post_data, expect_response_code=202) + + def show_limit_bandwidth_rule(self, qos_policy_id, rule_id, **fields): + """Show details of a limit bandwidth rule. + + For full list of available parameters, please refer to the official + API reference: + https://docs.openstack.org/api-ref/network/v2/index.html#show-bandwidth-limit-rule-details + """ + uri = '/qos/policies/{}/bandwidth_limit_rules/{}'.format( + qos_policy_id, rule_id) + return self.show_resource(uri, **fields) + + def delete_limit_bandwidth_rule(self, qos_policy_id, rule_id): + """Deletes a limit bandwidth rule for a QoS policy. + + For full list of available parameters, please refer to the official + API reference: + https://docs.openstack.org/api-ref/network/v2/index.html#delete-bandwidth-limit-rule + """ + uri = '/qos/policies/{}/bandwidth_limit_rules/{}'.format( + qos_policy_id, rule_id) + return self.delete_resource(uri) + + def list_limit_bandwidth_rules(self, qos_policy_id, **filters): + """Lists all limit bandwidth rules for a QoS policy. + + For full list of available parameters, please refer to the official + API reference: + https://docs.openstack.org/api-ref/network/v2/index.html#list-bandwidth-limit-rules-for-qos-policy + """ + uri = '/qos/policies/%s/bandwidth_limit_rules'.format(qos_policy_id) + return self.list_resources(uri, **filters) diff --git a/tempest/lib/services/network/qos_minimum_bandwidth_rules_client.py b/tempest/lib/services/network/qos_minimum_bandwidth_rules_client.py index dd9f45f22a..e512acafb4 100644 --- a/tempest/lib/services/network/qos_minimum_bandwidth_rules_client.py +++ b/tempest/lib/services/network/qos_minimum_bandwidth_rules_client.py @@ -38,7 +38,7 @@ class QosMinimumBandwidthRulesClient(base.BaseNetworkClient): uri = '/qos/policies/%s/minimum_bandwidth_rules/%s' % ( qos_policy_id, rule_id) post_data = {'minimum_bandwidth_rule': kwargs} - return self.update_resource(uri, post_data) + return self.update_resource(uri, post_data, expect_response_code=202) def show_minimum_bandwidth_rule(self, qos_policy_id, rule_id, **fields): """Show details of a minimum bandwidth rule. diff --git a/tempest/tests/lib/services/network/test_qos_limit_bandwidth_rules_client.py b/tempest/tests/lib/services/network/test_qos_limit_bandwidth_rules_client.py new file mode 100644 index 0000000000..b03896867f --- /dev/null +++ b/tempest/tests/lib/services/network/test_qos_limit_bandwidth_rules_client.py @@ -0,0 +1,124 @@ +# Copyright 2021 Red Hat. +# +# 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 copy + +from tempest.lib import decorators + +from tempest.lib.services.network import qos_limit_bandwidth_rules_client +from tempest.tests.lib import fake_auth_provider +from tempest.tests.lib.services import base + +from oslo_log import log as logging +LOG = logging.getLogger('tempest') + + +class TestQosLimitBandwidthRulesClient(base.BaseServiceTest): + + FAKE_QOS_POLICY_ID = "f1011b08-1297-11e9-a1e7-c7e6825a2616" + FAKE_MAX_BW_RULE_ID = "e758c89e-1297-11e9-a6cf-cf46a71e6699" + + FAKE_MAX_BW_RULE_REQUEST = { + 'qos_policy_id': FAKE_QOS_POLICY_ID, + 'max_kbps': 1000, + 'max_burst_kbps': 0, + 'direction': 'ingress' + } + + FAKE_MAX_BW_RULE_RESPONSE = { + 'bandwidth_limit_rule': { + 'id': FAKE_MAX_BW_RULE_ID, + 'max_kbps': 10000, + 'max_burst_kbps': 0, + 'direction': 'ingress' + } + } + + FAKE_MAX_BW_RULES = { + 'bandwidth_limit_rules': [ + FAKE_MAX_BW_RULE_RESPONSE['bandwidth_limit_rule'] + ] + } + + def setUp(self): + super(TestQosLimitBandwidthRulesClient, self).setUp() + fake_auth = fake_auth_provider.FakeAuthProvider() + self.qos_limit_bw_client = qos_limit_bandwidth_rules_client.\ + QosLimitBandwidthRulesClient(fake_auth, "network", "regionOne") + + @decorators.idempotent_id('cde981fa-e93b-11eb-aacb-74e5f9e2a801') + def test_create_limit_bandwidth_rules(self, bytes_body=False): + self.check_service_client_function( + self.qos_limit_bw_client.create_limit_bandwidth_rule, + "tempest.lib.common.rest_client.RestClient.post", + self.FAKE_MAX_BW_RULE_RESPONSE, + bytes_body, + 201, + **self.FAKE_MAX_BW_RULE_REQUEST + ) + + @decorators.idempotent_id('86e6803a-e974-11eb-aacb-74e5f9e2a801') + def test_update_limit_bandwidth_rules(self, bytes_body=False): + update_kwargs = { + "max_kbps": "20000" + } + + resp_body = { + "bandwidth_limit_rule": copy.deepcopy( + self.FAKE_MAX_BW_RULE_RESPONSE['bandwidth_limit_rule'] + ) + } + resp_body["bandwidth_limit_rule"].update(update_kwargs) + + self.check_service_client_function( + self.qos_limit_bw_client.update_limit_bandwidth_rule, + "tempest.lib.common.rest_client.RestClient.put", + resp_body, + bytes_body, + 202, + qos_policy_id=self.FAKE_QOS_POLICY_ID, + rule_id=self.FAKE_MAX_BW_RULE_ID, + **update_kwargs) + + @decorators.idempotent_id('be60ae6e-e979-11eb-aacb-74e5f9e2a801') + def test_show_limit_bandwidth_rules(self, bytes_body=False): + self.check_service_client_function( + self.qos_limit_bw_client.show_limit_bandwidth_rule, + "tempest.lib.common.rest_client.RestClient.get", + self.FAKE_MAX_BW_RULE_RESPONSE, + bytes_body, + 200, + qos_policy_id=self.FAKE_QOS_POLICY_ID, + rule_id=self.FAKE_MAX_BW_RULE_ID + ) + + @decorators.idempotent_id('0a7c0964-e97b-11eb-aacb-74e5f9e2a801') + def test_delete_limit_bandwidth_rule(self): + self.check_service_client_function( + self.qos_limit_bw_client.delete_limit_bandwidth_rule, + "tempest.lib.common.rest_client.RestClient.delete", + {}, + status=204, + qos_policy_id=self.FAKE_QOS_POLICY_ID, + rule_id=self.FAKE_MAX_BW_RULE_ID) + + @decorators.idempotent_id('08df88ae-e97d-11eb-aacb-74e5f9e2a801') + def test_list_minimum_bandwidth_rules(self, bytes_body=False): + self.check_service_client_function( + self.qos_limit_bw_client.list_limit_bandwidth_rules, + "tempest.lib.common.rest_client.RestClient.get", + self.FAKE_MAX_BW_RULES, + bytes_body, + 200, + qos_policy_id=self.FAKE_QOS_POLICY_ID + ) diff --git a/tempest/tests/lib/services/network/test_qos_minimum_bandwidth_rules_client.py b/tempest/tests/lib/services/network/test_qos_minimum_bandwidth_rules_client.py index 8234ddac20..7187ffa276 100644 --- a/tempest/tests/lib/services/network/test_qos_minimum_bandwidth_rules_client.py +++ b/tempest/tests/lib/services/network/test_qos_minimum_bandwidth_rules_client.py @@ -98,7 +98,7 @@ class TestQosMinimumBandwidthRulesClient(base.BaseServiceTest): "tempest.lib.common.rest_client.RestClient.put", resp_body, bytes_body, - 200, + 202, qos_policy_id=self.FAKE_QOS_POLICY_ID, rule_id=self.FAKE_MIN_BW_RULE_ID, **update_kwargs)