ia64/xen-unstable

view tools/xm-test/lib/XmTestReport/OSReport.py @ 8261:9089801e73ce

xm-test report fails because IA64's /cpu/procinfo format is different from
x86's. Here's a small patch to fix the problem.

Signed-off-by: Matsumoto <n_matumoto@soft.fujitsu.com>
author emellor@leeni.uk.xensource.com
date Wed Dec 07 10:27:03 2005 +0000 (2005-12-07)
parents e33f8d664e2d
children 4d5e9f9caed2
line source
1 #!/usr/bin/python
3 """
4 OSReport.py - Handles the gathering and xml-formatting of operating
5 system environment information.
7 Copyright (C) International Business Machines Corp., 2005
8 Author: Dan Smith <danms@us.ibm.com>
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; under version 2 of the License.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 """
25 import utils
27 import posix
28 import re
29 import os
30 import commands
31 import sys
33 class Machine:
35 def __parseInfoLine(self, line):
36 if ":" in line:
37 name, value = line.split(":", 1)
38 name = name.strip()
39 value = value.strip()
41 name = re.sub(" ", "_", name)
43 return name, value
44 else:
45 return None, None
47 def __getCpuInfo(self, values):
49 processors = 0
50 cpuinfo = file("/proc/cpuinfo")
52 if not cpuinfo:
53 return "Unable to read /proc/cpuinfo"
55 lines = cpuinfo.readlines()
57 for l in lines:
58 name, value = self.__parseInfoLine(l)
60 if name in values.keys():
61 values[name] = value
63 if name == "processor":
64 processors += 1
66 values["dom0procs"] = str(processors)
68 return values
70 def __getXenInfo(self, values):
72 status, output = commands.getstatusoutput("xm info")
73 if status != 0:
74 self.errors += 1
75 return values
77 lines = output.split("\n")
79 for l in lines:
80 name, value = self.__parseInfoLine(l)
82 if name in values.keys():
83 values[name] = value
85 return values
87 def __init__(self):
89 self.values = {}
90 self.errors = 0
92 cpuValues = {"model_name" : "Unknown",
93 "flags" : "Unknown"}
94 xenValues = {"nr_cpus" : "Unknown",
95 "nr_nodes" : "Unknown",
96 "sockets_per_node" : "Unknown",
97 "cores_per_socket" : "Unknown",
98 "threads_per_core" : "Unknown",
99 "cpu_mhz" : "Unknown",
100 "total_memory" : "Unknown"}
102 xen = self.__getXenInfo(xenValues)
103 cpu = self.__getCpuInfo(cpuValues)
105 if cpu["model_name"] == "Unknown":
106 cpuValues={"arch" : "Unknown",
107 "features": "Unknown"}
108 cpu=self.__getCpuInfo(cpuValues)
110 for k in xen.keys():
111 self.values[k] = xen[k]
112 if xen[k] == "Unknown":
113 self.errors += 1
115 for k in cpu.keys():
116 self.values[k] = cpu[k]
117 if cpu[k] == "Unknown":
118 self.errors += 1
121 def __str__(self):
122 string = "<machine>\n"
124 for k in self.values.keys():
125 string += " " + utils.tagify(k, self.values[k]) + "\n"
127 string += "</machine>\n"
129 return string
131 class OperatingSystem:
133 def __redhatStyleRelease(self):
134 rFile = None
136 if os.access("/etc/redhat-release", os.R_OK):
137 rFile = file("/etc/redhat-release")
138 if os.access("/etc/SuSe-release", os.R_OK):
139 rFile = file("/etc/SuSe-release")
140 if os.access("/etc/SuSE-release", os.R_OK):
141 rFile = file("/etc/SuSE-release")
142 if os.access("/etc/mandrake-release", os.R_OK):
143 rFile = file("/etc/mandrake-release")
145 if not rFile:
146 return None, None
148 rLine = rFile.readline()
149 rFile.close()
151 match = re.match("^([^0-9]+)([0-9\.]+).*$", rLine)
152 if match:
153 return match.group(1), match.group(2)
154 else:
155 return None, None
157 def __debianStyleRelease(self):
158 if os.access("/etc/debian_version", os.R_OK):
159 rFile = file("/etc/debian_version")
160 else:
161 rFile = None
163 if not rFile:
164 return None, None
166 line = rFile.readline()
167 return "Debian", line.rstrip("\n");
169 def __lsbStyleRelease(self):
170 if os.access("/etc/lsb-release", os.R_OK):
171 rFile = file("/etc/lsb-release")
172 else:
173 rFile = None
175 if not rFile:
176 return None, None
178 lines = rFile.readlines()
180 vendor = None
181 version = None
183 for l in lines:
184 match = re.match("^DISTRIB_ID=(.*)$", l)
185 if match:
186 vendor = match.group(1)
187 match = re.match("^DISTRIB_RELEASE=(.*)$", l)
188 if match:
189 version = match.group(1)
191 return vendor, version
193 def __init__(self):
195 self.values = {}
196 self.errors = 0
198 # Try to resolve the vendor and version information
199 # for the distro we're running on
200 vendor = None
201 version = None
202 for r in [self.__redhatStyleRelease, self.__debianStyleRelease, self.__lsbStyleRelease]:
203 vendor, version = r()
204 if vendor and version:
205 break
207 self.values["vendor"] = vendor or "Unknown vendor"
208 self.values["version"] = version or "Unknown version"
210 self.values["name"], nodename, release, version, self.values["arch"] = posix.uname()
212 for k in self.values.keys():
213 if not self.values[k]:
214 self.errors += 1
216 def __str__(self):
217 string = "<os>\n"
219 for k in self.values.keys():
220 string += " " + utils.tagify(k, self.values[k]) + "\n"
222 string += "</os>\n"
224 return string
227 class OSReport:
229 def __init__(self):
231 self.reports = {}
232 self.reports["os"] = OperatingSystem()
233 self.reports["machine"] = Machine()
234 self.errors = 0
236 for k in self.reports.keys():
237 self.errors += self.reports[k].errors
239 def __str__(self):
241 string = ""
243 for k in self.reports.keys():
244 string += str(self.reports[k])
246 return string
248 if __name__ == "__main__":
249 r = OSReport()
251 print str(r)
253 sys.exit(r.errors)