diff --git a/cloudkitty_tempest_plugin/services/client.py b/cloudkitty_tempest_plugin/services/client.py index cbe57e7..e49fa94 100644 --- a/cloudkitty_tempest_plugin/services/client.py +++ b/cloudkitty_tempest_plugin/services/client.py @@ -241,7 +241,8 @@ class RatingClientV1(BaseRatingClient): def update_hashmap_mapping(self, mapping_id, cost=0, field_id=None, group_id=None, map_type=None, - service_id=None, tenant_id=None, value=None): + service_id=None, tenant_id=None, value=None, + end=None): args = locals() args.pop('self') uri = '/rating/module_config/hashmap/mappings/' @@ -360,7 +361,7 @@ class RatingClientV1(BaseRatingClient): return self._do_request('GET', uri) @staticmethod - def _get_pyscript_request_body(name, data, checksum, script_id): + def _get_pyscript_request_body(name, data, checksum, script_id, end=None): args = locals() request_body = dict((k, v) for k, v in args.items() if v is not None) @@ -374,10 +375,12 @@ class RatingClientV1(BaseRatingClient): body=self.serialize(request_body), expected_code=201) - def update_pyscript(self, script_id, name=None, data=None, checksum=None): + def update_pyscript(self, script_id, name=None, data=None, checksum=None, + end=None): uri = '/rating/module_config/pyscripts/scripts/' request_body = self._get_pyscript_request_body(name, data, - checksum, script_id) + checksum, script_id, + end) return self._do_request('PUT', uri, body=self.serialize(request_body), expected_code=201) diff --git a/cloudkitty_tempest_plugin/tests/api/v1/test_hashmap_api.py b/cloudkitty_tempest_plugin/tests/api/v1/test_hashmap_api.py index c616216..bd06621 100644 --- a/cloudkitty_tempest_plugin/tests/api/v1/test_hashmap_api.py +++ b/cloudkitty_tempest_plugin/tests/api/v1/test_hashmap_api.py @@ -15,6 +15,7 @@ # from tempest.lib.common.utils import data_utils from tempest.lib import decorators +from tempest.lib import exceptions from cloudkitty_tempest_plugin.tests.api import base @@ -154,14 +155,57 @@ class CloudkittyHashmapAPITest(base.BaseRatingTest): mapping['mapping_id'], ) self.assertEqual('dummy field', mapping['value']) + # We are creating this flag to allow the test to work for + # both old and new API version. We can remove this validation + # in the end of life of version 2024.1. + old_version = True + try: + self.rating_client.update_hashmap_mapping( + mapping['mapping_id'], + value='new value', + ) + except exceptions.BadRequest as e: + old_version = False + self.assertTrue("You are allowed to update only the attribute " + "[end] as this rule is already running as it " + "started on " in e.resp_body['faultstring']) + + if old_version: + mapping = self.rating_client.get_hashmap_mapping( + mapping['mapping_id'] + ) + self.assertEqual('new value', mapping['value']) + return + + end_date = '3000-01-01T23:59:59' + # Disable follow redirects to avoid doing the request twice + # as it returns HTTP 302 in the first time and in the second + # time it raises an error as the end_date was already defined. + self.rating_client.http_obj.follow_redirects = False self.rating_client.update_hashmap_mapping( mapping['mapping_id'], - value='new value', + end=end_date ) + try: + self.rating_client.update_hashmap_mapping( + mapping['mapping_id'], + end=end_date + ) + except exceptions.BadRequest as e: + self.assertTrue("Cannot update a rule that was already " + "processed and has a defined end date." + in e.resp_body['faultstring']) + + # Enable follow redirects + self.rating_client.http_obj.follow_redirects = True + mapping = self.rating_client.get_hashmap_mapping( mapping['mapping_id'] ) - self.assertEqual('new value', mapping['value']) + # In the new version it is not more possible to + # update mappings anymore + self.assertEqual('dummy field', mapping['value']) + self.assertEqual(end_date, mapping['end']) @decorators.idempotent_id('0f9200ab-146b-4349-a579-ce12062f465b') def test_create_delete_hashmap_group(self): diff --git a/cloudkitty_tempest_plugin/tests/api/v1/test_pyscript_api.py b/cloudkitty_tempest_plugin/tests/api/v1/test_pyscript_api.py index 1797253..d39e711 100644 --- a/cloudkitty_tempest_plugin/tests/api/v1/test_pyscript_api.py +++ b/cloudkitty_tempest_plugin/tests/api/v1/test_pyscript_api.py @@ -50,11 +50,43 @@ class CloudkittyPyscriptAPITest(base.BaseRatingTest): ) self._created_resources['pyscript'].append(pyscript['script_id']) self.assertEqual(pyscript['data'], SCRIPT_DATA_ONE) + # We are creating this flag to allow the test to work for + # both old and new API version. We can remove this validation + # in the end of life of version 2024.1. + old_version = True + try: + self.rating_client.update_pyscript(pyscript['script_id'], + data=SCRIPT_DATA_TWO, + name=pyscript['name']) + except lib_exc.BadRequest as e: + old_version = False + self.assertTrue("You are allowed to update only the attribute " + "[end] as this rule is already running as it " + "started on " in e.resp_body['faultstring']) + + if old_version: + pyscript = self.rating_client.get_pyscript(pyscript['script_id']) + self.assertEqual(pyscript['data'], SCRIPT_DATA_TWO) + self.rating_client.delete_pyscript(pyscript['script_id']) + return + + end_date = '3000-01-01T23:59:59' + self.rating_client.update_pyscript(pyscript['script_id'], - data=SCRIPT_DATA_TWO, - name=pyscript['name']) + name=pyscript['name'], + end=end_date) + try: + self.rating_client.update_pyscript(pyscript['script_id'], + name=pyscript['name'], + end=end_date) + except lib_exc.BadRequest as e: + self.assertTrue("Cannot update a rule that was already " + "processed and has a defined end date." + in e.resp_body['faultstring']) + pyscript = self.rating_client.get_pyscript(pyscript['script_id']) - self.assertEqual(pyscript['data'], SCRIPT_DATA_TWO) + self.assertEqual(pyscript['data'], SCRIPT_DATA_ONE) + self.assertEqual(pyscript['end'], end_date) self.rating_client.delete_pyscript(pyscript['script_id']) @decorators.idempotent_id('3fbaf8b4-c472-4509-8d73-55dc4a87a442')