[KVM-AUTOTEST PATCH] KVM test: support TAP networking mode when executing tests in parallel

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

 



- Add kvm_utils.get_sub_pool() which splits a MAC-IP pool in several pieces.
- Use get_sub_pool() in kvm_scheduler immediately before launching a test.

Signed-off-by: Michael Goldish <mgoldish@xxxxxxxxxx>
---
 client/tests/kvm/kvm_scheduler.py |    1 +
 client/tests/kvm/kvm_utils.py     |   55 +++++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+), 0 deletions(-)

diff --git a/client/tests/kvm/kvm_scheduler.py b/client/tests/kvm/kvm_scheduler.py
index 93b7df6..f1adb39 100644
--- a/client/tests/kvm/kvm_scheduler.py
+++ b/client/tests/kvm/kvm_scheduler.py
@@ -63,6 +63,7 @@ class scheduler:
                 test_index = int(cmd[1])
                 test = self.tests[test_index].copy()
                 test.update(self_dict)
+                test = kvm_utils.get_sub_pool(test, index, self.num_workers)
                 test_iterations = int(test.get("iterations", 1))
                 status = run_test_func("kvm", params=test,
                                        tag=test.get("shortname"),
diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py
index 78da9f1..d386456 100644
--- a/client/tests/kvm/kvm_utils.py
+++ b/client/tests/kvm/kvm_utils.py
@@ -178,6 +178,61 @@ def get_mac_ip_pair_from_dict(dict):
     return (None, None)
 
 
+def get_sub_pool(dict, piece, num_pieces):
+    """
+    Split a MAC-IP pool and return a single requested piece.
+
+    For example, get_sub_pool(dict, 0, 3) will split the pool in 3 pieces and
+    return a dict representing the first piece.
+
+    @param dict: A dict that contains pool parameters.
+    @param piece: The index of the requested piece.  Should range from 0 to
+        num_pieces - 1.
+    @param num_pieces: The total number of pieces.
+    @return: A copy of dict, modified to describe the requested sub-pool.
+    """
+    range_dicts = [get_sub_dict(dict, name) for name in
+                   get_sub_dict_names(dict, "address_ranges")]
+    if not range_dicts:
+        return dict
+    ranges = [[d.get("address_range_base_mac"),
+               d.get("address_range_base_ip"),
+               int(d.get("address_range_size", 1))] for d in range_dicts]
+    total_size = sum(r[2] for r in ranges)
+    base = total_size * piece / num_pieces
+    size = total_size * (piece + 1) / num_pieces - base
+
+    # Find base of current sub-pool
+    for i in range(len(ranges)):
+        r = ranges[i]
+        if base < r[2]:
+            r[0] = r[0] and offset_mac(r[0], base)
+            r[1] = r[1] and offset_ip(r[1], base)
+            r[2] -= base
+            break
+        base -= r[2]
+
+    # Collect ranges up to end of current sub-pool
+    new_ranges = []
+    for i in range(i, len(ranges)):
+        r = ranges[i]
+        new_ranges.append(r)
+        if size <= r[2]:
+            r[2] = size
+            break
+        size -= r[2]
+
+    # Write new dict
+    new_dict = dict.copy()
+    new_dict["address_ranges"] = " ".join("r%d" % i for i in
+                                          range(len(new_ranges)))
+    for i in range(len(new_ranges)):
+        new_dict["address_range_base_mac_r%d" % i] = new_ranges[i][0]
+        new_dict["address_range_base_ip_r%d" % i] = new_ranges[i][1]
+        new_dict["address_range_size_r%d" % i] = new_ranges[i][2]
+    return new_dict
+
+
 def verify_ip_address_ownership(ip, macs, timeout=10.0):
     """
     Use arping and the ARP cache to make sure a given IP address belongs to one
-- 
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