Add blacklist client + smoke tests
Change-Id: I2b780f5bada2272f6fd37a45f0b66f1a3ada0613
diff --git a/designate_tempest_plugin/clients.py b/designate_tempest_plugin/clients.py
index 805eeda..8e83bcf 100644
--- a/designate_tempest_plugin/clients.py
+++ b/designate_tempest_plugin/clients.py
@@ -18,6 +18,8 @@
ZonesClient
from designate_tempest_plugin.services.dns.v2.json.zone_imports_client import \
ZoneImportsClient
+from designate_tempest_plugin.services.dns.v2.json.blacklists_client import \
+ BlacklistsClient
CONF = config.CONF
@@ -38,3 +40,4 @@
self.zones_client = ZonesClient(self.auth_provider, **params)
self.zone_imports_client = ZoneImportsClient(self.auth_provider,
**params)
+ self.blacklists_client = BlacklistsClient(self.auth_provider, **params)
diff --git a/designate_tempest_plugin/services/dns/json/base.py b/designate_tempest_plugin/services/dns/json/base.py
index e49885a..9068c78 100644
--- a/designate_tempest_plugin/services/dns/json/base.py
+++ b/designate_tempest_plugin/services/dns/json/base.py
@@ -156,7 +156,7 @@
resp, body = self.patch(uri, body=body)
- self.expected_success(202, resp.status)
+ self.expected_success([200, 202], resp.status)
return resp, self.deserialize(body)
diff --git a/designate_tempest_plugin/services/dns/v2/json/blacklists_client.py b/designate_tempest_plugin/services/dns/v2/json/blacklists_client.py
new file mode 100644
index 0000000..c3f6de1
--- /dev/null
+++ b/designate_tempest_plugin/services/dns/v2/json/blacklists_client.py
@@ -0,0 +1,106 @@
+# Copyright 2016 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.
+from tempest.lib.common.utils import data_utils
+
+from designate_tempest_plugin import data_utils as dns_data_utils
+from designate_tempest_plugin.services.dns.v2.json import base
+
+
+class BlacklistsClient(base.DnsClientV2Base):
+
+ @base.handle_errors
+ def create_blacklist(self, pattern=None, description=None, params=None):
+ """Create a blacklist
+
+ :param pattern: The blacklist pattern.
+ Default: Random Value
+ :param description: A description of the blacklist.
+ Default: Random Value
+ :param params: A Python dict that represents the query paramaters to
+ include in the request URI.
+ :return: A tuple with the server response and the created blacklist.
+ """
+ blacklist = {
+ 'pattern': pattern or dns_data_utils.rand_zone_name(),
+ 'description': description or data_utils.rand_name(),
+ }
+
+ resp, body = self._create_request('blacklists', blacklist,
+ params=params)
+
+ self.expected_success(201, resp.status)
+
+ return resp, body
+
+ @base.handle_errors
+ def show_blacklist(self, uuid, params=None):
+ """Gets a specified blacklist.
+
+ :param uuid: Unique identifier of the blacklist in UUID format.
+ :param params: A Python dict that represents the query paramaters to
+ include in the request URI.
+ :return: Serialized blacklist as a dictionary.
+ """
+ return self._show_request('blacklists', uuid, params=params)
+
+ @base.handle_errors
+ def list_blacklists(self, params=None):
+ """Gets a list of blacklists.
+
+ :param params: A Python dict that represents the query paramaters to
+ include in the request URI.
+ :return: Serialized blacklists as a list.
+ """
+ return self._list_request('blacklists', params=params)
+
+ @base.handle_errors
+ def delete_blacklist(self, uuid, params=None):
+ """Deletes a blacklist having the specified UUID.
+
+ :param uuid: The unique identifier of the blacklist.
+ :param params: A Python dict that represents the query paramaters to
+ include in the request URI.
+ :return: A tuple with the server response and the response body.
+ """
+ resp, body = self._delete_request('blacklists', uuid, params=params)
+
+ self.expected_success(204, resp.status)
+
+ return resp, body
+
+ @base.handle_errors
+ def update_blacklist(self, uuid, pattern=None, description=None,
+ params=None):
+ """Update a blacklist with the specified parameters.
+
+ :param uuid: The unique identifier of the blacklist.
+ :param pattern: The blacklist pattern.
+ Default: Random Value
+ :param description: A description of the blacklist.
+ Default: Random Value
+ :param params: A Python dict that represents the query paramaters to
+ include in the request URI.
+ :return: A tuple with the server response and the updated blacklist.
+ """
+ blacklist = {
+ 'pattern': pattern or dns_data_utils.rand_zone_name(),
+ 'description': description or data_utils.rand_name(),
+ }
+
+ resp, body = self._update_request('blacklists', uuid, blacklist,
+ params=params)
+
+ self.expected_success(200, resp.status)
+
+ return resp, body
diff --git a/designate_tempest_plugin/tests/api/v2/test_blacklists.py b/designate_tempest_plugin/tests/api/v2/test_blacklists.py
new file mode 100644
index 0000000..791a22c
--- /dev/null
+++ b/designate_tempest_plugin/tests/api/v2/test_blacklists.py
@@ -0,0 +1,109 @@
+# Copyright 2016 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.
+from oslo_log import log as logging
+from tempest import test
+from tempest.lib import exceptions as lib_exc
+from tempest.lib.common.utils import data_utils
+
+from designate_tempest_plugin import data_utils as dns_data_utils
+from designate_tempest_plugin.tests import base
+
+LOG = logging.getLogger(__name__)
+
+
+class BaseBlacklistsTest(base.BaseDnsTest):
+ excluded_keys = ['created_at', 'updated_at', 'links']
+
+
+class BlacklistsAdminTest(BaseBlacklistsTest):
+
+ credentials = ["admin"]
+
+ @classmethod
+ def setup_clients(cls):
+ super(BlacklistsAdminTest, cls).setup_clients()
+ cls.admin_client = cls.os_adm.blacklists_client
+
+ @test.attr(type='smoke')
+ @test.idempotent_id('3a7f7564-6bdd-446e-addc-a3475b4c3f71')
+ def test_create_blacklist(self):
+ LOG.info('Create a blacklist')
+ blacklist = {
+ 'pattern': dns_data_utils.rand_zone_name(),
+ 'description': data_utils.rand_name(),
+ }
+ _, body = self.admin_client.create_blacklist(**blacklist)
+ self.addCleanup(self.admin_client.delete_blacklist, body['id'])
+
+ self.assertExpected(blacklist, body, self.excluded_keys)
+
+ @test.attr(type='smoke')
+ @test.idempotent_id('5bc02942-6225-4619-8f49-2105581a8dd6')
+ def test_show_blacklist(self):
+ LOG.info('Create a blacklist')
+ _, blacklist = self.admin_client.create_blacklist()
+ self.addCleanup(self.admin_client.delete_blacklist, blacklist['id'])
+
+ LOG.info('Fetch the blacklist')
+ _, body = self.admin_client.show_blacklist(blacklist['id'])
+
+ LOG.info('Ensure the fetched response matches the created blacklist')
+ self.assertExpected(blacklist, body, self.excluded_keys)
+
+ @test.attr(type='smoke')
+ @test.idempotent_id('dcea40d9-8d36-43cb-8440-4a842faaef0d')
+ def test_delete_blacklist(self):
+ LOG.info('Create a blacklist')
+ _, blacklist = self.admin_client.create_blacklist()
+ self.addCleanup(self.admin_client.delete_blacklist, blacklist['id'],
+ ignore_errors=lib_exc.NotFound)
+
+ LOG.info('Delete the blacklist')
+ _, body = self.admin_client.delete_blacklist(blacklist['id'])
+
+ # A blacklist delete returns an empty body
+ self.assertEqual(body.strip(), "")
+
+ @test.attr(type='smoke')
+ @test.idempotent_id('3a2a1e6c-8176-428c-b5dd-d85217c0209d')
+ def test_list_blacklists(self):
+ LOG.info('Create a blacklist')
+ _, blacklist = self.admin_client.create_blacklist()
+ self.addCleanup(self.admin_client.delete_blacklist, blacklist['id'])
+
+ LOG.info('List blacklists')
+ _, body = self.admin_client.list_blacklists()
+
+ # TODO(pglass): Assert that the created blacklist is in the response
+ self.assertGreater(len(body['blacklists']), 0)
+
+ @test.attr(type='smoke')
+ @test.idempotent_id('0063d6ad-9557-49c7-b521-e64a14d4d0d0')
+ def test_update_blacklist(self):
+ LOG.info('Create a blacklist')
+ _, blacklist = self.admin_client.create_blacklist()
+ self.addCleanup(self.admin_client.delete_blacklist, blacklist['id'])
+
+ LOG.info('Update the blacklist')
+ pattern = dns_data_utils.rand_zone_name()
+ description = data_utils.rand_name()
+ _, body = self.admin_client.update_blacklist(
+ uuid=blacklist['id'],
+ pattern=pattern,
+ description=description,
+ )
+
+ LOG.info('Ensure we response with updated values')
+ self.assertEqual(pattern, body['pattern'])
+ self.assertEqual(description, body['description'])