diff mbox

[2/3] KVM-Test: unattended_install.py: Get anaconda log and save it to log file

Message ID 1309254319-30182-1-git-send-email-qzhou@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

qzhou@redhat.com June 28, 2011, 9:45 a.m. UTC
This patch will save guest's anaconda log to 'anaconda.log' in debug directory.

Signed-off-by: Qingtang Zhou <qzhou@redhat.com>
---
 client/tests/kvm/tests/unattended_install.py |   31 ++++++++++++++++++++++++++
 1 files changed, 31 insertions(+), 0 deletions(-)

Comments

Lucas Meneghel Rodrigues July 5, 2011, 3:56 p.m. UTC | #1
On Tue, 2011-06-28 at 17:45 +0800, Qingtang Zhou wrote:
> This patch will save guest's anaconda log to 'anaconda.log' in debug directory.
> 
> Signed-off-by: Qingtang Zhou <qzhou@redhat.com>
> ---
>  client/tests/kvm/tests/unattended_install.py |   31 ++++++++++++++++++++++++++
>  1 files changed, 31 insertions(+), 0 deletions(-)
> 
> diff --git a/client/tests/kvm/tests/unattended_install.py b/client/tests/kvm/tests/unattended_install.py
> index 50a8c7a..d631404 100644
> --- a/client/tests/kvm/tests/unattended_install.py
> +++ b/client/tests/kvm/tests/unattended_install.py
> @@ -494,6 +494,28 @@ class UnattendedInstallConfig(object):
>              raise ValueError("Unexpected installation method %s" %
>                               self.medium)
>  
> +def _get_anaconda_log(vm, log_file):
> +    port = int(vm.params.get("guest_port_unattended_install")) - 1
> +    port = vm.get_port(port)
> +
> +    anaconda_logfile = open(log_file, 'w')
> +
> +    while True:
> +        client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> +        try:
> +            client.connect((vm.get_address(), port))
> +            install_log = client.recv(10240)
> +            if install_log != "":
> +                anaconda_logfile.write(install_log)
> +                anaconda_logfile.flush()
> +                client.send("ok %s\n" % str(time.time()))
> +        except (socket.error, virt_vm.VMAddressError):
> +            pass
> +        finally:
> +            client.close()
> +        time.sleep(1)

^ Here we have a try/except/finally block, which is illegal in py 2.4.
This needs to be fixed.

> +    anaconda_logfile.close()
>  
>  @error.context_aware
>  def run_unattended_install(test, params, env):
> @@ -524,6 +546,13 @@ def run_unattended_install(test, params, env):
>                   "(%d min)", install_timeout, install_timeout/60)
>      error.context("waiting for installation to finish")
>  
> +    get_anaconda_log = params.get("get_anaconda_log") == "yes"

^ In case get_anaconda_log is not defined for that specific variant,
better to make it default to 'no', so it'd be something like:

    get_anaconda_log = params.get("get_anaconda_log", "no") == "yes"


> +    if get_anaconda_log:
> +        log_file = os.path.join(test.debugdir, "anaconda.log")
> +        bg = virt_utils.Thread(_get_anaconda_log,
> +                            kwargs={"vm": vm, "log_file": log_file})
> +        bg.start()
> +
>      start_time = time.time()
>      while (time.time() - start_time) < install_timeout:
>          try:
> @@ -539,6 +568,8 @@ def run_unattended_install(test, params, env):
>              try:
>                  client.connect((vm.get_address(), port))
>                  if client.recv(1024) == "done":
> +                    if get_anaconda_log:
> +                        bg.join()
>                      break
>              except (socket.error, virt_vm.VMAddressError):
>                  pass


--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/client/tests/kvm/tests/unattended_install.py b/client/tests/kvm/tests/unattended_install.py
index 50a8c7a..d631404 100644
--- a/client/tests/kvm/tests/unattended_install.py
+++ b/client/tests/kvm/tests/unattended_install.py
@@ -494,6 +494,28 @@  class UnattendedInstallConfig(object):
             raise ValueError("Unexpected installation method %s" %
                              self.medium)
 
+def _get_anaconda_log(vm, log_file):
+    port = int(vm.params.get("guest_port_unattended_install")) - 1
+    port = vm.get_port(port)
+
+    anaconda_logfile = open(log_file, 'w')
+
+    while True:
+        client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        try:
+            client.connect((vm.get_address(), port))
+            install_log = client.recv(10240)
+            if install_log != "":
+                anaconda_logfile.write(install_log)
+                anaconda_logfile.flush()
+                client.send("ok %s\n" % str(time.time()))
+        except (socket.error, virt_vm.VMAddressError):
+            pass
+        finally:
+            client.close()
+        time.sleep(1)
+
+    anaconda_logfile.close()
 
 @error.context_aware
 def run_unattended_install(test, params, env):
@@ -524,6 +546,13 @@  def run_unattended_install(test, params, env):
                  "(%d min)", install_timeout, install_timeout/60)
     error.context("waiting for installation to finish")
 
+    get_anaconda_log = params.get("get_anaconda_log") == "yes"
+    if get_anaconda_log:
+        log_file = os.path.join(test.debugdir, "anaconda.log")
+        bg = virt_utils.Thread(_get_anaconda_log,
+                            kwargs={"vm": vm, "log_file": log_file})
+        bg.start()
+
     start_time = time.time()
     while (time.time() - start_time) < install_timeout:
         try:
@@ -539,6 +568,8 @@  def run_unattended_install(test, params, env):
             try:
                 client.connect((vm.get_address(), port))
                 if client.recv(1024) == "done":
+                    if get_anaconda_log:
+                        bg.join()
                     break
             except (socket.error, virt_vm.VMAddressError):
                 pass