summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCédric Ollivier <cedric.ollivier@orange.com>2019-01-07 13:28:45 +0100
committerCédric Ollivier <cedric.ollivier@orange.com>2019-01-07 15:53:16 +0100
commit8d39247624690d28b2a4f039d139446393f8a5da (patch)
tree57438649d5813e4423b5b83d2ccbc8b2df732749
parent26ec93dfa0e31da888b7a98eec072595111dfbdc (diff)
Check if key exists instead of leveraging on update_if_exists
It seems falsy (see line 72) 2019-01-07 11:50:32,550 - functest.core.cloudify - DEBUG - try 9: Cloudify Manager isn't up and running Traceback (most recent call last): File "/usr/lib/python2.7/site-packages/functest/core/cloudify.py", line 72, in execute "foo", "bar", update_if_exists=True) File "/usr/lib/python2.7/site-packages/cloudify_rest_client/secrets.py", line 86, in create response = self.api.put('/secrets/{0}'.format(key), data=data) File "/usr/lib/python2.7/site-packages/cloudify_rest_client/client.py", line 263, in put timeout=timeout) File "/usr/lib/python2.7/site-packages/cloudify_rest_client/client.py", line 224, in do_request verify=self.get_request_verify(), timeout=timeout) File "/usr/lib/python2.7/site-packages/cloudify_rest_client/client.py", line 158, in _do_request self._raise_client_error(response, request_url) File "/usr/lib/python2.7/site-packages/cloudify_rest_client/client.py", line 119, in _raise_client_error response=response) File "/usr/lib/python2.7/site-packages/cloudify_rest_client/client.py", line 131, in _prepare_and_raise_exception status_code, error_code=error_code, response=response) CloudifyClientError: 409: <Secret id=`foo` tenant=`default_tenant`> already exists on <Tenant name=`default_tenant`> Change-Id: I6f4e2719ad2e55e997ebbd158dce4c6a204b2c36 Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com> (cherry picked from commit 73f4aee1a22e502a7775a9be43829174f18fbc84)
-rw-r--r--functest/core/cloudify.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/functest/core/cloudify.py b/functest/core/cloudify.py
index 47d1f4e25..83dd603ad 100644
--- a/functest/core/cloudify.py
+++ b/functest/core/cloudify.py
@@ -59,6 +59,8 @@ class Cloudify(singlevm.SingleVm2):
username='admin', password='admin', tenant='default_tenant',
api_version='v3')
self.__logger.info("Attemps running status of the Manager")
+ secret_key = "foo"
+ secret_value = "bar"
for loop in range(10):
try:
self.__logger.debug(
@@ -68,11 +70,16 @@ class Cloudify(singlevm.SingleVm2):
"The current manager status is %s", cfy_status)
if str(cfy_status) != 'running':
raise Exception("Cloudify Manager isn't up and running")
- self.cfy_client.secrets.create(
- "foo", "bar", update_if_exists=True)
- self.__logger.debug(
- "List secrets: %s", self.cfy_client.secrets.list())
- self.cfy_client.secrets.delete("foo")
+ for secret in iter(self.cfy_client.secrets.list()):
+ if secret_key == secret["key"]:
+ self.__logger.debug("Updating secrets: %s", secret_key)
+ self.cfy_client.secrets.update(
+ secret_key, secret_value)
+ break
+ else:
+ self.__logger.debug("Creating secrets: %s", secret_key)
+ self.cfy_client.secrets.create(secret_key, secret_value)
+ self.cfy_client.secrets.delete(secret_key)
self.__logger.info("Secrets API successfully reached")
break
except Exception: # pylint: disable=broad-except