Merge "Adding four new test cases to "import zone" test suite"
This commit is contained in:
commit
2be3d99449
|
@ -12,5 +12,10 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
# API statuses
|
||||
# Designate statuses strings
|
||||
PENDING = 'PENDING'
|
||||
COMPLETE = 'COMPLETE'
|
||||
ERROR = 'ERROR'
|
||||
DELETED = 'DELETED'
|
||||
ACTIVE = 'ACTIVE'
|
||||
UP = 'UP'
|
||||
|
|
|
@ -43,25 +43,27 @@ class ZoneImportsClient(base.DnsClientV2Base):
|
|||
return resp, body
|
||||
|
||||
@base.handle_errors
|
||||
def show_zone_import(self, uuid, params=None):
|
||||
def show_zone_import(self, uuid, params=None, headers=None):
|
||||
"""Gets a specific zone import.
|
||||
:param uuid: Unique identifier of the imported zone in UUID format.
|
||||
:param params: A Python dict that represents the query paramaters to
|
||||
include in the request URI.
|
||||
:param headers (dict): The headers to use for the request.
|
||||
:return: Serialized imported zone as a dictionary.
|
||||
"""
|
||||
return self._show_request(
|
||||
'zones/tasks/imports', uuid, params=params)
|
||||
'zones/tasks/imports', uuid, params=params, headers=headers)
|
||||
|
||||
@base.handle_errors
|
||||
def list_zone_imports(self, params=None):
|
||||
def list_zone_imports(self, params=None, headers=None):
|
||||
"""Gets all the imported zones.
|
||||
:param params: A Python dict that represents the query paramaters to
|
||||
include in the request URI.
|
||||
:param headers (dict): The headers to use for the request.
|
||||
:return: Serialized imported zones as a list.
|
||||
"""
|
||||
return self._list_request(
|
||||
'zones/tasks/imports', params=params)
|
||||
'zones/tasks/imports', params=params, headers=headers)
|
||||
|
||||
@base.handle_errors
|
||||
def delete_zone_import(self, uuid, params=None):
|
||||
|
|
|
@ -16,8 +16,10 @@ from oslo_log import log as logging
|
|||
from tempest.lib import decorators
|
||||
from tempest.lib import exceptions as lib_exc
|
||||
|
||||
from designate_tempest_plugin.common import constants as const
|
||||
from designate_tempest_plugin.common import waiters
|
||||
from designate_tempest_plugin.tests import base
|
||||
from designate_tempest_plugin import data_utils as dns_data_utils
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
@ -28,6 +30,8 @@ class BaseZonesImportTest(base.BaseDnsV2Test):
|
|||
|
||||
|
||||
class ZonesImportTest(BaseZonesImportTest):
|
||||
credentials = ['primary', 'admin', 'alt']
|
||||
|
||||
@classmethod
|
||||
def setup_credentials(cls):
|
||||
# Do not create network resources for these test.
|
||||
|
@ -39,14 +43,19 @@ class ZonesImportTest(BaseZonesImportTest):
|
|||
super(ZonesImportTest, cls).setup_clients()
|
||||
|
||||
cls.client = cls.os_primary.zone_imports_client
|
||||
cls.alt_client = cls.os_alt.zone_imports_client
|
||||
cls.admin_client = cls.os_admin.zone_imports_client
|
||||
cls.zone_client = cls.os_primary.zones_client
|
||||
|
||||
def clean_up_resources(self, zone_import_id):
|
||||
waiters.wait_for_zone_import_status(self.client, zone_import_id,
|
||||
"COMPLETE")
|
||||
_, zone_import = self.client.show_zone_import(zone_import_id)
|
||||
self.client.delete_zone_import(zone_import['id'])
|
||||
self.wait_zone_delete(self.zone_client, zone_import['zone_id'])
|
||||
zone_import = self.client.show_zone_import(zone_import_id)[1]
|
||||
if zone_import['zone_id']: # A zone was actually created.
|
||||
waiters.wait_for_zone_import_status(
|
||||
self.client, zone_import_id, const.COMPLETE)
|
||||
self.client.delete_zone_import(zone_import['id'])
|
||||
self.wait_zone_delete(self.zone_client, zone_import['zone_id'])
|
||||
else: # Import has failed and zone wasn't created.
|
||||
self.client.delete_zone_import(zone_import['id'])
|
||||
|
||||
@decorators.idempotent_id('2e2d907d-0609-405b-9c96-3cb2b87e3dce')
|
||||
def test_create_zone_import(self):
|
||||
|
@ -55,7 +64,29 @@ class ZonesImportTest(BaseZonesImportTest):
|
|||
self.addCleanup(self.clean_up_resources, zone_import['id'])
|
||||
|
||||
LOG.info('Ensure we respond with PENDING')
|
||||
self.assertEqual('PENDING', zone_import['status'])
|
||||
self.assertEqual(const.PENDING, zone_import['status'])
|
||||
|
||||
@decorators.idempotent_id('31eaf25a-9532-11eb-a55d-74e5f9e2a801')
|
||||
def test_create_zone_import_invalid_ttl(self):
|
||||
LOG.info('Try to create a zone import using invalid TTL value')
|
||||
zone_import = self.client.create_zone_import(
|
||||
zonefile_data=dns_data_utils.rand_zonefile_data(ttl='zahlabut'))[1]
|
||||
self.addCleanup(self.clean_up_resources, zone_import['id'])
|
||||
self.assertEqual(
|
||||
const.ERROR,
|
||||
self.client.show_zone_import(zone_import['id'])[1]['status'],
|
||||
'Failed, expected status is: ERROR')
|
||||
|
||||
@decorators.idempotent_id('31eaf25a-9532-11eb-a55d-74e5f9e2a801')
|
||||
def test_create_zone_import_invalid_name(self):
|
||||
LOG.info('Try to create a zone import using invalid name')
|
||||
zone_import = self.client.create_zone_import(
|
||||
zonefile_data=dns_data_utils.rand_zonefile_data(name='@@@'))[1]
|
||||
self.addCleanup(self.clean_up_resources, zone_import['id'])
|
||||
self.assertEqual(
|
||||
const.ERROR,
|
||||
self.client.show_zone_import(zone_import['id'])[1]['status'],
|
||||
'Failed, expected status is: ERROR')
|
||||
|
||||
@decorators.attr(type='smoke')
|
||||
@decorators.idempotent_id('c8909558-0dc6-478a-9e91-eb97b52e59e0')
|
||||
|
@ -75,7 +106,7 @@ class ZonesImportTest(BaseZonesImportTest):
|
|||
LOG.info('Create a zone import')
|
||||
_, zone_import = self.client.create_zone_import()
|
||||
waiters.wait_for_zone_import_status(self.client, zone_import['id'],
|
||||
"COMPLETE")
|
||||
const.COMPLETE)
|
||||
_, zone_import = self.client.show_zone_import(zone_import['id'])
|
||||
self.addCleanup(self.wait_zone_delete,
|
||||
self.zone_client,
|
||||
|
@ -98,3 +129,78 @@ class ZonesImportTest(BaseZonesImportTest):
|
|||
_, body = self.client.list_zone_imports()
|
||||
|
||||
self.assertGreater(len(body['imports']), 0)
|
||||
|
||||
@decorators.idempotent_id('2c1fa20e-9554-11eb-a55d-74e5f9e2a801')
|
||||
def test_show_import_impersonate_another_project(self):
|
||||
|
||||
LOG.info('Import zone "A" using primary client')
|
||||
zone_import = self.client.create_zone_import()[1]
|
||||
self.addCleanup(self.clean_up_resources, zone_import['id'])
|
||||
|
||||
LOG.info('Ensure we respond with PENDING')
|
||||
self.assertEqual(const.PENDING, zone_import['status'])
|
||||
|
||||
LOG.info('Show a zone import for a Primary tenant, using Alt tenant. '
|
||||
'Expected:404 NotFound')
|
||||
self.assertRaises(lib_exc.NotFound,
|
||||
lambda: self.alt_client.show_zone_import(
|
||||
zone_import['id']))
|
||||
|
||||
LOG.info('Show a zone import for a Primary tenant using Alt tenant '
|
||||
'and "x-auth-sudo-project-id" HTTP header. '
|
||||
'Expected:403 Forbidden')
|
||||
self.assertRaises(
|
||||
lib_exc.Forbidden,
|
||||
lambda: self.alt_client.show_zone_import(
|
||||
zone_import['id'],
|
||||
headers={'x-auth-sudo-project-id': zone_import[
|
||||
'project_id']}))
|
||||
|
||||
LOG.info('Show a zone import for a Primary tenant, using Admin '
|
||||
'tenant and "x-auth-sudo-project-id" HTTP header.')
|
||||
resp_body = self.admin_client.show_zone_import(uuid=None, headers={
|
||||
'x-auth-sudo-project-id': zone_import['project_id']})[1]
|
||||
|
||||
LOG.info('Show a zone import for a Primary tenant, using Admin '
|
||||
'tenant without "x-auth-sudo-project-id" HTTP header. '
|
||||
'Expected:404 NotFound')
|
||||
self.assertRaises(
|
||||
lib_exc.NotFound, lambda: self.admin_client.show_zone_import(
|
||||
zone_import['id']))
|
||||
|
||||
LOG.info('Ensure that the shown response matches the expected one')
|
||||
self.assertExpected(
|
||||
zone_import, resp_body['imports'][0], self.excluded_keys)
|
||||
|
||||
@decorators.idempotent_id('7bd06ec6-9556-11eb-a55d-74e5f9e2a801')
|
||||
def test_list_import_zones_all_projects(self):
|
||||
LOG.info('Create import zone "A" using primary client')
|
||||
zone_import = self.client.create_zone_import()[1]
|
||||
self.addCleanup(self.clean_up_resources, zone_import['id'])
|
||||
|
||||
LOG.info('As Alt user list import zones for a Primary tenant, '
|
||||
'using "x-auth-sudo-project-id" HTTP header. '
|
||||
'Expected: 403 Forbidden')
|
||||
self.assertRaises(
|
||||
lib_exc.Forbidden, lambda: self.alt_client.list_zone_imports(
|
||||
headers={
|
||||
'x-auth-sudo-project-id': zone_import['project_id']}))
|
||||
|
||||
LOG.info('As Alt tenant list zone imports for all projects, using '
|
||||
'"x-auth-all-projects" HTTP header, Expected: 403 Forbidden')
|
||||
self.assertRaises(
|
||||
lib_exc.Forbidden, lambda: self.alt_client.list_zone_imports(
|
||||
headers={'x-auth-all-projects': True}))
|
||||
|
||||
LOG.info('As Admin tenant list import zones for all projects')
|
||||
body = self.admin_client.list_zone_imports(headers={
|
||||
'x-auth-all-projects': True})[1]['imports']
|
||||
|
||||
LOG.info('Ensure the fetched response includes previously '
|
||||
'created import ID')
|
||||
listed_zone_import_ids = [item['id'] for item in body]
|
||||
self.assertIn(
|
||||
zone_import['id'], listed_zone_import_ids,
|
||||
"Failed, expected import ID:{} wasn't found in "
|
||||
"listed import IDs".format(
|
||||
zone_import['id'], listed_zone_import_ids))
|
||||
|
|
Loading…
Reference in New Issue