diff mbox

[KVM-AUTOTEST,3/4] kvm_guest_wizard: allow keeping screendump history for debugging purposes

Message ID 450b0ac3f003f5e9d56267d3dabee881ee35fe78.1245094830.git.mgoldish@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Michael Goldish June 15, 2009, 7:45 p.m. UTC
Add two new step file test parameters:
- keep_screendump_history: if equals 'yes', screendump history is saved in
  test.debugdir/barrier_history in JPG format.  Each screendump taken by the
  test is saved if it differs from the previous screendump.  By default, when
  a barrier succeeds all history is removed, so eventually the remaining files
  are only those of the (last) failed barrier, if any.
- keep_all_history: if equals 'yes', screendump history is not removed upon
  barrier success.  The test leaves behind all the collected screendump history.

Signed-off-by: Michael Goldish <mgoldish@redhat.com>
---
 client/tests/kvm/kvm_guest_wizard.py |   38 ++++++++++++++++++++++++++++-----
 1 files changed, 32 insertions(+), 6 deletions(-)

Comments

Lucas Meneghel Rodrigues June 18, 2009, 2:30 p.m. UTC | #1
On Mon, 2009-06-15 at 22:45 +0300, Michael Goldish wrote:
> Add two new step file test parameters:
> - keep_screendump_history: if equals 'yes', screendump history is saved in
>   test.debugdir/barrier_history in JPG format.  Each screendump taken by the
>   test is saved if it differs from the previous screendump.  By default, when
>   a barrier succeeds all history is removed, so eventually the remaining files
>   are only those of the (last) failed barrier, if any.
> - keep_all_history: if equals 'yes', screendump history is not removed upon
>   barrier success.  The test leaves behind all the collected screendump history.
> 
> Signed-off-by: Michael Goldish <mgoldish@redhat.com>
> ---
>  client/tests/kvm/kvm_guest_wizard.py |   38 ++++++++++++++++++++++++++++-----
>  1 files changed, 32 insertions(+), 6 deletions(-)
> 
> diff --git a/client/tests/kvm/kvm_guest_wizard.py b/client/tests/kvm/kvm_guest_wizard.py
> index eb0e2d5..73b830e 100644
> --- a/client/tests/kvm/kvm_guest_wizard.py
> +++ b/client/tests/kvm/kvm_guest_wizard.py
> @@ -1,6 +1,6 @@
>  import os, time, md5, re, shutil, logging
>  from autotest_lib.client.common_lib import utils, error
> -import kvm_utils, ppm_utils
> +import kvm_utils, ppm_utils, kvm_subprocess

I see, it depends on kvm subprocess, so I will apply this patch after
the kvm subprocess patch is applied.

