Skip to content

Commit

Permalink
fix return value
Browse files Browse the repository at this point in the history
  • Loading branch information
adhorn committed Feb 4, 2022
1 parent 294956d commit a6d10af
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
26 changes: 13 additions & 13 deletions chaos_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def handler(event, context):
from ssm_cache import SSMParameter
from ssm_cache.cache import InvalidParameterError

LOGGER = logging.getLogger(__name__)
logger = logging.getLogger(__name__)

__version__ = '0.3'

Expand All @@ -189,7 +189,7 @@ def get_config():
try:
value = json.loads(param.value)
if not value["is_enabled"]:
return 0
return
return value
except InvalidParameterError as ex:
# key does not exist in SSM
Expand Down Expand Up @@ -284,7 +284,7 @@ def wrapper(*args, **kwargs):
if not _chaos_conf:
return func(*args, **kwargs)

LOGGER.info(
logger.info(
"Got SSM configuration: %s",
_chaos_conf
)
Expand All @@ -296,10 +296,10 @@ def wrapper(*args, **kwargs):
if isinstance(_chaos_conf.get("delay"), int):
_delay = _chaos_conf.get("delay")
else:
LOGGER.info("Parameter delay is no valid int")
logger.info("Parameter delay is no valid int")
return func(*args, **kwargs)

LOGGER.info(
logger.info(
"Injecting %d ms of delay with a rate of %s",
_delay, rate
)
Expand All @@ -308,12 +308,12 @@ def wrapper(*args, **kwargs):
if _delay > 0 and rate >= 0:
# add latency approx rate% of the time
if round(random.random(), 5) <= rate:
LOGGER.debug('sleeping now')
logger.debug('sleeping now')
time.sleep(_delay / 1000.0)

end = time.time()

LOGGER.debug(
logger.debug(
'Added %.2fms to %s',
(end - start) * 1000,
func.__name__
Expand All @@ -325,10 +325,10 @@ def wrapper(*args, **kwargs):
if isinstance(_chaos_conf.get("exception_msg"), str):
_exception_msg = _chaos_conf.get("exception_msg")
else:
LOGGER.info("Parameter exception_msg is no valid string")
logger.info("Parameter exception_msg is no valid string")
return func(*args, **kwargs)

LOGGER.info(
logger.info(
"Injecting exception_type %s with message %s a rate of %d",
_exception_type,
_exception_msg,
Expand All @@ -337,21 +337,21 @@ def wrapper(*args, **kwargs):

# add injection approx rate% of the time
if round(random.random(), 5) <= rate:
LOGGER.debug("corrupting now")
logger.debug("corrupting now")
raise _exception_type(_exception_msg)

if _fault_type == "status_code":
result = func(*args, **kwargs)
if isinstance(_chaos_conf.get("error_code"), int):
_error_code = _chaos_conf.get("error_code")
else:
LOGGER.info("Parameter error_code is no valid int")
logger.info("Parameter error_code is no valid int")
return func(*args, **kwargs)

LOGGER.info("Injecting Error %s at a rate of %d", _error_code, rate)
logger.info("Injecting Error %s at a rate of %d", _error_code, rate)
# add injection approx rate% of the time
if round(random.random(), 5) <= rate:
LOGGER.debug("corrupting now")
logger.debug("corrupting now")
result['statusCode'] = _error_code
return result

Expand Down
2 changes: 1 addition & 1 deletion tests/test_getconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_config_not_enabled(self):
method_name = sys._getframe().f_code.co_name
self._setTestUp(method_name)
_config = get_config()
self.assertEqual(_config, 0)
self.assertEqual(_config, None)


if __name__ == '__main__':
Expand Down

0 comments on commit a6d10af

Please sign in to comment.