Adapt tests to new rating API

With the introduction of start and end dates in the rating rules, the
update of rating rules for both mappings and pyscripts was
disabled as well as the deletion. In the new versions the
rating rules can be disabled instead of deleted so it is possible
to track all changes in the rating rules.

We are accepting both results for the tests, the old behavior and
the new one. We had to do it to keep stable branches pipeline
working, otherwise old stable versions pipeline would fail for
this new validation. As soon as the support for release 2024.1
ends, we can remove the old versions validation and keep only the
new one.

Change-Id: Idf632f229e2bc2a52eb24c138477f1b70f7fe936
Depends-On: https://review.opendev.org/c/openstack/cloudkitty-tempest-plugin/+/925736
Signed-off-by: Pedro Henrique <phpm13@gmail.com>
This commit is contained in:
Pedro Henrique
2023-08-22 12:58:23 -03:00
parent 106137decf
commit 3961dcddb8
3 changed files with 88 additions and 9 deletions

View File

@@ -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)

View File

@@ -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):

View File

@@ -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')