Skip to content

Commit

Permalink
Merge pull request #112 from rukapse/dev
Browse files Browse the repository at this point in the history
Logging Bug Fix: dnac_log_level paramter not specified in the playbook (Raises 'NoneType' object has no attribute 'upper' error)
  • Loading branch information
madhansansel authored Jan 26, 2024
2 parents e8dfe7d + f27c018 commit 1abb44a
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions plugins/module_utils/dnac.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,12 @@ def __init__(self, module):
}
self.dnac_log = dnac_params.get("dnac_log")

# Check if 'dnac_log_level' in the playbook params. If available,
# convert it to uppercase; otherwise, set it to 'INFO'
self.dnac_log_level = dnac_params.get("dnac_log_level", "INFO").upper()
self.dnac_log_level = dnac_params.get("dnac_log_level")
if self.dnac_log_level is None:
self.dnac_log_level = "INFO"
else:
self.dnac_log_level = self.dnac_log_level.upper()
self.is_valid_log_level()

log(str(dnac_params))
self.supported_states = ["merged", "deleted", "replaced", "overridden", "gathered", "rendered", "parsed"]
Expand Down Expand Up @@ -163,7 +166,6 @@ def log(self, message, level="info", frameIncrement=0):
level = level.upper()
if (
self.dnac_log
and self.dnac_log_level in ('DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL')
and logging.getLevelName(level) >= logging.getLevelName(self.dnac_log_level)
):
message = "Module: " + self.__class__.__name__ + ", " + message
Expand Down Expand Up @@ -404,6 +406,12 @@ def camel_to_snake_case(self, config):
return config
return new_config

def is_valid_log_level(self):
valid_log_levels = ('DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL')
if self.dnac_log_level not in valid_log_levels:
raise ValueError("Invalid log level: 'dnac_log_level:{0}'."
" Expected one of {1}.".format(self.dnac_log_level, valid_log_levels))


def log(msg, level='info', frameIncrement=0):
with open('dnac.log', 'a') as of:
Expand Down

0 comments on commit 1abb44a

Please sign in to comment.