From patchwork Sun Aug 9 16:33:56 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Goldish X-Patchwork-Id: 40270 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n79GVcwm000549 for ; Sun, 9 Aug 2009 16:31:38 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751969AbZHIQbe (ORCPT ); Sun, 9 Aug 2009 12:31:34 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751926AbZHIQbd (ORCPT ); Sun, 9 Aug 2009 12:31:33 -0400 Received: from mx2.redhat.com ([66.187.237.31]:35277 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751941AbZHIQbZ (ORCPT ); Sun, 9 Aug 2009 12:31:25 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n79GVPTk021931; Sun, 9 Aug 2009 12:31:25 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n79GVPPf030026; Sun, 9 Aug 2009 12:31:25 -0400 Received: from localhost.localdomain (dhcp-1-31.tlv.redhat.com [10.35.1.31]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n79GVGYG020666; Sun, 9 Aug 2009 12:31:23 -0400 From: Michael Goldish To: autotest@test.kernel.org, kvm@vger.kernel.org Cc: Michael Goldish Subject: [KVM-AUTOTEST PATCH 4/6] KVM test: allow for regex matching of keys in the config parser Date: Sun, 9 Aug 2009 19:33:56 +0300 Message-Id: In-Reply-To: <1872f2f7ac12ca9fa788f5f14ae2f8afc9f26db7.1249835043.git.mgoldish@redhat.com> References: <1249835638-18153-1-git-send-email-mgoldish@redhat.com> <836c405266cd58509071052cc25072d52e84f9a7.1249835043.git.mgoldish@redhat.com> <1872f2f7ac12ca9fa788f5f14ae2f8afc9f26db7.1249835043.git.mgoldish@redhat.com> In-Reply-To: References: X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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 --- 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":