Fix invocations of module.fail_json with no msg=

Bonus: add missing % in cs_nic.py
This commit is contained in:
Kamil Cholewiński 2017-03-07 13:51:38 +01:00 committed by Brian Coca
commit ec9582fd83
15 changed files with 25 additions and 25 deletions

View file

@ -161,7 +161,7 @@ def create_meter(module, name, apiid, apikey):
try:
os.makedirs(config_directory)
except:
module.fail_json("Could not create " + config_directory)
module.fail_json(msg="Could not create " + config_directory)
# Download both cert files from the api host
@ -174,7 +174,7 @@ def create_meter(module, name, apiid, apikey):
# Now download the file...
rc = download_request(module, name, apiid, apikey, cert_type)
if rc is False:
module.fail_json("Download request for " + cert_type + ".pem failed")
module.fail_json(msg="Download request for " + cert_type + ".pem failed")
return 0, "Meter " + name + " created"
@ -183,7 +183,7 @@ def search_meter(module, name, apiid, apikey):
response, info = http_request(module, name, apiid, apikey, action="search")
if info['status'] != 200:
module.fail_json("Failed to connect to api host to search for meter")
module.fail_json(msg="Failed to connect to api host to search for meter")
# Return meters
return json.loads(response.read())
@ -206,7 +206,7 @@ def delete_meter(module, name, apiid, apikey):
else:
response, info = http_request(module, name, apiid, apikey, action, meter_id)
if info['status'] != 200:
module.fail_json("Failed to delete meter")
module.fail_json(msg="Failed to delete meter")
# Each new meter gets a new key.pem and ca.pem file, so they should be deleted
types = ['cert', 'key']
@ -215,7 +215,7 @@ def delete_meter(module, name, apiid, apikey):
cert_file = '%s/%s.pem' % (config_directory,cert_type)
os.remove(cert_file)
except OSError:
module.fail_json("Failed to remove " + cert_type + ".pem file")
module.fail_json(msg="Failed to remove " + cert_type + ".pem file")
return 0, "Meter " + name + " deleted"
@ -227,7 +227,7 @@ def download_request(module, name, apiid, apikey, cert_type):
action = "certificates"
response, info = http_request(module, name, apiid, apikey, action, meter_id, cert_type)
if info['status'] != 200:
module.fail_json("Failed to connect to api host to download certificate")
module.fail_json(msg="Failed to connect to api host to download certificate")
if result:
try:
@ -238,11 +238,11 @@ def download_request(module, name, apiid, apikey, cert_type):
cert_file.close()
os.chmod(cert_file_path, int('0600', 8))
except:
module.fail_json("Could not write to certificate file")
module.fail_json(msg="Could not write to certificate file")
return True
else:
module.fail_json("Could not get meter id")
module.fail_json(msg="Could not get meter id")
def main():