Extend client silent mode

Allow resources get operations to be silent, and also not log
the validate result warning if silent.
The reason is that get actions are sometimes used in order to verify
that the object does not exist, and so we do not want to log it.

Change-Id: Ib32637da86e72ff22a7c5684a3f179b91f09406f
This commit is contained in:
Adit Sarfaty 2017-06-08 10:38:30 +03:00
parent 667beecf9a
commit 55f5303572
2 changed files with 13 additions and 11 deletions

View File

@ -123,16 +123,17 @@ class RESTClient(object):
raise error(manager='', operation=operation, details=result_msg,
error_code=error_code)
def _validate_result(self, result, expected, operation):
def _validate_result(self, result, expected, operation, silent=False):
if result.status_code not in expected:
result_msg = result.json() if result.content else ''
LOG.warning("The HTTP request returned error code "
"%(result)s, whereas %(expected)s response "
"codes were expected. Response body %(body)s",
{'result': result.status_code,
'expected': '/'.join([str(code)
for code in expected]),
'body': result_msg})
if not silent:
LOG.warning("The HTTP request returned error code "
"%(result)s, whereas %(expected)s response "
"codes were expected. Response body %(body)s",
{'result': result.status_code,
'expected': '/'.join([str(code)
for code in expected]),
'body': result_msg})
error_code = None
if isinstance(result_msg, dict) and 'error_message' in result_msg:
@ -199,7 +200,8 @@ class RESTClient(object):
self._validate_result(
result, RESTClient._VERB_RESP_CODES[method.lower()],
_("%(verb)s %(url)s") % {'verb': method, 'url': request_url})
_("%(verb)s %(url)s") % {'verb': method, 'url': request_url},
silent=silent)
return result

View File

@ -153,8 +153,8 @@ class NsxLibApiBase(object):
def list(self):
return self.client.list(self.uri_segment)
def get(self, uuid):
return self.client.get(self.get_path(uuid))
def get(self, uuid, silent=False):
return self.client.get(self.get_path(uuid), silent=silent)
def delete(self, uuid):
return self.client.delete(self.get_path(uuid))