Assert with integer status codes to avoid hidden errors
We are using `resp['status']` which is a string ('202').
Instead, use `resp.status` which is an int. This is a problem
because `self.expected_success(202, '201')` doesn't raise an
error.
This also adds an `expected_success` method to the proper base
class to intercept calls to this method. This lets us warn about
this and cast to int.
And:
- check for 202 (not 200) on a zone update.
- add a .testr.conf so `ostestr` runs all the tests in the
current dir
Change-Id: I102c35eb6da0c5f99fd548b169ce490027fdb981
diff --git a/.testr.conf b/.testr.conf
new file mode 100644
index 0000000..fee97eb
--- /dev/null
+++ b/.testr.conf
@@ -0,0 +1,12 @@
+[DEFAULT]
+test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \
+ OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \
+ OS_LOG_CAPTURE=${OS_LOG_CAPTURE:-1} \
+ OS_DEBUG=${OS_DEBUG:-1} \
+ OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-500} \
+ OS_TEST_LOCK_PATH=${OS_TEST_LOCK_PATH:-${TMPDIR:-'/tmp'}} \
+ ${PYTHON:-python} -m subunit.run discover -t ${OS_TOP_LEVEL:-./} ${OS_TEST_PATH:-./designate_tempest_plugin} $LISTOPT $IDOPTION
+
+test_id_option=--load-list $IDFILE
+test_list_option=--list
+group_regex=([^\.]*\.)*
diff --git a/designate_tempest_plugin/services/dns/json/base.py b/designate_tempest_plugin/services/dns/json/base.py
index 4fc1998..94307b8 100644
--- a/designate_tempest_plugin/services/dns/json/base.py
+++ b/designate_tempest_plugin/services/dns/json/base.py
@@ -53,6 +53,19 @@
def deserialize(self, object_str):
return json.loads(object_str)
+ def expected_success(self, expected_code, read_code):
+ # the base class method does not check correctly if read_code is not
+ # an int. warn about this and cast to int to avoid silent errors.
+ if not isinstance(read_code, int):
+ message = ("expected_success(%(expected_code)r, %(read_code)r) "
+ "received not-int read_code %(read_code)r" %
+ {'expected_code': expected_code,
+ 'read_code': read_code})
+ LOG.warn(message)
+ return super(DnsClientBase, self).expected_success(
+ expected_code=expected_code, read_code=int(read_code),
+ )
+
def get_uri(self, resource_name, uuid=None, params=None):
"""Get URI for a specific resource or object.
:param resource_name: The name of the REST resource, e.g., 'zones'.
@@ -85,7 +98,7 @@
uri = self.get_uri(resource, params=params)
resp, body = self.post(uri, body=body)
- self.expected_success([201, 202], resp['status'])
+ self.expected_success([201, 202], resp.status)
return resp, self.deserialize(body)
@@ -101,7 +114,7 @@
resp, body = self.get(uri)
- self.expected_success(200, resp['status'])
+ self.expected_success(200, resp.status)
return resp, self.deserialize(body)
@@ -116,7 +129,7 @@
resp, body = self.get(uri)
- self.expected_success(200, resp['status'])
+ self.expected_success(200, resp.status)
return resp, self.deserialize(body)
@@ -135,7 +148,7 @@
resp, body = self.patch(uri, body=body)
- self.expected_success(200, resp['status'])
+ self.expected_success(202, resp.status)
return resp, self.deserialize(body)
@@ -150,5 +163,5 @@
uri = self.get_uri(resource, uuid=uuid, params=params)
resp, body = self.delete(uri)
- self.expected_success([202, 204], resp['status'])
+ self.expected_success([202, 204], resp.status)
return resp, self.deserialize(body)
diff --git a/designate_tempest_plugin/services/dns/v2/json/zones_client.py b/designate_tempest_plugin/services/dns/v2/json/zones_client.py
index c8e4687..ac360e6 100644
--- a/designate_tempest_plugin/services/dns/v2/json/zones_client.py
+++ b/designate_tempest_plugin/services/dns/v2/json/zones_client.py
@@ -49,7 +49,7 @@
resp, body = self._create_request('zones', zone, params=params)
# Create Zone should Return a HTTP 202
- self.expected_success(202, resp['status'])
+ self.expected_success(202, resp.status)
if wait_until:
waiters.wait_for_zone_status(self, body['id'], wait_until)
@@ -86,7 +86,7 @@
resp, body = self._delete_request('zones', uuid, params=params)
# Delete Zone should Return a HTTP 202
- self.expected_success(202, resp['status'])
+ self.expected_success(202, resp.status)
return resp, body
@@ -115,7 +115,7 @@
resp, body = self._update_request('zones', uuid, zone, params=params)
# Update Zone should Return a HTTP 202
- self.expected_success(202, resp['status'])
+ self.expected_success(202, resp.status)
if wait_until:
waiters.wait_for_zone_status(self, body['id'], wait_until)