Add host version check when generate the test dicts. Add host
related parameters and a class of variants for host:
OS_distributions: Record the pattern and distribution name
in pairs
$distribution_name_version_standard: Record the version name
and kernel version in pairs
and the tags in variants for host is the $version_name.
For linux system, we will use /etc/issue and `uname -r` to get the
distribution and kernel infomation. And configure test commands by
these.
This can makes the same test case run with different parameters in
different hsot.
Signed-off-by: Yiqiao Pu <[email protected]>
---
client/common_lib/cartesian_config.py | 88 +++++++++++++++++++++++++++++-
client/tests/kvm/control | 13 +++++
client/tests/kvm/control.parallel | 13 +++++
client/tests/kvm/host-version.cfg.sample | 29 ++++++++++
client/tests/kvm/tests.cfg.sample | 1 +
5 files changed, 143 insertions(+), 1 deletions(-)
create mode 100644 client/tests/kvm/host-version.cfg.sample
diff --git a/client/common_lib/cartesian_config.py
b/client/common_lib/cartesian_config.py
index 62bc925..f9a28ab 100755
--- a/client/common_lib/cartesian_config.py
+++ b/client/common_lib/cartesian_config.py
@@ -28,7 +28,8 @@ Cartesian configuration format file parser.
@copyright: Red Hat 2008-2011
"""
-import re, os, optparse, collections
+import re, os, optparse, collections, commands
+from distutils import version
class ParserError:
def __init__(self, msg, line=None, filename=None, linenum=None):
@@ -674,6 +675,77 @@ class FileReader(StrReader):
StrReader.__init__(self, open(filename).read())
self.filename = filename
+def get_host_distribution(os_distributions):
+ """
+ Get the host distribution category
+
+ @os_distributions: String with the pattern and distribution name
+ @return: None or distribution name
+ """
+ s, o = commands.getstatusoutput("cat /etc/issue")
+ if s != 0:
+ print "Can not get host distribution."
+ os_distribution = None
+
+ dict_os = {}
+ for i in re.split(";", os_distributions):
+ dict_os[re.split(":", i)[0]] = re.split(":", i)[1]
+
+ for keys in dict_os:
+ distribution = re.findall(keys, o)
+ if distribution:
+ os_distribution = dict_os[distribution[0]]
+ print "Host distribution is %s" % os_distribution
+ break;
+ else:
+ print "Distribution don't fit"
+ os_distribution = None
+ return os_distribution
+
+def get_host_verson(dict_test):
+ """
+ Get host version by kernel version
+
+ @dict_test: one dict of the list test cases
+ @return: host version category
+ """
+ os_distribution = get_host_distribution(dict_test.get("OS_distributions"))
+ if os_distribution:
+ s, o = commands.getstatusoutput("uname -r")
+ if s != 0:
+ print "Can not get kernel version"
+ host_version = None
+ else:
+ cur_v = version.LooseVersion(o)
+ hvs = dict_test.get("%s_version_standard" % os_distribution)
+ v_dict = {}
+ for i in re.split(";", hvs):
+ v_dict[re.split(":", i)[1]] = re.split(":", i)[0]
+
+ v_list = sorted(v_dict.items()
+ ,key=lambda v_dict:version.LooseVersion(v_dict[0]))
+
+ if cur_v < version.LooseVersion(v_list[0][0]):
+ print "Old version of %s" % os_distribution
+ host_version = None
+ elif cur_v > version.LooseVersion(v_list[-1][0]):
+ host_version = v_list[-1][1]
+ else:
+ count = 1
+ while count < len(v_list):
+ if cur_v >= version.LooseVersion(v_list[count-1][0]) and\
+ cur_v <= version.LooseVersion(v_list[count][0]):
+ host_version = v_list[count-1][1]
+ break;
+ elif cur_v >= version.LooseVersion(v_list[count][0]):
+ count += 1
+ if host_version:
+ print "Host kernel version is %s" % host_version
+ else:
+ print "Unknown distribution"
+ host_version = None
+ return host_version
+
if __name__ == "__main__":
parser = optparse.OptionParser('usage: %prog [options] filename '
@@ -691,6 +763,20 @@ if __name__ == "__main__":
parser.error("filename required")
c = Parser(args[0], debug=options.debug)
+
+ # Get host version related parameters
+ host_tmp = {}
+ for i in c.get_dicts():
+ host_tmp = i
+ if len(host_tmp) > 0:
+ host_version = get_host_verson(host_tmp)
+ str = ""
+ if host_version:
+ str += "only %s_host\n" % host_version
+ else:
+ str += "only default_host"
+ c.parse_string(str)
+
for s in args[1:]:
c.parse_string(s)
diff --git a/client/tests/kvm/control b/client/tests/kvm/control
index 760d408..38e6cf1 100644
--- a/client/tests/kvm/control
+++ b/client/tests/kvm/control
@@ -64,6 +64,19 @@ if args:
str += "%s = %s\n" % (key, value)
except IndexError:
pass
+
+# Catch the host version for different host
+dict_test = {}
+for i in parser.get_dicts():
+ dict_test = i
+
+if len(dict_test) > 0:
+ host_version = cartesian_config.get_host_verson(dict_test)
+ if host_version:
+ str += "only %s_host\n" % host_version
+ else:
+ str += "only default_host"
+
parser.parse_string(str)
virt_utils.run_tests(parser, job)
diff --git a/client/tests/kvm/control.parallel
b/client/tests/kvm/control.parallel
index 966d8bc..34ee9be 100644
--- a/client/tests/kvm/control.parallel
+++ b/client/tests/kvm/control.parallel
@@ -169,6 +169,19 @@ str = """
parser = cartesian_config.Parser()
parser.parse_file(os.path.join(pwd, "tests.cfg"))
+
+# Catch the host version for different host
+dict_test = {}
+for i in parser.get_dicts():
+ dict_test = i
+
+if len(dict_test) > 0:
+ host_version = cartesian_config.get_host_verson(dict_test)
+ if host_version:
+ str += "only %s_host\n" % host_version
+ else:
+ str += "only default_host"
+
parser.parse_string(str)
tests = list(parser.get_dicts())
diff --git a/client/tests/kvm/host-version.cfg.sample
b/client/tests/kvm/host-version.cfg.sample
new file mode 100644
index 0000000..2295a82
--- /dev/null
+++ b/client/tests/kvm/host-version.cfg.sample
@@ -0,0 +1,29 @@
+# Host version related parameters
+Fedora_version_standard =
"Fedora_13:2.6.33;Fedora_14:2.6.35;Fedora_15:2.6.38;Fedora_16:3.1.0"
+
+RHEL_Server_version_standard =
"RHEL_Server_5.5:2.6.18-194;RHEL_Server_5.6:2.6.18-238;RHEL_Server_5.7:2.6.18-274;RHEL_Server_6.0:2.6.32-71;RHEL_Server_6.1:2.6.32-131;RHEL_Server_6.2:2.6.32-132"
+
+OS_distributions = "Fedora:Fedora;Red Hat Enterprise Linux:RHEL_Server"
+
+# Host
+variants:
+ - @default_host:
+ - RHEL_Server_5.6_host:
+
+ - RHEL_Server_5.7_host:
+
+ - RHEL_Server_6.0_host:
+ - RHEL_Server_6.1_host:
+ virtio_nic:
+ vhost = "vhost=on"
+ - RHEL_Server_6.2_host:
+ virtio_nic:
+ vhost = "vhost=on"
+ - Fedora_13_host:
+
+ - Fedora_14_host:
+
+ - Fedora_15_host:
+
+ - Fedora_16_host:
+
diff --git a/client/tests/kvm/tests.cfg.sample
b/client/tests/kvm/tests.cfg.sample
index b011540..1b332f8 100644
--- a/client/tests/kvm/tests.cfg.sample
+++ b/client/tests/kvm/tests.cfg.sample
@@ -9,6 +9,7 @@ include guest-os.cfg
include guest-hw.cfg
include cdkeys.cfg
include virtio-win.cfg
+include host-version.cfg
# Here you can override the image name for our custom linux and windows guests
#
--
1.7.1
_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest