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
This commit is contained in:
parent
99763c97f5
commit
471df92f96
|
@ -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=([^\.]*\.)*
|
|
@ -53,6 +53,19 @@ class DnsClientBase(rest_client.RestClient):
|
|||
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 @@ class DnsClientBase(rest_client.RestClient):
|
|||
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 @@ class DnsClientBase(rest_client.RestClient):
|
|||
|
||||
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 @@ class DnsClientBase(rest_client.RestClient):
|
|||
|
||||
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 @@ class DnsClientBase(rest_client.RestClient):
|
|||
|
||||
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 @@ class DnsClientBase(rest_client.RestClient):
|
|||
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)
|
||||
|
|
|
@ -49,7 +49,7 @@ class ZonesClient(base.DnsClientV2Base):
|
|||
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 @@ class ZonesClient(base.DnsClientV2Base):
|
|||
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 @@ class ZonesClient(base.DnsClientV2Base):
|
|||
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)
|
||||
|
|
Loading…
Reference in New Issue