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
1=== modified file 'landscape/lib/tests/test_vm_info.py'
2--- landscape/lib/tests/test_vm_info.py 2014-10-01 09:05:23 +0000
3+++ landscape/lib/tests/test_vm_info.py 2015-05-07 11:09:58 +0000
4@@ -1,7 +1,6 @@
5 import os
6
7 from landscape.tests.helpers import LandscapeTest
8-
9 from landscape.lib.vm_info import get_vm_info, get_container_info
10
11
12@@ -162,16 +161,35 @@
13
14 class GetContainerInfoTest(LandscapeTest):
15
16+ def setUp(self):
17+ super(GetContainerInfoTest, self).setUp()
18+ self.run_path = self.makeDir()
19+
20 def test_no_container(self):
21 """If not running in a container, an empty string is returned."""
22- self.assertEqual("", get_container_info(path="/does/not/exist"))
23-
24- def test_in_container(self):
25- """If running in a container, the container type is returned."""
26- path = self.makeFile(content="lxc")
27- self.assertEqual("lxc", get_container_info(path=path))
28+ self.assertEqual("", get_container_info(self.run_path))
29+
30+ def test_in_container_with_container_type_file(self):
31+ """
32+ If the /run/container_type file is found, the content is returned as
33+ container type.
34+ """
35+ container_type_file = os.path.join(self.run_path, "container_type")
36+ self.makeFile(content="lxc", path=container_type_file)
37+ self.assertEqual("lxc", get_container_info(run_path=self.run_path))
38+
39+ def test_in_container_with_systemd_container_file(self):
40+ """
41+ If the /run/systemd/container file is found, the content is returned as
42+ container type.
43+ """
44+ os.mkdir(os.path.join(self.run_path, "systemd"))
45+ container_type_file = os.path.join(self.run_path, "systemd/container")
46+ self.makeFile(content="lxc", path=container_type_file)
47+ self.assertEqual("lxc", get_container_info(run_path=self.run_path))
48
49 def test_strip_newline(self):
50 """The container type doesn't contain newlines."""
51- path = self.makeFile(content="lxc\n")
52- self.assertEqual("lxc", get_container_info(path=path))
53+ container_type_file = os.path.join(self.run_path, "container_type")
54+ self.makeFile(content="lxc\n", path=container_type_file)
55+ self.assertEqual("lxc", get_container_info(run_path=self.run_path))
56
57=== modified file 'landscape/lib/vm_info.py'
58--- landscape/lib/vm_info.py 2014-10-01 09:05:23 +0000
59+++ landscape/lib/vm_info.py 2015-05-07 11:09:58 +0000
60@@ -29,12 +29,16 @@
61 return _get_vm_legacy(root_path)
62
63
64-def get_container_info(path="/run/container_type"):
65+def get_container_info(run_path="/run"):
66 """
67 Return a string with the type of container the client is running in, if
68 any, an empty string otherwise.
69 """
70- return read_file(path).strip() if os.path.exists(path) else ""
71+ for filename in ("container_type", "systemd/container"):
72+ path = os.path.join(run_path, filename)
73+ if os.path.exists(path):
74+ return read_file(path).strip()
75+ return ""
76
77
78 def _is_vm_xen(root_path):

Subscribers

People subscribed via source and target branches

to all changes: