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-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-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-03-13 15:19:00 +00:00
|
|
|
|
2015-04-21 21:05:45 +00:00
|
|
|
def _create_zone(self, zone_model, user='default'):
|
|
|
|
resp, model = ZoneClient.as_user(user).post_zone(zone_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(user).wait_for_zone(model.id)
|
2015-03-13 15:19:00 +00:00
|
|
|
return resp, model
|
2015-03-05 17:49:23 +00:00
|
|
|
|
|
|
|
def test_list_zones(self):
|
2015-03-13 15:19:00 +00:00
|
|
|
self._create_zone(datagen.random_zone_data())
|
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-04-21 21:05:45 +00:00
|
|
|
self._create_zone(datagen.random_zone_data(), user='default')
|
2015-03-13 15:19:00 +00:00
|
|
|
|
|
|
|
def test_update_zone(self):
|
|
|
|
post_model = datagen.random_zone_data()
|
|
|
|
resp, old_model = self._create_zone(post_model)
|
|
|
|
|
|
|
|
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):
|
|
|
|
resp, model = self._create_zone(datagen.random_zone_data())
|
2015-04-21 21:05:45 +00:00
|
|
|
resp, model = ZoneClient.as_user('default').delete_zone(model.id)
|
|
|
|
self.assertEqual(resp.status, 202)
|
|
|
|
ZoneClient.as_user('default').wait_for_zone_404(model.id)
|
|
|
|
|
|
|
|
|
|
|
|
class ZoneOwnershipTest(DesignateV2Test):
|
|
|
|
|
|
|
|
def setup(self):
|
|
|
|
super(ZoneTest, self).setUp()
|
|
|
|
self.increase_quotas(user='default')
|
|
|
|
self.increase_quotas(user='alt')
|
|
|
|
|
|
|
|
def _create_zone(self, zone_model, user):
|
|
|
|
resp, model = ZoneClient.as_user(user).post_zone(zone_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(user).wait_for_zone(model.id)
|
|
|
|
return resp, model
|
|
|
|
|
|
|
|
def test_no_create_duplicate_domain(self):
|
|
|
|
zone = datagen.random_zone_data()
|
|
|
|
self._create_zone(zone, user='default')
|
|
|
|
self.assertRaises(Conflict,
|
|
|
|
lambda: self._create_zone(zone, user='default'))
|
|
|
|
self.assertRaises(Conflict,
|
|
|
|
lambda: self._create_zone(zone, user='alt'))
|
|
|
|
|
|
|
|
def test_no_create_subdomain_by_alt_user(self):
|
|
|
|
zone = datagen.random_zone_data()
|
|
|
|
subzone = datagen.random_zone_data(name='sub.' + zone.name)
|
|
|
|
subsubzone = datagen.random_zone_data(name='sub.sub.' + zone.name)
|
|
|
|
self._create_zone(zone, user='default')
|
|
|
|
self.assertRaises(Forbidden,
|
|
|
|
lambda: self._create_zone(subzone, user='alt'))
|
|
|
|
self.assertRaises(Forbidden,
|
|
|
|
lambda: self._create_zone(subsubzone, user='alt'))
|
|
|
|
|
|
|
|
def test_no_create_superdomain_by_alt_user(self):
|
|
|
|
superzone = datagen.random_zone_data()
|
|
|
|
zone = datagen.random_zone_data(name="a.b." + superzone.name)
|
|
|
|
self._create_zone(zone, user='default')
|
|
|
|
self.assertRaises(Forbidden,
|
|
|
|
lambda: self._create_zone(superzone, user='alt'))
|