From bb73819c43bfb0069c5459924e26014ef0a4fe35 Mon Sep 17 00:00:00 2001 From: Jonathan Mainguy Date: Sun, 30 Mar 2014 13:39:00 -0400 Subject: [PATCH 1/4] mysql_db module now correctly fails on import if bz2 or gz fails. --- library/database/mysql_db | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/library/database/mysql_db b/library/database/mysql_db index c9fd5b4e087..aa852ea78c1 100644 --- a/library/database/mysql_db +++ b/library/database/mysql_db @@ -148,12 +148,42 @@ def db_import(module, host, user, password, db_name, target, port, socket=None): cmd += " --host=%s --port=%s" % (pipes.quote(host), pipes.quote(port)) cmd += " -D %s" % pipes.quote(db_name) if os.path.splitext(target)[-1] == '.gz': - cmd = 'gunzip < ' + pipes.quote(target) + ' | ' + cmd + gunzip_path = module.get_bin_path('gunzip') + if gunzip_path: + rc, stdout, stderr = module.run_command('%s %s' % (gunzip_path, target)) + if rc != 0: + return rc, stdout, stderr + cmd += " < %s" % pipes.quote(target[0:-3]) + rc, stdout, stderr = module.run_command(cmd, use_unsafe_shell=True) + if rc != 0: + return rc, stdout, stderr + gzip_path = module.get_bin_path('gzip') + if gzip_path: + rc, stdout, stderr = module.run_command('%s %s' % (gzip_path, target[0:-3])) + else: + module.fail_json(msg="gzip command not found") + else: + module.fail_json(msg="gunzip command not found") elif os.path.splitext(target)[-1] == '.bz2': - cmd = 'bunzip2 < ' + pipes.quote(target) + ' | ' + cmd + bunzip2_path = module.get_bin_path('bunzip2') + if bunzip2_path: + rc, stdout, stderr = module.run_command('%s %s' % (bunzip2_path, target)) + if rc != 0: + return rc, stdout, stderr + cmd += " < %s" % pipes.quote(target[0:-4]) + rc, stdout, stderr = module.run_command(cmd, use_unsafe_shell=True) + if rc != 0: + return rc, stdout, stderr + bzip2_path = module.get_bin_path('bzip2') + if bzip2_path: + rc, stdout, stderr = module.run_command('%s %s' % (bzip2_path, target[0:-4])) + else: + module.fail_json(msg="bzip2 command not found") + else: + module.fail_json(msg="bunzip2 command not found") else: cmd += " < %s" % pipes.quote(target) - rc, stdout, stderr = module.run_command(cmd, use_unsafe_shell=True) + rc, stdout, stderr = module.run_command(cmd, use_unsafe_shell=True) return rc, stdout, stderr def db_create(cursor, db, encoding, collation): From 8928a5ede12d2093a479379a1cf73b9c10fc1e93 Mon Sep 17 00:00:00 2001 From: Jonathan Mainguy Date: Mon, 31 Mar 2014 11:09:00 -0400 Subject: [PATCH 2/4] Added mpdehaan suggestion to use os.path.splitext. Wise suggestion, does look clearner --- library/database/mysql_db | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/database/mysql_db b/library/database/mysql_db index aa852ea78c1..97655fbc006 100644 --- a/library/database/mysql_db +++ b/library/database/mysql_db @@ -153,13 +153,13 @@ def db_import(module, host, user, password, db_name, target, port, socket=None): rc, stdout, stderr = module.run_command('%s %s' % (gunzip_path, target)) if rc != 0: return rc, stdout, stderr - cmd += " < %s" % pipes.quote(target[0:-3]) + cmd += " < %s" % pipes.quote(os.path.splitext(target)[0]) rc, stdout, stderr = module.run_command(cmd, use_unsafe_shell=True) if rc != 0: return rc, stdout, stderr gzip_path = module.get_bin_path('gzip') if gzip_path: - rc, stdout, stderr = module.run_command('%s %s' % (gzip_path, target[0:-3])) + rc, stdout, stderr = module.run_command('%s %s' % (gzip_path, os.path.splitext(target)[0])) else: module.fail_json(msg="gzip command not found") else: @@ -170,13 +170,13 @@ def db_import(module, host, user, password, db_name, target, port, socket=None): rc, stdout, stderr = module.run_command('%s %s' % (bunzip2_path, target)) if rc != 0: return rc, stdout, stderr - cmd += " < %s" % pipes.quote(target[0:-4]) + cmd += " < %s" % pipes.quote(os.path.splitext(target)[0]) rc, stdout, stderr = module.run_command(cmd, use_unsafe_shell=True) if rc != 0: return rc, stdout, stderr bzip2_path = module.get_bin_path('bzip2') if bzip2_path: - rc, stdout, stderr = module.run_command('%s %s' % (bzip2_path, target[0:-4])) + rc, stdout, stderr = module.run_command('%s %s' % (bzip2_path, os.path.splitext(target)[0])) else: module.fail_json(msg="bzip2 command not found") else: From 726a61eb43bed5621f37930f785a6a31bc8c3e14 Mon Sep 17 00:00:00 2001 From: Jakub Jirutka Date: Mon, 23 Jun 2014 15:23:57 +0200 Subject: [PATCH 3/4] Add os relpath filter --- lib/ansible/runner/filter_plugins/core.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/ansible/runner/filter_plugins/core.py b/lib/ansible/runner/filter_plugins/core.py index 443d1574ca2..6d2e9f3017e 100644 --- a/lib/ansible/runner/filter_plugins/core.py +++ b/lib/ansible/runner/filter_plugins/core.py @@ -226,6 +226,7 @@ class FilterModule(object): 'dirname': os.path.dirname, 'expanduser': os.path.expanduser, 'realpath': os.path.realpath, + 'relpath': os.path.relpath, # failure testing 'failed' : failed, From 677e99e3758a8ff6c49fd0c02931fb4588bb29ed Mon Sep 17 00:00:00 2001 From: Dann Bohn Date: Mon, 23 Jun 2014 11:16:03 -0400 Subject: [PATCH 4/4] force evaluation of vars memory_mb, num_cpus to be int fixes #7903 --- library/cloud/vsphere_guest | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/library/cloud/vsphere_guest b/library/cloud/vsphere_guest index 2a02b933b20..efb35de2fcd 100644 --- a/library/cloud/vsphere_guest +++ b/library/cloud/vsphere_guest @@ -496,7 +496,7 @@ def reconfigure_vm(vsphere_client, vm, module, esxi, resource_pool, cluster_name # Change Memory if vm_hardware['memory_mb']: - if vm_hardware['memory_mb'] != vm.properties.config.hardware.memoryMB: + if int(vm_hardware['memory_mb']) != vm.properties.config.hardware.memoryMB: spec = spec_singleton(spec, request, vm) if vm.is_powered_on(): @@ -504,7 +504,7 @@ def reconfigure_vm(vsphere_client, vm, module, esxi, resource_pool, cluster_name # No hot add but force if not memoryHotAddEnabled: shutdown = True - elif vm_hardware['memory_mb'] < vm.properties.config.hardware.memoryMB: + elif int(vm_hardware['memory_mb']) < vm.properties.config.hardware.memoryMB: shutdown = True else: # Fail on no hot add and no force @@ -514,7 +514,7 @@ def reconfigure_vm(vsphere_client, vm, module, esxi, resource_pool, cluster_name "required for shutdown") # Fail on no force and memory shrink - elif vm_hardware['memory_mb'] < vm.properties.config.hardware.memoryMB: + elif int(vm_hardware['memory_mb']) < vm.properties.config.hardware.memoryMB: module.fail_json( msg="Cannot lower memory on a live VM. force is " "required for shutdown") @@ -525,7 +525,7 @@ def reconfigure_vm(vsphere_client, vm, module, esxi, resource_pool, cluster_name # ====( Config Memory )====# if vm_hardware['num_cpus']: - if vm_hardware['num_cpus'] != vm.properties.config.hardware.numCPU: + if int(vm_hardware['num_cpus']) != vm.properties.config.hardware.numCPU: spec = spec_singleton(spec, request, vm) if vm.is_powered_on(): @@ -533,7 +533,7 @@ def reconfigure_vm(vsphere_client, vm, module, esxi, resource_pool, cluster_name # No hot add but force if not cpuHotAddEnabled: shutdown = True - elif vm_hardware['num_cpus'] < vm.properties.config.hardware.numCPU: + elif int(vm_hardware['num_cpus']) < vm.properties.config.hardware.numCPU: if not cpuHotRemoveEnabled: shutdown = True else: @@ -544,7 +544,7 @@ def reconfigure_vm(vsphere_client, vm, module, esxi, resource_pool, cluster_name "required for shutdown") # Fail on no force and cpu shrink without hot remove - elif vm_hardware['num_cpus'] < vm.properties.config.hardware.numCPU: + elif int(vm_hardware['num_cpus']) < vm.properties.config.hardware.numCPU: if not cpuHotRemoveEnabled: module.fail_json( msg="Cannot lower CPU on a live VM without "