[KVM-AUTOTEST PATCH 4/6] KVM test: allow for regex matching of keys in the config parser

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

 



Allow for statements with the following syntax:
regex ?= value         (set)
regex ?+= value        (append)
regex ?<= value        (prepend)

These operations are performed only for keys that match regex.
The whole key name must match the expression, so if regex is a regular string,
only the key whose name equals this string is modified.

This is useful for modifying all parameters of a certain type regardless of the
objects they apply to.  For example, the following parameters specify the cdrom
filenames for different objects: cdrom_vm1, cdrom_vm2, cdrom.  It is now
possible to modify all of them with a statement such
cdrom.* ?<= shared_
which would prepend the string 'shared_' to all cdrom filenames.

Signed-off-by: Michael Goldish <mgoldish@xxxxxxxxxx>
---
 client/tests/kvm/kvm_config.py |   34 +++++++++++++++++++++++-----------
 1 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/client/tests/kvm/kvm_config.py b/client/tests/kvm/kvm_config.py
index 7ff7a07..b7bddbd 100755
--- a/client/tests/kvm/kvm_config.py
+++ b/client/tests/kvm/kvm_config.py
@@ -316,20 +316,32 @@ class config:
                 for filter in filters:
                     filtered_list = self.filter(filter, filtered_list)
                 # Apply the operation to the filtered list
-                for dict in filtered_list:
-                    if op_found == "=":
+                if op_found == "=":
+                    for dict in filtered_list:
                         dict[key] = value
-                    elif op_found == "+=":
+                elif op_found == "+=":
+                    for dict in filtered_list:
                         dict[key] = dict.get(key, "") + value
-                    elif op_found == "<=":
+                elif op_found == "<=":
+                    for dict in filtered_list:
                         dict[key] = value + dict.get(key, "")
-                    elif op_found.startswith("?") and dict.has_key(key):
-                        if op_found == "?=":
-                            dict[key] = value
-                        elif op_found == "?+=":
-                            dict[key] = dict.get(key, "") + value
-                        elif op_found == "?<=":
-                            dict[key] = value + dict.get(key, "")
+                elif op_found.startswith("?"):
+                    exp = re.compile("^(%s)$" % key)
+                    if op_found == "?=":
+                        for dict in filtered_list:
+                            for key in dict.keys():
+                                if exp.match(key):
+                                    dict[key] = value
+                    elif op_found == "?+=":
+                        for dict in filtered_list:
+                            for key in dict.keys():
+                                if exp.match(key):
+                                    dict[key] = dict.get(key, "") + value
+                    elif op_found == "?<=":
+                        for dict in filtered_list:
+                            for key in dict.keys():
+                                if exp.match(key):
+                                    dict[key] = value + dict.get(key, "")
 
             # Parse 'no' and 'only' statements
             elif words[0] == "no" or words[0] == "only":
-- 
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