11
22from pyvcloud .vcd .exceptions import (
3+ AccessForbiddenException ,
34 EntityNotFoundException ,
45 UnauthorizedException ,
56 BadRequestException ,
7+ NotFoundException ,
68 VcdTaskException )
79
810from functools import wraps
@@ -38,17 +40,35 @@ def wrapper(*_, **kwargs):
3840
3941 if not resource_data .primary_external :
4042 try :
41- ctx .logger .info ('Before' )
43+ ctx .logger .debug ('Executing func {func} '
44+ 'with args {args} '
45+ 'kwargs {kwargs}' .format (
46+ func = func , args = args , kwargs = kwargs ))
4247 resource , result = func (* args , ** kwargs )
43- ctx .logger .info ('After' )
44- except (EntityNotFoundException , BadRequestException ) as e :
45- if isinstance (e , EntityNotFoundException ):
48+ ctx .logger .debug ('Executed func {func} '
49+ 'result {result}' .format (
50+ func = func , result = result ))
51+ except (AccessForbiddenException ,
52+ EntityNotFoundException ,
53+ BadRequestException ,
54+ NotFoundException ) as e :
55+ ctx .logger .error (
56+ 'Failed to execute func {func} '
57+ 'with args {args} '
58+ 'kwargs {kwargs} '
59+ 'Error: {e}' .format (func = func ,
60+ args = args ,
61+ kwargs = kwargs ,
62+ e = str (e )))
63+ if isinstance (e , (TypeError ,
64+ NotFoundException ,
65+ EntityNotFoundException )):
4666 if operation_name not in NO_RESOURCE_OK :
4767 raise NonRecoverableError (
4868 'The expected resource {r} does not exist.' .format (
4969 r = resource_data .primary_id ))
5070 ctx .logger .error ('Attempted to perform {op} '
51- 'operation on {r},'
71+ 'operation on {r}, '
5272 'but the resource was not '
5373 'found.' .format (
5474 op = operation_name ,
@@ -57,15 +77,15 @@ def wrapper(*_, **kwargs):
5777 resource_data .primary_ctx .instance .runtime_properties [
5878 '__RETRY_BAD_REQUEST' ] = True
5979 resource_data .primary_ctx .instance .update ()
60- raise OperationRetry (str (e ))
80+ raise OperationRetry (str (e ))
6181 else :
6282 last_task = get_last_task (result )
6383
6484 if not resource :
6585 args [0 ] = True # Tell the function to expect external resource.
6686 try :
6787 resource , _ = func (* args , ** kwargs )
68- except EntityNotFoundException :
88+ except ( TypeError , NotFoundException , EntityNotFoundException ) :
6989 if operation_name not in NO_RESOURCE_OK :
7090 raise NonRecoverableError (
7191 'The expected resource {r} does not exist.' .format (
0 commit comments