Merge "add quotas tests"
diff --git a/tempest/api/compute/admin/test_quotas.py b/tempest/api/compute/admin/test_quotas.py
index 09c7274..32e0478 100644
--- a/tempest/api/compute/admin/test_quotas.py
+++ b/tempest/api/compute/admin/test_quotas.py
@@ -76,21 +76,38 @@
# TODO(afazekas): merge these test cases
@test.attr(type='gate')
def test_get_updated_quotas(self):
- # Verify that GET shows the updated quota set
+ # Verify that GET shows the updated quota set of tenant
tenant_name = data_utils.rand_name('cpu_quota_tenant_')
tenant_desc = tenant_name + '-desc'
identity_client = self.os_adm.identity_client
_, tenant = identity_client.create_tenant(name=tenant_name,
description=tenant_desc)
tenant_id = tenant['id']
- self.addCleanup(identity_client.delete_tenant,
- tenant_id)
+ self.addCleanup(identity_client.delete_tenant, tenant_id)
- self.adm_client.update_quota_set(tenant_id,
- ram='5120')
+ self.adm_client.update_quota_set(tenant_id, ram='5120')
resp, quota_set = self.adm_client.get_quota_set(tenant_id)
self.assertEqual(200, resp.status)
- self.assertEqual(quota_set['ram'], 5120)
+ self.assertEqual(5120, quota_set['ram'])
+
+ # Verify that GET shows the updated quota set of user
+ user_name = data_utils.rand_name('cpu_quota_user_')
+ password = data_utils.rand_name('password-')
+ email = user_name + '@testmail.tm'
+ _, user = identity_client.create_user(name=user_name,
+ password=password,
+ tenant_id=tenant_id,
+ email=email)
+ user_id = user['id']
+ self.addCleanup(identity_client.delete_user, user_id)
+
+ self.adm_client.update_quota_set(tenant_id,
+ user_id=user_id,
+ ram='2048')
+ resp, quota_set = self.adm_client.get_quota_set(tenant_id,
+ user_id=user_id)
+ self.assertEqual(200, resp.status)
+ self.assertEqual(2048, quota_set['ram'])
@test.attr(type='gate')
def test_delete_quota(self):
diff --git a/tempest/api/compute/v3/admin/test_quotas.py b/tempest/api/compute/v3/admin/test_quotas.py
index 917c115..b70e254 100644
--- a/tempest/api/compute/v3/admin/test_quotas.py
+++ b/tempest/api/compute/v3/admin/test_quotas.py
@@ -94,21 +94,38 @@
# TODO(afazekas): merge these test cases
@test.attr(type='gate')
def test_get_updated_quotas(self):
- # Verify that GET shows the updated quota set
+ # Verify that GET shows the updated quota set of tenant
tenant_name = data_utils.rand_name('cpu_quota_tenant_')
tenant_desc = tenant_name + '-desc'
identity_client = self.os_adm.identity_client
_, tenant = identity_client.create_tenant(name=tenant_name,
description=tenant_desc)
tenant_id = tenant['id']
- self.addCleanup(identity_client.delete_tenant,
- tenant_id)
+ self.addCleanup(identity_client.delete_tenant, tenant_id)
- self.adm_client.update_quota_set(tenant_id,
- ram='5120')
+ self.adm_client.update_quota_set(tenant_id, ram='5120')
resp, quota_set = self.adm_client.get_quota_set(tenant_id)
self.assertEqual(200, resp.status)
- self.assertEqual(quota_set['ram'], 5120)
+ self.assertEqual(5120, quota_set['ram'])
+
+ # Verify that GET shows the updated quota set of user
+ user_name = data_utils.rand_name('cpu_quota_user_')
+ password = data_utils.rand_name('password-')
+ email = user_name + '@testmail.tm'
+ _, user = identity_client.create_user(name=user_name,
+ password=password,
+ tenant_id=tenant_id,
+ email=email)
+ user_id = user['id']
+ self.addCleanup(identity_client.delete_user, user_id)
+
+ self.adm_client.update_quota_set(tenant_id,
+ user_id=user_id,
+ ram='2048')
+ resp, quota_set = self.adm_client.get_quota_set(tenant_id,
+ user_id=user_id)
+ self.assertEqual(200, resp.status)
+ self.assertEqual(2048, quota_set['ram'])
@test.attr(type='gate')
def test_delete_quota(self):
diff --git a/tempest/services/compute/json/quotas_client.py b/tempest/services/compute/json/quotas_client.py
index ee2c43f..9bddf2c 100644
--- a/tempest/services/compute/json/quotas_client.py
+++ b/tempest/services/compute/json/quotas_client.py
@@ -48,8 +48,8 @@
self.validate_response(schema.quota_set, resp, body)
return resp, body['quota_set']
- def update_quota_set(self, tenant_id, force=None,
- injected_file_content_bytes=None,
+ def update_quota_set(self, tenant_id, user_id=None,
+ force=None, injected_file_content_bytes=None,
metadata_items=None, ram=None, floating_ips=None,
fixed_ips=None, key_pairs=None, instances=None,
security_group_rules=None, injected_files=None,
@@ -101,7 +101,13 @@
post_body['security_groups'] = security_groups
post_body = json.dumps({'quota_set': post_body})
- resp, body = self.put('os-quota-sets/%s' % str(tenant_id), post_body)
+
+ if user_id:
+ resp, body = self.put('os-quota-sets/%s?user_id=%s' %
+ (str(tenant_id), str(user_id)), post_body)
+ else:
+ resp, body = self.put('os-quota-sets/%s' % str(tenant_id),
+ post_body)
body = json.loads(body)
return resp, body['quota_set']
diff --git a/tempest/services/compute/v3/json/quotas_client.py b/tempest/services/compute/v3/json/quotas_client.py
index 783e3a7..37a8906 100644
--- a/tempest/services/compute/v3/json/quotas_client.py
+++ b/tempest/services/compute/v3/json/quotas_client.py
@@ -57,7 +57,7 @@
self.validate_response(schema.quota_set, resp, body)
return resp, body['quota_set']
- def update_quota_set(self, tenant_id, force=None,
+ def update_quota_set(self, tenant_id, user_id=None, force=None,
metadata_items=None, ram=None, floating_ips=None,
fixed_ips=None, key_pairs=None, instances=None,
security_group_rules=None, cores=None,
@@ -98,7 +98,13 @@
post_body['security_groups'] = security_groups
post_body = json.dumps({'quota_set': post_body})
- resp, body = self.put('os-quota-sets/%s' % str(tenant_id), post_body)
+
+ if user_id:
+ resp, body = self.put('os-quota-sets/%s?user_id=%s' %
+ (str(tenant_id), str(user_id)), post_body)
+ else:
+ resp, body = self.put('os-quota-sets/%s' % str(tenant_id),
+ post_body)
body = json.loads(body)
self.validate_response(schema.quota_set, resp, body)
diff --git a/tempest/services/compute/xml/quotas_client.py b/tempest/services/compute/xml/quotas_client.py
index 8a521ab..5502fcc 100644
--- a/tempest/services/compute/xml/quotas_client.py
+++ b/tempest/services/compute/xml/quotas_client.py
@@ -61,8 +61,8 @@
body = self._format_quota(body)
return resp, body
- def update_quota_set(self, tenant_id, force=None,
- injected_file_content_bytes=None,
+ def update_quota_set(self, tenant_id, user_id=None,
+ force=None, injected_file_content_bytes=None,
metadata_items=None, ram=None, floating_ips=None,
fixed_ips=None, key_pairs=None, instances=None,
security_group_rules=None, injected_files=None,
@@ -115,8 +115,14 @@
if security_groups is not None:
post_body.add_attr('security_groups', security_groups)
- resp, body = self.put('os-quota-sets/%s' % str(tenant_id),
- str(xml_utils.Document(post_body)))
+ if user_id:
+ resp, body = self.put('os-quota-sets/%s?user_id=%s' %
+ (str(tenant_id), str(user_id)),
+ str(xml_utils.Document(post_body)))
+ else:
+ resp, body = self.put('os-quota-sets/%s' % str(tenant_id),
+ str(xml_utils.Document(post_body)))
+
body = xml_utils.xml_to_json(etree.fromstring(body))
body = self._format_quota(body)
return resp, body