Merge lp:~wgrant/launchpad/no-more-vhost-config into lp:launchpad
- no-more-vhost-config
- Merge into devel
Proposed by
William Grant
Status: | Work in progress |
---|---|
Proposed branch: | lp:~wgrant/launchpad/no-more-vhost-config |
Merge into: | lp:launchpad |
Diff against target: |
1296 lines (+910/-80) (has conflicts) 12 files modified
configs/development/launchpad-lazr.conf (+17/-2) configs/testrunner-appserver/launchpad-lazr.conf (+5/-0) configs/testrunner/launchpad-lazr.conf (+4/-0) lib/devscripts/ec2test/instance.py.OTHER (+695/-0) lib/lp/services/config/schema-lazr.conf (+28/-19) lib/lp/services/openid/adapters/openid.py (+23/-0) lib/lp/services/webapp/doc/webapp-publication.txt (+16/-0) lib/lp/services/webapp/metazcml.py (+12/-3) lib/lp/services/webapp/servers.py (+14/-1) lib/lp/services/webapp/vhosts.py (+58/-53) lib/lp/testing/layers.py (+29/-1) lib/lp/testing/tests/test_layers_functional.py (+9/-1) Text conflict in configs/development/launchpad-lazr.conf Text conflict in configs/testrunner-appserver/launchpad-lazr.conf Text conflict in configs/testrunner/launchpad-lazr.conf Conflict adding files to lib/devscripts/ec2test. Created directory. Conflict because lib/devscripts/ec2test is not versioned, but has versioned children. Versioned directory. Contents conflict in lib/devscripts/ec2test/instance.py Text conflict in lib/lp/services/config/schema-lazr.conf Text conflict in lib/lp/services/openid/adapters/openid.py Text conflict in lib/lp/services/webapp/doc/webapp-publication.txt Text conflict in lib/lp/services/webapp/metazcml.py Text conflict in lib/lp/services/webapp/servers.py Text conflict in lib/lp/services/webapp/vhosts.py Text conflict in lib/lp/testing/layers.py Text conflict in lib/lp/testing/tests/test_layers_functional.py |
To merge this branch: | bzr merge lp:~wgrant/launchpad/no-more-vhost-config |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Launchpad code reviewers | Pending | ||
Review via email: mp+306686@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Unmerged revisions
- 14141. By William Grant
-
Drop unneeded vhost config sections from the schema.
- 14140. By William Grant
-
Fix AppServerLayer.
- 14139. By William Grant
-
appserver config now uses a custom port. Doesn't actually work, because the layer relies on config.
vhost.mainsite. rooturl. - 14138. By William Grant
-
Comment the config schema, and use a custom portin the vhost config if it's specified.
- 14137. By William Grant
-
Inline logic slightly.
- 14136. By William Grant
-
Refactor the vhost setup code a bit.
- 14135. By William Grant
-
VirtualHostConfig now takes a port, instead of a rooturl.
- 14134. By William Grant
-
Rename the xmlrpc_private vhost to xmlrpc-private, to match the subdomain.
- 14133. By William Grant
-
Since vhost config is pretty much defined from a base domain and a port, move all that stuff into code.
- 14132. By William Grant
-
Our publisher ZCML directive now checks allvhosts, rather than config.vhosts directly.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'configs/development/launchpad-lazr.conf' | |||
2 | --- configs/development/launchpad-lazr.conf 2016-06-30 16:05:11 +0000 | |||
3 | +++ configs/development/launchpad-lazr.conf 2016-09-24 06:42:11 +0000 | |||
4 | @@ -94,8 +94,12 @@ | |||
5 | 94 | 94 | ||
6 | 95 | [launchpad] | 95 | [launchpad] |
7 | 96 | enable_test_openid_provider: True | 96 | enable_test_openid_provider: True |
8 | 97 | <<<<<<< TREE | ||
9 | 97 | openid_canonical_root: https://testopenid.dev/ | 98 | openid_canonical_root: https://testopenid.dev/ |
10 | 98 | openid_provider_root: https://testopenid.dev/ | 99 | openid_provider_root: https://testopenid.dev/ |
11 | 100 | ======= | ||
12 | 101 | openid_provider_root: https://testopenid.dev/ | ||
13 | 102 | >>>>>>> MERGE-SOURCE | ||
14 | 99 | code_domain: code.launchpad.dev | 103 | code_domain: code.launchpad.dev |
15 | 100 | default_batch_size: 5 | 104 | default_batch_size: 5 |
16 | 101 | max_attachment_size: 2097152 | 105 | max_attachment_size: 2097152 |
17 | @@ -213,15 +217,24 @@ | |||
18 | 213 | 217 | ||
19 | 214 | [vhosts] | 218 | [vhosts] |
20 | 215 | use_https: True | 219 | use_https: True |
21 | 220 | base_hostname: launchpad.dev | ||
22 | 221 | vostok_hostname: vostok.dev | ||
23 | 222 | testopenid_hostname: testopenid.dev | ||
24 | 223 | enable_apidoc: True | ||
25 | 216 | 224 | ||
26 | 217 | [vhost.mainsite] | 225 | [vhost.mainsite] |
27 | 218 | hostname: launchpad.dev | ||
28 | 219 | althostnames: localhost | ||
29 | 220 | openid_delegate_profile: True | 226 | openid_delegate_profile: True |
30 | 221 | 227 | ||
31 | 222 | [vhost.api] | 228 | [vhost.api] |
32 | 229 | <<<<<<< TREE | ||
33 | 223 | hostname: api.launchpad.dev | 230 | hostname: api.launchpad.dev |
34 | 231 | ======= | ||
35 | 232 | # Turn this on once we've solved cache invalidation problems and are | ||
36 | 233 | # ready to test. | ||
37 | 234 | # enable_server_side_representation_cache: True | ||
38 | 235 | >>>>>>> MERGE-SOURCE | ||
39 | 224 | 236 | ||
40 | 237 | <<<<<<< TREE | ||
41 | 225 | [vhost.blueprints] | 238 | [vhost.blueprints] |
42 | 226 | hostname: blueprints.launchpad.dev | 239 | hostname: blueprints.launchpad.dev |
43 | 227 | 240 | ||
44 | @@ -249,6 +262,8 @@ | |||
45 | 249 | [vhost.feeds] | 262 | [vhost.feeds] |
46 | 250 | hostname: feeds.launchpad.dev | 263 | hostname: feeds.launchpad.dev |
47 | 251 | 264 | ||
48 | 265 | ======= | ||
49 | 266 | >>>>>>> MERGE-SOURCE | ||
50 | 252 | [immediate_mail] | 267 | [immediate_mail] |
51 | 253 | # XXX sinzui 2008-03-26: | 268 | # XXX sinzui 2008-03-26: |
52 | 254 | # A development box should never send email to the outer world, | 269 | # A development box should never send email to the outer world, |
53 | 255 | 270 | ||
54 | === modified file 'configs/testrunner-appserver/launchpad-lazr.conf' | |||
55 | --- configs/testrunner-appserver/launchpad-lazr.conf 2014-02-27 08:39:44 +0000 | |||
56 | +++ configs/testrunner-appserver/launchpad-lazr.conf 2016-09-24 06:42:11 +0000 | |||
57 | @@ -22,6 +22,7 @@ | |||
58 | 22 | xmlrpc_runner_sleep: 1 | 22 | xmlrpc_runner_sleep: 1 |
59 | 23 | register_bounces_every: 1 | 23 | register_bounces_every: 1 |
60 | 24 | 24 | ||
61 | 25 | <<<<<<< TREE | ||
62 | 25 | [vhost.mainsite] | 26 | [vhost.mainsite] |
63 | 26 | rooturl: http://launchpad.dev:8085/ | 27 | rooturl: http://launchpad.dev:8085/ |
64 | 27 | 28 | ||
65 | @@ -54,6 +55,10 @@ | |||
66 | 54 | 55 | ||
67 | 55 | [vhost.feeds] | 56 | [vhost.feeds] |
68 | 56 | rooturl: http://feeds.launchpad.dev:8085/ | 57 | rooturl: http://feeds.launchpad.dev:8085/ |
69 | 58 | ======= | ||
70 | 59 | [vhosts] | ||
71 | 60 | port: 8085 | ||
72 | 61 | >>>>>>> MERGE-SOURCE | ||
73 | 57 | 62 | ||
74 | 58 | [immediate_mail] | 63 | [immediate_mail] |
75 | 59 | # BarryWarsaw 04-Dec-2008: AppServerLayer tests should send email to the fake | 64 | # BarryWarsaw 04-Dec-2008: AppServerLayer tests should send email to the fake |
76 | 60 | 65 | ||
77 | === modified file 'configs/testrunner/launchpad-lazr.conf' | |||
78 | --- configs/testrunner/launchpad-lazr.conf 2016-05-18 00:33:18 +0000 | |||
79 | +++ configs/testrunner/launchpad-lazr.conf 2016-09-24 06:42:11 +0000 | |||
80 | @@ -107,9 +107,13 @@ | |||
81 | 107 | # We use the stub Google Service here which maps URL fragment to | 107 | # We use the stub Google Service here which maps URL fragment to |
82 | 108 | # to static content | 108 | # to static content |
83 | 109 | homepage_recent_posts_feed: http://launchpad.dev:8092/blog-feed | 109 | homepage_recent_posts_feed: http://launchpad.dev:8092/blog-feed |
84 | 110 | <<<<<<< TREE | ||
85 | 110 | openid_canonical_root: http://testopenid.dev/ | 111 | openid_canonical_root: http://testopenid.dev/ |
86 | 111 | openid_provider_root: http://testopenid.dev/ | 112 | openid_provider_root: http://testopenid.dev/ |
87 | 112 | openid_alternate_provider_roots: http://login1.dev/, http://login2.dev/ | 113 | openid_alternate_provider_roots: http://login1.dev/, http://login2.dev/ |
88 | 114 | ======= | ||
89 | 115 | openid_provider_root: http://testopenid.dev/ | ||
90 | 116 | >>>>>>> MERGE-SOURCE | ||
91 | 113 | 117 | ||
92 | 114 | [launchpad_session] | 118 | [launchpad_session] |
93 | 115 | cookie: launchpad_tests | 119 | cookie: launchpad_tests |
94 | 116 | 120 | ||
95 | === added directory 'lib/devscripts/ec2test' | |||
96 | === added file 'lib/devscripts/ec2test/instance.py.OTHER' | |||
97 | --- lib/devscripts/ec2test/instance.py.OTHER 1970-01-01 00:00:00 +0000 | |||
98 | +++ lib/devscripts/ec2test/instance.py.OTHER 2016-09-24 06:42:11 +0000 | |||
99 | @@ -0,0 +1,695 @@ | |||
100 | 1 | # Copyright 2009-2011 Canonical Ltd. This software is licensed under the | ||
101 | 2 | # GNU Affero General Public License version 3 (see the file LICENSE). | ||
102 | 3 | |||
103 | 4 | """Code to represent a single machine instance in EC2.""" | ||
104 | 5 | |||
105 | 6 | __metaclass__ = type | ||
106 | 7 | __all__ = [ | ||
107 | 8 | 'EC2Instance', | ||
108 | 9 | ] | ||
109 | 10 | |||
110 | 11 | import code | ||
111 | 12 | import errno | ||
112 | 13 | import glob | ||
113 | 14 | import os | ||
114 | 15 | import select | ||
115 | 16 | import socket | ||
116 | 17 | import subprocess | ||
117 | 18 | import sys | ||
118 | 19 | import time | ||
119 | 20 | import traceback | ||
120 | 21 | from datetime import datetime | ||
121 | 22 | from bzrlib.errors import BzrCommandError | ||
122 | 23 | from devscripts.ec2test.session import EC2SessionName | ||
123 | 24 | import paramiko | ||
124 | 25 | |||
125 | 26 | |||
126 | 27 | DEFAULT_INSTANCE_TYPE = 'c1.xlarge' | ||
127 | 28 | AVAILABLE_INSTANCE_TYPES = ('m1.large', 'm1.xlarge', 'c1.xlarge') | ||
128 | 29 | |||
129 | 30 | |||
130 | 31 | class AcceptAllPolicy: | ||
131 | 32 | """We accept all unknown host key.""" | ||
132 | 33 | |||
133 | 34 | def missing_host_key(self, client, hostname, key): | ||
134 | 35 | # Normally the console output is supposed to contain the Host key but | ||
135 | 36 | # it doesn't seem to be the case here, so we trust that the host we | ||
136 | 37 | # are connecting to is the correct one. | ||
137 | 38 | pass | ||
138 | 39 | |||
139 | 40 | |||
140 | 41 | def get_user_key(): | ||
141 | 42 | """Get a SSH key from the agent. Raise an error if no keys were found. | ||
142 | 43 | |||
143 | 44 | This key will be used to let the user log in (as $USER) to the instance. | ||
144 | 45 | """ | ||
145 | 46 | agent = paramiko.Agent() | ||
146 | 47 | keys = agent.get_keys() | ||
147 | 48 | if len(keys) == 0: | ||
148 | 49 | raise BzrCommandError( | ||
149 | 50 | 'You must have an ssh agent running with keys installed that ' | ||
150 | 51 | 'will allow the script to access Launchpad and get your ' | ||
151 | 52 | 'branch.\n') | ||
152 | 53 | |||
153 | 54 | # XXX mars 2010-05-07 bug=577118 | ||
154 | 55 | # Popping the first key off of the stack can create problems if the person | ||
155 | 56 | # has more than one key in their ssh-agent, but alas, we have no good way | ||
156 | 57 | # to detect the right key to use. See bug 577118 for a workaround. | ||
157 | 58 | return keys[0] | ||
158 | 59 | |||
159 | 60 | |||
160 | 61 | # Commands to run to turn a blank image into one usable for the rest of the | ||
161 | 62 | # ec2 functionality. They come in two parts, one set that need to be run as | ||
162 | 63 | # root and another that should be run as the 'ec2test' user. | ||
163 | 64 | # Note that the sources from http://us.ec2.archive.ubuntu.com/ubuntu/ are per | ||
164 | 65 | # instructions described in http://is.gd/g1MIT . When we switch to | ||
165 | 66 | # Eucalyptus, we can dump this. | ||
166 | 67 | |||
167 | 68 | from_scratch_root = """ | ||
168 | 69 | # From 'help set': | ||
169 | 70 | # -x Print commands and their arguments as they are executed. | ||
170 | 71 | # -e Exit immediately if a command exits with a non-zero status. | ||
171 | 72 | set -xe | ||
172 | 73 | |||
173 | 74 | sed -ie 's/main universe/main universe multiverse/' /etc/apt/sources.list | ||
174 | 75 | |||
175 | 76 | . /etc/lsb-release | ||
176 | 77 | |||
177 | 78 | cat >> /etc/apt/sources.list << EOF | ||
178 | 79 | deb http://ppa.launchpad.net/launchpad/ubuntu $DISTRIB_CODENAME main | ||
179 | 80 | deb http://ppa.launchpad.net/bzr/ubuntu $DISTRIB_CODENAME main | ||
180 | 81 | deb http://ppa.launchpad.net/bzr-beta-ppa/ubuntu $DISTRIB_CODENAME main | ||
181 | 82 | deb http://us.ec2.archive.ubuntu.com/ubuntu/ $DISTRIB_CODENAME multiverse | ||
182 | 83 | deb-src http://us.ec2.archive.ubuntu.com/ubuntu/ $DISTRIB_CODENAME main | ||
183 | 84 | EOF | ||
184 | 85 | |||
185 | 86 | # This next part is cribbed from rocketfuel-setup | ||
186 | 87 | dev_host() { | ||
187 | 88 | sed -i \"s/^127.0.0.88.*$/&\ ${hostname}/\" /etc/hosts | ||
188 | 89 | } | ||
189 | 90 | |||
190 | 91 | echo 'Adding development hosts on local machine' | ||
191 | 92 | echo ' | ||
192 | 93 | # Launchpad virtual domains. This should be on one line. | ||
193 | 94 | 127.0.0.88 launchpad.dev | ||
194 | 95 | ' >> /etc/hosts | ||
195 | 96 | |||
196 | 97 | declare -a hostnames | ||
197 | 98 | hostnames=$(cat <<EOF | ||
198 | 99 | answers.launchpad.dev | ||
199 | 100 | archive.launchpad.dev | ||
200 | 101 | api.launchpad.dev | ||
201 | 102 | bazaar-internal.launchpad.dev | ||
202 | 103 | blueprints.launchpad.dev | ||
203 | 104 | bugs.launchpad.dev | ||
204 | 105 | code.launchpad.dev | ||
205 | 106 | feeds.launchpad.dev | ||
206 | 107 | keyserver.launchpad.dev | ||
207 | 108 | lists.launchpad.dev | ||
208 | 109 | ppa.launchpad.dev | ||
209 | 110 | private-ppa.launchpad.dev | ||
210 | 111 | testopenid.dev | ||
211 | 112 | translations.launchpad.dev | ||
212 | 113 | xmlrpc-private.launchpad.dev | ||
213 | 114 | xmlrpc.launchpad.dev | ||
214 | 115 | EOF | ||
215 | 116 | ) | ||
216 | 117 | |||
217 | 118 | for hostname in $hostnames; do | ||
218 | 119 | dev_host; | ||
219 | 120 | done | ||
220 | 121 | |||
221 | 122 | echo ' | ||
222 | 123 | 127.0.0.99 bazaar.launchpad.dev | ||
223 | 124 | ' >> /etc/hosts | ||
224 | 125 | |||
225 | 126 | # Add the keys for the three PPAs added to sources.list above. | ||
226 | 127 | apt-key adv --recv-keys --keyserver pool.sks-keyservers.net 2af499cb24ac5f65461405572d1ffb6c0a5174af | ||
227 | 128 | apt-key adv --recv-keys --keyserver pool.sks-keyservers.net ece2800bacf028b31ee3657cd702bf6b8c6c1efd | ||
228 | 129 | apt-key adv --recv-keys --keyserver pool.sks-keyservers.net cbede690576d1e4e813f6bb3ebaf723d37b19b80 | ||
229 | 130 | |||
230 | 131 | aptitude update | ||
231 | 132 | aptitude -y full-upgrade | ||
232 | 133 | |||
233 | 134 | DEBIAN_FRONTEND=noninteractive apt-get -y install launchpad-developer-dependencies apache2 apache2-mpm-worker | ||
234 | 135 | |||
235 | 136 | # Create the ec2test user, give them passwordless sudo. | ||
236 | 137 | adduser --gecos "" --disabled-password ec2test | ||
237 | 138 | echo 'ec2test\tALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers | ||
238 | 139 | |||
239 | 140 | mkdir /home/ec2test/.ssh | ||
240 | 141 | cat > /home/ec2test/.ssh/config << EOF | ||
241 | 142 | CheckHostIP no | ||
242 | 143 | StrictHostKeyChecking no | ||
243 | 144 | EOF | ||
244 | 145 | |||
245 | 146 | mkdir /var/launchpad | ||
246 | 147 | chown -R ec2test:ec2test /var/www /var/launchpad /home/ec2test/ | ||
247 | 148 | """ | ||
248 | 149 | |||
249 | 150 | |||
250 | 151 | from_scratch_ec2test = """ | ||
251 | 152 | # From 'help set': | ||
252 | 153 | # -x Print commands and their arguments as they are executed. | ||
253 | 154 | # -e Exit immediately if a command exits with a non-zero status. | ||
254 | 155 | set -xe | ||
255 | 156 | |||
256 | 157 | bzr launchpad-login %(launchpad-login)s | ||
257 | 158 | bzr init-repo --2a /var/launchpad | ||
258 | 159 | bzr branch lp:~launchpad-pqm/launchpad/devel /var/launchpad/test | ||
259 | 160 | bzr branch --standalone lp:lp-source-dependencies /var/launchpad/download-cache | ||
260 | 161 | mkdir /var/launchpad/sourcecode | ||
261 | 162 | /var/launchpad/test/utilities/update-sourcecode /var/launchpad/sourcecode | ||
262 | 163 | """ | ||
263 | 164 | |||
264 | 165 | |||
265 | 166 | postmortem_banner = """\ | ||
266 | 167 | Postmortem Console. EC2 instance is not yet dead. | ||
267 | 168 | It will shut down when you exit this prompt (CTRL-D) | ||
268 | 169 | |||
269 | 170 | Tab-completion is enabled. | ||
270 | 171 | EC2Instance is available as `instance`. | ||
271 | 172 | Also try these: | ||
272 | 173 | http://%(dns)s/current_test.log | ||
273 | 174 | ssh -A ec2test@%(dns)s | ||
274 | 175 | """ | ||
275 | 176 | |||
276 | 177 | |||
277 | 178 | class EC2Instance: | ||
278 | 179 | """A single EC2 instance.""" | ||
279 | 180 | |||
280 | 181 | @classmethod | ||
281 | 182 | def make(cls, name, instance_type, machine_id, demo_networks=None, | ||
282 | 183 | credentials=None): | ||
283 | 184 | """Construct an `EC2Instance`. | ||
284 | 185 | |||
285 | 186 | :param name: The name to use for the key pair and security group for | ||
286 | 187 | the instance. | ||
287 | 188 | :type name: `EC2SessionName` | ||
288 | 189 | :param instance_type: One of the AVAILABLE_INSTANCE_TYPES. | ||
289 | 190 | :param machine_id: The AMI to use, or None to do the usual regexp | ||
290 | 191 | matching. If you put 'based-on:' before the AMI id, it is assumed | ||
291 | 192 | that the id specifies a blank image that should be made into one | ||
292 | 193 | suitable for the other ec2 functions (see `from_scratch_root` and | ||
293 | 194 | `from_scratch_ec2test` above). | ||
294 | 195 | :param demo_networks: A list of networks to add to the security group | ||
295 | 196 | to allow access to the instance. | ||
296 | 197 | :param credentials: An `EC2Credentials` object. | ||
297 | 198 | """ | ||
298 | 199 | # This import breaks in the test environment. Do it here so | ||
299 | 200 | # that unit tests (which don't use this factory) can still | ||
300 | 201 | # import EC2Instance. | ||
301 | 202 | from bzrlib.plugins.launchpad.account import get_lp_login | ||
302 | 203 | |||
303 | 204 | # XXX JeroenVermeulen 2009-11-27 bug=489073: EC2Credentials | ||
304 | 205 | # imports boto, which isn't necessarily installed in our test | ||
305 | 206 | # environment. Doing the import here so that unit tests (which | ||
306 | 207 | # don't use this factory) can still import EC2Instance. | ||
307 | 208 | from devscripts.ec2test.credentials import EC2Credentials | ||
308 | 209 | |||
309 | 210 | assert isinstance(name, EC2SessionName) | ||
310 | 211 | if instance_type not in AVAILABLE_INSTANCE_TYPES: | ||
311 | 212 | raise ValueError('unknown instance_type %s' % (instance_type,)) | ||
312 | 213 | |||
313 | 214 | # We call this here so that it has a chance to complain before the | ||
314 | 215 | # instance is started (which can take some time). | ||
315 | 216 | user_key = get_user_key() | ||
316 | 217 | |||
317 | 218 | if credentials is None: | ||
318 | 219 | credentials = EC2Credentials.load_from_file() | ||
319 | 220 | |||
320 | 221 | # Make the EC2 connection. | ||
321 | 222 | account = credentials.connect(name) | ||
322 | 223 | |||
323 | 224 | # We do this here because it (1) cleans things up and (2) verifies | ||
324 | 225 | # that the account is correctly set up. Both of these are appropriate | ||
325 | 226 | # for initialization. | ||
326 | 227 | # | ||
327 | 228 | # We always recreate the keypairs because there is no way to | ||
328 | 229 | # programmatically retrieve the private key component, unless we | ||
329 | 230 | # generate it. | ||
330 | 231 | account.collect_garbage() | ||
331 | 232 | |||
332 | 233 | if machine_id and machine_id.startswith('based-on:'): | ||
333 | 234 | from_scratch = True | ||
334 | 235 | machine_id = machine_id[len('based-on:'):] | ||
335 | 236 | else: | ||
336 | 237 | from_scratch = False | ||
337 | 238 | |||
338 | 239 | # get the image | ||
339 | 240 | image = account.acquire_image(machine_id) | ||
340 | 241 | |||
341 | 242 | login = get_lp_login() | ||
342 | 243 | if not login: | ||
343 | 244 | raise BzrCommandError( | ||
344 | 245 | 'you must have set your launchpad login in bzr.') | ||
345 | 246 | |||
346 | 247 | return EC2Instance( | ||
347 | 248 | name, image, instance_type, demo_networks, account, | ||
348 | 249 | from_scratch, user_key, login) | ||
349 | 250 | |||
350 | 251 | def __init__(self, name, image, instance_type, demo_networks, account, | ||
351 | 252 | from_scratch, user_key, launchpad_login): | ||
352 | 253 | self._name = name | ||
353 | 254 | self._image = image | ||
354 | 255 | self._account = account | ||
355 | 256 | self._instance_type = instance_type | ||
356 | 257 | self._demo_networks = demo_networks | ||
357 | 258 | self._boto_instance = None | ||
358 | 259 | self._from_scratch = from_scratch | ||
359 | 260 | self._user_key = user_key | ||
360 | 261 | self._launchpad_login = launchpad_login | ||
361 | 262 | |||
362 | 263 | def log(self, msg): | ||
363 | 264 | """Log a message on stdout, flushing afterwards.""" | ||
364 | 265 | # XXX: JonathanLange 2009-05-31 bug=383076: Should delete this and use | ||
365 | 266 | # Python logging module instead. | ||
366 | 267 | sys.stdout.write(msg) | ||
367 | 268 | sys.stdout.flush() | ||
368 | 269 | |||
369 | 270 | def start(self): | ||
370 | 271 | """Start the instance.""" | ||
371 | 272 | if self._boto_instance is not None: | ||
372 | 273 | self.log('Instance %s already started' % self._boto_instance.id) | ||
373 | 274 | return | ||
374 | 275 | start = time.time() | ||
375 | 276 | self.private_key = self._account.acquire_private_key() | ||
376 | 277 | self.security_group = self._account.acquire_security_group( | ||
377 | 278 | demo_networks=self._demo_networks) | ||
378 | 279 | reservation = self._image.run( | ||
379 | 280 | key_name=self._name, security_groups=[self._name], | ||
380 | 281 | instance_type=self._instance_type) | ||
381 | 282 | self._boto_instance = reservation.instances[0] | ||
382 | 283 | self.log('Instance %s starting..' % self._boto_instance.id) | ||
383 | 284 | while self._boto_instance.state == 'pending': | ||
384 | 285 | self.log('.') | ||
385 | 286 | time.sleep(5) | ||
386 | 287 | self._boto_instance.update() | ||
387 | 288 | if self._boto_instance.state == 'running': | ||
388 | 289 | self.log(' started on %s\n' % self.hostname) | ||
389 | 290 | elapsed = time.time() - start | ||
390 | 291 | self.log('Started in %d minutes %d seconds\n' % | ||
391 | 292 | (elapsed // 60, elapsed % 60)) | ||
392 | 293 | self._output = self._boto_instance.get_console_output() | ||
393 | 294 | self.log(self._output.output) | ||
394 | 295 | self._ec2test_user_has_keys = False | ||
395 | 296 | else: | ||
396 | 297 | raise BzrCommandError( | ||
397 | 298 | 'failed to start: %s\n' % self._boto_instance.state) | ||
398 | 299 | |||
399 | 300 | def shutdown(self): | ||
400 | 301 | """Shut down the instance.""" | ||
401 | 302 | if self._boto_instance is None: | ||
402 | 303 | self.log('no instance created\n') | ||
403 | 304 | return | ||
404 | 305 | self._boto_instance.update() | ||
405 | 306 | if self._boto_instance.state not in ('shutting-down', 'terminated'): | ||
406 | 307 | # terminate instance | ||
407 | 308 | self._boto_instance.stop() | ||
408 | 309 | self._boto_instance.update() | ||
409 | 310 | self.log('instance %s\n' % (self._boto_instance.state,)) | ||
410 | 311 | |||
411 | 312 | @property | ||
412 | 313 | def hostname(self): | ||
413 | 314 | if self._boto_instance is None: | ||
414 | 315 | return None | ||
415 | 316 | return self._boto_instance.public_dns_name | ||
416 | 317 | |||
417 | 318 | def _connect(self, username): | ||
418 | 319 | """Connect to the instance as `user`. """ | ||
419 | 320 | ssh = paramiko.SSHClient() | ||
420 | 321 | ssh.set_missing_host_key_policy(AcceptAllPolicy()) | ||
421 | 322 | connect_args = { | ||
422 | 323 | 'username': username, | ||
423 | 324 | 'pkey': self.private_key, | ||
424 | 325 | 'allow_agent': False, | ||
425 | 326 | 'look_for_keys': False, | ||
426 | 327 | } | ||
427 | 328 | for count in range(10): | ||
428 | 329 | try: | ||
429 | 330 | ssh.connect(self.hostname, **connect_args) | ||
430 | 331 | except (socket.error, paramiko.AuthenticationException), e: | ||
431 | 332 | self.log('_connect: %r\n' % (e,)) | ||
432 | 333 | if count < 9: | ||
433 | 334 | time.sleep(5) | ||
434 | 335 | self.log('retrying...') | ||
435 | 336 | else: | ||
436 | 337 | raise | ||
437 | 338 | else: | ||
438 | 339 | break | ||
439 | 340 | return EC2InstanceConnection(self, username, ssh) | ||
440 | 341 | |||
441 | 342 | def _upload_local_key(self, conn, remote_filename): | ||
442 | 343 | """Upload a key from the local user's agent to `remote_filename`. | ||
443 | 344 | |||
444 | 345 | The key will be uploaded in a format suitable for | ||
445 | 346 | ~/.ssh/authorized_keys. | ||
446 | 347 | """ | ||
447 | 348 | authorized_keys_file = conn.sftp.open(remote_filename, 'w') | ||
448 | 349 | authorized_keys_file.write( | ||
449 | 350 | "%s %s\n" % ( | ||
450 | 351 | self._user_key.get_name(), self._user_key.get_base64())) | ||
451 | 352 | authorized_keys_file.close() | ||
452 | 353 | |||
453 | 354 | def _ensure_ec2test_user_has_keys(self, connection=None): | ||
454 | 355 | """Make sure that we can connect over ssh as the 'ec2test' user. | ||
455 | 356 | |||
456 | 357 | We add both the key that was used to start the instance (so | ||
457 | 358 | _connect('ec2test') works and a key from the locally running ssh agent | ||
458 | 359 | (so EC2InstanceConnection.run_with_ssh_agent works). | ||
459 | 360 | """ | ||
460 | 361 | if not self._ec2test_user_has_keys: | ||
461 | 362 | if connection is None: | ||
462 | 363 | connection = self._connect('ubuntu') | ||
463 | 364 | our_connection = True | ||
464 | 365 | else: | ||
465 | 366 | our_connection = False | ||
466 | 367 | self._upload_local_key(connection, 'local_key') | ||
467 | 368 | connection.perform( | ||
468 | 369 | 'cat /home/ubuntu/.ssh/authorized_keys local_key ' | ||
469 | 370 | '| sudo tee /home/ec2test/.ssh/authorized_keys > /dev/null' | ||
470 | 371 | '&& rm local_key') | ||
471 | 372 | connection.perform('sudo chown -R ec2test:ec2test /home/ec2test/') | ||
472 | 373 | connection.perform('sudo chmod 644 /home/ec2test/.ssh/*') | ||
473 | 374 | if our_connection: | ||
474 | 375 | connection.close() | ||
475 | 376 | self.log( | ||
476 | 377 | 'You can now use ssh -A ec2test@%s to ' | ||
477 | 378 | 'log in the instance.\n' % self.hostname) | ||
478 | 379 | self._ec2test_user_has_keys = True | ||
479 | 380 | |||
480 | 381 | def connect(self): | ||
481 | 382 | """Connect to the instance as a user with passwordless sudo. | ||
482 | 383 | |||
483 | 384 | This may involve first connecting as root and adding SSH keys to the | ||
484 | 385 | user's account, and in the case of a from scratch image, it will do a | ||
485 | 386 | lot of set up. | ||
486 | 387 | """ | ||
487 | 388 | if self._from_scratch: | ||
488 | 389 | ubuntu_connection = self._connect('ubuntu') | ||
489 | 390 | self._upload_local_key(ubuntu_connection, 'local_key') | ||
490 | 391 | ubuntu_connection.perform( | ||
491 | 392 | 'cat local_key >> ~/.ssh/authorized_keys && rm local_key') | ||
492 | 393 | ubuntu_connection.run_script(from_scratch_root, sudo=True) | ||
493 | 394 | self._ensure_ec2test_user_has_keys(ubuntu_connection) | ||
494 | 395 | ubuntu_connection.close() | ||
495 | 396 | conn = self._connect('ec2test') | ||
496 | 397 | conn.run_script( | ||
497 | 398 | from_scratch_ec2test | ||
498 | 399 | % {'launchpad-login': self._launchpad_login}) | ||
499 | 400 | self._from_scratch = False | ||
500 | 401 | return conn | ||
501 | 402 | self._ensure_ec2test_user_has_keys() | ||
502 | 403 | return self._connect('ec2test') | ||
503 | 404 | |||
504 | 405 | def _report_traceback(self): | ||
505 | 406 | """Print traceback.""" | ||
506 | 407 | traceback.print_exc() | ||
507 | 408 | |||
508 | 409 | def set_up_and_run(self, postmortem, shutdown, func, *args, **kw): | ||
509 | 410 | """Start, run `func` and then maybe shut down. | ||
510 | 411 | |||
511 | 412 | :param config: A dictionary specifying details of how the instance | ||
512 | 413 | should be run: | ||
513 | 414 | :param postmortem: If true, any exceptions will be caught and an | ||
514 | 415 | interactive session run to allow debugging the problem. | ||
515 | 416 | :param shutdown: If true, shut down the instance after `func` and | ||
516 | 417 | postmortem (if any) are completed. | ||
517 | 418 | :param func: A callable that will be called when the instance is | ||
518 | 419 | running and a user account has been set up on it. | ||
519 | 420 | :param args: Passed to `func`. | ||
520 | 421 | :param kw: Passed to `func`. | ||
521 | 422 | """ | ||
522 | 423 | # We ignore the value of the 'shutdown' argument and always shut down | ||
523 | 424 | # unless `func` returns normally. | ||
524 | 425 | really_shutdown = True | ||
525 | 426 | retval = None | ||
526 | 427 | try: | ||
527 | 428 | self.start() | ||
528 | 429 | try: | ||
529 | 430 | retval = func(*args, **kw) | ||
530 | 431 | except Exception: | ||
531 | 432 | # When running in postmortem mode, it is really helpful to see | ||
532 | 433 | # if there are any exceptions before it waits in the console | ||
533 | 434 | # (in the finally block), and you can't figure out why it's | ||
534 | 435 | # broken. | ||
535 | 436 | self._report_traceback() | ||
536 | 437 | else: | ||
537 | 438 | really_shutdown = shutdown | ||
538 | 439 | finally: | ||
539 | 440 | try: | ||
540 | 441 | if postmortem: | ||
541 | 442 | console = code.InteractiveConsole(locals()) | ||
542 | 443 | console.interact( | ||
543 | 444 | postmortem_banner % {'dns': self.hostname}) | ||
544 | 445 | print 'Postmortem console closed.' | ||
545 | 446 | finally: | ||
546 | 447 | if really_shutdown: | ||
547 | 448 | self.shutdown() | ||
548 | 449 | return retval | ||
549 | 450 | |||
550 | 451 | def _copy_single_file(self, sftp, local_path, remote_dir): | ||
551 | 452 | """Copy `local_path` to `remote_dir` on this instance. | ||
552 | 453 | |||
553 | 454 | The name in the remote directory will be that of the local file. | ||
554 | 455 | |||
555 | 456 | :param sftp: A paramiko SFTP object. | ||
556 | 457 | :param local_path: The local path. | ||
557 | 458 | :param remote_dir: The directory on the instance to copy into. | ||
558 | 459 | """ | ||
559 | 460 | name = os.path.basename(local_path) | ||
560 | 461 | remote_path = os.path.join(remote_dir, name) | ||
561 | 462 | remote_file = sftp.open(remote_path, 'w') | ||
562 | 463 | remote_file.write(open(local_path).read()) | ||
563 | 464 | remote_file.close() | ||
564 | 465 | return remote_path | ||
565 | 466 | |||
566 | 467 | def copy_key_and_certificate_to_image(self, sftp): | ||
567 | 468 | """Copy the AWS private key and certificate to the image. | ||
568 | 469 | |||
569 | 470 | :param sftp: A paramiko SFTP object. | ||
570 | 471 | """ | ||
571 | 472 | remote_ec2_dir = '/mnt/ec2' | ||
572 | 473 | remote_pk = self._copy_single_file( | ||
573 | 474 | sftp, self.local_pk, remote_ec2_dir) | ||
574 | 475 | remote_cert = self._copy_single_file( | ||
575 | 476 | sftp, self.local_cert, remote_ec2_dir) | ||
576 | 477 | return (remote_pk, remote_cert) | ||
577 | 478 | |||
578 | 479 | def _check_single_glob_match(self, local_dir, pattern, file_kind): | ||
579 | 480 | """Check that `pattern` matches one file in `local_dir` and return it. | ||
580 | 481 | |||
581 | 482 | :param local_dir: The local directory to look in. | ||
582 | 483 | :param pattern: The glob patten to match. | ||
583 | 484 | :param file_kind: The sort of file we're looking for, to be used in | ||
584 | 485 | error messages. | ||
585 | 486 | """ | ||
586 | 487 | pattern = os.path.join(local_dir, pattern) | ||
587 | 488 | matches = glob.glob(pattern) | ||
588 | 489 | if len(matches) != 1: | ||
589 | 490 | raise BzrCommandError( | ||
590 | 491 | '%r must match a single %s file' % (pattern, file_kind)) | ||
591 | 492 | return matches[0] | ||
592 | 493 | |||
593 | 494 | def check_bundling_prerequisites(self, name, credentials): | ||
594 | 495 | """Check, as best we can, that all the files we need to bundle exist. | ||
595 | 496 | """ | ||
596 | 497 | if subprocess.call(['which', 'ec2-register']): | ||
597 | 498 | raise BzrCommandError( | ||
598 | 499 | '`ec2-register` command not found. ' | ||
599 | 500 | 'Try `sudo apt-get install ec2-api-tools`.') | ||
600 | 501 | local_ec2_dir = os.path.expanduser('~/.ec2') | ||
601 | 502 | if not os.path.exists(local_ec2_dir): | ||
602 | 503 | raise BzrCommandError( | ||
603 | 504 | "~/.ec2 must exist and contain aws_user, aws_id, a private " | ||
604 | 505 | "key file and a certificate.") | ||
605 | 506 | aws_user_file = os.path.expanduser('~/.ec2/aws_user') | ||
606 | 507 | if not os.path.exists(aws_user_file): | ||
607 | 508 | raise BzrCommandError( | ||
608 | 509 | "~/.ec2/aws_user must exist and contain your numeric AWS id.") | ||
609 | 510 | self.aws_user = open(aws_user_file).read().strip() | ||
610 | 511 | self.local_cert = self._check_single_glob_match( | ||
611 | 512 | local_ec2_dir, 'cert-*.pem', 'certificate') | ||
612 | 513 | self.local_pk = self._check_single_glob_match( | ||
613 | 514 | local_ec2_dir, 'pk-*.pem', 'private key') | ||
614 | 515 | # The bucket `name` needs to exist and be accessible. We create it | ||
615 | 516 | # here to reserve the name. If the bucket already exists and conforms | ||
616 | 517 | # to the above requirements, this is a no-op. | ||
617 | 518 | credentials.connect_s3().create_bucket(name) | ||
618 | 519 | |||
619 | 520 | def bundle(self, name, credentials): | ||
620 | 521 | """Bundle, upload and register the instance as a new AMI. | ||
621 | 522 | |||
622 | 523 | :param name: The name-to-be of the new AMI. | ||
623 | 524 | :param credentials: An `EC2Credentials` object. | ||
624 | 525 | """ | ||
625 | 526 | connection = self.connect() | ||
626 | 527 | # See http://is.gd/g1MIT . When we switch to Eucalyptus, we can dump | ||
627 | 528 | # this installation of the ec2-ami-tools. | ||
628 | 529 | connection.perform( | ||
629 | 530 | 'sudo env DEBIAN_FRONTEND=noninteractive ' | ||
630 | 531 | 'apt-get -y install ec2-ami-tools') | ||
631 | 532 | connection.perform('rm -f .ssh/authorized_keys') | ||
632 | 533 | connection.perform('sudo mkdir /mnt/ec2') | ||
633 | 534 | connection.perform('sudo chown $USER:$USER /mnt/ec2') | ||
634 | 535 | |||
635 | 536 | remote_pk, remote_cert = self.copy_key_and_certificate_to_image( | ||
636 | 537 | connection.sftp) | ||
637 | 538 | |||
638 | 539 | bundle_dir = os.path.join('/mnt', name) | ||
639 | 540 | |||
640 | 541 | connection.perform('sudo mkdir ' + bundle_dir) | ||
641 | 542 | connection.perform(' '.join([ | ||
642 | 543 | 'sudo ec2-bundle-vol', | ||
643 | 544 | '-d %s' % bundle_dir, | ||
644 | 545 | '--batch', # Set batch-mode, which doesn't use prompts. | ||
645 | 546 | '-k %s' % remote_pk, | ||
646 | 547 | '-c %s' % remote_cert, | ||
647 | 548 | '-u %s' % self.aws_user, | ||
648 | 549 | ])) | ||
649 | 550 | |||
650 | 551 | # Assume that the manifest is 'image.manifest.xml', since "image" is | ||
651 | 552 | # the default prefix. | ||
652 | 553 | manifest = os.path.join(bundle_dir, 'image.manifest.xml') | ||
653 | 554 | |||
654 | 555 | # Best check that the manifest actually exists though. | ||
655 | 556 | test = 'test -f %s' % manifest | ||
656 | 557 | connection.perform(test) | ||
657 | 558 | |||
658 | 559 | connection.perform(' '.join([ | ||
659 | 560 | 'sudo ec2-upload-bundle', | ||
660 | 561 | '-b %s' % name, | ||
661 | 562 | '-m %s' % manifest, | ||
662 | 563 | '-a %s' % credentials.identifier, | ||
663 | 564 | '-s %s' % credentials.secret, | ||
664 | 565 | ])) | ||
665 | 566 | |||
666 | 567 | connection.close() | ||
667 | 568 | |||
668 | 569 | # This is invoked locally. | ||
669 | 570 | mfilename = os.path.basename(manifest) | ||
670 | 571 | manifest_path = os.path.join(name, mfilename) | ||
671 | 572 | |||
672 | 573 | env = os.environ.copy() | ||
673 | 574 | if 'JAVA_HOME' not in os.environ: | ||
674 | 575 | env['JAVA_HOME'] = '/usr/lib/jvm/default-java' | ||
675 | 576 | now = datetime.strftime(datetime.utcnow(), "%Y-%m-%d %H:%M:%S UTC") | ||
676 | 577 | description = "Created %s" % now | ||
677 | 578 | cmd = [ | ||
678 | 579 | 'ec2-register', | ||
679 | 580 | '--private-key=%s' % self.local_pk, | ||
680 | 581 | '--cert=%s' % self.local_cert, | ||
681 | 582 | '--name=%s' % (name,), | ||
682 | 583 | '--description=%s' % description, | ||
683 | 584 | manifest_path, | ||
684 | 585 | ] | ||
685 | 586 | self.log("Executing command: %s" % ' '.join(cmd)) | ||
686 | 587 | subprocess.check_call(cmd, env=env) | ||
687 | 588 | |||
688 | 589 | |||
689 | 590 | class EC2InstanceConnection: | ||
690 | 591 | """An ssh connection to an `EC2Instance`.""" | ||
691 | 592 | |||
692 | 593 | def __init__(self, instance, username, ssh): | ||
693 | 594 | self._instance = instance | ||
694 | 595 | self._username = username | ||
695 | 596 | self._ssh = ssh | ||
696 | 597 | self._sftp = None | ||
697 | 598 | |||
698 | 599 | @property | ||
699 | 600 | def sftp(self): | ||
700 | 601 | if self._sftp is None: | ||
701 | 602 | self._sftp = self._ssh.open_sftp() | ||
702 | 603 | return self._sftp | ||
703 | 604 | |||
704 | 605 | def perform(self, cmd, ignore_failure=False, out=None, err=None): | ||
705 | 606 | """Perform 'cmd' on server. | ||
706 | 607 | |||
707 | 608 | :param ignore_failure: If False, raise an error on non-zero exit | ||
708 | 609 | statuses. | ||
709 | 610 | :param out: A stream to write the output of the remote command to. | ||
710 | 611 | :param err: A stream to write the error of the remote command to. | ||
711 | 612 | """ | ||
712 | 613 | if out is None: | ||
713 | 614 | out = sys.stdout | ||
714 | 615 | if err is None: | ||
715 | 616 | err = sys.stderr | ||
716 | 617 | self._instance.log( | ||
717 | 618 | '%s@%s$ %s\n' | ||
718 | 619 | % (self._username, self._instance._boto_instance.id, cmd)) | ||
719 | 620 | session = self._ssh.get_transport().open_session() | ||
720 | 621 | session.exec_command(cmd) | ||
721 | 622 | session.shutdown_write() | ||
722 | 623 | while 1: | ||
723 | 624 | try: | ||
724 | 625 | select.select([session], [], [], 0.5) | ||
725 | 626 | except (IOError, select.error), e: | ||
726 | 627 | if e.errno == errno.EINTR: | ||
727 | 628 | continue | ||
728 | 629 | if session.recv_ready(): | ||
729 | 630 | data = session.recv(4096) | ||
730 | 631 | if data: | ||
731 | 632 | out.write(data) | ||
732 | 633 | out.flush() | ||
733 | 634 | if session.recv_stderr_ready(): | ||
734 | 635 | data = session.recv_stderr(4096) | ||
735 | 636 | if data: | ||
736 | 637 | err.write(data) | ||
737 | 638 | err.flush() | ||
738 | 639 | if session.exit_status_ready(): | ||
739 | 640 | break | ||
740 | 641 | session.close() | ||
741 | 642 | # XXX: JonathanLange 2009-05-31: If the command is killed by a signal | ||
742 | 643 | # on the remote server, the SSH protocol does not send an exit_status, | ||
743 | 644 | # it instead sends a different message with the number of the signal | ||
744 | 645 | # that killed the process. AIUI, this code will fail confusingly if | ||
745 | 646 | # that happens. | ||
746 | 647 | res = session.recv_exit_status() | ||
747 | 648 | if res and not ignore_failure: | ||
748 | 649 | raise RuntimeError('Command failed: %s' % (cmd,)) | ||
749 | 650 | return res | ||
750 | 651 | |||
751 | 652 | def run_with_ssh_agent(self, cmd, ignore_failure=False): | ||
752 | 653 | """Run 'cmd' in a subprocess. | ||
753 | 654 | |||
754 | 655 | Use this to run commands that require local SSH credentials. For | ||
755 | 656 | example, getting private branches from Launchpad. | ||
756 | 657 | """ | ||
757 | 658 | self._instance.log( | ||
758 | 659 | '%s@%s$ %s\n' | ||
759 | 660 | % (self._username, self._instance._boto_instance.id, cmd)) | ||
760 | 661 | call = ['ssh', '-A', self._username + '@' + self._instance.hostname, | ||
761 | 662 | '-o', 'CheckHostIP no', | ||
762 | 663 | '-o', 'StrictHostKeyChecking no', | ||
763 | 664 | '-o', 'UserKnownHostsFile ~/.ec2/known_hosts', | ||
764 | 665 | cmd] | ||
765 | 666 | res = subprocess.call(call) | ||
766 | 667 | if res and not ignore_failure: | ||
767 | 668 | raise RuntimeError('Command failed: %s' % (cmd,)) | ||
768 | 669 | return res | ||
769 | 670 | |||
770 | 671 | def run_script(self, script_text, sudo=False): | ||
771 | 672 | """Upload `script_text` to the instance and run it with bash.""" | ||
772 | 673 | script = self.sftp.open('script.sh', 'w') | ||
773 | 674 | script.write(script_text) | ||
774 | 675 | script.close() | ||
775 | 676 | cmd = '/bin/bash script.sh' | ||
776 | 677 | if sudo: | ||
777 | 678 | cmd = 'sudo ' + cmd | ||
778 | 679 | self.run_with_ssh_agent(cmd) | ||
779 | 680 | # At least for mwhudson, the paramiko connection often drops while the | ||
780 | 681 | # script is running. Reconnect just in case. | ||
781 | 682 | self.reconnect() | ||
782 | 683 | self.perform('rm script.sh') | ||
783 | 684 | |||
784 | 685 | def reconnect(self): | ||
785 | 686 | """Close the connection and reopen it.""" | ||
786 | 687 | self.close() | ||
787 | 688 | self._ssh = self._instance._connect(self._username)._ssh | ||
788 | 689 | |||
789 | 690 | def close(self): | ||
790 | 691 | if self._sftp is not None: | ||
791 | 692 | self._sftp.close() | ||
792 | 693 | self._sftp = None | ||
793 | 694 | self._ssh.close() | ||
794 | 695 | self._ssh = None | ||
795 | 0 | 696 | ||
796 | === modified file 'lib/launchpad_loggerhead/app.py' | |||
797 | === modified file 'lib/lp/services/config/schema-lazr.conf' | |||
798 | --- lib/lp/services/config/schema-lazr.conf 2016-09-02 18:21:07 +0000 | |||
799 | +++ lib/lp/services/config/schema-lazr.conf 2016-09-24 06:42:11 +0000 | |||
800 | @@ -864,6 +864,7 @@ | |||
801 | 864 | # datatype: boolean | 864 | # datatype: boolean |
802 | 865 | launch: True | 865 | launch: True |
803 | 866 | 866 | ||
804 | 867 | <<<<<<< TREE | ||
805 | 867 | # The root URL of the canonical OpenID provider. This is used when constructing | 868 | # The root URL of the canonical OpenID provider. This is used when constructing |
806 | 868 | # OpenID URLs as user identifiers for external services such as gpgservice. | 869 | # OpenID URLs as user identifiers for external services such as gpgservice. |
807 | 869 | # Since these user identifiers must remain constant forever, this setting must | 870 | # Since these user identifiers must remain constant forever, this setting must |
808 | @@ -878,6 +879,11 @@ | |||
809 | 878 | # for our accounts' OpenID identifiers. We only store the suffix, and | 879 | # for our accounts' OpenID identifiers. We only store the suffix, and |
810 | 879 | # the suffix is provided by two providers. | 880 | # the suffix is provided by two providers. |
811 | 880 | openid_alternate_provider_roots: none | 881 | openid_alternate_provider_roots: none |
812 | 882 | ======= | ||
813 | 883 | # The root URL of the OpenID provider used to log into Launchpad. | ||
814 | 884 | # datatype: string | ||
815 | 885 | openid_provider_root: none | ||
816 | 886 | >>>>>>> MERGE-SOURCE | ||
817 | 881 | 887 | ||
818 | 882 | # If true, the main template will be styled so that it is | 888 | # If true, the main template will be styled so that it is |
819 | 883 | # obvious to the end user that they are using a demo system | 889 | # obvious to the end user that they are using a demo system |
820 | @@ -1700,26 +1706,23 @@ | |||
821 | 1700 | # datatype: boolean | 1706 | # datatype: boolean |
822 | 1701 | use_https: True | 1707 | use_https: True |
823 | 1702 | 1708 | ||
828 | 1703 | [vhost.template] | 1709 | # Base hostname for the Launchpad virtual hosts. |
825 | 1704 | # Host name of this virtual host. | ||
826 | 1705 | # This is matched from the incoming Host header, and | ||
827 | 1706 | # also used to put together URLs if rooturl is not provided. | ||
829 | 1707 | # Example: launchpad.net | 1710 | # Example: launchpad.net |
845 | 1708 | # datatype: string | 1711 | base_hostname: none |
846 | 1709 | hostname: none | 1712 | |
847 | 1710 | 1713 | # Custom port for all virtual hosts. | |
848 | 1711 | # Alternative host names to match, in addition to | 1714 | # Only used by the test suite. |
849 | 1712 | # the one given in hostname, comma separated. | 1715 | port: none |
850 | 1713 | # Example: wwwww.launchpad.net, www.launchpad.net | 1716 | |
851 | 1714 | # datatype: string | 1717 | # Hostnames for non-Launchpad virtual hosts. |
852 | 1715 | althostnames: none | 1718 | # Presently only used in development and tests. |
853 | 1716 | 1719 | vostok_hostname: none | |
854 | 1717 | # Explicit root URL for this virtual host. | 1720 | testopenid_hostname: none |
855 | 1718 | # If this is not provided, the root URL is calculated | 1721 | |
856 | 1719 | # based on the host name. | 1722 | # Should the apidoc virtual host be enabled? |
857 | 1720 | # Example: https://launchpad.net/ | 1723 | # This is the internal Zope apidoc, not public lazr.restful API docs. |
858 | 1721 | # datatype: string | 1724 | enable_apidoc: False |
859 | 1722 | rooturl: none | 1725 | |
860 | 1723 | 1726 | ||
861 | 1724 | [vhost.mainsite] | 1727 | [vhost.mainsite] |
862 | 1725 | # Can the profile page act as a OpenID delegated identity? | 1728 | # Can the profile page act as a OpenID delegated identity? |
863 | @@ -1728,6 +1731,7 @@ | |||
864 | 1728 | 1731 | ||
865 | 1729 | [vhost.api] | 1732 | [vhost.api] |
866 | 1730 | 1733 | ||
867 | 1734 | <<<<<<< TREE | ||
868 | 1731 | [vhost.blueprints] | 1735 | [vhost.blueprints] |
869 | 1732 | 1736 | ||
870 | 1733 | [vhost.code] | 1737 | [vhost.code] |
871 | @@ -1749,6 +1753,11 @@ | |||
872 | 1749 | 1753 | ||
873 | 1750 | # Stubbed Key server for testing purposes. It can serve a restricted set of | 1754 | # Stubbed Key server for testing purposes. It can serve a restricted set of |
874 | 1751 | # keys in SKS format. | 1755 | # keys in SKS format. |
875 | 1756 | ======= | ||
876 | 1757 | |||
877 | 1758 | # Stubed Key server for test proposes, it's able to serve | ||
878 | 1759 | # in SKS format, a restricted set of keys. | ||
879 | 1760 | >>>>>>> MERGE-SOURCE | ||
880 | 1752 | [testkeyserver] | 1761 | [testkeyserver] |
881 | 1753 | # Directory to be created to store the pre-installed key-files | 1762 | # Directory to be created to store the pre-installed key-files |
882 | 1754 | # datatype: string | 1763 | # datatype: string |
883 | 1755 | 1764 | ||
884 | === modified file 'lib/lp/services/openid/adapters/openid.py' | |||
885 | --- lib/lp/services/openid/adapters/openid.py 2016-05-24 04:45:38 +0000 | |||
886 | +++ lib/lp/services/openid/adapters/openid.py 2016-09-24 06:42:11 +0000 | |||
887 | @@ -10,9 +10,26 @@ | |||
888 | 10 | 'OpenIDPersistentIdentity', | 10 | 'OpenIDPersistentIdentity', |
889 | 11 | ] | 11 | ] |
890 | 12 | 12 | ||
891 | 13 | <<<<<<< TREE | ||
892 | 13 | from zope.component import adapter | 14 | from zope.component import adapter |
893 | 14 | from zope.interface import implementer | 15 | from zope.interface import implementer |
894 | 16 | ======= | ||
895 | 17 | from zope.component import ( | ||
896 | 18 | adapter, | ||
897 | 19 | adapts, | ||
898 | 20 | ) | ||
899 | 21 | from zope.interface import ( | ||
900 | 22 | implementer, | ||
901 | 23 | implements, | ||
902 | 24 | ) | ||
903 | 25 | >>>>>>> MERGE-SOURCE | ||
904 | 15 | 26 | ||
905 | 27 | <<<<<<< TREE | ||
906 | 28 | ======= | ||
907 | 29 | from canonical.config import config | ||
908 | 30 | from canonical.launchpad.interfaces.account import IAccount | ||
909 | 31 | from canonical.launchpad.interfaces.lpstorm import IStore | ||
910 | 32 | >>>>>>> MERGE-SOURCE | ||
911 | 16 | from lp.registry.interfaces.person import IPerson | 33 | from lp.registry.interfaces.person import IPerson |
912 | 17 | from lp.services.config import config | 34 | from lp.services.config import config |
913 | 18 | from lp.services.database.interfaces import IStore | 35 | from lp.services.database.interfaces import IStore |
914 | @@ -27,6 +44,7 @@ | |||
915 | 27 | @staticmethod | 44 | @staticmethod |
916 | 28 | def getServiceURL(): | 45 | def getServiceURL(): |
917 | 29 | """The OpenID server URL (/+openid) for the current request.""" | 46 | """The OpenID server URL (/+openid) for the current request.""" |
918 | 47 | <<<<<<< TREE | ||
919 | 30 | return config.launchpad.openid_provider_root + '+openid' | 48 | return config.launchpad.openid_provider_root + '+openid' |
920 | 31 | 49 | ||
921 | 32 | @staticmethod | 50 | @staticmethod |
922 | @@ -42,6 +60,11 @@ | |||
923 | 42 | 60 | ||
924 | 43 | @adapter(IAccount) | 61 | @adapter(IAccount) |
925 | 44 | @implementer(IOpenIDPersistentIdentity) | 62 | @implementer(IOpenIDPersistentIdentity) |
926 | 63 | ======= | ||
927 | 64 | return config.openid_provider_root + '+openid' | ||
928 | 65 | |||
929 | 66 | |||
930 | 67 | >>>>>>> MERGE-SOURCE | ||
931 | 45 | class OpenIDPersistentIdentity: | 68 | class OpenIDPersistentIdentity: |
932 | 46 | """A persistent OpenID identifier for a user.""" | 69 | """A persistent OpenID identifier for a user.""" |
933 | 47 | 70 | ||
934 | 48 | 71 | ||
935 | === modified file 'lib/lp/services/webapp/doc/webapp-publication.txt' | |||
936 | --- lib/lp/services/webapp/doc/webapp-publication.txt 2016-09-21 02:50:41 +0000 | |||
937 | +++ lib/lp/services/webapp/doc/webapp-publication.txt 2016-09-24 06:42:11 +0000 | |||
938 | @@ -71,12 +71,24 @@ | |||
939 | 71 | rooturl: http://translations.launchpad.dev/ | 71 | rooturl: http://translations.launchpad.dev/ |
940 | 72 | althosts: | 72 | althosts: |
941 | 73 | ---- | 73 | ---- |
942 | 74 | <<<<<<< TREE | ||
943 | 75 | ======= | ||
944 | 76 | vostok @ vostok.dev | ||
945 | 77 | rooturl: http://vostok.dev/ | ||
946 | 78 | althosts: | ||
947 | 79 | ---- | ||
948 | 80 | >>>>>>> MERGE-SOURCE | ||
949 | 74 | xmlrpc @ xmlrpc.launchpad.dev | 81 | xmlrpc @ xmlrpc.launchpad.dev |
950 | 75 | rooturl: http://xmlrpc.launchpad.dev/ | 82 | rooturl: http://xmlrpc.launchpad.dev/ |
951 | 76 | althosts: | 83 | althosts: |
952 | 77 | ---- | 84 | ---- |
953 | 85 | <<<<<<< TREE | ||
954 | 78 | xmlrpc_private @ xmlrpc-private.launchpad.dev | 86 | xmlrpc_private @ xmlrpc-private.launchpad.dev |
955 | 79 | rooturl: http://xmlrpc-private.launchpad.dev/ | 87 | rooturl: http://xmlrpc-private.launchpad.dev/ |
956 | 88 | ======= | ||
957 | 89 | xmlrpc-private @ xmlrpc-private.launchpad.dev | ||
958 | 90 | rooturl: http://launchpad.dev/ | ||
959 | 91 | >>>>>>> MERGE-SOURCE | ||
960 | 80 | althosts: | 92 | althosts: |
961 | 81 | ---- | 93 | ---- |
962 | 82 | 94 | ||
963 | @@ -96,6 +108,10 @@ | |||
964 | 96 | localhost | 108 | localhost |
965 | 97 | testopenid.dev | 109 | testopenid.dev |
966 | 98 | translations.launchpad.dev | 110 | translations.launchpad.dev |
967 | 111 | <<<<<<< TREE | ||
968 | 112 | ======= | ||
969 | 113 | vostok.dev | ||
970 | 114 | >>>>>>> MERGE-SOURCE | ||
971 | 99 | xmlrpc-private.launchpad.dev | 115 | xmlrpc-private.launchpad.dev |
972 | 100 | xmlrpc.launchpad.dev | 116 | xmlrpc.launchpad.dev |
973 | 101 | 117 | ||
974 | 102 | 118 | ||
975 | === modified file 'lib/lp/services/webapp/login.py' | |||
976 | === modified file 'lib/lp/services/webapp/metazcml.py' | |||
977 | --- lib/lp/services/webapp/metazcml.py 2015-10-14 15:22:01 +0000 | |||
978 | +++ lib/lp/services/webapp/metazcml.py 2016-09-24 06:42:11 +0000 | |||
979 | @@ -49,10 +49,15 @@ | |||
980 | 49 | from zope.security.proxy import ProxyFactory | 49 | from zope.security.proxy import ProxyFactory |
981 | 50 | from zope.security.zcml import IPermissionDirective | 50 | from zope.security.zcml import IPermissionDirective |
982 | 51 | 51 | ||
983 | 52 | <<<<<<< TREE | ||
984 | 52 | from lp.app.interfaces.security import IAuthorization | 53 | from lp.app.interfaces.security import IAuthorization |
985 | 53 | from lp.layers import FeedsLayer | 54 | from lp.layers import FeedsLayer |
986 | 54 | from lp.services.config import config | 55 | from lp.services.config import config |
987 | 55 | from lp.services.webapp.interfaces import ( | 56 | from lp.services.webapp.interfaces import ( |
988 | 57 | ======= | ||
989 | 58 | from canonical.launchpad.layers import FeedsLayer | ||
990 | 59 | from canonical.launchpad.webapp.interfaces import ( | ||
991 | 60 | >>>>>>> MERGE-SOURCE | ||
992 | 56 | IApplicationMenu, | 61 | IApplicationMenu, |
993 | 57 | ICanonicalUrlData, | 62 | ICanonicalUrlData, |
994 | 58 | IContextMenu, | 63 | IContextMenu, |
995 | @@ -60,7 +65,13 @@ | |||
996 | 60 | IFavicon, | 65 | IFavicon, |
997 | 61 | INavigationMenu, | 66 | INavigationMenu, |
998 | 62 | ) | 67 | ) |
999 | 68 | <<<<<<< TREE | ||
1000 | 63 | from lp.services.webapp.publisher import RenamedView | 69 | from lp.services.webapp.publisher import RenamedView |
1001 | 70 | ======= | ||
1002 | 71 | from canonical.launchpad.webapp.publisher import RenamedView | ||
1003 | 72 | from canonical.launchpad.webapp.vhosts import allvhosts | ||
1004 | 73 | from lp.app.interfaces.security import IAuthorization | ||
1005 | 74 | >>>>>>> MERGE-SOURCE | ||
1006 | 64 | 75 | ||
1007 | 65 | 76 | ||
1008 | 66 | class IAuthorizationsDirective(Interface): | 77 | class IAuthorizationsDirective(Interface): |
1009 | @@ -617,9 +628,7 @@ | |||
1010 | 617 | # supplied -- we don't care about the priority in Launchpad but it | 628 | # supplied -- we don't care about the priority in Launchpad but it |
1011 | 618 | # needs to be unique -- and to do nothing if no hostname is | 629 | # needs to be unique -- and to do nothing if no hostname is |
1012 | 619 | # configured for this publisher. | 630 | # configured for this publisher. |
1016 | 620 | 631 | if name not in allvhosts.configs: | |
1014 | 621 | section = getattr(config.vhost, name, None) | ||
1015 | 622 | if section is None or section.hostname is None: | ||
1017 | 623 | return | 632 | return |
1018 | 624 | global _arbitrary_priority | 633 | global _arbitrary_priority |
1019 | 625 | if priority is None: | 634 | if priority is None: |
1020 | 626 | 635 | ||
1021 | === modified file 'lib/lp/services/webapp/servers.py' | |||
1022 | --- lib/lp/services/webapp/servers.py 2016-09-14 11:13:06 +0000 | |||
1023 | +++ lib/lp/services/webapp/servers.py 2016-09-24 06:42:11 +0000 | |||
1024 | @@ -1434,6 +1434,7 @@ | |||
1025 | 1434 | ErrorReportRequest): | 1434 | ErrorReportRequest): |
1026 | 1435 | """Request type for doing public XML-RPC in Launchpad.""" | 1435 | """Request type for doing public XML-RPC in Launchpad.""" |
1027 | 1436 | 1436 | ||
1028 | 1437 | <<<<<<< TREE | ||
1029 | 1437 | def getRootURL(self, rootsite): | 1438 | def getRootURL(self, rootsite): |
1030 | 1438 | """See IBasicLaunchpadRequest.""" | 1439 | """See IBasicLaunchpadRequest.""" |
1031 | 1439 | # XML-RPC requests occasionally need to use canonical_url, for | 1440 | # XML-RPC requests occasionally need to use canonical_url, for |
1032 | @@ -1444,6 +1445,18 @@ | |||
1033 | 1444 | rootsite = 'mainsite' | 1445 | rootsite = 'mainsite' |
1034 | 1445 | return super(PublicXMLRPCRequest, self).getRootURL(rootsite) | 1446 | return super(PublicXMLRPCRequest, self).getRootURL(rootsite) |
1035 | 1446 | 1447 | ||
1036 | 1448 | ======= | ||
1037 | 1449 | def getRootURL(self, rootsite): | ||
1038 | 1450 | """See IBasicLaunchpadRequest.""" | ||
1039 | 1451 | # XML-RPC requests occasionally need to use canonical_url, for | ||
1040 | 1452 | # the likes of sending emails. Until these are tracked down and | ||
1041 | 1453 | # fixed to use mainsite explicitly, replace the XML-RPC root | ||
1042 | 1454 | # URLs with mainsite's, so that URLs are meaningful. | ||
1043 | 1455 | if rootsite in (None, 'xmlrpc', 'xmlrpc-private'): | ||
1044 | 1456 | rootsite = 'mainsite' | ||
1045 | 1457 | return super(PublicXMLRPCRequest, self).getRootURL(rootsite) | ||
1046 | 1458 | |||
1047 | 1459 | >>>>>>> MERGE-SOURCE | ||
1048 | 1447 | def _createResponse(self): | 1460 | def _createResponse(self): |
1049 | 1448 | return PublicXMLRPCResponse() | 1461 | return PublicXMLRPCResponse() |
1050 | 1449 | 1462 | ||
1051 | @@ -1584,7 +1597,7 @@ | |||
1052 | 1584 | 1597 | ||
1053 | 1585 | if private_port is not None: | 1598 | if private_port is not None: |
1054 | 1586 | factories.append(XMLRPCRequestPublicationFactory( | 1599 | factories.append(XMLRPCRequestPublicationFactory( |
1056 | 1587 | 'xmlrpc_private', PrivateXMLRPCRequest, | 1600 | 'xmlrpc-private', PrivateXMLRPCRequest, |
1057 | 1588 | PrivateXMLRPCPublication, port=private_port)) | 1601 | PrivateXMLRPCPublication, port=private_port)) |
1058 | 1589 | 1602 | ||
1059 | 1590 | # Register those factories, in priority order corresponding to | 1603 | # Register those factories, in priority order corresponding to |
1060 | 1591 | 1604 | ||
1061 | === modified file 'lib/lp/services/webapp/vhosts.py' | |||
1062 | --- lib/lp/services/webapp/vhosts.py 2015-10-14 15:22:01 +0000 | |||
1063 | +++ lib/lp/services/webapp/vhosts.py 2016-09-24 06:42:11 +0000 | |||
1064 | @@ -3,56 +3,28 @@ | |||
1065 | 3 | 3 | ||
1066 | 4 | """Virtual host handling for the Launchpad webapp.""" | 4 | """Virtual host handling for the Launchpad webapp.""" |
1067 | 5 | 5 | ||
1069 | 6 | __all__ = ['allvhosts'] | 6 | __all__ = [ |
1070 | 7 | 'allvhosts', | ||
1071 | 8 | 'AllVirtualHostsConfiguration', | ||
1072 | 9 | ] | ||
1073 | 7 | 10 | ||
1074 | 8 | 11 | ||
1075 | 9 | class VirtualHostConfig: | 12 | class VirtualHostConfig: |
1076 | 10 | """The configuration of a single virtual host.""" | 13 | """The configuration of a single virtual host.""" |
1077 | 11 | 14 | ||
1081 | 12 | def __init__(self, hostname, althostnames, rooturl, use_https): | 15 | def __init__(self, hostname, althostnames, use_https, port=None): |
1082 | 13 | if althostnames is None: | 16 | if use_https: |
1083 | 14 | althostnames = [] | 17 | protocol = 'https' |
1084 | 15 | else: | 18 | else: |
1093 | 16 | althostnames = self._hostnameStrToList(althostnames) | 19 | protocol = 'http' |
1094 | 17 | 20 | rooturl = ( | |
1095 | 18 | if rooturl is None: | 21 | '%s://%s%s/' % |
1096 | 19 | if use_https: | 22 | (protocol, hostname, (':%d' % port) if port is not None else '')) |
1089 | 20 | protocol = 'https' | ||
1090 | 21 | else: | ||
1091 | 22 | protocol = 'http' | ||
1092 | 23 | rooturl = '%s://%s/' % (protocol, hostname) | ||
1097 | 24 | 23 | ||
1098 | 25 | self.hostname = hostname | 24 | self.hostname = hostname |
1099 | 26 | self.rooturl = rooturl | 25 | self.rooturl = rooturl |
1100 | 27 | self.althostnames = althostnames | 26 | self.althostnames = althostnames |
1101 | 28 | 27 | ||
1102 | 29 | @staticmethod | ||
1103 | 30 | def _hostnameStrToList(althostnames): | ||
1104 | 31 | """Return list of hostname strings given a string of althostnames. | ||
1105 | 32 | |||
1106 | 33 | This is to parse althostnames from the launchpad.conf file. | ||
1107 | 34 | |||
1108 | 35 | Basically, it's a comma separated list, but we're quite flexible | ||
1109 | 36 | about what is accepted. See the examples in the following doctest. | ||
1110 | 37 | |||
1111 | 38 | >>> thismethod = VirtualHostConfig._hostnameStrToList | ||
1112 | 39 | >>> thismethod('foo') | ||
1113 | 40 | ['foo'] | ||
1114 | 41 | >>> thismethod('foo,bar, baz') | ||
1115 | 42 | ['foo', 'bar', 'baz'] | ||
1116 | 43 | >>> thismethod('foo,,bar, ,baz ,') | ||
1117 | 44 | ['foo', 'bar', 'baz'] | ||
1118 | 45 | >>> thismethod('') | ||
1119 | 46 | [] | ||
1120 | 47 | >>> thismethod(' ') | ||
1121 | 48 | [] | ||
1122 | 49 | |||
1123 | 50 | """ | ||
1124 | 51 | if not althostnames.strip(): | ||
1125 | 52 | return [] | ||
1126 | 53 | return [ | ||
1127 | 54 | name.strip() for name in althostnames.split(',') if name.strip()] | ||
1128 | 55 | |||
1129 | 56 | 28 | ||
1130 | 57 | class AllVirtualHostsConfiguration: | 29 | class AllVirtualHostsConfiguration: |
1131 | 58 | """A representation of the virtual hosting configuration for | 30 | """A representation of the virtual hosting configuration for |
1132 | @@ -69,7 +41,7 @@ | |||
1133 | 69 | self.hostnames : set of hostnames handled by the vhost config | 41 | self.hostnames : set of hostnames handled by the vhost config |
1134 | 70 | """ | 42 | """ |
1135 | 71 | 43 | ||
1137 | 72 | def __init__(self): | 44 | def __init__(self, config=None): |
1138 | 73 | """Initialize all virtual host settings from launchpad.conf. | 45 | """Initialize all virtual host settings from launchpad.conf. |
1139 | 74 | 46 | ||
1140 | 75 | launchpad_conf_vhosts: The virtual_hosts config item from | 47 | launchpad_conf_vhosts: The virtual_hosts config item from |
1141 | @@ -77,27 +49,60 @@ | |||
1142 | 77 | 49 | ||
1143 | 78 | """ | 50 | """ |
1144 | 79 | self._has_vhost_data = False | 51 | self._has_vhost_data = False |
1146 | 80 | 52 | self._config = config | |
1147 | 53 | |||
1148 | 54 | <<<<<<< TREE | ||
1149 | 55 | ======= | ||
1150 | 56 | def _addVHost(self, vhost, hostname, use_https=True, althostnames=None): | ||
1151 | 57 | self._configs[vhost] = VirtualHostConfig( | ||
1152 | 58 | hostname, althostnames or [], self._use_https and use_https, | ||
1153 | 59 | self._port) | ||
1154 | 60 | |||
1155 | 61 | >>>>>>> MERGE-SOURCE | ||
1156 | 81 | def _getVHostData(self): | 62 | def _getVHostData(self): |
1158 | 82 | """Parse the vhosts on demand.""" | 63 | """Construct the vhosts on demand.""" |
1159 | 83 | # Avoid the circular imports inherent with the use of canonical.lazr. | 64 | # Avoid the circular imports inherent with the use of canonical.lazr. |
1160 | 84 | if self._has_vhost_data: | 65 | if self._has_vhost_data: |
1161 | 85 | return | 66 | return |
1162 | 67 | <<<<<<< TREE | ||
1163 | 86 | from lp.services.config import config | 68 | from lp.services.config import config |
1164 | 69 | ======= | ||
1165 | 70 | if self._config is None: | ||
1166 | 71 | import canonical.config | ||
1167 | 72 | self._config = canonical.config.config | ||
1168 | 73 | config = self._config | ||
1169 | 74 | >>>>>>> MERGE-SOURCE | ||
1170 | 87 | self._use_https = config.vhosts.use_https | 75 | self._use_https = config.vhosts.use_https |
1171 | 76 | self._port = config.vhosts.port | ||
1172 | 88 | self._configs = {} | 77 | self._configs = {} |
1173 | 89 | self._hostnames = set() | 78 | self._hostnames = set() |
1185 | 90 | for section in config.getByCategory('vhost'): | 79 | |
1186 | 91 | if section.hostname is None: | 80 | # Most vhosts are just subdomains of base_hostname. |
1187 | 92 | continue | 81 | normal_vhosts = [ |
1188 | 93 | category, vhost = section.category_and_section_names | 82 | 'api', 'xmlrpc', 'xmlrpc-private', |
1189 | 94 | self._configs[vhost] = config = VirtualHostConfig( | 83 | 'answers', 'blueprints', 'bugs', 'code', 'translations'] |
1190 | 95 | section.hostname, | 84 | if config.vhosts.enable_apidoc: |
1191 | 96 | section.althostnames, | 85 | normal_vhosts.append('apidoc') |
1192 | 97 | section.rooturl, | 86 | for vhost in normal_vhosts: |
1193 | 98 | self._use_https) | 87 | self._addVHost( |
1194 | 99 | self._hostnames.add(config.hostname) | 88 | vhost, '%s.%s' % (vhost, config.vhosts.base_hostname)) |
1195 | 100 | self._hostnames.update(config.althostnames) | 89 | # mainsite is base_hostname (eg. launchpad.dev), with an optional |
1196 | 90 | # www subdomain. | ||
1197 | 91 | self._addVHost( | ||
1198 | 92 | 'mainsite', config.vhosts.base_hostname, | ||
1199 | 93 | althostnames=['www.' + config.vhosts.base_hostname, 'localhost']) | ||
1200 | 94 | # feeds never uses SSL, but is otherwise normal. | ||
1201 | 95 | self._addVHost( | ||
1202 | 96 | 'feeds', 'feeds.' + config.vhosts.base_hostname, use_https=False) | ||
1203 | 97 | |||
1204 | 98 | if config.vhosts.testopenid_hostname: | ||
1205 | 99 | self._addVHost('testopenid', config.vhosts.testopenid_hostname) | ||
1206 | 100 | if config.vhosts.vostok_hostname: | ||
1207 | 101 | self._addVHost('vostok', config.vhosts.vostok_hostname) | ||
1208 | 102 | |||
1209 | 103 | for conf in self._configs.itervalues(): | ||
1210 | 104 | self._hostnames.add(conf.hostname) | ||
1211 | 105 | self._hostnames.update(conf.althostnames) | ||
1212 | 101 | self._has_vhost_data = True | 106 | self._has_vhost_data = True |
1213 | 102 | 107 | ||
1214 | 103 | def reload(self): | 108 | def reload(self): |
1215 | 104 | 109 | ||
1216 | === modified file 'lib/lp/testing/layers.py' | |||
1217 | --- lib/lp/testing/layers.py 2016-02-22 23:43:33 +0000 | |||
1218 | +++ lib/lp/testing/layers.py 2016-09-24 06:42:11 +0000 | |||
1219 | @@ -113,8 +113,35 @@ | |||
1220 | 113 | ConfigFixture, | 113 | ConfigFixture, |
1221 | 114 | ConfigUseFixture, | 114 | ConfigUseFixture, |
1222 | 115 | ) | 115 | ) |
1223 | 116 | <<<<<<< TREE | ||
1224 | 116 | from lp.services.database.interfaces import IStore | 117 | from lp.services.database.interfaces import IStore |
1225 | 117 | from lp.services.database.sqlbase import session_store | 118 | from lp.services.database.sqlbase import session_store |
1226 | 119 | ======= | ||
1227 | 120 | from canonical.database.sqlbase import session_store | ||
1228 | 121 | from canonical.launchpad.scripts import execute_zcml_for_scripts | ||
1229 | 122 | from canonical.launchpad.webapp.interfaces import ( | ||
1230 | 123 | DEFAULT_FLAVOR, | ||
1231 | 124 | IOpenLaunchBag, | ||
1232 | 125 | IStoreSelector, | ||
1233 | 126 | MAIN_STORE, | ||
1234 | 127 | ) | ||
1235 | 128 | from canonical.launchpad.webapp.servers import ( | ||
1236 | 129 | LaunchpadAccessLogger, | ||
1237 | 130 | register_launchpad_request_publication_factories, | ||
1238 | 131 | ) | ||
1239 | 132 | import canonical.launchpad.webapp.session | ||
1240 | 133 | from canonical.launchpad.webapp.vhosts import AllVirtualHostsConfiguration | ||
1241 | 134 | from canonical.lazr import pidfile | ||
1242 | 135 | from canonical.lazr.testing.layers import MockRootFolder | ||
1243 | 136 | from canonical.lazr.timeout import ( | ||
1244 | 137 | get_default_timeout_function, | ||
1245 | 138 | set_default_timeout_function, | ||
1246 | 139 | ) | ||
1247 | 140 | from canonical.librarian.testing.server import LibrarianServerFixture | ||
1248 | 141 | from canonical.testing import reset_logging | ||
1249 | 142 | from canonical.testing.profiled import profiled | ||
1250 | 143 | from canonical.testing.smtpd import SMTPController | ||
1251 | 144 | >>>>>>> MERGE-SOURCE | ||
1252 | 118 | from lp.services.googlesearch.tests.googleserviceharness import ( | 145 | from lp.services.googlesearch.tests.googleserviceharness import ( |
1253 | 119 | GoogleServiceTestSetup, | 146 | GoogleServiceTestSetup, |
1254 | 120 | ) | 147 | ) |
1255 | @@ -1850,7 +1877,8 @@ | |||
1256 | 1850 | 1877 | ||
1257 | 1851 | @classmethod | 1878 | @classmethod |
1258 | 1852 | def appserver_root_url(cls): | 1879 | def appserver_root_url(cls): |
1260 | 1853 | return cls.appserver_config.vhost.mainsite.rooturl | 1880 | return AllVirtualHostsConfiguration( |
1261 | 1881 | cls.appserver_config).configs['mainsite'].rooturl | ||
1262 | 1854 | 1882 | ||
1263 | 1855 | @classmethod | 1883 | @classmethod |
1264 | 1856 | def _waitUntilAppServerIsReady(cls): | 1884 | def _waitUntilAppServerIsReady(cls): |
1265 | 1857 | 1885 | ||
1266 | === modified file 'lib/lp/testing/tests/test_layers_functional.py' | |||
1267 | --- lib/lp/testing/tests/test_layers_functional.py 2015-10-13 14:01:25 +0000 | |||
1268 | +++ lib/lp/testing/tests/test_layers_functional.py 2016-09-24 06:42:11 +0000 | |||
1269 | @@ -32,8 +32,15 @@ | |||
1270 | 32 | getUtility, | 32 | getUtility, |
1271 | 33 | ) | 33 | ) |
1272 | 34 | 34 | ||
1273 | 35 | <<<<<<< TREE | ||
1274 | 35 | from lp.services.config import config | 36 | from lp.services.config import config |
1275 | 36 | from lp.services.librarian.client import ( | 37 | from lp.services.librarian.client import ( |
1276 | 38 | ======= | ||
1277 | 39 | from canonical.config import config | ||
1278 | 40 | from canonical.launchpad.webapp.vhosts import AllVirtualHostsConfiguration | ||
1279 | 41 | from canonical.lazr.pidfile import pidfile_path | ||
1280 | 42 | from canonical.librarian.client import ( | ||
1281 | 43 | >>>>>>> MERGE-SOURCE | ||
1282 | 37 | LibrarianClient, | 44 | LibrarianClient, |
1283 | 38 | UploadFailed, | 45 | UploadFailed, |
1284 | 39 | ) | 46 | ) |
1285 | @@ -498,7 +505,8 @@ | |||
1286 | 498 | 505 | ||
1287 | 499 | def testAppServerIsAvailable(self): | 506 | def testAppServerIsAvailable(self): |
1288 | 500 | # Test that the app server is up and running. | 507 | # Test that the app server is up and running. |
1290 | 501 | mainsite = LayerProcessController.appserver_config.vhost.mainsite | 508 | mainsite = AllVirtualHostsConfiguration( |
1291 | 509 | LayerProcessController.appserver_config).configs['mainsite'] | ||
1292 | 502 | home_page = urlopen(mainsite.rooturl).read() | 510 | home_page = urlopen(mainsite.rooturl).read() |
1293 | 503 | self.failUnless( | 511 | self.failUnless( |
1294 | 504 | 'Is your project registered yet?' in home_page, | 512 | 'Is your project registered yet?' in home_page, |
1295 | 505 | 513 | ||
1296 | === modified file 'utilities/rocketfuel-setup' |