From patchwork Mon Dec 27 23:00:45 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Goldish X-Patchwork-Id: 435321 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oBRN0U6S026382 for ; Mon, 27 Dec 2010 23:00:31 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752115Ab0L0XA2 (ORCPT ); Mon, 27 Dec 2010 18:00:28 -0500 Received: from mx1.redhat.com ([209.132.183.28]:15871 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751527Ab0L0XA1 (ORCPT ); Mon, 27 Dec 2010 18:00:27 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oBRN0Q4s016834 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 27 Dec 2010 18:00:26 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id oBRN0PPf030009; Mon, 27 Dec 2010 18:00:26 -0500 Received: from moof.tlv.redhat.com (dhcp-1-185.tlv.redhat.com [10.35.1.185]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id oBRN0ORK023933; Mon, 27 Dec 2010 18:00:24 -0500 From: Michael Goldish To: autotest@test.kernel.org, kvm@vger.kernel.org Cc: Michael Goldish Subject: [KVM-AUTOTEST PATCH 1/4] KVM test: introduce Params, a dict-like object containing test parameters Date: Tue, 28 Dec 2010 01:00:45 +0200 Message-Id: <1293490848-28376-1-git-send-email-mgoldish@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Mon, 27 Dec 2010 23:00:31 +0000 (UTC) diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py index 57c9951..1e32e30 100644 --- a/client/tests/kvm/kvm_utils.py +++ b/client/tests/kvm/kvm_utils.py @@ -5,7 +5,7 @@ KVM test utility functions. """ import time, string, random, socket, os, signal, re, logging, commands, cPickle -import fcntl, shelve, ConfigParser, rss_file_transfer, threading, sys +import fcntl, shelve, ConfigParser, rss_file_transfer, threading, sys, UserDict from autotest_lib.client.bin import utils, os_dep from autotest_lib.client.common_lib import error, logging_config import kvm_subprocess @@ -97,6 +97,42 @@ def get_sub_dict_names(dict, keyword): return [] +class Params(UserDict.IterableUserDict): + """ + A dict-like object passed to every test. + """ + def objects(self, key): + """ + Return the names of objects defined using a given key. + + @param key: The name of the key whose value lists the objects + (e.g. 'nics'). + """ + return self.get(key, "").split() + + + def object_params(self, obj_name): + """ + Return a dict-like object containing the parameters of an individual + object. + + This method behaves as follows: the suffix '_' + obj_name is removed + from all key names that have it. Other key names are left unchanged. + The values of keys with the suffix overwrite the values of their + suffixless versions. + + @param obj_name: The name of the object (objects are listed by the + objects() method). + """ + suffix = "_" + obj_name + new_dict = self.copy() + for key in self: + if key.endswith(suffix): + new_key = key.split(suffix)[0] + new_dict[new_key] = self[key] + return new_dict + + # Functions related to MAC/IP addresses def _open_mac_pool(lock_mode):