From 1948bcb9e7225019e5fd0c192eb44999fb87b501 Mon Sep 17 00:00:00 2001 From: Michael Scherer Date: Sun, 16 Oct 2016 09:41:02 +0200 Subject: [PATCH] Make zabbix modules compile on python 3 Since the module is not compatible with python 2.4, we do not need to use the get_exception trick --- .../modules/extras/monitoring/zabbix_group.py | 6 +++--- lib/ansible/modules/extras/monitoring/zabbix_host.py | 12 ++++++------ .../modules/extras/monitoring/zabbix_hostmacro.py | 12 ++++++------ .../modules/extras/monitoring/zabbix_screen.py | 2 +- .../test/utils/shippable/sanity-skip-python3.txt | 4 ---- 5 files changed, 16 insertions(+), 20 deletions(-) diff --git a/lib/ansible/modules/extras/monitoring/zabbix_group.py b/lib/ansible/modules/extras/monitoring/zabbix_group.py index a19c49794f9..ec1f65ed358 100644 --- a/lib/ansible/modules/extras/monitoring/zabbix_group.py +++ b/lib/ansible/modules/extras/monitoring/zabbix_group.py @@ -136,7 +136,7 @@ class HostGroup(object): except Already_Exists: return group_add_list return group_add_list - except Exception, e: + except Exception as e: self._module.fail_json(msg="Failed to create host group(s): %s" % e) # delete host group(s) @@ -145,7 +145,7 @@ class HostGroup(object): if self._module.check_mode: self._module.exit_json(changed=True) self._zapi.hostgroup.delete(group_ids) - except Exception, e: + except Exception as e: self._module.fail_json(msg="Failed to delete host group(s), Exception: %s" % e) # get group ids by name @@ -192,7 +192,7 @@ def main(): try: zbx = ZabbixAPI(server_url, timeout=timeout, user=http_login_user, passwd=http_login_password) zbx.login(login_user, login_password) - except Exception, e: + except Exception as e: module.fail_json(msg="Failed to connect to Zabbix server: %s" % e) hostGroup = HostGroup(module, zbx) diff --git a/lib/ansible/modules/extras/monitoring/zabbix_host.py b/lib/ansible/modules/extras/monitoring/zabbix_host.py index 20d8b6e21fb..6ba256897bd 100644 --- a/lib/ansible/modules/extras/monitoring/zabbix_host.py +++ b/lib/ansible/modules/extras/monitoring/zabbix_host.py @@ -216,7 +216,7 @@ class Host(object): host_list = self._zapi.host.create(parameters) if len(host_list) >= 1: return host_list['hostids'][0] - except Exception, e: + except Exception as e: self._module.fail_json(msg="Failed to create host %s: %s" % (host_name, e)) def update_host(self, host_name, group_ids, status, host_id, interfaces, exist_interface_list, proxy_id): @@ -253,7 +253,7 @@ class Host(object): remove_interface_ids.append(interface_id) if len(remove_interface_ids) > 0: self._zapi.hostinterface.delete(remove_interface_ids) - except Exception, e: + except Exception as e: self._module.fail_json(msg="Failed to update host %s: %s" % (host_name, e)) def delete_host(self, host_id, host_name): @@ -261,7 +261,7 @@ class Host(object): if self._module.check_mode: self._module.exit_json(changed=True) self._zapi.host.delete([host_id]) - except Exception, e: + except Exception as e: self._module.fail_json(msg="Failed to delete host %s: %s" % (host_name, e)) # get host by host name @@ -385,7 +385,7 @@ class Host(object): if self._module.check_mode: self._module.exit_json(changed=True) self._zapi.host.update(request_str) - except Exception, e: + except Exception as e: self._module.fail_json(msg="Failed to link template to host: %s" % e) # Update the host inventory_mode @@ -408,7 +408,7 @@ class Host(object): if self._module.check_mode: self._module.exit_json(changed=True) self._zapi.host.update(request_str) - except Exception, e: + except Exception as e: self._module.fail_json(msg="Failed to set inventory_mode to host: %s" % e) def main(): @@ -460,7 +460,7 @@ def main(): try: zbx = ZabbixAPIExtends(server_url, timeout=timeout, user=http_login_user, passwd=http_login_password) zbx.login(login_user, login_password) - except Exception, e: + except Exception as e: module.fail_json(msg="Failed to connect to Zabbix server: %s" % e) host = Host(module, zbx) diff --git a/lib/ansible/modules/extras/monitoring/zabbix_hostmacro.py b/lib/ansible/modules/extras/monitoring/zabbix_hostmacro.py index c431ab0f17e..2f7fa37be7f 100644 --- a/lib/ansible/modules/extras/monitoring/zabbix_hostmacro.py +++ b/lib/ansible/modules/extras/monitoring/zabbix_hostmacro.py @@ -127,7 +127,7 @@ class HostMacro(object): else: host_id = host_list[0]['hostid'] return host_id - except Exception, e: + except Exception as e: self._module.fail_json(msg="Failed to get the host %s id: %s." % (host_name, e)) # get host macro @@ -138,7 +138,7 @@ class HostMacro(object): if len(host_macro_list) > 0: return host_macro_list[0] return None - except Exception, e: + except Exception as e: self._module.fail_json(msg="Failed to get host macro %s: %s" % (macro_name, e)) # create host macro @@ -148,7 +148,7 @@ class HostMacro(object): self._module.exit_json(changed=True) self._zapi.usermacro.create({'hostid': host_id, 'macro': '{$' + macro_name + '}', 'value': macro_value}) self._module.exit_json(changed=True, result="Successfully added host macro %s " % macro_name) - except Exception, e: + except Exception as e: self._module.fail_json(msg="Failed to create host macro %s: %s" % (macro_name, e)) # update host macro @@ -161,7 +161,7 @@ class HostMacro(object): self._module.exit_json(changed=True) self._zapi.usermacro.update({'hostmacroid': host_macro_id, 'value': macro_value}) self._module.exit_json(changed=True, result="Successfully updated host macro %s " % macro_name) - except Exception, e: + except Exception as e: self._module.fail_json(msg="Failed to updated host macro %s: %s" % (macro_name, e)) # delete host macro @@ -172,7 +172,7 @@ class HostMacro(object): self._module.exit_json(changed=True) self._zapi.usermacro.delete([host_macro_id]) self._module.exit_json(changed=True, result="Successfully deleted host macro %s " % macro_name) - except Exception, e: + except Exception as e: self._module.fail_json(msg="Failed to delete host macro %s: %s" % (macro_name, e)) def main(): @@ -211,7 +211,7 @@ def main(): try: zbx = ZabbixAPIExtends(server_url, timeout=timeout, user=http_login_user, passwd=http_login_password) zbx.login(login_user, login_password) - except Exception, e: + except Exception as e: module.fail_json(msg="Failed to connect to Zabbix server: %s" % e) host_macro_class_obj = HostMacro(module, zbx) diff --git a/lib/ansible/modules/extras/monitoring/zabbix_screen.py b/lib/ansible/modules/extras/monitoring/zabbix_screen.py index ffdcb21b5f3..85af561c965 100644 --- a/lib/ansible/modules/extras/monitoring/zabbix_screen.py +++ b/lib/ansible/modules/extras/monitoring/zabbix_screen.py @@ -354,7 +354,7 @@ def main(): try: zbx = ZabbixAPIExtends(server_url, timeout=timeout, user=http_login_user, passwd=http_login_password) zbx.login(login_user, login_password) - except Exception, e: + except Exception as e: module.fail_json(msg="Failed to connect to Zabbix server: %s" % e) screen = Screen(module, zbx) diff --git a/lib/ansible/modules/extras/test/utils/shippable/sanity-skip-python3.txt b/lib/ansible/modules/extras/test/utils/shippable/sanity-skip-python3.txt index c7ed2636df0..2674bf0584a 100644 --- a/lib/ansible/modules/extras/test/utils/shippable/sanity-skip-python3.txt +++ b/lib/ansible/modules/extras/test/utils/shippable/sanity-skip-python3.txt @@ -56,10 +56,6 @@ /monitoring/datadog_monitor.py /monitoring/rollbar_deployment.py /monitoring/stackdriver.py -/monitoring/zabbix_group.py -/monitoring/zabbix_host.py -/monitoring/zabbix_hostmacro.py -/monitoring/zabbix_screen.py /network/citrix/netscaler.py /network/cloudflare_dns.py /network/dnsmadeeasy.py