[libvirt] [test-API][PATCH 1/2] Fix the undefined local variable problem in remote_exec

* subproc_flag should be global when used between functions * print error msg when exception happened Signed-off-by: Wayne Sun <gsun@redhat.com> --- utils/utils.py | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-) diff --git a/utils/utils.py b/utils/utils.py index 455e9cf..be87cdc 100644 --- a/utils/utils.py +++ b/utils/utils.py @@ -32,6 +32,8 @@ import subprocess from xml.dom import minidom from urlparse import urlparse +subproc_flag = 0 + def get_hypervisor(): if commands.getoutput("lsmod | grep kvm"): return 'kvm' @@ -439,10 +441,12 @@ def support_virt(self): return True def subproc(a, b): + global subproc_flag subproc_flag = 1 def remote_exec(hostname, username, password, cmd): """Remote execution on specified host""" + global subproc_flag pid, fd = pty.fork() if pid == 0: try: @@ -479,6 +483,7 @@ def remote_exec(hostname, username, password, cmd): subproc_flag = 0 return ret except Exception, e: + print e subproc_flag = 0 return -1 -- 1.7.1

* add imageformat as optional param in define * modify define xml for image format support Signed-off-by: Wayne Sun <gsun@redhat.com> --- repos/domain/define.py | 1 + repos/domain/xmls/kvm_guest_define.xml | 2 +- 2 files changed, 2 insertions(+), 1 deletions(-) diff --git a/repos/domain/define.py b/repos/domain/define.py index 0a06dfd..a70ddad 100644 --- a/repos/domain/define.py +++ b/repos/domain/define.py @@ -16,6 +16,7 @@ from utils import utils required_params = ('guestname', 'diskpath',) optional_params = {'memory': 1048576, 'vcpu': 1, + 'imageformat' : 'raw', 'hddriver' : 'virtio', 'nicdriver': 'virtio', 'macaddr': '52:54:00:97:e4:28', diff --git a/repos/domain/xmls/kvm_guest_define.xml b/repos/domain/xmls/kvm_guest_define.xml index 4599b2e..6da0ad4 100644 --- a/repos/domain/xmls/kvm_guest_define.xml +++ b/repos/domain/xmls/kvm_guest_define.xml @@ -19,7 +19,7 @@ <on_crash>restart</on_crash> <devices> <disk type='file' device='disk'> - <driver name='qemu' type='qcow2'/> + <driver name='qemu' type='IMAGEFORMAT'/> <source file='DISKPATH'/> <target dev='vda' bus='HDDRIVER'/> </disk> -- 1.7.1

On 07/31/2012 04:23 PM, Wayne Sun wrote:
* add imageformat as optional param in define * modify define xml for image format support
Signed-off-by: Wayne Sun <gsun@redhat.com> --- repos/domain/define.py | 1 + repos/domain/xmls/kvm_guest_define.xml | 2 +- 2 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/repos/domain/define.py b/repos/domain/define.py index 0a06dfd..a70ddad 100644 --- a/repos/domain/define.py +++ b/repos/domain/define.py @@ -16,6 +16,7 @@ from utils import utils required_params = ('guestname', 'diskpath',) optional_params = {'memory': 1048576, 'vcpu': 1, + 'imageformat' : 'raw', 'hddriver' : 'virtio', 'nicdriver': 'virtio', 'macaddr': '52:54:00:97:e4:28', diff --git a/repos/domain/xmls/kvm_guest_define.xml b/repos/domain/xmls/kvm_guest_define.xml index 4599b2e..6da0ad4 100644 --- a/repos/domain/xmls/kvm_guest_define.xml +++ b/repos/domain/xmls/kvm_guest_define.xml @@ -19,7 +19,7 @@ <on_crash>restart</on_crash> <devices> <disk type='file' device='disk'> - <driver name='qemu' type='qcow2'/> + <driver name='qemu' type='IMAGEFORMAT'/> <source file='DISKPATH'/> <target dev='vda' bus='HDDRIVER'/> </disk>
The create.py needs the same change, I will do it with this patch together. ACK Guannan

On 07/31/2012 04:23 PM, Wayne Sun wrote:
* subproc_flag should be global when used between functions * print error msg when exception happened
Signed-off-by: Wayne Sun <gsun@redhat.com> --- utils/utils.py | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/utils/utils.py b/utils/utils.py index 455e9cf..be87cdc 100644 --- a/utils/utils.py +++ b/utils/utils.py @@ -32,6 +32,8 @@ import subprocess from xml.dom import minidom from urlparse import urlparse
+subproc_flag = 0 + def get_hypervisor(): if commands.getoutput("lsmod | grep kvm"): return 'kvm' @@ -439,10 +441,12 @@ def support_virt(self): return True
def subproc(a, b): + global subproc_flag subproc_flag = 1
def remote_exec(hostname, username, password, cmd): """Remote execution on specified host""" + global subproc_flag pid, fd = pty.fork() if pid == 0: try: @@ -479,6 +483,7 @@ def remote_exec(hostname, username, password, cmd): subproc_flag = 0 return ret except Exception, e: + print e subproc_flag = 0 return -1
ACK. Guannan

On 07/31/2012 04:23 PM, Wayne Sun wrote:
* subproc_flag should be global when used between functions * print error msg when exception happened
Signed-off-by: Wayne Sun <gsun@redhat.com> --- utils/utils.py | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/utils/utils.py b/utils/utils.py index 455e9cf..be87cdc 100644 --- a/utils/utils.py +++ b/utils/utils.py @@ -32,6 +32,8 @@ import subprocess from xml.dom import minidom from urlparse import urlparse
+subproc_flag = 0 + def get_hypervisor(): if commands.getoutput("lsmod | grep kvm"): return 'kvm' @@ -439,10 +441,12 @@ def support_virt(self): return True
def subproc(a, b): + global subproc_flag subproc_flag = 1
def remote_exec(hostname, username, password, cmd): """Remote execution on specified host""" + global subproc_flag pid, fd = pty.fork() if pid == 0: try: @@ -479,6 +483,7 @@ def remote_exec(hostname, username, password, cmd): subproc_flag = 0 return ret except Exception, e: + print e subproc_flag = 0 return -1
These two patches has been pushed.
participants (2)
-
Guannan Ren
-
Wayne Sun