>  """
>  Utilities to perform automatic guest installation using step files.
> @@ -53,6 +53,11 @@ def barrier_2(vm, words, params, debug_dir, data_scrdump_filename,
>      else:
>          stuck_detection_history = 2
>  
> +    keep_screendump_history = params.get("keep_screendump_history") == "yes"
> +    if keep_screendump_history:
> +        keep_all_history = params.get("keep_all_history") == "yes"
> +        history_dir = os.path.join(debug_dir, "barrier_history")
> +

Here I also think that we should check for the presence of ImageMagick
to avoid failing the test out of necessity.

>      end_time = time.time() + timeout
>      end_time_stuck = time.time() + fail_if_stuck_for
>      start_time = time.time()
> @@ -91,21 +96,42 @@ def barrier_2(vm, words, params, debug_dir, data_scrdump_filename,
>          # Read image file
>          (w, h, data) = ppm_utils.image_read_from_ppm_file(scrdump_filename)
>  
> +        # Compute md5sum of whole image
> +        whole_image_md5sum = ppm_utils.image_md5sum(w, h, data)
> +
> +        # Write screendump to history_dir (as JPG) if requested
> +        # and if the screendump differs from the previous one
> +        if (keep_screendump_history and
> +            whole_image_md5sum not in prev_whole_image_md5sums[:1]):
> +            try:
> +                os.makedirs(history_dir)
> +            except:
> +                pass
> +            history_scrdump_filename = os.path.join(history_dir,
> +                    "scrdump-step_%s-%s.jpg" % (current_step_num,
> +                                                time.strftime("%Y%m%d-%H%M%S")))
> +            kvm_subprocess.run_fg("convert -quality 30 %s %s" %
> +                                  (scrdump_filename, history_scrdump_filename),
> +                                  logging.debug, "(convert) ", timeout=30)
> +
>          # Compare md5sum of barrier region with the expected md5sum
>          calced_md5sum = ppm_utils.get_region_md5sum(w, h, data, x1, y1, dx, dy,
>                                                      cropped_scrdump_filename)
>          if calced_md5sum == md5sum:
> +            # Success -- remove screendump history unless requested not to
> +            if keep_screendump_history and not keep_all_history:
> +                kvm_subprocess.run_fg("rm -rvf %s" % history_dir,
> +                                      logging.debug, "(rm) ", timeout=30)
> +            # Report success
>              return True
>  
> -        # Compute md5sum of whole image in order to compare it with
> -        # previous ones
> -        whole_image_md5sum = ppm_utils.image_md5sum(w, h, data)
> +        # Insert image md5sum into queue of last seen images:
>          # If md5sum is already in queue...
>          if whole_image_md5sum in prev_whole_image_md5sums:
>              # Remove md5sum from queue
>              prev_whole_image_md5sums.remove(whole_image_md5sum)
>          else:
> -            # Extend 'stuck' timeout
> +            # Otherwise extend 'stuck' timeout
>              end_time_stuck = time.time() + fail_if_stuck_for
>          # Insert md5sum at beginning of queue
>          prev_whole_image_md5sums.insert(0, whole_image_md5sum)
> @@ -129,7 +155,7 @@ def barrier_2(vm, words, params, debug_dir, data_scrdump_filename,
>          if data_scrdump_filename and os.path.exists(data_scrdump_filename):
>              # Read expected screendump image
>              (ew, eh, edata) = \
> -            ppm_utils.image_read_from_ppm_file(data_scrdump_filename)
> +                    ppm_utils.image_read_from_ppm_file(data_scrdump_filename)
>              # Write it in debug_dir
>              ppm_utils.image_write_to_ppm_file(expected_scrdump_filename,
>                                                ew, eh, edata)
Michael Goldish June 18, 2009, 3:30 p.m. UTC | #2
----- "Lucas Meneghel Rodrigues" <lmr@redhat.com> wrote:

> On Mon, 2009-06-15 at 22:45 +0300, Michael Goldish wrote:
> > Add two new step file test parameters:
> > - keep_screendump_history: if equals 'yes', screendump history is
> saved in
> >   test.debugdir/barrier_history in JPG format.  Each screendump
> taken by the
> >   test is saved if it differs from the previous screendump.  By
> default, when
> >   a barrier succeeds all history is removed, so eventually the
> remaining files
> >   are only those of the (last) failed barrier, if any.
> > - keep_all_history: if equals 'yes', screendump history is not
> removed upon
> >   barrier success.  The test leaves behind all the collected
> screendump history.
> > 
> > Signed-off-by: Michael Goldish <mgoldish@redhat.com>
> > ---
> >  client/tests/kvm/kvm_guest_wizard.py |   38
> ++++++++++++++++++++++++++++-----
> >  1 files changed, 32 insertions(+), 6 deletions(-)
> > 
> > diff --git a/client/tests/kvm/kvm_guest_wizard.py
> b/client/tests/kvm/kvm_guest_wizard.py
> > index eb0e2d5..73b830e 100644
> > --- a/client/tests/kvm/kvm_guest_wizard.py
> > +++ b/client/tests/kvm/kvm_guest_wizard.py
> > @@ -1,6 +1,6 @@
> >  import os, time, md5, re, shutil, logging
> >  from autotest_lib.client.common_lib import utils, error
> > -import kvm_utils, ppm_utils
> > +import kvm_utils, ppm_utils, kvm_subprocess
> 
> I see, it depends on kvm subprocess, so I will apply this patch after
> the kvm subprocess patch is applied.
> 
> >  """
> >  Utilities to perform automatic guest installation using step
> files.
> > @@ -53,6 +53,11 @@ def barrier_2(vm, words, params, debug_dir,
> data_scrdump_filename,
> >      else:
> >          stuck_detection_history = 2
> >  
> > +    keep_screendump_history = params.get("keep_screendump_history")
> == "yes"
> > +    if keep_screendump_history:
> > +        keep_all_history = params.get("keep_all_history") == "yes"
> > +        history_dir = os.path.join(debug_dir, "barrier_history")
> > +
> 
> Here I also think that we should check for the presence of
> ImageMagick to avoid failing the test out of necessity.

Again, the test won't fail as long as kvm_subprocess doesn't raise exceptions.
It'll just display bash's "command not found" response in debug messages with
a "(convert) " prefix.

> >      end_time = time.time() + timeout
> >      end_time_stuck = time.time() + fail_if_stuck_for
> >      start_time = time.time()
> > @@ -91,21 +96,42 @@ def barrier_2(vm, words, params, debug_dir,
> data_scrdump_filename,
> >          # Read image file
> >          (w, h, data) =
> ppm_utils.image_read_from_ppm_file(scrdump_filename)
> >  
> > +        # Compute md5sum of whole image
> > +        whole_image_md5sum = ppm_utils.image_md5sum(w, h, data)
> > +
> > +        # Write screendump to history_dir (as JPG) if requested
> > +        # and if the screendump differs from the previous one
> > +        if (keep_screendump_history and
> > +            whole_image_md5sum not in
> prev_whole_image_md5sums[:1]):
> > +            try:
> > +                os.makedirs(history_dir)
> > +            except:
> > +                pass
> > +            history_scrdump_filename = os.path.join(history_dir,
> > +                    "scrdump-step_%s-%s.jpg" % (current_step_num,
> > +                                               
> time.strftime("%Y%m%d-%H%M%S")))
> > +            kvm_subprocess.run_fg("convert -quality 30 %s %s" %
> > +                                  (scrdump_filename,
> history_scrdump_filename),
> > +                                  logging.debug, "(convert) ",
> timeout=30)
> > +
> >          # Compare md5sum of barrier region with the expected
> md5sum
> >          calced_md5sum = ppm_utils.get_region_md5sum(w, h, data, x1,
> y1, dx, dy,
> >                                                     
> cropped_scrdump_filename)
> >          if calced_md5sum == md5sum:
> > +            # Success -- remove screendump history unless requested
> not to
> > +            if keep_screendump_history and not keep_all_history:
> > +                kvm_subprocess.run_fg("rm -rvf %s" % history_dir,
> > +                                      logging.debug, "(rm) ",
> timeout=30)
> > +            # Report success
> >              return True
> >  
> > -        # Compute md5sum of whole image in order to compare it
> with
> > -        # previous ones
> > -        whole_image_md5sum = ppm_utils.image_md5sum(w, h, data)
> > +        # Insert image md5sum into queue of last seen images:
> >          # If md5sum is already in queue...
> >          if whole_image_md5sum in prev_whole_image_md5sums:
> >              # Remove md5sum from queue
> >              prev_whole_image_md5sums.remove(whole_image_md5sum)
> >          else:
> > -            # Extend 'stuck' timeout
> > +            # Otherwise extend 'stuck' timeout
> >              end_time_stuck = time.time() + fail_if_stuck_for
> >          # Insert md5sum at beginning of queue
> >          prev_whole_image_md5sums.insert(0, whole_image_md5sum)
> > @@ -129,7 +155,7 @@ def barrier_2(vm, words, params, debug_dir,
> data_scrdump_filename,
> >          if data_scrdump_filename and
> os.path.exists(data_scrdump_filename):
> >              # Read expected screendump image
> >              (ew, eh, edata) = \
> > -           
> ppm_utils.image_read_from_ppm_file(data_scrdump_filename)
> > +                   
> ppm_utils.image_read_from_ppm_file(data_scrdump_filename)
> >              # Write it in debug_dir
> >             
> ppm_utils.image_write_to_ppm_file(expected_scrdump_filename,
> >                                                ew, eh, edata)
> -- 
> Lucas Meneghel Rodrigues
> Software Engineer (QE)
> Red Hat - Emerging Technologies
--
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/kvm_guest_wizard.py b/client/tests/kvm/kvm_guest_wizard.py
index eb0e2d5..73b830e 100644
--- a/client/tests/kvm/kvm_guest_wizard.py
+++ b/client/tests/kvm/kvm_guest_wizard.py
@@ -1,6 +1,6 @@ 
 import os, time, md5, re, shutil, logging
 from autotest_lib.client.common_lib import utils, error
-import kvm_utils, ppm_utils
+import kvm_utils, ppm_utils, kvm_subprocess
 
 """
 Utilities to perform automatic guest installation using step files.
@@ -53,6 +53,11 @@  def barrier_2(vm, words, params, debug_dir, data_scrdump_filename,
     else:
         stuck_detection_history = 2
 
+    keep_screendump_history = params.get("keep_screendump_history") == "yes"
+    if keep_screendump_history:
+        keep_all_history = params.get("keep_all_history") == "yes"
+        history_dir = os.path.join(debug_dir, "barrier_history")
+
     end_time = time.time() + timeout
     end_time_stuck = time.time() + fail_if_stuck_for
     start_time = time.time()
@@ -91,21 +96,42 @@  def barrier_2(vm, words, params, debug_dir, data_scrdump_filename,
         # Read image file
         (w, h, data) = ppm_utils.image_read_from_ppm_file(scrdump_filename)
 
+        # Compute md5sum of whole image
+        whole_image_md5sum = ppm_utils.image_md5sum(w, h, data)
+
+        # Write screendump to history_dir (as JPG) if requested
+        # and if the screendump differs from the previous one
+        if (keep_screendump_history and
+            whole_image_md5sum not in prev_whole_image_md5sums[:1]):
+            try:
+                os.makedirs(history_dir)
+            except:
+                pass
+            history_scrdump_filename = os.path.join(history_dir,
+                    "scrdump-step_%s-%s.jpg" % (current_step_num,
+                                                time.strftime("%Y%m%d-%H%M%S")))
+            kvm_subprocess.run_fg("convert -quality 30 %s %s" %
+                                  (scrdump_filename, history_scrdump_filename),
+                                  logging.debug, "(convert) ", timeout=30)
+
         # Compare md5sum of barrier region with the expected md5sum
         calced_md5sum = ppm_utils.get_region_md5sum(w, h, data, x1, y1, dx, dy,
                                                     cropped_scrdump_filename)
         if calced_md5sum == md5sum:
+            # Success -- remove screendump history unless requested not to
+            if keep_screendump_history and not keep_all_history:
+                kvm_subprocess.run_fg("rm -rvf %s" % history_dir,
+                                      logging.debug, "(rm) ", timeout=30)
+            # Report success
             return True
 
-        # Compute md5sum of whole image in order to compare it with
-        # previous ones
-        whole_image_md5sum = ppm_utils.image_md5sum(w, h, data)
+        # Insert image md5sum into queue of last seen images:
         # If md5sum is already in queue...
         if whole_image_md5sum in prev_whole_image_md5sums:
             # Remove md5sum from queue
             prev_whole_image_md5sums.remove(whole_image_md5sum)
         else:
-            # Extend 'stuck' timeout
+            # Otherwise extend 'stuck' timeout
             end_time_stuck = time.time() + fail_if_stuck_for
         # Insert md5sum at beginning of queue
         prev_whole_image_md5sums.insert(0, whole_image_md5sum)
@@ -129,7 +155,7 @@  def barrier_2(vm, words, params, debug_dir, data_scrdump_filename,
         if data_scrdump_filename and os.path.exists(data_scrdump_filename):
             # Read expected screendump image
             (ew, eh, edata) = \
-            ppm_utils.image_read_from_ppm_file(data_scrdump_filename)
+                    ppm_utils.image_read_from_ppm_file(data_scrdump_filename)
             # Write it in debug_dir
             ppm_utils.image_write_to_ppm_file(expected_scrdump_filename,
                                               ew, eh, edata)