Merge "Add Tempest tests for V2 Pools"
This commit is contained in:
commit
77db137bfd
53
functionaltests/api/v2/clients/pool_client.py
Normal file
53
functionaltests/api/v2/clients/pool_client.py
Normal file
@ -0,0 +1,53 @@
|
||||
# Copyright 2015 Hewlett-Packard Development Company, L.P.
|
||||
#
|
||||
# Author: Endre Karlson <endre.karlson@hp.com>
|
||||
#
|
||||
# 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 functionaltests.api.v2.models.pool_model import PoolModel
|
||||
from functionaltests.api.v2.models.pool_model import PoolListModel
|
||||
from functionaltests.common.client import ClientMixin
|
||||
|
||||
|
||||
class PoolClient(ClientMixin):
|
||||
|
||||
@classmethod
|
||||
def pools_uri(cls):
|
||||
return "/v2/pools"
|
||||
|
||||
@classmethod
|
||||
def pool_uri(cls, pool_id):
|
||||
return "{0}/{1}".format(cls.pools_uri(), pool_id)
|
||||
|
||||
def list_pools(self, **kwargs):
|
||||
resp, body = self.client.get(self.pools_uri(), **kwargs)
|
||||
return self.deserialize(resp, body, PoolListModel)
|
||||
|
||||
def get_pool(self, pool_id, **kwargs):
|
||||
resp, body = self.client.get(self.pool_uri(pool_id))
|
||||
return self.deserialize(resp, body, PoolModel)
|
||||
|
||||
def post_pool(self, pool_model, **kwargs):
|
||||
resp, body = self.client.post(
|
||||
self.pools_uri(),
|
||||
body=pool_model.to_json(), **kwargs)
|
||||
return self.deserialize(resp, body, PoolModel)
|
||||
|
||||
def patch_pool(self, pool_id, pool_model, **kwargs):
|
||||
resp, body = self.client.patch(
|
||||
self.pool_uri(pool_id),
|
||||
body=pool_model.to_json(), **kwargs)
|
||||
return self.deserialize(resp, body, PoolModel)
|
||||
|
||||
def delete_pool(self, pool_id, **kwargs):
|
||||
return self.client.delete(self.pool_uri(pool_id), **kwargs)
|
33
functionaltests/api/v2/models/pool_model.py
Normal file
33
functionaltests/api/v2/models/pool_model.py
Normal file
@ -0,0 +1,33 @@
|
||||
# Copyright 2015 Hewlett-Packard Development Company, L.P.
|
||||
#
|
||||
# Author: Endre Karlson <endre.karlson@hp.com>
|
||||
#
|
||||
# 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 functionaltests.common.models import BaseModel
|
||||
from functionaltests.common.models import CollectionModel
|
||||
from functionaltests.common.models import EntityModel
|
||||
|
||||
|
||||
class PoolData(BaseModel):
|
||||
pass
|
||||
|
||||
|
||||
class PoolModel(EntityModel):
|
||||
ENTITY_NAME = 'pool'
|
||||
MODEL_TYPE = PoolData
|
||||
|
||||
|
||||
class PoolListModel(CollectionModel):
|
||||
COLLECTION_NAME = 'pools'
|
||||
MODEL_TYPE = PoolData
|
92
functionaltests/api/v2/test_pool.py
Normal file
92
functionaltests/api/v2/test_pool.py
Normal file
@ -0,0 +1,92 @@
|
||||
# Copyright 2015 Hewlett-Packard Development Company, L.P.
|
||||
#
|
||||
# Author: Endre Karlson <endre.karlson@hp.com>
|
||||
#
|
||||
# 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 uuid
|
||||
|
||||
from tempest_lib import exceptions
|
||||
|
||||
from functionaltests.common import datagen
|
||||
from functionaltests.api.v2.base import DesignateV2Test
|
||||
from functionaltests.api.v2.clients.pool_client import PoolClient
|
||||
|
||||
|
||||
class PoolTest(DesignateV2Test):
|
||||
def _create_pool(self, pool_model, user='admin'):
|
||||
resp, model = PoolClient.as_user(user).post_pool(pool_model)
|
||||
self.assertEqual(resp.status, 201)
|
||||
return resp, model
|
||||
|
||||
def test_list_pools(self):
|
||||
self._create_pool(datagen.random_pool_data())
|
||||
resp, model = PoolClient.as_user('admin').list_pools()
|
||||
self.assertEqual(resp.status, 200)
|
||||
self.assertGreater(len(model.pools), 0)
|
||||
|
||||
def test_create_pool(self):
|
||||
self._create_pool(datagen.random_pool_data(), user='admin')
|
||||
|
||||
def test_update_pool(self):
|
||||
post_model = datagen.random_pool_data()
|
||||
resp, old_model = self._create_pool(post_model)
|
||||
|
||||
patch_model = datagen.random_pool_data()
|
||||
resp, new_model = PoolClient.as_user('admin').patch_pool(
|
||||
old_model.id, patch_model)
|
||||
self.assertEqual(resp.status, 200)
|
||||
|
||||
resp, model = PoolClient.as_user('admin').get_pool(new_model.id)
|
||||
self.assertEqual(resp.status, 200)
|
||||
self.assertEqual(new_model.id, old_model.id)
|
||||
self.assertEqual(new_model.name, patch_model.name)
|
||||
|
||||
def test_delete_pool(self):
|
||||
resp, model = self._create_pool(datagen.random_pool_data())
|
||||
resp, model = PoolClient.as_user('admin').delete_pool(model.id)
|
||||
self.assertEqual(resp.status, 204)
|
||||
|
||||
def test_get_pool_404(self):
|
||||
client = PoolClient.as_user('admin')
|
||||
self._assert_exception(
|
||||
exceptions.NotFound, 'pool_not_found', 404, client.get_pool,
|
||||
str(uuid.uuid4()))
|
||||
|
||||
def test_update_pool_404(self):
|
||||
model = datagen.random_pool_data()
|
||||
|
||||
client = PoolClient.as_user('admin')
|
||||
self._assert_exception(
|
||||
exceptions.NotFound, 'pool_not_found', 404, client.patch_pool,
|
||||
str(uuid.uuid4()), model)
|
||||
|
||||
def test_delete_pool_404(self):
|
||||
client = PoolClient.as_user('admin')
|
||||
self._assert_exception(
|
||||
exceptions.NotFound, 'pool_not_found', 404, client.delete_pool,
|
||||
str(uuid.uuid4()))
|
||||
|
||||
def test_get_pool_invalid_uuid(self):
|
||||
client = PoolClient.as_user('admin')
|
||||
self._assert_invalid_uuid(client.get_pool, 'fooo')
|
||||
|
||||
def test_update_pool_invalid_uuid(self):
|
||||
model = datagen.random_pool_data()
|
||||
|
||||
client = PoolClient.as_user('admin')
|
||||
self._assert_invalid_uuid(client.patch_pool, 'fooo', model)
|
||||
|
||||
def test_delete_pool_invalid_uuid(self):
|
||||
client = PoolClient.as_user('admin')
|
||||
self._assert_invalid_uuid(client.get_pool, 'fooo')
|
@ -18,6 +18,7 @@ import random
|
||||
|
||||
from functionaltests.api.v2.models.zone_model import ZoneModel
|
||||
from functionaltests.api.v2.models.recordset_model import RecordsetModel
|
||||
from functionaltests.api.v2.models.pool_model import PoolModel
|
||||
|
||||
|
||||
def random_ip():
|
||||
@ -106,3 +107,16 @@ def random_mx_recordset(zone_name, pref=None, host=None, **kwargs):
|
||||
host = random_string(prefix='mail', suffix='.' + zone_name)
|
||||
data = "{0} {1}".format(pref, host)
|
||||
return random_recordset_data('MX', zone_name, records=[data], **kwargs)
|
||||
|
||||
|
||||
def random_pool_data():
|
||||
ns_zone = random_zone_data().name
|
||||
data = {
|
||||
"name": random_string(),
|
||||
}
|
||||
ns_records = []
|
||||
for i in range(0, 2):
|
||||
ns_records.append("ns%s.%s" % (i, ns_zone))
|
||||
data["ns_records"] = []
|
||||
|
||||
return PoolModel.from_dict(data)
|
||||
|
Loading…
Reference in New Issue
Block a user