This object should replace get_sub_dict_names() and get_sub_dict(). Signed-off-by: Michael Goldish <mgoldish@xxxxxxxxxx> --- client/tests/kvm/kvm_utils.py | 38 +++++++++++++++++++++++++++++++++++++- 1 files changed, 37 insertions(+), 1 deletions(-) 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): -- 1.7.3.4 -- 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