Merge quotas clients
The quotas clients admin and "non-admin" part using the same base url.
The flavors client not broken into pieces, the quotas client should not be
different.
The Compute Admin tests will be able to use a non-admin account
for negative tests.
Change-Id: I0c358f791b250feb50fffcfc059d7e62c3d506b6
diff --git a/tempest/services/compute/admin/__init__.py b/tempest/services/compute/admin/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/tempest/services/compute/admin/__init__.py
+++ /dev/null
diff --git a/tempest/services/compute/admin/json/__init__.py b/tempest/services/compute/admin/json/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/tempest/services/compute/admin/json/__init__.py
+++ /dev/null
diff --git a/tempest/services/compute/admin/json/quotas_client.py b/tempest/services/compute/admin/json/quotas_client.py
deleted file mode 100644
index b886834..0000000
--- a/tempest/services/compute/admin/json/quotas_client.py
+++ /dev/null
@@ -1,79 +0,0 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
-# Copyright 2012 NTT Data
-# All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License"); you may
-# not use this file except in compliance with the License. You may obtain
-# a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-
-import json
-
-from tempest.services.compute.json.quotas_client import QuotasClientJSON
-
-
-class AdminQuotasClientJSON(QuotasClientJSON):
-
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(AdminQuotasClientJSON, self).__init__(config, username, password,
- auth_url, tenant_name)
-
- def update_quota_set(self, tenant_id, injected_file_content_bytes=None,
- metadata_items=None, ram=None, floating_ips=None,
- key_pairs=None, instances=None,
- security_group_rules=None, injected_files=None,
- cores=None, injected_file_path_bytes=None,
- security_groups=None):
- """
- Updates the tenant's quota limits for one or more resources
- """
- post_body = {}
-
- if injected_file_content_bytes is not None:
- post_body['injected_file_content_bytes'] = \
- injected_file_content_bytes
-
- if metadata_items is not None:
- post_body['metadata_items'] = metadata_items
-
- if ram is not None:
- post_body['ram'] = ram
-
- if floating_ips is not None:
- post_body['floating_ips'] = floating_ips
-
- if key_pairs is not None:
- post_body['key_pairs'] = key_pairs
-
- if instances is not None:
- post_body['instances'] = instances
-
- if security_group_rules is not None:
- post_body['security_group_rules'] = security_group_rules
-
- if injected_files is not None:
- post_body['injected_files'] = injected_files
-
- if cores is not None:
- post_body['cores'] = cores
-
- if injected_file_path_bytes is not None:
- post_body['injected_file_path_bytes'] = injected_file_path_bytes
-
- if security_groups is not None:
- 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,
- self.headers)
-
- body = json.loads(body)
- return resp, body['quota_set']
diff --git a/tempest/services/compute/admin/xml/__init__.py b/tempest/services/compute/admin/xml/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/tempest/services/compute/admin/xml/__init__.py
+++ /dev/null
diff --git a/tempest/services/compute/admin/xml/quotas_client.py b/tempest/services/compute/admin/xml/quotas_client.py
deleted file mode 100644
index f416334..0000000
--- a/tempest/services/compute/admin/xml/quotas_client.py
+++ /dev/null
@@ -1,85 +0,0 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
-# Copyright 2012 NTT Data
-# All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License"); you may
-# not use this file except in compliance with the License. You may obtain
-# a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-
-from lxml import etree
-
-from tempest.services.compute.xml.common import Document
-from tempest.services.compute.xml.common import Element
-from tempest.services.compute.xml.common import xml_to_json
-from tempest.services.compute.xml.common import XMLNS_11
-from tempest.services.compute.xml.quotas_client import QuotasClientXML
-
-
-class AdminQuotasClientXML(QuotasClientXML):
-
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(AdminQuotasClientXML, self).__init__(config, username, password,
- auth_url, tenant_name)
-
- def update_quota_set(self, tenant_id, injected_file_content_bytes=None,
- metadata_items=None, ram=None, floating_ips=None,
- key_pairs=None, instances=None,
- security_group_rules=None, injected_files=None,
- cores=None, injected_file_path_bytes=None,
- security_groups=None):
- """
- Updates the tenant's quota limits for one or more resources
- """
- post_body = Element("quota_set",
- xmlns=XMLNS_11)
-
- if injected_file_content_bytes is not None:
- post_body.add_attr('injected_file_content_bytes',
- injected_file_content_bytes)
-
- if metadata_items is not None:
- post_body.add_attr('metadata_items', metadata_items)
-
- if ram is not None:
- post_body.add_attr('ram', ram)
-
- if floating_ips is not None:
- post_body.add_attr('floating_ips', floating_ips)
-
- if key_pairs is not None:
- post_body.add_attr('key_pairs', key_pairs)
-
- if instances is not None:
- post_body.add_attr('instances', instances)
-
- if security_group_rules is not None:
- post_body.add_attr('security_group_rules', security_group_rules)
-
- if injected_files is not None:
- post_body.add_attr('injected_files', injected_files)
-
- if cores is not None:
- post_body.add_attr('cores', cores)
-
- if injected_file_path_bytes is not None:
- post_body.add_attr('injected_file_path_bytes',
- injected_file_path_bytes)
-
- 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(Document(post_body)),
- self.headers)
- body = xml_to_json(etree.fromstring(body))
- body = self._format_quota(body)
- return resp, body
diff --git a/tempest/services/compute/json/quotas_client.py b/tempest/services/compute/json/quotas_client.py
index a95ff1c..330e80b 100644
--- a/tempest/services/compute/json/quotas_client.py
+++ b/tempest/services/compute/json/quotas_client.py
@@ -34,3 +34,55 @@
resp, body = self.get(url)
body = json.loads(body)
return resp, body['quota_set']
+
+ def update_quota_set(self, tenant_id, injected_file_content_bytes=None,
+ metadata_items=None, ram=None, floating_ips=None,
+ key_pairs=None, instances=None,
+ security_group_rules=None, injected_files=None,
+ cores=None, injected_file_path_bytes=None,
+ security_groups=None):
+ """
+ Updates the tenant's quota limits for one or more resources
+ """
+ post_body = {}
+
+ if injected_file_content_bytes is not None:
+ post_body['injected_file_content_bytes'] = \
+ injected_file_content_bytes
+
+ if metadata_items is not None:
+ post_body['metadata_items'] = metadata_items
+
+ if ram is not None:
+ post_body['ram'] = ram
+
+ if floating_ips is not None:
+ post_body['floating_ips'] = floating_ips
+
+ if key_pairs is not None:
+ post_body['key_pairs'] = key_pairs
+
+ if instances is not None:
+ post_body['instances'] = instances
+
+ if security_group_rules is not None:
+ post_body['security_group_rules'] = security_group_rules
+
+ if injected_files is not None:
+ post_body['injected_files'] = injected_files
+
+ if cores is not None:
+ post_body['cores'] = cores
+
+ if injected_file_path_bytes is not None:
+ post_body['injected_file_path_bytes'] = injected_file_path_bytes
+
+ if security_groups is not None:
+ 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,
+ self.headers)
+
+ body = json.loads(body)
+ return resp, body['quota_set']
diff --git a/tempest/services/compute/xml/quotas_client.py b/tempest/services/compute/xml/quotas_client.py
index faa0aab..0437205 100644
--- a/tempest/services/compute/xml/quotas_client.py
+++ b/tempest/services/compute/xml/quotas_client.py
@@ -18,7 +18,10 @@
from lxml import etree
from tempest.common.rest_client import RestClientXML
+from tempest.services.compute.xml.common import Document
+from tempest.services.compute.xml.common import Element
from tempest.services.compute.xml.common import xml_to_json
+from tempest.services.compute.xml.common import XMLNS_11
class QuotasClientXML(RestClientXML):
@@ -51,3 +54,57 @@
body = xml_to_json(etree.fromstring(body))
body = self._format_quota(body)
return resp, body
+
+ def update_quota_set(self, tenant_id, injected_file_content_bytes=None,
+ metadata_items=None, ram=None, floating_ips=None,
+ key_pairs=None, instances=None,
+ security_group_rules=None, injected_files=None,
+ cores=None, injected_file_path_bytes=None,
+ security_groups=None):
+ """
+ Updates the tenant's quota limits for one or more resources
+ """
+ post_body = Element("quota_set",
+ xmlns=XMLNS_11)
+
+ if injected_file_content_bytes is not None:
+ post_body.add_attr('injected_file_content_bytes',
+ injected_file_content_bytes)
+
+ if metadata_items is not None:
+ post_body.add_attr('metadata_items', metadata_items)
+
+ if ram is not None:
+ post_body.add_attr('ram', ram)
+
+ if floating_ips is not None:
+ post_body.add_attr('floating_ips', floating_ips)
+
+ if key_pairs is not None:
+ post_body.add_attr('key_pairs', key_pairs)
+
+ if instances is not None:
+ post_body.add_attr('instances', instances)
+
+ if security_group_rules is not None:
+ post_body.add_attr('security_group_rules', security_group_rules)
+
+ if injected_files is not None:
+ post_body.add_attr('injected_files', injected_files)
+
+ if cores is not None:
+ post_body.add_attr('cores', cores)
+
+ if injected_file_path_bytes is not None:
+ post_body.add_attr('injected_file_path_bytes',
+ injected_file_path_bytes)
+
+ 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(Document(post_body)),
+ self.headers)
+ body = xml_to_json(etree.fromstring(body))
+ body = self._format_quota(body)
+ return resp, body
diff --git a/tempest/tests/compute/admin/test_flavors.py b/tempest/tests/compute/admin/test_flavors.py
index 9ad8745..30c3d59 100644
--- a/tempest/tests/compute/admin/test_flavors.py
+++ b/tempest/tests/compute/admin/test_flavors.py
@@ -35,7 +35,7 @@
msg = "FlavorExtraData extension not enabled."
raise cls.skipException(msg)
- cls.client = cls.os.flavors_client
+ cls.client = cls.os_adm.flavors_client
cls.flavor_name_prefix = 'test_flavor_'
cls.ram = 512
cls.vcpus = 1
@@ -312,6 +312,8 @@
self.client.list_flavors_with_detail,
{'is_public': 'invalid'})
+#TODO(afazekas): Negative tests with regular user
+
class FlavorsAdminTestXML(base.BaseComputeAdminTestXML,
base.BaseComputeTestXML,
diff --git a/tempest/tests/compute/admin/test_flavors_extra_specs.py b/tempest/tests/compute/admin/test_flavors_extra_specs.py
index ef4c20e..968603d 100644
--- a/tempest/tests/compute/admin/test_flavors_extra_specs.py
+++ b/tempest/tests/compute/admin/test_flavors_extra_specs.py
@@ -35,7 +35,7 @@
msg = "FlavorExtraData extension not enabled."
raise cls.skipException(msg)
- cls.client = cls.os.flavors_client
+ cls.client = cls.os_adm.flavors_client
flavor_name = 'test_flavor2'
ram = 512
vcpus = 1
diff --git a/tempest/tests/compute/admin/test_quotas.py b/tempest/tests/compute/admin/test_quotas.py
index a4b106b..a845632 100644
--- a/tempest/tests/compute/admin/test_quotas.py
+++ b/tempest/tests/compute/admin/test_quotas.py
@@ -16,9 +16,6 @@
# under the License.
from tempest import exceptions
-from tempest.services.compute.admin.json \
- import quotas_client as adm_quotas_json
-from tempest.services.compute.admin.xml import quotas_client as adm_quotas_xml
from tempest.test import attr
from tempest.tests.compute import base
@@ -27,23 +24,21 @@
@classmethod
def setUpClass(cls):
- cls.c_adm_user = cls.config.compute_admin.username
- cls.c_adm_pass = cls.config.compute_admin.password
- cls.c_adm_tenant = cls.config.compute_admin.tenant_name
cls.auth_url = cls.config.identity.uri
cls.client = cls.os.quotas_client
+ cls.adm_client = cls.os_adm.quotas_client
cls.identity_admin_client = cls._get_identity_admin_client()
+
resp, tenants = cls.identity_admin_client.list_tenants()
+ #NOTE(afazekas): these test cases should always create and use a new
+ # tenant most of them should be skipped if we can't do that
if cls.config.compute.allow_tenant_isolation:
cls.demo_tenant_id = cls.isolated_creds[0][0]['tenantId']
else:
cls.demo_tenant_id = [tnt['id'] for tnt in tenants if tnt['name']
== cls.config.identity.tenant_name][0]
- cls.adm_tenant_id = [tnt['id'] for tnt in tenants if tnt['name'] ==
- cls.config.compute_admin.tenant_name][0]
-
cls.default_quota_set = {'injected_file_content_bytes': 10240,
'metadata_items': 128, 'injected_files': 5,
'ram': 51200, 'floating_ips': 10,
@@ -97,6 +92,7 @@
self.assertEqual(200, resp.status, "Failed to reset quota "
"defaults")
+ #TODO(afazekas): merge these test cases
def test_get_updated_quotas(self):
# Verify that GET shows the updated quota set
self.adm_client.update_quota_set(self.demo_tenant_id,
@@ -151,6 +147,8 @@
self.adm_client.update_quota_set(self.demo_tenant_id,
ram=default_mem_quota)
+#TODO(afazekas): Add test that tried to update the quota_set as a regular user
+
class QuotasAdminTestJSON(QuotasAdminTestBase, base.BaseComputeAdminTestJSON,
base.BaseComputeTest):
@@ -161,10 +159,6 @@
base.BaseComputeTest.setUpClass()
super(QuotasAdminTestJSON, cls).setUpClass()
- cls.adm_client = adm_quotas_json.AdminQuotasClientJSON(
- cls.config, cls.c_adm_user, cls.c_adm_pass,
- cls.auth_url, cls.c_adm_tenant)
-
@classmethod
def tearDownClass(cls):
super(QuotasAdminTestJSON, cls).tearDownClass()
@@ -180,12 +174,6 @@
base.BaseComputeTest.setUpClass()
super(QuotasAdminTestXML, cls).setUpClass()
- cls.adm_client = adm_quotas_xml.AdminQuotasClientXML(cls.config,
- cls.c_adm_user,
- cls.c_adm_pass,
- cls.auth_url,
- cls.c_adm_tenant)
-
@classmethod
def tearDownClass(cls):
super(QuotasAdminTestXML, cls).tearDownClass()
diff --git a/tempest/tests/compute/base.py b/tempest/tests/compute/base.py
index 594535f..2aae89c 100644
--- a/tempest/tests/compute/base.py
+++ b/tempest/tests/compute/base.py
@@ -247,23 +247,23 @@
super(BaseComputeTestXML, cls).setUpClass()
-class BaseComputeAdminTest(testtools.TestCase):
+class BaseComputeAdminTest(BaseCompTest):
"""Base test case class for all Compute Admin API tests."""
@classmethod
def setUpClass(cls):
- cls.config = config.TempestConfig()
- cls.admin_username = cls.config.identity.admin_username
- cls.admin_password = cls.config.identity.admin_password
- cls.admin_tenant = cls.config.identity.admin_tenant_name
+ super(BaseComputeAdminTest, cls).setUpClass()
+ admin_username = cls.config.compute_admin.username
+ admin_password = cls.config.compute_admin.password
+ admin_tenant = cls.config.compute_admin.tenant_name
- if not cls.admin_username and cls.admin_password and cls.admin_tenant:
+ if not (admin_username and admin_password and admin_tenant):
msg = ("Missing Compute Admin API credentials "
"in configuration.")
raise cls.skipException(msg)
- cls.os = clients.ComputeAdminManager(interface=cls._interface)
+ cls.os_adm = clients.ComputeAdminManager(interface=cls._interface)
class BaseComputeAdminTestJSON(BaseComputeAdminTest):