From ab86051c0ba53837e0b1a8413793179a8befa2a1 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Fri, 2 Nov 2018 02:05:56 +0530 Subject: [PATCH] Misc fixes for several errors * aci: Correct usage in fail_json * Fixes incorrect usage of fail_json * Raise exception object Signed-off-by: Abhijeet Kasurde --- lib/ansible/module_utils/compat/ipaddress.py | 2 +- lib/ansible/module_utils/network/aci/msc.py | 2 +- lib/ansible/modules/cloud/amazon/lambda_event.py | 2 +- lib/ansible/modules/net_tools/basics/get_url.py | 2 +- lib/ansible/modules/network/f5/bigip_pool_member.py | 2 +- .../modules/network/onyx/onyx_igmp_interface.py | 2 +- .../modules/storage/netapp/netapp_e_iscsi_interface.py | 10 +++++----- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/ansible/module_utils/compat/ipaddress.py b/lib/ansible/module_utils/compat/ipaddress.py index d6e781b926c..db4f5ac62f5 100644 --- a/lib/ansible/module_utils/compat/ipaddress.py +++ b/lib/ansible/module_utils/compat/ipaddress.py @@ -1155,7 +1155,7 @@ class _BaseNetwork(_IPAddressBase): try: # Always false if one is v4 and the other is v6. if a._version != b._version: - raise TypeError("%s and %s are not of the same version" (a, b)) + raise TypeError("%s and %s are not of the same version" % (a, b)) return (b.network_address <= a.network_address and b.broadcast_address >= a.broadcast_address) except AttributeError: diff --git a/lib/ansible/module_utils/network/aci/msc.py b/lib/ansible/module_utils/network/aci/msc.py index 99e159ffa86..62e5d951249 100644 --- a/lib/ansible/module_utils/network/aci/msc.py +++ b/lib/ansible/module_utils/network/aci/msc.py @@ -210,7 +210,7 @@ class MSCModule(object): if len(objs) == 0: return {} if len(objs) > 1: - self.fail_json('More than one object matches unique filter: {1}'.format(kwargs)) + self.fail_json(msg='More than one object matches unique filter: {0}'.format(kwargs)) return objs[0] def sanitize(self, updates, collate=False): diff --git a/lib/ansible/modules/cloud/amazon/lambda_event.py b/lib/ansible/modules/cloud/amazon/lambda_event.py index 5930f6aefe5..37442bdc5f3 100644 --- a/lib/ansible/modules/cloud/amazon/lambda_event.py +++ b/lib/ansible/modules/cloud/amazon/lambda_event.py @@ -426,7 +426,7 @@ def main(): if module.params['event_source'].lower() in ('stream', 'sqs'): results = lambda_event_stream(module, aws) else: - module.fail_json('Please select `stream` or `sqs` as the event type') + module.fail_json(msg='Please select `stream` or `sqs` as the event type') module.exit_json(**results) diff --git a/lib/ansible/modules/net_tools/basics/get_url.py b/lib/ansible/modules/net_tools/basics/get_url.py index 62f1844af40..2e55e001906 100644 --- a/lib/ansible/modules/net_tools/basics/get_url.py +++ b/lib/ansible/modules/net_tools/basics/get_url.py @@ -492,7 +492,7 @@ def main(): checksum = None if checksum is None: - module.fail_json("Unable to find a checksum for file '%s' in '%s'" % (filename, checksum_url)) + module.fail_json(msg="Unable to find a checksum for file '%s' in '%s'" % (filename, checksum_url)) # Remove any non-alphanumeric characters, including the infamous # Unicode zero-width space checksum = re.sub(r'\W+', '', checksum).lower() diff --git a/lib/ansible/modules/network/f5/bigip_pool_member.py b/lib/ansible/modules/network/f5/bigip_pool_member.py index 50d4b9bcd16..88429f4ebdd 100644 --- a/lib/ansible/modules/network/f5/bigip_pool_member.py +++ b/lib/ansible/modules/network/f5/bigip_pool_member.py @@ -596,7 +596,7 @@ class ModuleManager(object): def exists(self): if not self.pool_exist(): - F5ModuleError('The specified pool does not exist') + raise F5ModuleError('The specified pool does not exist') uri = "https://{0}:{1}/mgmt/tm/ltm/pool/{2}/members/{3}".format( self.client.provider['server'], diff --git a/lib/ansible/modules/network/onyx/onyx_igmp_interface.py b/lib/ansible/modules/network/onyx/onyx_igmp_interface.py index a067ef2cd5e..3a20da3d827 100644 --- a/lib/ansible/modules/network/onyx/onyx_igmp_interface.py +++ b/lib/ansible/modules/network/onyx/onyx_igmp_interface.py @@ -77,7 +77,7 @@ class OnyxIgmpInterfaceModule(BaseOnyxModule): self._required_config = dict(module_params) match = self.IF_NAME_REGEX.match(self._required_config["name"]) if not match: - AttributeError("Please Insert Valide Interface Name") + raise AttributeError("Please Insert Valid Interface Name") self.validate_param_values(self._required_config) diff --git a/lib/ansible/modules/storage/netapp/netapp_e_iscsi_interface.py b/lib/ansible/modules/storage/netapp/netapp_e_iscsi_interface.py index 54939c75c9e..31a2c0a5d66 100644 --- a/lib/ansible/modules/storage/netapp/netapp_e_iscsi_interface.py +++ b/lib/ansible/modules/storage/netapp/netapp_e_iscsi_interface.py @@ -226,20 +226,20 @@ class IscsiInterface(object): self.module.fail_json(msg="The provided mtu is invalid, it must be > 1500 and < 9000 bytes.") if self.config_method == 'dhcp' and any([self.address, self.subnet_mask, self.gateway]): - self.module.fail_json( - 'A config_method of dhcp is mutually exclusive with the address, subnet_mask, and gateway options.') + self.module.fail_json(msg='A config_method of dhcp is mutually exclusive with the address,' + ' subnet_mask, and gateway options.') # A relatively primitive regex to validate that the input is formatted like a valid ip address address_regex = re.compile(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}') if self.address and not address_regex.match(self.address): - self.module.fail_json("An invalid ip address was provided for address.") + self.module.fail_json(msg="An invalid ip address was provided for address.") if self.subnet_mask and not address_regex.match(self.subnet_mask): - self.module.fail_json("An invalid ip address was provided for subnet_mask.") + self.module.fail_json(msg="An invalid ip address was provided for subnet_mask.") if self.gateway and not address_regex.match(self.gateway): - self.module.fail_json("An invalid ip address was provided for gateway.") + self.module.fail_json(msg="An invalid ip address was provided for gateway.") @property def interfaces(self):