Merge lp:~ack/landscape-client/fix-vivid-lxc-detection into lp:~landscape/landscape-client/trunk

Proposed by Alberto Donato
Status: Merged
Approved by: Alberto Donato
Approved revision: 819
Merged at revision: 819
Proposed branch: lp:~ack/landscape-client/fix-vivid-lxc-detection
Merge into: lp:~landscape/landscape-client/trunk
Diff against target: 78 lines (+33/-11)
2 files modified
landscape/lib/tests/test_vm_info.py (+27/-9)
landscape/lib/vm_info.py (+6/-2)
To merge this branch: bzr merge lp:~ack/landscape-client/fix-vivid-lxc-detection
Reviewer Review Type Date Requested Status
Geoff Teale (community) Approve
Fernando Correa Neto (community) Approve
Review via email: mp+258484@code.launchpad.net

Commit message

This fixes container detection on Vivid hosts.
With the switch to systemd, the /run/container_type is no longer created (unless init-system-helpers is installed), so container detection fails.

The same information is also available in /run/systemd/container, so the branch also checks for that file.

Description of the change

This fixes container detection on Vivid hosts.
With the switch to systemd, the /run/container_type is no longer created (unless init-system-helpers is installed), so container detection fails.

The same information is also available in /run/systemd/container, so the branch also checks for that file.

To post a comment you must log in.
Revision history for this message
Fernando Correa Neto (fcorrea) wrote :

Looks great! (and it works too) +1

review: Approve
Revision history for this message
Geoff Teale (tealeg) wrote :

+1 great, thanks!

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 2014-10-01 09:05:23 +0000
+++ landscape/lib/tests/test_vm_info.py 2015-05-07 11:09:58 +0000
@@ -1,7 +1,6 @@
1import os1import os
22
3from landscape.tests.helpers import LandscapeTest3from landscape.tests.helpers import LandscapeTest
4
5from landscape.lib.vm_info import get_vm_info, get_container_info4from landscape.lib.vm_info import get_vm_info, get_container_info
65
76
@@ -162,16 +161,35 @@
162161
163class GetContainerInfoTest(LandscapeTest):162class GetContainerInfoTest(LandscapeTest):
164163
164 def setUp(self):
165 super(GetContainerInfoTest, self).setUp()
166 self.run_path = self.makeDir()
167
165 def test_no_container(self):168 def test_no_container(self):
166 """If not running in a container, an empty string is returned."""169 """If not running in a container, an empty string is returned."""
167 self.assertEqual("", get_container_info(path="/does/not/exist"))170 self.assertEqual("", get_container_info(self.run_path))
168171
169 def test_in_container(self):172 def test_in_container_with_container_type_file(self):
170 """If running in a container, the container type is returned."""173 """
171 path = self.makeFile(content="lxc")174 If the /run/container_type file is found, the content is returned as
172 self.assertEqual("lxc", get_container_info(path=path))175 container type.
176 """
177 container_type_file = os.path.join(self.run_path, "container_type")
178 self.makeFile(content="lxc", path=container_type_file)
179 self.assertEqual("lxc", get_container_info(run_path=self.run_path))
180
181 def test_in_container_with_systemd_container_file(self):
182 """
183 If the /run/systemd/container file is found, the content is returned as
184 container type.
185 """
186 os.mkdir(os.path.join(self.run_path, "systemd"))
187 container_type_file = os.path.join(self.run_path, "systemd/container")
188 self.makeFile(content="lxc", path=container_type_file)
189 self.assertEqual("lxc", get_container_info(run_path=self.run_path))
173190
174 def test_strip_newline(self):191 def test_strip_newline(self):
175 """The container type doesn't contain newlines."""192 """The container type doesn't contain newlines."""
176 path = self.makeFile(content="lxc\n")193 container_type_file = os.path.join(self.run_path, "container_type")
177 self.assertEqual("lxc", get_container_info(path=path))194 self.makeFile(content="lxc\n", path=container_type_file)
195 self.assertEqual("lxc", get_container_info(run_path=self.run_path))
178196
=== modified file 'landscape/lib/vm_info.py'
--- landscape/lib/vm_info.py 2014-10-01 09:05:23 +0000
+++ landscape/lib/vm_info.py 2015-05-07 11:09:58 +0000
@@ -29,12 +29,16 @@
29 return _get_vm_legacy(root_path)29 return _get_vm_legacy(root_path)
3030
3131
32def get_container_info(path="/run/container_type"):32def get_container_info(run_path="/run"):
33 """33 """
34 Return a string with the type of container the client is running in, if34 Return a string with the type of container the client is running in, if
35 any, an empty string otherwise.35 any, an empty string otherwise.
36 """36 """
37 return read_file(path).strip() if os.path.exists(path) else ""37 for filename in ("container_type", "systemd/container"):
38 path = os.path.join(run_path, filename)
39 if os.path.exists(path):
40 return read_file(path).strip()
41 return ""
3842
3943
40def _is_vm_xen(root_path):44def _is_vm_xen(root_path):

Subscribers

People subscribed via source and target branches

to all changes: