Merge "Adding five test cases into the 'zone export' test suite."
diff --git a/designate_tempest_plugin/services/dns/v2/json/zone_exports_client.py b/designate_tempest_plugin/services/dns/v2/json/zone_exports_client.py
index 3bbd6c9..8915ceb 100644
--- a/designate_tempest_plugin/services/dns/v2/json/zone_exports_client.py
+++ b/designate_tempest_plugin/services/dns/v2/json/zone_exports_client.py
@@ -43,16 +43,17 @@
return resp, body
@base.handle_errors
- def show_zone_export(self, uuid, params=None):
+ def show_zone_export(self, uuid, params=None, headers=None):
"""Get the zone export task
:param uuid: Unique identifier of the zone export task 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 exported zone as a dictionary.
"""
return self._show_request(
- 'zones/tasks/exports', uuid, params=params)
+ 'zones/tasks/exports', uuid, params=params, headers=headers)
@base.handle_errors
def show_exported_zonefile(self, uuid, params=None):
@@ -70,15 +71,16 @@
headers=headers, params=params)
@base.handle_errors
- def list_zone_exports(self, params=None):
+ def list_zone_exports(self, params=None, headers=None):
"""List zone export tasks
: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 exported zone as a list.
"""
return self._list_request(
- 'zones/tasks/exports', params=params)
+ 'zones/tasks/exports', params=params, headers=headers)
@base.handle_errors
def delete_zone_export(self, uuid, params=None):
diff --git a/designate_tempest_plugin/tests/api/v2/test_zones_exports.py b/designate_tempest_plugin/tests/api/v2/test_zones_exports.py
index 13cd077..34a2c41 100644
--- a/designate_tempest_plugin/tests/api/v2/test_zones_exports.py
+++ b/designate_tempest_plugin/tests/api/v2/test_zones_exports.py
@@ -27,6 +27,8 @@
class ZonesExportTest(BaseZoneExportsTest):
+ credentials = ['primary', 'admin', 'alt']
+
@classmethod
def setup_credentials(cls):
# Do not create network resources for these test.
@@ -38,7 +40,10 @@
super(ZonesExportTest, cls).setup_clients()
cls.zone_client = cls.os_primary.zones_client
+ cls.alt_zone_client = cls.os_alt.zones_client
cls.client = cls.os_primary.zone_exports_client
+ cls.alt_client = cls.os_alt.zone_exports_client
+ cls.admin_client = cls.os_admin.zone_exports_client
@decorators.idempotent_id('2dd8a9a0-98a2-4bf6-bb51-286583b30f40')
def test_create_zone_export(self):
@@ -53,6 +58,12 @@
LOG.info('Ensure we respond with PENDING')
self.assertEqual('PENDING', zone_export['status'])
+ @decorators.idempotent_id('76ab8ec4-95fd-11eb-b1cd-74e5f9e2a801')
+ def test_create_zone_export_using_invalid_zone_id(self):
+ self.assertRaises(
+ lib_exc.NotFound, self.client.create_zone_export,
+ 'e35bc796-9841-11eb-898b-74e5f9e2a801')
+
@decorators.attr(type='smoke')
@decorators.idempotent_id('2d29a2a9-1941-4b7e-9d8a-ad6c2140ea68')
def test_show_zone_export(self):
@@ -70,6 +81,29 @@
LOG.info('Ensure the fetched response matches the zone export')
self.assertExpected(zone_export, body, self.excluded_keys)
+ @decorators.idempotent_id('fb04507c-9600-11eb-b1cd-74e5f9e2a801')
+ def test_show_zone_export_impersonate_another_project(self):
+ LOG.info('Create a zone')
+ zone = self.zone_client.create_zone()[1]
+ self.addCleanup(self.wait_zone_delete, self.zone_client, zone['id'])
+
+ LOG.info('Create a zone export using primary client')
+ resp, zone_export = self.client.create_zone_export(zone['id'])
+ self.addCleanup(self.client.delete_zone_export, zone_export['id'])
+
+ LOG.info('Impersonate "primary" client, to show created zone exports')
+ body = self.admin_client.show_zone_export(uuid=None, headers={
+ 'x-auth-sudo-project-id': zone['project_id']})[1]['exports']
+ listed_export_ids = [item['id'] for item in body]
+
+ LOG.info('Ensure that the fetched response, contains the ID '
+ 'for a zone export created by primary client.')
+ self.assertIn(
+ zone_export['id'], listed_export_ids,
+ 'Failed, expected ID:{} was not found in listed export zones '
+ 'for a primary client: {}'.format(
+ zone_export['id'], listed_export_ids))
+
@decorators.idempotent_id('97234f00-8bcb-43f8-84dd-874f8bc4a80e')
def test_delete_zone_export(self):
LOG.info('Create a zone')
@@ -100,3 +134,59 @@
_, body = self.client.list_zone_exports()
self.assertGreater(len(body['exports']), 0)
+
+ @decorators.idempotent_id('f34e7f34-9613-11eb-b1cd-74e5f9e2a801')
+ def test_list_zone_exports_all_projects(self):
+ LOG.info('Create a primary zone and its export')
+ primary_zone = self.zone_client.create_zone()[1]
+ self.addCleanup(
+ self.wait_zone_delete, self.zone_client, primary_zone['id'])
+ primary_export = self.client.create_zone_export(primary_zone['id'])[1]
+ self.addCleanup(self.client.delete_zone_export, primary_export['id'])
+
+ LOG.info('Create an alt zone and its export')
+ alt_zone = self.alt_zone_client.create_zone()[1]
+ self.addCleanup(
+ self.wait_zone_delete, self.alt_zone_client, alt_zone['id'])
+ alt_export = self.alt_client.create_zone_export(alt_zone['id'])[1]
+ self.addCleanup(self.alt_client.delete_zone_export, alt_export['id'])
+
+ LOG.info('As admin user list zone exports for all projects')
+ listed_exports_ids = [
+ item['id'] for item in self.admin_client.list_zone_exports(
+ headers={'x-auth-all-projects': True})[1]['exports']]
+
+ LOG.info('Make sure that all previously created zone '
+ 'export IDs are listed')
+ for id in [primary_export['id'], alt_export['id']]:
+ self.assertIn(
+ id, listed_exports_ids,
+ 'Failed, expected ID:{} was not found in '
+ 'listed IDs:{}'.format(id, listed_exports_ids))
+
+ @decorators.idempotent_id('943dad4a-9617-11eb-b1cd-74e5f9e2a801')
+ def test_export_not_your_zone(self):
+ LOG.info('Create a primary zone.')
+ primary_zone = self.zone_client.create_zone()[1]
+ self.addCleanup(
+ self.wait_zone_delete, self.zone_client, primary_zone['id'])
+
+ LOG.info('Make sure that "404 NotFound" status code is raised.')
+ self.assertRaises(
+ lib_exc.NotFound, self.alt_client.create_zone_export,
+ primary_zone['id'])
+
+ @decorators.idempotent_id('518dc308-9604-11eb-b1cd-74e5f9e2a801')
+ def test_create_zone_export_using_deleted_zone(self):
+ LOG.info('Create a zone')
+ zone = self.zone_client.create_zone()[1]
+ self.addCleanup(self.wait_zone_delete, self.zone_client, zone['id'],
+ ignore_errors=lib_exc.NotFound)
+
+ LOG.info("Delete the zone and wait till it's done.")
+ self.zone_client.delete_zone(zone['id'])[1]
+ self.wait_zone_delete(self.zone_client, zone['id'])
+
+ LOG.info('Ensure we respond with NotFound exception')
+ self.assertRaises(
+ lib_exc.NotFound, self.client.create_zone_export, zone['id'])