Merge lp:~therve/landscape-client/cloud-init-startup into lp:~landscape/landscape-client/trunk

Proposed by Thomas Herve
Status: Merged
Approved by: Thomas Herve
Approved revision: 305
Merged at revision: 306
Proposed branch: lp:~therve/landscape-client/cloud-init-startup
Merge into: lp:~landscape/landscape-client/trunk
Diff against target: 115 lines (+45/-2)
5 files modified
landscape/broker/config.py (+3/-0)
landscape/broker/registration.py (+3/-0)
landscape/broker/tests/test_registration.py (+22/-0)
landscape/configuration.py (+3/-2)
landscape/tests/test_configuration.py (+14/-0)
To merge this branch: bzr merge lp:~therve/landscape-client/cloud-init-startup
Reviewer Review Type Date Requested Status
Frank Wierzbicki (community) Approve
Kevin McDermott (community) Approve
Review via email: mp+46007@code.launchpad.net

Description of the change

The changes are in 2 parts:
 * Add the option to the configuration, and make it sufficient to configure the client
 * Use it in the registration process

To post a comment you must log in.
304. By Thomas Herve

Don't restart if otp is specified

Revision history for this message
Kevin McDermott (bigkevmcd) wrote :

Simple changes, +1

review: Approve
Revision history for this message
Frank Wierzbicki (fwierzbicki) wrote :

Looks good to me! +1

Trivial grammar point:

s/there is not need/there is no need/

review: Approve
305. By Thomas Herve

Typo

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'landscape/broker/config.py'
2--- landscape/broker/config.py 2010-04-30 10:40:11 +0000
3+++ landscape/broker/config.py 2011-01-12 21:27:14 +0000
4@@ -38,6 +38,7 @@
5 - C{http_proxy}
6 - C{https_proxy}
7 - C{cloud}
8+ - C{otp}
9 """
10 parser = super(BrokerConfiguration, self).make_parser()
11
12@@ -70,6 +71,8 @@
13 help="The URL of the HTTPS proxy, if one is needed.")
14 parser.add_option("--cloud", action="store_true",
15 help="Set this if your computer is in an EC2 cloud.")
16+ parser.add_option("--otp",
17+ help="The OTP to use in cloud configuration.")
18 parser.add_option("--tags",
19 help="Comma separated list of tag names to be sent "
20 "to the server.")
21
22=== modified file 'landscape/broker/registration.py'
23--- landscape/broker/registration.py 2010-12-07 14:32:55 +0000
24+++ landscape/broker/registration.py 2011-01-12 21:27:14 +0000
25@@ -179,6 +179,9 @@
26 self._ec2_data["launch_index"] = int(
27 self._ec2_data["launch_index"])
28
29+ if self._config.otp:
30+ self._otp = self._config.otp
31+ return
32 instance_data = _extract_ec2_instance_data(
33 raw_user_data, int(launch_index))
34 if instance_data is not None:
35
36=== modified file 'landscape/broker/tests/test_registration.py'
37--- landscape/broker/tests/test_registration.py 2010-09-09 16:10:07 +0000
38+++ landscape/broker/tests/test_registration.py 2011-01-12 21:27:14 +0000
39@@ -563,6 +563,28 @@
40 self.transport.payloads[0]["messages"],
41 [self.get_expected_cloud_message(tags=u"server,london")])
42
43+ def test_cloud_registration_with_otp(self):
44+ """
45+ If the OTP is present in the configuration, it's used to trigger the
46+ registration instead of using the user data.
47+ """
48+ self.config.otp = "otp1"
49+ self.prepare_query_results(user_data=None)
50+
51+ self.prepare_cloud_registration()
52+
53+ # metadata is fetched and stored at reactor startup:
54+ self.reactor.fire("run")
55+
56+ # Okay! Exchange should cause the registration to happen.
57+ self.exchanger.exchange()
58+ # This *should* be asynchronous, but I think a billion tests are
59+ # written like this
60+ self.assertEqual(len(self.transport.payloads), 1)
61+ self.assertMessages(
62+ self.transport.payloads[0]["messages"],
63+ [self.get_expected_cloud_message()])
64+
65 def test_cloud_registration_with_invalid_tags(self):
66 """
67 Invalid tags in the configuration should result in the tags not being
68
69=== modified file 'landscape/configuration.py'
70--- landscape/configuration.py 2010-08-04 09:36:55 +0000
71+++ landscape/configuration.py 2011-01-12 21:27:14 +0000
72@@ -440,7 +440,8 @@
73 config.https_proxy = os.environ["https_proxy"]
74
75 if config.silent:
76- if not config.get("account_name") or not config.get("computer_title"):
77+ if not config.get("otp") and (not config.get("account_name") or not
78+ config.get("computer_title")):
79 raise ConfigurationError("An account name and computer title are "
80 "required.")
81 if config.get("script_users"):
82@@ -463,7 +464,7 @@
83
84 config.write()
85 # Restart the client to ensure that it's using the new configuration.
86- if not config.no_start:
87+ if not config.no_start and not config.otp:
88 try:
89 sysvconfig.restart_landscape()
90 except ProcessError:
91
92=== modified file 'landscape/tests/test_configuration.py'
93--- landscape/tests/test_configuration.py 2010-08-23 11:53:32 +0000
94+++ landscape/tests/test_configuration.py 2011-01-12 21:27:14 +0000
95@@ -738,6 +738,20 @@
96 config = self.get_config(["--silent", "-t", "rex"])
97 self.assertRaises(ConfigurationError, setup, config)
98
99+ def test_silent_setup_with_otp(self):
100+ """
101+ If the OTP is specified, there is no need to pass the account name and
102+ the computer title.
103+ """
104+ sysvconfig_mock = self.mocker.patch(SysVConfig)
105+ sysvconfig_mock.set_start_on_boot(True)
106+ self.mocker.replay()
107+
108+ config = self.get_config(["--silent", "--otp", "otp1"])
109+ setup(config)
110+
111+ self.assertEqual("otp1", config.otp)
112+
113 def test_silent_script_users_imply_script_execution_plugin(self):
114 """
115 If C{--script-users} is specified, without C{ScriptExecution} in the

Subscribers

People subscribed via source and target branches

to all changes: