From 5d8302120b7ce951f79b44f3ea1272b58ec25153 Mon Sep 17 00:00:00 2001 From: silverwizard Date: Wed, 7 Aug 2019 16:43:14 -0400 Subject: [PATCH] Removed breaking type check from nagios module (#49568) * Removed extraneous type check from nagios module, in order to allow python 3.x * Removed now useless import types * Added changelog fragment * Update changelog. * Rebased and removed check due to module adding earlier guardrails * Updated changelog to mention earlier fix adding now completely removed guardrails * Remove superfluous type checks. Fix docs type. * Update ignore.txt. --- changelogs/fragments/49568-type-checking.yaml | 3 +++ lib/ansible/modules/monitoring/nagios.py | 21 +++---------------- test/sanity/ignore.txt | 1 - 3 files changed, 6 insertions(+), 19 deletions(-) create mode 100644 changelogs/fragments/49568-type-checking.yaml diff --git a/changelogs/fragments/49568-type-checking.yaml b/changelogs/fragments/49568-type-checking.yaml new file mode 100644 index 00000000000..ab4bedbaa64 --- /dev/null +++ b/changelogs/fragments/49568-type-checking.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: +- "nagios - Removed redundant type check which caused crashes. Guardrails added elsewhere in earlier change." diff --git a/lib/ansible/modules/monitoring/nagios.py b/lib/ansible/modules/monitoring/nagios.py index 24cade85c90..d144ea6cb54 100644 --- a/lib/ansible/modules/monitoring/nagios.py +++ b/lib/ansible/modules/monitoring/nagios.py @@ -65,6 +65,7 @@ options: description: - Minutes to schedule downtime for. - Only usable with the C(downtime) action. + type: int default: 30 services: description: @@ -193,7 +194,6 @@ EXAMPLES = ''' command: DISABLE_FAILURE_PREDICTION ''' -import types import time import os.path import stat @@ -271,7 +271,6 @@ def main(): action = module.params['action'] host = module.params['host'] servicegroup = module.params['servicegroup'] - minutes = module.params['minutes'] services = module.params['services'] cmdfile = module.params['cmdfile'] command = module.params['command'] @@ -284,7 +283,7 @@ def main(): # command = command # # AnsibleModule will verify most stuff, we need to verify - # 'minutes' and 'service' manually. + # 'service' manually. ################################################################## if action not in ['command', 'silence_nagios', 'unsilence_nagios']: @@ -295,13 +294,6 @@ def main(): # Make sure there's an actual service selected if not services: module.fail_json(msg='no service selected to set downtime for') - # Make sure minutes is a number - try: - m = int(minutes) - if not isinstance(m, types.IntType): - module.fail_json(msg='minutes must be a number') - except Exception: - module.fail_json(msg='invalid entry for minutes') ###################################################################### if action == 'delete_downtime': @@ -315,13 +307,6 @@ def main(): # Make sure there's an actual servicegroup selected if not servicegroup: module.fail_json(msg='no servicegroup selected to set downtime for') - # Make sure minutes is a number - try: - m = int(minutes) - if not isinstance(m, types.IntType): - module.fail_json(msg='minutes must be a number') - except Exception: - module.fail_json(msg='invalid entry for minutes') ################################################################## if action in ['enable_alerts', 'disable_alerts']: @@ -367,7 +352,7 @@ class Nagios(object): self.comment = kwargs['comment'] self.host = kwargs['host'] self.servicegroup = kwargs['servicegroup'] - self.minutes = int(kwargs['minutes']) + self.minutes = kwargs['minutes'] self.cmdfile = kwargs['cmdfile'] self.command = kwargs['command'] diff --git a/test/sanity/ignore.txt b/test/sanity/ignore.txt index 3b984ee7e3e..c993fbcd4b9 100644 --- a/test/sanity/ignore.txt +++ b/test/sanity/ignore.txt @@ -2389,7 +2389,6 @@ lib/ansible/modules/monitoring/monit.py validate-modules:E337 lib/ansible/modules/monitoring/monit.py validate-modules:E338 lib/ansible/modules/monitoring/nagios.py validate-modules:E317 lib/ansible/modules/monitoring/nagios.py validate-modules:E324 -lib/ansible/modules/monitoring/nagios.py validate-modules:E337 lib/ansible/modules/monitoring/nagios.py validate-modules:E338 lib/ansible/modules/monitoring/newrelic_deployment.py validate-modules:E338 lib/ansible/modules/monitoring/pagerduty.py validate-modules:E324