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 <akasurde@redhat.com>
This commit is contained in:
Abhijeet Kasurde 2018-11-02 02:05:56 +05:30 committed by Brian Coca
parent 638834dc4e
commit ab86051c0b
7 changed files with 11 additions and 11 deletions

View file

@ -1155,7 +1155,7 @@ class _BaseNetwork(_IPAddressBase):
try: try:
# Always false if one is v4 and the other is v6. # Always false if one is v4 and the other is v6.
if a._version != b._version: 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 return (b.network_address <= a.network_address and
b.broadcast_address >= a.broadcast_address) b.broadcast_address >= a.broadcast_address)
except AttributeError: except AttributeError:

View file

@ -210,7 +210,7 @@ class MSCModule(object):
if len(objs) == 0: if len(objs) == 0:
return {} return {}
if len(objs) > 1: 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] return objs[0]
def sanitize(self, updates, collate=False): def sanitize(self, updates, collate=False):

View file

@ -426,7 +426,7 @@ def main():
if module.params['event_source'].lower() in ('stream', 'sqs'): if module.params['event_source'].lower() in ('stream', 'sqs'):
results = lambda_event_stream(module, aws) results = lambda_event_stream(module, aws)
else: 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) module.exit_json(**results)

View file

@ -492,7 +492,7 @@ def main():
checksum = None checksum = None
if checksum is 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 # Remove any non-alphanumeric characters, including the infamous
# Unicode zero-width space # Unicode zero-width space
checksum = re.sub(r'\W+', '', checksum).lower() checksum = re.sub(r'\W+', '', checksum).lower()

View file

@ -596,7 +596,7 @@ class ModuleManager(object):
def exists(self): def exists(self):
if not self.pool_exist(): 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( uri = "https://{0}:{1}/mgmt/tm/ltm/pool/{2}/members/{3}".format(
self.client.provider['server'], self.client.provider['server'],

View file

@ -77,7 +77,7 @@ class OnyxIgmpInterfaceModule(BaseOnyxModule):
self._required_config = dict(module_params) self._required_config = dict(module_params)
match = self.IF_NAME_REGEX.match(self._required_config["name"]) match = self.IF_NAME_REGEX.match(self._required_config["name"])
if not match: if not match:
AttributeError("Please Insert Valide Interface Name") raise AttributeError("Please Insert Valid Interface Name")
self.validate_param_values(self._required_config) self.validate_param_values(self._required_config)

View file

@ -226,20 +226,20 @@ class IscsiInterface(object):
self.module.fail_json(msg="The provided mtu is invalid, it must be > 1500 and < 9000 bytes.") 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]): if self.config_method == 'dhcp' and any([self.address, self.subnet_mask, self.gateway]):
self.module.fail_json( self.module.fail_json(msg='A config_method of dhcp is mutually exclusive with the address,'
'A config_method of dhcp is mutually exclusive with the address, subnet_mask, and gateway options.') ' subnet_mask, and gateway options.')
# A relatively primitive regex to validate that the input is formatted like a valid ip address # 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}') 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): 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): 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): 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 @property
def interfaces(self): def interfaces(self):