Merge lp:~julian-edwards/maas/mipf-optional-proxy into lp:maas/trunk

Proposed by Julian Edwards on 2012-10-23
Status: Merged
Approved by: Julian Edwards on 2012-10-23
Approved revision: 1291
Merged at revision: 1291
Proposed branch: lp:~julian-edwards/maas/mipf-optional-proxy
Merge into: lp:maas/trunk
Diff against target: 70 lines (+27/-5)
2 files modified
src/provisioningserver/tasks.py (+7/-2)
src/provisioningserver/tests/test_tasks.py (+20/-3)
To merge this branch: bzr merge lp:~julian-edwards/maas/mipf-optional-proxy
Reviewer Review Type Date Requested Status
Gavin Panella (community) 2012-10-23 Approve on 2012-10-23
Review via email: mp+130964@code.launchpad.net

Commit message

Make the celery task 'import-pxe-files' take an optional http proxy.

To post a comment you must log in.
Gavin Panella (allenap) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/provisioningserver/tasks.py'
2--- src/provisioningserver/tasks.py 2012-10-23 08:27:11 +0000
3+++ src/provisioningserver/tasks.py 2012-10-23 09:40:27 +0000
4@@ -23,6 +23,7 @@
5 'write_full_dns_config',
6 ]
7
8+import os
9 from subprocess import (
10 CalledProcessError,
11 check_call,
12@@ -375,5 +376,9 @@
13 # =====================================================================
14
15 @task
16-def import_pxe_files():
17- check_call(['maas-import-pxe-files'])
18+def import_pxe_files(http_proxy=None):
19+ env = dict(os.environ)
20+ if http_proxy is not None:
21+ env['http_proxy'] = http_proxy
22+ env['https_proxy'] = http_proxy
23+ check_call(['maas-import-pxe-files'], env=env)
24
25=== modified file 'src/provisioningserver/tests/test_tasks.py'
26--- src/provisioningserver/tests/test_tasks.py 2012-10-23 08:27:11 +0000
27+++ src/provisioningserver/tests/test_tasks.py 2012-10-23 09:40:27 +0000
28@@ -24,8 +24,8 @@
29 from apiclient.creds import convert_tuple_to_string
30 from apiclient.maas_client import MAASClient
31 from apiclient.testing.credentials import make_api_credentials
32+from celery.app import app_or_default
33 from celery.task import Task
34-from celery.app import app_or_default
35 from maastesting.celery import CeleryFixture
36 from maastesting.factory import factory
37 from maastesting.fakemethod import (
38@@ -33,7 +33,10 @@
39 MultiFakeMethod,
40 )
41 from maastesting.matchers import ContainsAll
42-from mock import Mock
43+from mock import (
44+ ANY,
45+ Mock,
46+ )
47 from netaddr import IPNetwork
48 from provisioningserver import (
49 auth,
50@@ -543,5 +546,19 @@
51 def test_import_pxe_files(self):
52 recorder = self.patch(tasks, 'check_call', Mock())
53 import_pxe_files()
54- recorder.assert_called_once_with(['maas-import-pxe-files'])
55+ recorder.assert_called_once_with(['maas-import-pxe-files'], env=ANY)
56 self.assertIsInstance(import_pxe_files, Task)
57+
58+ def test_import_pxe_files_preserves_environment(self):
59+ recorder = self.patch(tasks, 'check_call', Mock())
60+ import_pxe_files()
61+ recorder.assert_called_once_with(
62+ ['maas-import-pxe-files'], env=os.environ)
63+
64+ def test_import_pxe_files_sets_proxy(self):
65+ recorder = self.patch(tasks, 'check_call', Mock())
66+ proxy = factory.getRandomString()
67+ import_pxe_files(http_proxy=proxy)
68+ expected_env = dict(os.environ, http_proxy=proxy, https_proxy=proxy)
69+ recorder.assert_called_once_with(
70+ ['maas-import-pxe-files'], env=expected_env)