2015-03-05 17:49:23 +00:00
|
|
|
"""
|
|
|
|
Copyright 2015 Rackspace
|
|
|
|
|
|
|
|
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.
|
|
|
|
"""
|
|
|
|
|
2015-04-21 21:05:45 +00:00
|
|
|
from tempest_lib.exceptions import Conflict
|
|
|
|
from tempest_lib.exceptions import Forbidden
|
2015-05-08 19:50:31 +00:00
|
|
|
from tempest_lib.exceptions import NotFound
|
2015-04-21 21:05:45 +00:00
|
|
|
|
2015-03-13 15:19:00 +00:00
|
|
|
from functionaltests.common import datagen
|
2015-03-24 18:24:37 +00:00
|
|
|
from functionaltests.api.v2.base import DesignateV2Test
|
2015-04-21 21:05:45 +00:00
|
|
|
from functionaltests.api.v2.clients.zone_client import ZoneClient
|
2015-05-08 19:50:31 +00:00
|
|
|
from functionaltests.api.v2.clients.zone_import_client import ZoneImportClient
|
2015-08-27 15:38:54 -05:00
|
|
|
from functionaltests.api.v2.clients.zone_export_client import ZoneExportClient
|
2015-08-28 21:43:24 +00:00
|
|
|
from functionaltests.api.v2.fixtures import ZoneFixture
|
|
|
|
from functionaltests.api.v2.fixtures import ZoneImportFixture
|
|
|
|
from functionaltests.api.v2.fixtures import ZoneExportFixture
|
2015-03-05 17:49:23 +00:00
|
|
|
|
|
|
|
|
2015-03-24 18:24:37 +00:00
|
|
|
class ZoneTest(DesignateV2Test):
|
2015-03-13 15:19:00 +00:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(ZoneTest, self).setUp()
|
2015-04-21 21:05:45 +00:00
|
|
|
self.increase_quotas(user='default')
|
2015-08-28 21:43:24 +00:00
|
|
|
self.fixture = self.useFixture(ZoneFixture(user='default'))
|
2015-03-05 17:49:23 +00:00
|
|
|
|
|
|
|
def test_list_zones(self):
|
2015-04-21 21:05:45 +00:00
|
|
|
resp, model = ZoneClient.as_user('default').list_zones()
|
2015-03-05 17:49:23 +00:00
|
|
|
self.assertEqual(resp.status, 200)
|
2015-03-13 15:19:00 +00:00
|
|
|
self.assertGreater(len(model.zones), 0)
|
|
|
|
|
|
|
|
def test_create_zone(self):
|
2015-08-28 21:43:24 +00:00
|
|
|
self.assertEqual(self.fixture.post_resp.status, 202)
|
2015-03-13 15:19:00 +00:00
|
|
|
|
|
|
|
def test_update_zone(self):
|
2015-08-28 21:43:24 +00:00
|
|
|
old_model = self.fixture.created_zone
|
2015-03-13 15:19:00 +00:00
|
|
|
|
|
|
|
patch_model = datagen.random_zone_data()
|
2015-04-03 15:28:15 +00:00
|
|
|
del patch_model.name # don't try to override the zone name
|
2015-04-21 21:05:45 +00:00
|
|
|
resp, new_model = ZoneClient.as_user('default').patch_zone(
|
|
|
|
old_model.id, patch_model)
|
2015-03-13 15:19:00 +00:00
|
|
|
self.assertEqual(resp.status, 202)
|
2015-04-21 21:05:45 +00:00
|
|
|
ZoneClient.as_user('default').wait_for_zone(new_model.id)
|
2015-03-13 15:19:00 +00:00
|
|
|
|
2015-04-21 21:05:45 +00:00
|
|
|
resp, model = ZoneClient.as_user('default').get_zone(new_model.id)
|
2015-03-13 15:19:00 +00:00
|
|
|
self.assertEqual(resp.status, 200)
|
2015-04-03 15:28:15 +00:00
|
|
|
self.assertEqual(new_model.id, old_model.id)
|
|
|
|
self.assertEqual(new_model.name, old_model.name)
|
|
|
|
self.assertEqual(new_model.ttl, patch_model.ttl)
|
|
|
|
self.assertEqual(new_model.email, patch_model.email)
|
2015-03-13 15:19:00 +00:00
|
|
|
|
|
|
|
def test_delete_zone(self):
|
2015-08-28 21:43:24 +00:00
|
|
|
client = ZoneClient.as_user('default')
|
|
|
|
resp, model = client.delete_zone(self.fixture.created_zone.id)
|
2015-04-21 21:05:45 +00:00
|
|
|
self.assertEqual(resp.status, 202)
|
2015-08-28 21:43:24 +00:00
|
|
|
client.wait_for_zone_404(model.id)
|
2015-04-21 21:05:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ZoneOwnershipTest(DesignateV2Test):
|
|
|
|
|
|
|
|
def setup(self):
|
|
|
|
super(ZoneTest, self).setUp()
|
|
|
|
self.increase_quotas(user='default')
|
|
|
|
self.increase_quotas(user='alt')
|
|
|
|
|
|
|
|
def test_no_create_duplicate_domain(self):
|
2015-08-28 21:43:24 +00:00
|
|
|
post_model = self.useFixture(ZoneFixture(user='default')).post_model
|
2015-04-21 21:05:45 +00:00
|
|
|
self.assertRaises(Conflict,
|
2015-08-28 21:43:24 +00:00
|
|
|
lambda: ZoneClient.as_user('default').post_zone(post_model))
|
2015-04-21 21:05:45 +00:00
|
|
|
self.assertRaises(Conflict,
|
2015-08-28 21:43:24 +00:00
|
|
|
lambda: ZoneClient.as_user('alt').post_zone(post_model))
|
2015-04-21 21:05:45 +00:00
|
|
|
|
|
|
|
def test_no_create_subdomain_by_alt_user(self):
|
2015-08-28 21:43:24 +00:00
|
|
|
zone = self.useFixture(ZoneFixture(user='default')).post_model
|
2015-04-21 21:05:45 +00:00
|
|
|
subzone = datagen.random_zone_data(name='sub.' + zone.name)
|
|
|
|
subsubzone = datagen.random_zone_data(name='sub.sub.' + zone.name)
|
|
|
|
self.assertRaises(Forbidden,
|
2015-08-28 21:43:24 +00:00
|
|
|
lambda: ZoneClient.as_user('alt').post_zone(subzone))
|
2015-04-21 21:05:45 +00:00
|
|
|
self.assertRaises(Forbidden,
|
2015-08-28 21:43:24 +00:00
|
|
|
lambda: ZoneClient.as_user('alt').post_zone(subsubzone))
|
2015-04-21 21:05:45 +00:00
|
|
|
|
|
|
|
def test_no_create_superdomain_by_alt_user(self):
|
|
|
|
superzone = datagen.random_zone_data()
|
|
|
|
zone = datagen.random_zone_data(name="a.b." + superzone.name)
|
2015-08-28 21:43:24 +00:00
|
|
|
self.useFixture(ZoneFixture(zone, user='default'))
|
2015-04-21 21:05:45 +00:00
|
|
|
self.assertRaises(Forbidden,
|
2015-08-28 21:43:24 +00:00
|
|
|
lambda: ZoneClient.as_user('alt').post_zone(superzone))
|
2015-05-08 19:50:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ZoneImportTest(DesignateV2Test):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(ZoneImportTest, self).setUp()
|
2015-08-28 21:43:24 +00:00
|
|
|
self.increase_quotas(user='default')
|
2015-05-08 19:50:31 +00:00
|
|
|
|
|
|
|
def test_import_domain(self):
|
|
|
|
user = 'default'
|
|
|
|
import_client = ZoneImportClient.as_user(user)
|
|
|
|
zone_client = ZoneClient.as_user(user)
|
|
|
|
|
2015-08-28 21:43:24 +00:00
|
|
|
fixture = self.useFixture(ZoneImportFixture(user=user))
|
|
|
|
import_id = fixture.zone_import.id
|
2015-05-08 19:50:31 +00:00
|
|
|
|
2015-08-28 21:43:24 +00:00
|
|
|
resp, model = import_client.get_zone_import(import_id)
|
2015-05-08 19:50:31 +00:00
|
|
|
self.assertEqual(resp.status, 200)
|
|
|
|
self.assertEqual(model.status, 'COMPLETE')
|
2015-08-28 21:43:24 +00:00
|
|
|
self.addCleanup(ZoneFixture.cleanup_zone, zone_client, model.zone_id)
|
2015-05-08 19:50:31 +00:00
|
|
|
|
|
|
|
# Wait for the zone to become 'ACTIVE'
|
|
|
|
zone_client.wait_for_zone(model.zone_id)
|
|
|
|
resp, zone_model = zone_client.get_zone(model.zone_id)
|
|
|
|
|
|
|
|
# Now make sure we can delete the zone_import
|
|
|
|
import_client.delete_zone_import(import_id)
|
|
|
|
self.assertRaises(NotFound,
|
|
|
|
lambda: import_client.get_zone_import(model.id))
|
2015-08-27 15:38:54 -05:00
|
|
|
|
|
|
|
|
|
|
|
class ZoneExportTest(DesignateV2Test):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(ZoneExportTest, self).setUp()
|
2015-08-28 21:43:24 +00:00
|
|
|
self.increase_quotas(user='default')
|
2015-08-27 15:38:54 -05:00
|
|
|
|
2015-08-28 21:43:24 +00:00
|
|
|
def test_export_domain(self):
|
2015-08-27 15:38:54 -05:00
|
|
|
user = 'default'
|
2015-08-28 21:43:24 +00:00
|
|
|
zone_fixture = self.useFixture(ZoneFixture(user=user))
|
|
|
|
zone = zone_fixture.created_zone
|
2015-08-27 15:38:54 -05:00
|
|
|
|
2015-08-28 21:43:24 +00:00
|
|
|
export_fixture = self.useFixture(ZoneExportFixture(zone.id, user=user))
|
|
|
|
export_id = export_fixture.zone_export.id
|
2015-08-27 15:38:54 -05:00
|
|
|
|
2015-08-28 21:43:24 +00:00
|
|
|
export_client = ZoneExportClient.as_user(user)
|
2015-08-27 15:38:54 -05:00
|
|
|
|
|
|
|
resp, model = export_client.get_zone_export(export_id)
|
|
|
|
self.assertEqual(resp.status, 200)
|
|
|
|
self.assertEqual(model.status, 'COMPLETE')
|
|
|
|
|
|
|
|
resp, body = export_client.get_exported_zone(export_id)
|
|
|
|
self.assertEqual(resp.status, 200)
|
|
|
|
|
|
|
|
export_client.delete_zone_export(export_id)
|
|
|
|
self.assertRaises(NotFound,
|
|
|
|
lambda: export_client.get_zone_export(model.id))
|