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
=== modified file 'landscape/lib/tests/test_vm_info.py'
--- landscape/lib/tests/test_vm_info.py 2011-06-20 06:42:50 +0000
+++ landscape/lib/tests/test_vm_info.py 2012-01-30 10:07:42 +0000
@@ -64,9 +64,10 @@
6464
65 self.assertEqual("xen", get_vm_info(root_path=root_path))65 self.assertEqual("xen", get_vm_info(root_path=root_path))
6666
67 def test_get_vm_info_is_xen_when_sys_bus_xen_exists(self):67 def test_get_vm_info_is_xen_when_sys_bus_xen_is_non_empty(self):
68 """68 """
69 L{get_vm_info} should return 'xen' when /sys/bus/xen exists.69 L{get_vm_info} should return 'xen' when /sys/bus/xen exists and has
70 devices.
70 """71 """
71 root_path = self.makeDir()72 root_path = self.makeDir()
72 sys_path = os.path.join(root_path, "sys")73 sys_path = os.path.join(root_path, "sys")
@@ -76,7 +77,13 @@
76 self.makeDir(path=sys_bus_path)77 self.makeDir(path=sys_bus_path)
7778
78 sys_bus_xen_path = os.path.join(sys_bus_path, "xen")79 sys_bus_xen_path = os.path.join(sys_bus_path, "xen")
79 self.makeFile(path=sys_bus_xen_path, content="foo")80 self.makeDir(path=sys_bus_xen_path)
81
82 devices_xen_path = os.path.join(sys_bus_xen_path, "devices")
83 self.makeDir(path=devices_xen_path)
84
85 foo_devices_path = os.path.join(devices_xen_path, "foo")
86 self.makeFile(path=foo_devices_path, content="bar")
8087
81 self.assertEqual("xen", get_vm_info(root_path=root_path))88 self.assertEqual("xen", get_vm_info(root_path=root_path))
8289
@@ -130,3 +137,23 @@
130 os.makedirs(dmi_path)137 os.makedirs(dmi_path)
131 file(os.path.join(dmi_path, "sys_vendor"), "w+").write("VMware, Inc.")138 file(os.path.join(dmi_path, "sys_vendor"), "w+").write("VMware, Inc.")
132 self.assertEqual("vmware", get_vm_info(root_path=root_path))139 self.assertEqual("vmware", get_vm_info(root_path=root_path))
140
141 def test_get_vm_info_is_empty_without_xen_devices(self):
142 """
143 L{get_vm_info} returns an empty string if the /sys/bus/xen/devices
144 directory exists and but doesn't contain any file.
145 """
146 root_path = self.makeDir()
147 sys_path = os.path.join(root_path, "sys")
148 self.makeDir(path=sys_path)
149
150 sys_bus_path = os.path.join(sys_path, "bus")
151 self.makeDir(path=sys_bus_path)
152
153 sys_bus_xen_path = os.path.join(sys_bus_path, "xen")
154 self.makeDir(path=sys_bus_xen_path)
155
156 devices_xen_path = os.path.join(sys_bus_xen_path, "devices")
157 self.makeDir(path=devices_xen_path)
158
159 self.assertEqual("", get_vm_info(root_path=root_path))
133160
=== modified file 'landscape/lib/vm_info.py'
--- landscape/lib/vm_info.py 2011-06-20 07:41:27 +0000
+++ landscape/lib/vm_info.py 2012-01-30 10:07:42 +0000
@@ -14,7 +14,7 @@
14 def join_root_path(path):14 def join_root_path(path):
15 return os.path.join(root_path, path)15 return os.path.join(root_path, path)
1616
17 xen_paths = ["proc/sys/xen", "sys/bus/xen", "proc/xen"]17 xen_paths = ["proc/sys/xen", "proc/xen"]
18 xen_paths = map(join_root_path, xen_paths)18 xen_paths = map(join_root_path, xen_paths)
1919
20 vz_path = os.path.join(root_path, "proc/vz")20 vz_path = os.path.join(root_path, "proc/vz")
@@ -24,6 +24,12 @@
24 elif filter(os.path.exists, xen_paths):24 elif filter(os.path.exists, xen_paths):
25 return "xen"25 return "xen"
2626
27 # /sys/bus/xen exists on most machines, but only virtual machines have
28 # devices
29 sys_xen_path = join_root_path("sys/bus/xen/devices")
30 if os.path.isdir(sys_xen_path) and os.listdir(sys_xen_path):
31 return "xen"
32
27 cpu_info_path = os.path.join(root_path, "proc/cpuinfo")33 cpu_info_path = os.path.join(root_path, "proc/cpuinfo")
28 if os.path.exists(cpu_info_path):34 if os.path.exists(cpu_info_path):
29 try:35 try:

Subscribers

People subscribed via source and target branches

to all changes: