RequestOptional won't raise, only log, if request goes wrong

parent eeda26cc
...@@ -123,16 +123,16 @@ class Recipe(object): ...@@ -123,16 +123,16 @@ class Recipe(object):
isSlave = options.get('slave', '').lower() in \ isSlave = options.get('slave', '').lower() in \
librecipe.GenericBaseRecipe.TRUE_VALUES librecipe.GenericBaseRecipe.TRUE_VALUES
self._raise_request_exception = None
try:
self.instance = request(software_url, software_type, self.instance = request(software_url, software_type,
name, partition_parameter_kw=partition_parameter_kw, name, partition_parameter_kw=partition_parameter_kw,
filter_kw=filter_kw, shared=isSlave) filter_kw=filter_kw, shared=isSlave)
self._raise_resource_not_ready = None
try:
# XXX what is the right way to get a global id? # XXX what is the right way to get a global id?
options['instance_guid'] = self.instance.getId() options['instance_guid'] = self.instance.getId()
except slapmodule.ResourceNotReady as exc: except (slapmodule.NotFoundError, slapmodule.ServerError, slapmodule.ResourceNotReady) as exc:
self._raise_resource_not_ready = exc self._raise_request_exception = exc
for param in return_parameters: for param in return_parameters:
try: try:
...@@ -144,8 +144,8 @@ class Recipe(object): ...@@ -144,8 +144,8 @@ class Recipe(object):
self.failed = param self.failed = param
def install(self): def install(self):
if self._raise_resource_not_ready: if self._raise_request_exception:
raise slapmodule.ResourceNotReady(self._resource_not_ready) raise self._raise_request_exception
if self.failed is not None: if self.failed is not None:
# Check instance status to know if instance has been deployed # Check instance status to know if instance has been deployed
...@@ -169,11 +169,14 @@ class Recipe(object): ...@@ -169,11 +169,14 @@ class Recipe(object):
class RequestOptional(Recipe): class RequestOptional(Recipe):
""" """
Request a SlapOS instance. Won't fail if instance is not ready. Request a SlapOS instance. Won't fail if request failed or is not ready.
Same as slapos.cookbook:request, but won't raise in case of problem. Same as slapos.cookbook:request, but won't raise in case of problem.
""" """
def install(self): def install(self):
if self.failed is not None: if self._raise_request_exception:
self.logger.warning('Optional request failed:')
self.logger.warning(self._raise_request_exception)
elif self.failed is not None:
# Check instance status to know if instance has been deployed # Check instance status to know if instance has been deployed
try: try:
if self.instance._computer_id is not None: if self.instance._computer_id is not None:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment