Added new test cases for CMS service

Change-Id: I6f09d000652ad3a4967cc16874e23d2cada70cb8
This commit is contained in:
Chi Lo 2020-06-12 13:12:52 -07:00 committed by Jeremy Houser
parent a5237ba0bc
commit fc92e28653
5 changed files with 161 additions and 63 deletions

View File

@ -66,7 +66,7 @@ disable=protected-access,fixme,too-many-branches,
redefined-variable-type,
# bug in 1.7.2 https://github.com/PyCQA/pylint/issues/1493
not-callable,
C0411,R0901
C0411,R0901,C0103
[REPORTS]
@ -202,10 +202,10 @@ variable-rgx=[a-z_][a-z0-9_]{2,30}$
variable-name-hint=[a-z_][a-z0-9_]{2,30}$
# Regular expression matching correct constant names
const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$
const-rgx=(([a-z_][A-Z_][A-Z0-9_]*)|(__.*__))$
# Naming hint for constant names
const-name-hint=(([A-Z_][A-Z0-9_]*)|(__.*__))$
const-name-hint=(([a-z_][A-Z_][A-Z0-9_]*)|(__.*__))$
# Regular expression matching correct attribute names
attr-rgx=[a-z_][a-z0-9_]{2,30}$

View File

@ -95,6 +95,8 @@ add_regions = {
}
}
update_regions = add_regions
add_users = {
'status_code': [200],
'response_body': {

View File

@ -87,6 +87,13 @@ class CmsClient(base_client.RangerClientBase):
put_body = json.dumps(args)
return self.put_request(uri, put_body, schema.replace_users)
def update_region(self, customer_id, *args):
uri = '%s/%s/orm/customers/%s/regions' \
% (self.cms_url, self.version, customer_id)
put_body = json.dumps(args)
return self.put_request(uri, put_body, schema.update_regions)
def replace_metadata(self, customer_id, metadata):
uri = '%s/%s/orm/customers/%s/metadata' \
% (self.cms_url, self.version, customer_id)

View File

@ -57,6 +57,7 @@ class CmsBaseOrmTest(base.BaseOrmTest):
def setup_clients(cls):
super(CmsBaseOrmTest, cls).setup_clients()
cls.client = cls.os_primary.cms_client
cls.rms_client = cls.os_primary.rms_client
@classmethod
def _get_quota(cls):
@ -258,11 +259,13 @@ class CmsBaseOrmTest(base.BaseOrmTest):
@classmethod
def _del_cust_validate_deletion_on_dcp_and_lcp(cls, customer_id):
_, customer = cls.client.get_customer(customer_id)
regions_on_customer = [region for region in customer["regions"]]
if regions_on_customer:
region_name_on_customer = regions_on_customer[0]["name"]
regions_on_customer = \
[region['name'] for region in customer["regions"]]
for region in regions_on_customer:
cls._delete_region_from_customer_and_validate_deletion(
customer_id, region_name_on_customer)
customer_id, region)
cls.client.delete_customer(customer_id)
cls._wait_for_customer_deletion_on_dcp(customer_id)
cls._validate_customer_deletion_on_lcp(customer_id)
@ -273,14 +276,16 @@ class CmsBaseOrmTest(base.BaseOrmTest):
_, region = cls.os_admin.rms_client.get_region(rname)
region_id = region["id"]
cls.client.delete_region_from_customer(customer_id, region_id)
cls._wait_for_status(customer_id, "no regions")
time.sleep(cls.build_interval)
_, body = cls.client.get_customer(customer_id)
regions_on_customer = [rgn for rgn in body["regions"]]
if regions_on_customer:
message = "Region %s failed to get deleted from customer %s " % (
rname, customer_id)
raise exceptions.TempestException(message)
cls._validate_customer_deletion_on_lcp(customer_id)
for regions_on_customer in body['regions']:
if regions_on_customer['name'] == rname:
message = \
"Region %s failed to get deleted from customer %s " % (
rname, customer_id)
raise exceptions.TempestException(message)
@classmethod
def _wait_for_customer_deletion_on_dcp(cls, customer_id):

View File

@ -13,16 +13,22 @@
# License for the specific language governing permissions and limitations
# under the License.
import copy
import random
import uuid
from oslo_concurrency import lockutils
from ranger_tempest_plugin import data_utils as orm_data_utils
from ranger_tempest_plugin.tests.api import cms_base
from tempest import config
from tempest.lib import decorators
from tempest.lib import exceptions
import testtools
CONF = config.CONF
PREFIX = 'ranger'
SYNC = lockutils.synchronized_with_prefix(PREFIX)
class TestTempestCms(cms_base.CmsBaseOrmTest):
@ -39,14 +45,26 @@ class TestTempestCms(cms_base.CmsBaseOrmTest):
self.os_admin.rms_client.update_region_status(
region_name, status)
def _create_customer(self, post_body):
def _create_customer(self, post_body, cleanup=True):
customer_id = self._create_cust_validate_creation_on_dcp_and_lcp(
**post_body)
self.addCleanup(
self._del_cust_validate_deletion_on_dcp_and_lcp,
customer_id)
if cleanup:
self.addCleanup(
self._del_cust_validate_deletion_on_dcp_and_lcp, customer_id)
return customer_id
def _create_region_group(self):
_, body = self.rms_client.create_region_group(
**orm_data_utils.rand_region_group([CONF.identity.region,
CONF.ranger.alt_region]))
group_id = body['group']['id']
self.addCleanup(self.rms_client.delete_region_group, group_id)
return group_id
@decorators.idempotent_id('6072c438-1e45-4c0b-97a6-e5127bd33d89')
def test_get_customer(self):
"""Execute 'get_customer' using the following options
@ -108,11 +126,7 @@ class TestTempestCms(cms_base.CmsBaseOrmTest):
def test_enable_customer(self):
# setup data for test case
post_body = self._get_customer_params(enabled=False)
test_customer_id = self._create_cust_validate_creation_on_dcp_and_lcp(
**post_body)
self.addCleanup(
self._del_cust_validate_deletion_on_dcp_and_lcp,
test_customer_id)
test_customer_id = self._create_customer(post_body)
# update enabled status from 'False' to 'True' and validate update OK
_, body = self.client.get_customer(test_customer_id)
@ -128,11 +142,7 @@ class TestTempestCms(cms_base.CmsBaseOrmTest):
# and region users blank at the initial data creation
post_body = self._get_customer_params(default_users=False,
region_users=False)
test_customer_id = self._create_cust_validate_creation_on_dcp_and_lcp(
**post_body)
self.addCleanup(
self._del_cust_validate_deletion_on_dcp_and_lcp,
test_customer_id)
test_customer_id = self._create_customer(post_body)
_, body = self.client.get_customer(test_customer_id)
self.assertFalse(body['users'])
@ -155,11 +165,7 @@ class TestTempestCms(cms_base.CmsBaseOrmTest):
# setup data for delete_default_user test case
post_body = self._get_customer_params()
default_user_id = post_body["users"][0]["id"]
test_customer_id = self._create_cust_validate_creation_on_dcp_and_lcp(
**post_body)
self.addCleanup(
self._del_cust_validate_deletion_on_dcp_and_lcp,
test_customer_id)
test_customer_id = self._create_customer(post_body)
_, body = self.client.get_customer(test_customer_id)
self.assertEqual(default_user_id, body['users'][0]['id'])
self.assertIn(default_user_id,
@ -181,11 +187,7 @@ class TestTempestCms(cms_base.CmsBaseOrmTest):
# set region user as default user will also be assigned to it
post_body = self._get_customer_params(region_users=False)
default_user_id = post_body["users"][0]["id"]
test_customer_id = self._create_cust_validate_creation_on_dcp_and_lcp(
**post_body)
self.addCleanup(
self._del_cust_validate_deletion_on_dcp_and_lcp,
test_customer_id)
test_customer_id = self._create_customer(post_body)
_, body = self.client.get_customer(test_customer_id)
self.assertIn(default_user_id, [x['id'] for x in body['users']])
self.assertEqual(body['users'], body['regions'][0]['users'])
@ -211,11 +213,7 @@ class TestTempestCms(cms_base.CmsBaseOrmTest):
# region user is empty on initial data creation for this test case
post_body = self._get_customer_params(region_users=False,
default_users=False)
test_customer_id = self._create_cust_validate_creation_on_dcp_and_lcp(
**post_body)
self.addCleanup(
self._del_cust_validate_deletion_on_dcp_and_lcp,
test_customer_id)
test_customer_id = self._create_customer(post_body)
_, body = self.client.get_customer(test_customer_id)
# confirm that the region users body is empty after data creation
self.assertFalse(body["regions"][0]["users"])
@ -237,11 +235,7 @@ class TestTempestCms(cms_base.CmsBaseOrmTest):
# added as region user as well
post_body = self._get_customer_params(default_users=False)
region_user_id = post_body["regions"][0]["users"][0]["id"]
test_customer_id = self._create_cust_validate_creation_on_dcp_and_lcp(
**post_body)
self.addCleanup(
self._del_cust_validate_deletion_on_dcp_and_lcp,
test_customer_id)
test_customer_id = self._create_customer(post_body)
_, body = self.client.get_customer(test_customer_id)
self.assertTrue(body["regions"][0]["users"])
@ -257,11 +251,7 @@ class TestTempestCms(cms_base.CmsBaseOrmTest):
@decorators.idempotent_id('0ca59977-ef29-46b9-be92-14980a12c573')
def test_replace_region_user(self):
post_body = self._get_customer_params()
test_customer_id = self._create_cust_validate_creation_on_dcp_and_lcp(
**post_body)
self.addCleanup(
self._del_cust_validate_deletion_on_dcp_and_lcp,
test_customer_id)
test_customer_id = self._create_customer(post_body)
# update region user then confirm that update is successful
put_region_user = self._get_user_params(alt=True)
@ -310,11 +300,7 @@ class TestTempestCms(cms_base.CmsBaseOrmTest):
# setup data for delete_region
post_body = self._get_customer_params()
region_name = post_body["regions"][0]["name"]
test_customer_id = self._create_cust_validate_creation_on_dcp_and_lcp(
**post_body)
self.addCleanup(
self._del_cust_validate_deletion_on_dcp_and_lcp,
test_customer_id)
test_customer_id = self._create_customer(post_body)
_, customer = self.client.get_customer(test_customer_id)
self.assertTrue(customer["regions"])
_, body = self.client.delete_region_from_customer(test_customer_id,
@ -336,27 +322,77 @@ class TestTempestCms(cms_base.CmsBaseOrmTest):
_, body = self.client.get_customer(test_cust_name)
self.assertIn(test_customer_id, body['uuid'])
@testtools.skipUnless(CONF.ranger.alt_region_available,
'Alt region not provided, skipping this test')
@decorators.idempotent_id('c2f4e842-c0c3-4747-9b10-e86c25fe8283')
def test_create_customer_with_region_group(self):
# create region group
group_id = self._create_region_group()
post_body = self._get_bare_customer_params()
post_body['description'] = 'test create customer region group'
post_body['regions'] = [
{
'name': group_id,
'type': 'group'
}
]
test_customer_id = self._create_customer(post_body)
_, body = self.client.get_customer(test_customer_id)
self.assertEqual(body['status'], 'Success')
self.assertEqual(len(body['regions']), 2)
@testtools.skipUnless(CONF.ranger.alt_region_available,
'Alt region not provided, skipping this test')
@decorators.idempotent_id('5e6f1b6b-bff1-4d30-ba97-4ff66ad47ba9')
def test_create_customer_with_two_regions(self):
post_body = self._get_bare_customer_params()
post_body['description'] = 'test create customer multi regions'
region1 = {'name': CONF.identity.region,
'type': 'single'}
region2 = {'name': CONF.ranger.alt_region,
'type': 'single'}
post_body['regions'] = [region1, region2]
test_customer_id = self._create_customer(post_body)
_, body = self.client.get_customer(test_customer_id)
self.assertEqual(body['status'], 'Success')
self.assertEqual(len(body['regions']), 2)
@SYNC('customer')
@decorators.idempotent_id('43785f87-27d5-408d-997f-de602caeb698')
def test_replace_customer(self):
customer = self._get_bare_customer_params()
customer['name'] = self.setup_customer['name']
customer['description'] = 'test customer'
# Remove users and quotas under regions
customer['regions'] = [{'name': CONF.identity.region}]
_, body = self.client.update_customer(self.setup_customer_id,
customer)
self._wait_for_status(self.setup_customer_id, 'Success')
_, body = self.client.get_customer(self.setup_customer_id)
self.assert_expected(customer, body,
['name', 'description', 'regions'])
self.assert_expected(customer, body, ['name', 'regions'])
for region in customer['regions']:
self.assertIn(region['name'], [x['name'] for x in body['regions']])
# verify no users and quotas under regions
for region in body['regions']:
self.assertEqual(len(region['quotas']), 0)
self.assertEqual(len(region['users']), 0)
@decorators.idempotent_id('e8b9077a-d45c-4e24-a433-e7dfa07486b9')
def test_delete_customer(self):
# setup data for test case
post_body = self._get_customer_params()
test_customer_id = self._create_cust_validate_creation_on_dcp_and_lcp(
**post_body)
test_customer_id = self._create_customer(post_body, cleanup=False)
# delete the data and do get_customer to ensure 404-NotFound response
self._del_cust_validate_deletion_on_dcp_and_lcp(test_customer_id)
@ -437,16 +473,64 @@ class TestTempestCms(cms_base.CmsBaseOrmTest):
self.assertEqual(customer['uuid'], uuid_)
@decorators.idempotent_id('8bd31cee-825a-4542-aa1d-bf2d79dbac62')
def test_replace_customer_quota(self):
def test_replace_customer_default_and_region_quota(self):
customer = self._get_bare_customer_params()
customer['name'] = self.setup_customer['name']
# Remove quotas under regions
customer['regions'] = [{'name': CONF.identity.region}]
# Modify defaultQuotas for compute.ram
quota = self.setup_customer['defaultQuotas'][0]
quota['compute'][0]['ram'] = '20'
customer['defaultQuotas'] = [quota]
_, body = self.client.update_customer(self.setup_customer_id,
customer)
self._wait_for_status(self.setup_customer_id, 'Success')
_, body = self.client.get_customer(self.setup_customer_id)
self.assertEqual(len(body['defaultQuotas']), 1)
self.assertEqual(len(body['regions'][0]['quotas']), 0)
self.assertDictEqual(quota, body['defaultQuotas'][0])
@decorators.idempotent_id('710ee9a9-7629-4166-941c-75dbf1c10c9d')
def test_update_region_quota(self):
# Get original region quota and change a value
region_quotas = self.setup_customer['regions'][0]['quotas']
region = {}
region['type'] = 'single'
region['name'] = CONF.identity.region
region['quotas'] = copy.deepcopy(region_quotas)
region['quotas'][0]['compute'][0]['ram'] = '30'
_, body = self.client.update_region(self.setup_customer_id, *[region])
self._wait_for_status(self.setup_customer_id, 'Success')
_, body = self.client.get_customer(self.setup_customer_id)
self.assertDictEqual(region['quotas'][0],
body['regions'][0]['quotas'][0])
# Default quotas should not be affected
self.assertDictEqual(self.setup_customer['defaultQuotas'][0],
body['defaultQuotas'][0])
@testtools.skipUnless(CONF.ranger.alt_region_available,
'Alt region not provided, skipping this test')
@decorators.idempotent_id('4bd683c6-1e1c-4f5d-9f42-6af8ac0b2183')
def test_update_customer_region(self):
post_body = self._get_customer_params(
default_users=False, region_users=False)
test_customer_id = self._create_customer(post_body)
_, customer = self.client.get_customer(test_customer_id)
self.assertEqual(customer['regions'][0]['name'],
CONF.identity.region)
region = {'name': CONF.ranger.alt_region}
self.client.update_region(test_customer_id, *[region])
self._wait_for_status(test_customer_id, 'Success')
_, customer = self.client.get_customer(test_customer_id)
self.assertEqual(customer['regions'][0]['name'],
CONF.ranger.alt_region)