[KVM-AUTOTEST PATCH 5/6] KVM test: tests/steps.py: simplify barrier_2()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add a few comments, group similar lines and replace some blocks with one-liners.

Note: the weird form
timeout_multiplier = float(params.get("timeout_multiplier") or 1)
allows the user to fall back to the default value by setting timeout_multiplier
to "".
The more common form
timeout_multiplier = float(params.get("timeout_multiplier", 1))
will raise an exception if timeout_multiplier is "".

Signed-off-by: Michael Goldish <mgoldish@xxxxxxxxxx>
---
 client/tests/kvm/tests/steps.py |   32 ++++++++++----------------------
 1 files changed, 10 insertions(+), 22 deletions(-)

diff --git a/client/tests/kvm/tests/steps.py b/client/tests/kvm/tests/steps.py
index d0b7dbd..11b2ae1 100644
--- a/client/tests/kvm/tests/steps.py
+++ b/client/tests/kvm/tests/steps.py
@@ -30,22 +30,27 @@ def barrier_2(vm, words, params, debug_dir, data_scrdump_filename,
         logging.error("Bad barrier_2 command line")
         return False
 
+    # Parse barrier command line
     cmd, dx, dy, x1, y1, md5sum, timeout = words[:7]
     dx, dy, x1, y1, timeout = map(int, [dx, dy, x1, y1, timeout])
 
+    # Define some paths
     scrdump_filename = os.path.join(debug_dir, "scrdump.ppm")
     cropped_scrdump_filename = os.path.join(debug_dir, "cropped_scrdump.ppm")
     expected_scrdump_filename = os.path.join(debug_dir, "scrdump_expected.ppm")
     expected_cropped_scrdump_filename = os.path.join(debug_dir,
                                                  "cropped_scrdump_expected.ppm")
     comparison_filename = os.path.join(debug_dir, "comparison.ppm")
+    history_dir = os.path.join(debug_dir, "barrier_history")
+
+    # Collect a few parameters
+    timeout_multiplier = float(params.get("timeout_multiplier") or 1)
+    fail_if_stuck_for = float(params.get("fail_if_stuck_for") or 1e308)
+    stuck_detection_history = int(params.get("stuck_detection_history") or 2)
+    keep_screendump_history = params.get("keep_screendump_history") == "yes"
+    keep_all_history = params.get("keep_all_history") == "yes"
 
     # Multiply timeout by the timeout multiplier
-    timeout_multiplier = params.get("timeout_multiplier")
-    if timeout_multiplier:
-        timeout_multiplier = float(timeout_multiplier)
-    else:
-        timeout_multiplier = 1.0
     timeout *= timeout_multiplier
 
     # Timeout/5 is the time it took stepmaker to complete this step.
@@ -56,23 +61,6 @@ def barrier_2(vm, words, params, debug_dir, data_scrdump_filename,
     if sleep_duration < 1.0: sleep_duration = 1.0
     if sleep_duration > 10.0: sleep_duration = 10.0
 
-    fail_if_stuck_for = params.get("fail_if_stuck_for")
-    if fail_if_stuck_for:
-        fail_if_stuck_for = float(fail_if_stuck_for)
-    else:
-        fail_if_stuck_for = 1e308
-
-    stuck_detection_history = params.get("stuck_detection_history")
-    if stuck_detection_history:
-        stuck_detection_history = int(stuck_detection_history)
-    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()
-- 
1.5.4.1

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

[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux