From 1b71fb0499cc4591bfc32f7b05096002c49ac28f Mon Sep 17 00:00:00 2001 From: Eike Frost Date: Mon, 16 Oct 2017 19:20:54 +0200 Subject: [PATCH] fix legacy PEP8 violations in zabbix modules, remove test exception for them (#31702) * fix legacy PEP8 violations in zabbix_*, remove test exception for them * fix new pep8 violations for zabbix_maintenance.py --- lib/ansible/modules/monitoring/zabbix_group.py | 8 ++++---- lib/ansible/modules/monitoring/zabbix_host.py | 2 -- lib/ansible/modules/monitoring/zabbix_hostmacro.py | 5 +++-- .../modules/monitoring/zabbix_maintenance.py | 14 +++++++------- lib/ansible/modules/monitoring/zabbix_screen.py | 1 - test/sanity/pep8/legacy-files.txt | 5 ----- 6 files changed, 14 insertions(+), 21 deletions(-) diff --git a/lib/ansible/modules/monitoring/zabbix_group.py b/lib/ansible/modules/monitoring/zabbix_group.py index 77d24b6573..617c4ae159 100644 --- a/lib/ansible/modules/monitoring/zabbix_group.py +++ b/lib/ansible/modules/monitoring/zabbix_group.py @@ -165,11 +165,11 @@ def main(): server_url=dict(type='str', required=True, aliases=['url']), login_user=dict(type='str', required=True), login_password=dict(type='str', required=True, no_log=True), - http_login_user=dict(type='str',required=False, default=None), - http_login_password=dict(type='str',required=False, default=None, no_log=True), - validate_certs=dict(type='bool',required=False, default=True), + http_login_user=dict(type='str', required=False, default=None), + http_login_password=dict(type='str', required=False, default=None, no_log=True), + validate_certs=dict(type='bool', required=False, default=True), host_groups=dict(type='list', required=True, aliases=['host_group']), - state=dict(default="present", choices=['present','absent']), + state=dict(default="present", choices=['present', 'absent']), timeout=dict(type='int', default=10) ), supports_check_mode=True diff --git a/lib/ansible/modules/monitoring/zabbix_host.py b/lib/ansible/modules/monitoring/zabbix_host.py index eb5ba266ab..e57e0d951c 100644 --- a/lib/ansible/modules/monitoring/zabbix_host.py +++ b/lib/ansible/modules/monitoring/zabbix_host.py @@ -226,7 +226,6 @@ import copy try: from zabbix_api import ZabbixAPI, ZabbixAPISubClass - # Extend the ZabbixAPI # Since the zabbix-api python module too old (version 1.0, no higher version so far), # it does not support the 'hostinterface' api calls, @@ -238,7 +237,6 @@ try: ZabbixAPI.__init__(self, server, timeout=timeout, user=user, passwd=passwd, validate_certs=validate_certs) self.hostinterface = ZabbixAPISubClass(self, dict({"prefix": "hostinterface"}, **kwargs)) - HAS_ZABBIX_API = True except ImportError: HAS_ZABBIX_API = False diff --git a/lib/ansible/modules/monitoring/zabbix_hostmacro.py b/lib/ansible/modules/monitoring/zabbix_hostmacro.py index 64848fc73b..b17ad2cc9f 100644 --- a/lib/ansible/modules/monitoring/zabbix_hostmacro.py +++ b/lib/ansible/modules/monitoring/zabbix_hostmacro.py @@ -151,7 +151,7 @@ class HostMacro(object): # update host macro def update_host_macro(self, host_macro_obj, macro_name, macro_value): host_macro_id = host_macro_obj['hostmacroid'] - if host_macro_obj['macro'] == '{$'+macro_name+'}' and host_macro_obj['value'] == macro_value: + if host_macro_obj['macro'] == '{$' + macro_name + '}' and host_macro_obj['value'] == macro_value: self._module.exit_json(changed=False, result="Host macro %s already up to date" % macro_name) try: if self._module.check_mode: @@ -172,6 +172,7 @@ class HostMacro(object): except Exception as e: self._module.fail_json(msg="Failed to delete host macro %s: %s" % (macro_name, e)) + def main(): module = AnsibleModule( argument_spec=dict( @@ -200,7 +201,7 @@ def main(): http_login_password = module.params['http_login_password'] validate_certs = module.params['validate_certs'] host_name = module.params['host_name'] - macro_name = (module.params['macro_name']).upper() + macro_name = (module.params['macro_name']).upper() macro_value = module.params['macro_value'] state = module.params['state'] timeout = module.params['timeout'] diff --git a/lib/ansible/modules/monitoring/zabbix_maintenance.py b/lib/ansible/modules/monitoring/zabbix_maintenance.py index ecb62e9c07..bfe91b4225 100644 --- a/lib/ansible/modules/monitoring/zabbix_maintenance.py +++ b/lib/ansible/modules/monitoring/zabbix_maintenance.py @@ -184,7 +184,7 @@ def create_maintenance(zbx, group_ids, host_ids, start_time, maintenance_type, p "active_since": str(start_time), "active_till": str(end_time), "description": desc, - "timeperiods": [{ + "timeperiods": [{ "timeperiod_type": "0", "start_date": str(start_time), "period": str(period), @@ -208,7 +208,7 @@ def update_maintenance(zbx, maintenance_id, group_ids, host_ids, start_time, mai "active_since": str(start_time), "active_till": str(end_time), "description": desc, - "timeperiods": [{ + "timeperiods": [{ "timeperiod_type": "0", "start_date": str(start_time), "period": str(period), @@ -380,11 +380,11 @@ def main(): module.fail_json(msg="Failed to check maintenance %s existence: %s" % (name, error)) if maintenance and ( - sorted(group_ids) != sorted(maintenance["groupids"]) - or sorted(host_ids) != sorted(maintenance["hostids"]) - or str(maintenance_type) != maintenance["maintenance_type"] - or str(int(start_time)) != maintenance["active_since"] - or str(int(start_time + period)) != maintenance["active_till"] + sorted(group_ids) != sorted(maintenance["groupids"]) or + sorted(host_ids) != sorted(maintenance["hostids"]) or + str(maintenance_type) != maintenance["maintenance_type"] or + str(int(start_time)) != maintenance["active_since"] or + str(int(start_time + period)) != maintenance["active_till"] ): if module.check_mode: changed = True diff --git a/lib/ansible/modules/monitoring/zabbix_screen.py b/lib/ansible/modules/monitoring/zabbix_screen.py index 4be11200ab..32cf719ed6 100644 --- a/lib/ansible/modules/monitoring/zabbix_screen.py +++ b/lib/ansible/modules/monitoring/zabbix_screen.py @@ -8,7 +8,6 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type - ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ['preview'], 'supported_by': 'community'} diff --git a/test/sanity/pep8/legacy-files.txt b/test/sanity/pep8/legacy-files.txt index 92ceeb6bdd..63f66226ef 100644 --- a/test/sanity/pep8/legacy-files.txt +++ b/test/sanity/pep8/legacy-files.txt @@ -171,11 +171,6 @@ lib/ansible/modules/monitoring/sensu_check.py lib/ansible/modules/monitoring/sensu_subscription.py lib/ansible/modules/monitoring/stackdriver.py lib/ansible/modules/monitoring/uptimerobot.py -lib/ansible/modules/monitoring/zabbix_group.py -lib/ansible/modules/monitoring/zabbix_host.py -lib/ansible/modules/monitoring/zabbix_hostmacro.py -lib/ansible/modules/monitoring/zabbix_maintenance.py -lib/ansible/modules/monitoring/zabbix_screen.py lib/ansible/modules/network/a10/a10_server_axapi3.py lib/ansible/modules/network/a10/a10_virtual_server.py lib/ansible/modules/network/aos/aos_asn_pool.py