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