Merge lp:~therve/landscape-client/fix-xen-report into lp:~landscape/landscape-client/trunk

Proposed by Thomas Herve
Status: Merged
Approved by: Alberto Donato
Approved revision: 443
Merged at revision: 443
Proposed branch: lp:~therve/landscape-client/fix-xen-report
Merge into: lp:~landscape/landscape-client/trunk
Diff against target: 81 lines (+37/-4)
2 files modified
landscape/lib/tests/test_vm_info.py (+30/-3)
landscape/lib/vm_info.py (+7/-1)
To merge this branch: bzr merge lp:~therve/landscape-client/fix-xen-report
Reviewer Review Type Date Requested Status
Alberto Donato (community) Approve
Björn Tillenius (community) Approve
Review via email: mp+90663@code.launchpad.net

Description of the change

The branch makes a slightly smarter check by verifying if the devices directory contains files.

To post a comment you must log in.
Revision history for this message
Björn Tillenius (bjornt) wrote :

+1!

[1]

+ def test_get_vm_info_is_empty_without_xen_devices(self):
+ """
+ L{get_vm_info} returns "xen" if the /sys/bus/xen/devices directory
+ exists and contains file.

The docstring doesn't fit what is actually tested.

review: Approve
443. By Thomas Herve

Fix docstring

Revision history for this message
Alberto Donato (ack) wrote :

Good, +1!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'landscape/lib/tests/test_vm_info.py'
2--- landscape/lib/tests/test_vm_info.py 2011-06-20 06:42:50 +0000
3+++ landscape/lib/tests/test_vm_info.py 2012-01-30 10:07:42 +0000
4@@ -64,9 +64,10 @@
5
6 self.assertEqual("xen", get_vm_info(root_path=root_path))
7
8- def test_get_vm_info_is_xen_when_sys_bus_xen_exists(self):
9+ def test_get_vm_info_is_xen_when_sys_bus_xen_is_non_empty(self):
10 """
11- L{get_vm_info} should return 'xen' when /sys/bus/xen exists.
12+ L{get_vm_info} should return 'xen' when /sys/bus/xen exists and has
13+ devices.
14 """
15 root_path = self.makeDir()
16 sys_path = os.path.join(root_path, "sys")
17@@ -76,7 +77,13 @@
18 self.makeDir(path=sys_bus_path)
19
20 sys_bus_xen_path = os.path.join(sys_bus_path, "xen")
21- self.makeFile(path=sys_bus_xen_path, content="foo")
22+ self.makeDir(path=sys_bus_xen_path)
23+
24+ devices_xen_path = os.path.join(sys_bus_xen_path, "devices")
25+ self.makeDir(path=devices_xen_path)
26+
27+ foo_devices_path = os.path.join(devices_xen_path, "foo")
28+ self.makeFile(path=foo_devices_path, content="bar")
29
30 self.assertEqual("xen", get_vm_info(root_path=root_path))
31
32@@ -130,3 +137,23 @@
33 os.makedirs(dmi_path)
34 file(os.path.join(dmi_path, "sys_vendor"), "w+").write("VMware, Inc.")
35 self.assertEqual("vmware", get_vm_info(root_path=root_path))
36+
37+ def test_get_vm_info_is_empty_without_xen_devices(self):
38+ """
39+ L{get_vm_info} returns an empty string if the /sys/bus/xen/devices
40+ directory exists and but doesn't contain any file.
41+ """
42+ root_path = self.makeDir()
43+ sys_path = os.path.join(root_path, "sys")
44+ self.makeDir(path=sys_path)
45+
46+ sys_bus_path = os.path.join(sys_path, "bus")
47+ self.makeDir(path=sys_bus_path)
48+
49+ sys_bus_xen_path = os.path.join(sys_bus_path, "xen")
50+ self.makeDir(path=sys_bus_xen_path)
51+
52+ devices_xen_path = os.path.join(sys_bus_xen_path, "devices")
53+ self.makeDir(path=devices_xen_path)
54+
55+ self.assertEqual("", get_vm_info(root_path=root_path))
56
57=== modified file 'landscape/lib/vm_info.py'
58--- landscape/lib/vm_info.py 2011-06-20 07:41:27 +0000
59+++ landscape/lib/vm_info.py 2012-01-30 10:07:42 +0000
60@@ -14,7 +14,7 @@
61 def join_root_path(path):
62 return os.path.join(root_path, path)
63
64- xen_paths = ["proc/sys/xen", "sys/bus/xen", "proc/xen"]
65+ xen_paths = ["proc/sys/xen", "proc/xen"]
66 xen_paths = map(join_root_path, xen_paths)
67
68 vz_path = os.path.join(root_path, "proc/vz")
69@@ -24,6 +24,12 @@
70 elif filter(os.path.exists, xen_paths):
71 return "xen"
72
73+ # /sys/bus/xen exists on most machines, but only virtual machines have
74+ # devices
75+ sys_xen_path = join_root_path("sys/bus/xen/devices")
76+ if os.path.isdir(sys_xen_path) and os.listdir(sys_xen_path):
77+ return "xen"
78+
79 cpu_info_path = os.path.join(root_path, "proc/cpuinfo")
80 if os.path.exists(cpu_info_path):
81 try:

Subscribers

People subscribed via source and target branches

to all changes: