@@ -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):