@@ -80,6 +80,21 @@ def __virtual__():
80
80
return __virtualname__
81
81
82
82
83
+ def _check_return_value (ret ):
84
+ '''
85
+ Helper function to check if the 'result' key of the return value has been
86
+ properly set. This is to detect unexpected code-paths that would otherwise
87
+ return a 'success'-y value but not actually be succesful.
88
+
89
+ :param dict ret: The returned value of a state function.
90
+ '''
91
+ if ret ['result' ] == 'oops' :
92
+ ret ['result' ] = False
93
+ ret ['comment' ].append ('An internal error has occurred: The result value was '
94
+ 'not properly changed.' )
95
+ return ret
96
+
97
+
83
98
def present (
84
99
name ,
85
100
elasticsearch_version = None ,
@@ -363,11 +378,7 @@ def present(
363
378
'changes:new:tags' ,
364
379
res ['changes' ]['new' ]
365
380
)
366
-
367
- if ret ['result' ] == 'oops' :
368
- ret ['result' ] = False
369
- ret ['comment' ].append ('An internal error has occurred: The result value was '
370
- 'not properly changed.' )
381
+ ret = _check_return_value (ret )
371
382
return ret
372
383
373
384
@@ -425,10 +436,7 @@ def absent(
425
436
ret ['result' ] = True
426
437
ret ['comment' ].append ('Elasticsearch domain "{}" is already absent.'
427
438
'' .format (name ))
428
- if ret ['result' ] == 'oops' :
429
- ret ['result' ] = False
430
- ret ['comment' ].append ('An internal error has occurred: The result value was '
431
- 'not properly changed.' )
439
+ ret = _check_return_value (ret )
432
440
return ret
433
441
434
442
@@ -562,10 +570,7 @@ def upgraded(
562
570
'' .format (name , elasticsearch_version ))
563
571
ret ['changes' ] = {'old' : current_domain ['ElasticsearchVersion' ],
564
572
'new' : elasticsearch_version }
565
- if ret ['result' ] == 'oops' :
566
- ret ['result' ] = False
567
- ret ['comment' ].append ('An internal error has occurred: The result value was '
568
- 'not properly changed.' )
573
+ ret = _check_return_value (ret )
569
574
return ret
570
575
571
576
@@ -653,10 +658,7 @@ def latest(
653
658
ret ['comment' ].append ('Elasticsearch domain "{}" is already at its '
654
659
'latest minor version {}.'
655
660
'' .format (name , current_version ))
656
- if ret ['result' ] == 'oops' :
657
- ret ['result' ] = False
658
- ret ['comment' ].append ('An internal error has occurred: The result value was '
659
- 'not properly changed.' )
661
+ ret = _check_return_value (ret )
660
662
if ret ['result' ] and ret ['changes' ] and not minor_only :
661
663
# Try and see if we can upgrade again
662
664
res = latest (name , minor_only = minor_only , region = region , keyid = keyid , key = key , profile = profile )
@@ -748,8 +750,5 @@ def tagged(
748
750
ret ['result' ] = True
749
751
ret ['comment' ].append ('Tags on Elasticsearch domain "{}" have been '
750
752
'{}ed.' .format (name , 'replac' if replace else 'add' ))
751
- if ret ['result' ] == 'oops' :
752
- ret ['result' ] = False
753
- ret ['comment' ].append ('An internal error has occurred: The result value was '
754
- 'not properly changed.' )
753
+ ret = _check_return_value (ret )
755
754
return ret
0 commit comments