From dd9db65a9a2f134e59bec7cdaf83ff3d33dc5249 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Thu, 18 May 2017 08:35:42 +0530 Subject: [PATCH] PEP8 fixes for smartos module Signed-off-by: Abhijeet Kasurde --- lib/ansible/modules/cloud/smartos/imgadm.py | 6 +++--- .../modules/cloud/smartos/smartos_image_facts.py | 5 +---- lib/ansible/modules/cloud/smartos/vmadm.py | 10 +++++----- test/sanity/pep8/legacy-files.txt | 1 - 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/lib/ansible/modules/cloud/smartos/imgadm.py b/lib/ansible/modules/cloud/smartos/imgadm.py index 057117904f..a9012b3113 100644 --- a/lib/ansible/modules/cloud/smartos/imgadm.py +++ b/lib/ansible/modules/cloud/smartos/imgadm.py @@ -197,17 +197,17 @@ class Imgadm(object): self.changed = True else: # Type is ignored by imgadm(1M) here - cmd += ' -d %s' % (source) + cmd += ' -d %s' % source (rc, stdout, stderr) = self.module.run_command(cmd) if rc != 0: self.module.fail_json(msg='Failed to remove source: {0}'.format(self.errmsg(stderr))) - regex = 'Do not have image source "%s", no change' % (source) + regex = 'Do not have image source "%s", no change' % source if re.match(regex, stdout): self.changed = False - regex = 'Deleted ".*" image source "%s"' % (source) + regex = 'Deleted ".*" image source "%s"' % source if re.match(regex, stdout): self.changed = True diff --git a/lib/ansible/modules/cloud/smartos/smartos_image_facts.py b/lib/ansible/modules/cloud/smartos/smartos_image_facts.py index 58d0606569..0282c0bc27 100644 --- a/lib/ansible/modules/cloud/smartos/smartos_image_facts.py +++ b/lib/ansible/modules/cloud/smartos/smartos_image_facts.py @@ -53,7 +53,6 @@ RETURN = ''' ''' import json - from ansible.module_utils.basic import AnsibleModule @@ -101,11 +100,9 @@ def main(): image_facts = ImageFacts(module) - data = {} - data['smartos_images'] = image_facts.return_all_installed_images() + data = dict(smartos_images=image_facts.return_all_installed_images()) module.exit_json(ansible_facts=data) - if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/smartos/vmadm.py b/lib/ansible/modules/cloud/smartos/vmadm.py index fdbbd4dec9..abfeb72c7d 100644 --- a/lib/ansible/modules/cloud/smartos/vmadm.py +++ b/lib/ansible/modules/cloud/smartos/vmadm.py @@ -366,7 +366,7 @@ def get_vm_prop(module, uuid, prop): stdout_json = json.loads(stdout) except Exception as e: module.fail_json( - msg='Invalid JSON returned by vmadm for uuid lookup of {0}'.format(uuid), + msg='Invalid JSON returned by vmadm for uuid lookup of {0}'.format(prop), details=to_native(e), exception=traceback.format_exc()) if len(stdout_json) > 0 and prop in stdout_json[0]: @@ -524,15 +524,15 @@ def create_payload(module, uuid): # drop the mkstemp call and rely on ANSIBLE_KEEP_REMOTE_FILES to retain # the payload (thus removing the `save_payload` option). fname = tempfile.mkstemp()[1] - fh = open(fname, 'w') os.chmod(fname, 0o400) - fh.write(vmdef_json) - fh.close() + with open(fname, 'w') as fh: + fh.write(vmdef_json) except Exception as e: module.fail_json(msg='Could not save JSON payload: %s' % to_native(e), exception=traceback.format_exc()) return fname + def vm_state_transition(module, uuid, vm_state): ret = set_vm_state(module, uuid, vm_state) @@ -641,7 +641,7 @@ def main(): cpu_type=dict( default='qemu64', type='str', - choices=['host','qemu64'] + choices=['host', 'qemu64'] ), # Regular strings, however these require additional options. spice_password=dict(type='str', no_log=True), diff --git a/test/sanity/pep8/legacy-files.txt b/test/sanity/pep8/legacy-files.txt index 52afef708b..868d5a1eca 100644 --- a/test/sanity/pep8/legacy-files.txt +++ b/test/sanity/pep8/legacy-files.txt @@ -162,7 +162,6 @@ lib/ansible/modules/cloud/rackspace/rax_mon_check.py lib/ansible/modules/cloud/rackspace/rax_mon_entity.py lib/ansible/modules/cloud/rackspace/rax_mon_notification.py lib/ansible/modules/cloud/rackspace/rax_mon_notification_plan.py -lib/ansible/modules/cloud/smartos/vmadm.py lib/ansible/modules/cloud/softlayer/sl_vm.py lib/ansible/modules/cloud/univention/udm_dns_record.py lib/ansible/modules/cloud/univention/udm_dns_zone.py