Merge lp:~tribaal/landscape-client/isolate-lxc-container-tests into lp:~landscape/landscape-client/trunk

Proposed by Chris Glass
Status: Work in progress
Proposed branch: lp:~tribaal/landscape-client/isolate-lxc-container-tests
Merge into: lp:~landscape/landscape-client/trunk
Diff against target: 129 lines (+52/-0)
1 file modified
landscape/broker/tests/test_registration.py (+52/-0)
To merge this branch: bzr merge lp:~tribaal/landscape-client/isolate-lxc-container-tests
Reviewer Review Type Date Requested Status
Landscape Pending
Landscape Pending
Review via email: mp+192266@code.launchpad.net

Description of the change

This fixes the related bug - I added some mocking to make sure we enforce the "container status" part of the registration message to be "", in case the test suite is run inside an LXC container.

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

I think this adds too much noise to the tests. The tests aren't meant to test the
exact contents of the message, they mostly test that a registration message
was sent. I would suggest changing the tests to check parts of the message only.

Revision history for this message
Chris Glass (tribaal) wrote :

You are right, I'll refactor instead.

Unmerged revisions

740. By Chris Glass

Added some mocking to the tests for container detection, since in case the test
suite is run inside a container the tests would fail.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'landscape/broker/tests/test_registration.py'
2--- landscape/broker/tests/test_registration.py 2013-10-09 08:19:14 +0000
3+++ landscape/broker/tests/test_registration.py 2013-10-22 23:13:38 +0000
4@@ -158,6 +158,11 @@
5 secure_id is set, and an exchange is about to happen,
6 queue a registration message.
7 """
8+ get_container_info_mock = self.mocker.replace(
9+ "landscape.lib.vm_info.get_container_info")
10+ get_container_info_mock()
11+ self.mocker.result("")
12+ self.mocker.replay()
13 self.mstore.set_accepted_types(["register"])
14 self.config.computer_title = "Computer Title"
15 self.config.account_name = "account_name"
16@@ -181,10 +186,16 @@
17 secure_id is set, and an exchange is about to happen,
18 queue a registration message with VM information.
19 """
20+ get_container_info_mock = self.mocker.replace(
21+ "landscape.lib.vm_info.get_container_info")
22+ get_container_info_mock()
23+ self.mocker.result("")
24+
25 get_vm_info_mock = self.mocker.replace(get_vm_info)
26 get_vm_info_mock()
27 self.mocker.result("vmware")
28 self.mocker.replay()
29+
30 self.mstore.set_accepted_types(["register"])
31 self.config.computer_title = "Computer Title"
32 self.config.account_name = "account_name"
33@@ -198,6 +209,7 @@
34 "tags": None,
35 "vm-info": u"vmware",
36 "container-info": ""}])
37+
38 self.assertEqual(self.logfile.getvalue().strip(),
39 "INFO: Queueing message to register with account "
40 "'account_name' without a password.")
41@@ -229,6 +241,11 @@
42
43 def test_queue_message_on_exchange_with_password(self):
44 """If a registration password is available, we pass it on!"""
45+ get_container_info_mock = self.mocker.replace(
46+ "landscape.lib.vm_info.get_container_info")
47+ get_container_info_mock()
48+ self.mocker.result("")
49+ self.mocker.replay()
50 self.mstore.set_accepted_types(["register"])
51 self.config.computer_title = "Computer Title"
52 self.config.account_name = "account_name"
53@@ -252,6 +269,11 @@
54 If the admin has defined tags for this computer, we send them to the
55 server.
56 """
57+ get_container_info_mock = self.mocker.replace(
58+ "landscape.lib.vm_info.get_container_info")
59+ get_container_info_mock()
60+ self.mocker.result("")
61+ self.mocker.replay()
62 self.mstore.set_accepted_types(["register"])
63 self.config.computer_title = "Computer Title"
64 self.config.account_name = "account_name"
65@@ -277,6 +299,12 @@
66 If the admin has defined tags for this computer, but they are not
67 valid, we drop them, and report an error.
68 """
69+ get_container_info_mock = self.mocker.replace(
70+ "landscape.lib.vm_info.get_container_info")
71+ get_container_info_mock()
72+ self.mocker.result("")
73+ self.mocker.replay()
74+
75 self.log_helper.ignore_errors("Invalid tags provided for cloud "
76 "registration")
77 self.mstore.set_accepted_types(["register"])
78@@ -305,6 +333,12 @@
79 If the admin has defined tags for this computer, we send them to the
80 server.
81 """
82+ get_container_info_mock = self.mocker.replace(
83+ "landscape.lib.vm_info.get_container_info")
84+ get_container_info_mock()
85+ self.mocker.result("")
86+ self.mocker.replay()
87+
88 self.mstore.set_accepted_types(["register"])
89 self.config.computer_title = "Computer Title"
90 self.config.account_name = "account_name"
91@@ -501,6 +535,12 @@
92 self.reactor.fire("exchange-done")
93
94 def test_default_hostname(self):
95+ get_container_info_mock = self.mocker.replace(
96+ "landscape.lib.vm_info.get_container_info")
97+ get_container_info_mock()
98+ self.mocker.result("")
99+ self.mocker.replay()
100+
101 self.mstore.set_accepted_types(["register"])
102 self.config.computer_title = "Computer Title"
103 self.config.account_name = "account_name"
104@@ -529,6 +569,12 @@
105 When Juju information is found in $data_dir/juju-info.json,
106 key parts of it are sent in the registration message.
107 """
108+ get_container_info_mock = self.mocker.replace(
109+ "landscape.lib.vm_info.get_container_info")
110+ get_container_info_mock()
111+ self.mocker.result("")
112+ self.mocker.replay()
113+
114 self.mstore.set_accepted_types(["register"])
115 self.config.account_name = "account_name"
116 self.reactor.fire("run")
117@@ -957,6 +1003,12 @@
118 If fetching metadata fails, but we do have an account name, then we
119 fall back to normal 'register' registration.
120 """
121+ get_container_info_mock = self.mocker.replace(
122+ "landscape.lib.vm_info.get_container_info")
123+ get_container_info_mock()
124+ self.mocker.result("")
125+ self.mocker.replay()
126+
127 self.mstore.set_accepted_types(["register"])
128 self.log_helper.ignore_errors(HTTPCodeError)
129 self.prepare_query_results(

Subscribers

People subscribed via source and target branches

to all changes: