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

Proposed by Julian Edwards
Status: Merged
Approved by: Julian Edwards
Approved revision: no longer in the source branch.
Merged at revision: 1291
Proposed branch: lp:~julian-edwards/maas/mipf-optional-proxy
Merge into: lp:~maas-committers/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) Approve
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.
Revision history for this message
Gavin Panella (allenap) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/provisioningserver/tasks.py'
--- src/provisioningserver/tasks.py 2012-10-23 08:27:11 +0000
+++ src/provisioningserver/tasks.py 2012-10-23 09:40:27 +0000
@@ -23,6 +23,7 @@
23 'write_full_dns_config',23 'write_full_dns_config',
24 ]24 ]
2525
26import os
26from subprocess import (27from subprocess import (
27 CalledProcessError,28 CalledProcessError,
28 check_call,29 check_call,
@@ -375,5 +376,9 @@
375# =====================================================================376# =====================================================================
376377
377@task378@task
378def import_pxe_files():379def import_pxe_files(http_proxy=None):
379 check_call(['maas-import-pxe-files'])380 env = dict(os.environ)
381 if http_proxy is not None:
382 env['http_proxy'] = http_proxy
383 env['https_proxy'] = http_proxy
384 check_call(['maas-import-pxe-files'], env=env)
380385
=== modified file 'src/provisioningserver/tests/test_tasks.py'
--- src/provisioningserver/tests/test_tasks.py 2012-10-23 08:27:11 +0000
+++ src/provisioningserver/tests/test_tasks.py 2012-10-23 09:40:27 +0000
@@ -24,8 +24,8 @@
24from apiclient.creds import convert_tuple_to_string24from apiclient.creds import convert_tuple_to_string
25from apiclient.maas_client import MAASClient25from apiclient.maas_client import MAASClient
26from apiclient.testing.credentials import make_api_credentials26from apiclient.testing.credentials import make_api_credentials
27from celery.app import app_or_default
27from celery.task import Task28from celery.task import Task
28from celery.app import app_or_default
29from maastesting.celery import CeleryFixture29from maastesting.celery import CeleryFixture
30from maastesting.factory import factory30from maastesting.factory import factory
31from maastesting.fakemethod import (31from maastesting.fakemethod import (
@@ -33,7 +33,10 @@
33 MultiFakeMethod,33 MultiFakeMethod,
34 )34 )
35from maastesting.matchers import ContainsAll35from maastesting.matchers import ContainsAll
36from mock import Mock36from mock import (
37 ANY,
38 Mock,
39 )
37from netaddr import IPNetwork40from netaddr import IPNetwork
38from provisioningserver import (41from provisioningserver import (
39 auth,42 auth,
@@ -543,5 +546,19 @@
543 def test_import_pxe_files(self):546 def test_import_pxe_files(self):
544 recorder = self.patch(tasks, 'check_call', Mock())547 recorder = self.patch(tasks, 'check_call', Mock())
545 import_pxe_files()548 import_pxe_files()
546 recorder.assert_called_once_with(['maas-import-pxe-files'])549 recorder.assert_called_once_with(['maas-import-pxe-files'], env=ANY)
547 self.assertIsInstance(import_pxe_files, Task)550 self.assertIsInstance(import_pxe_files, Task)
551
552 def test_import_pxe_files_preserves_environment(self):
553 recorder = self.patch(tasks, 'check_call', Mock())
554 import_pxe_files()
555 recorder.assert_called_once_with(
556 ['maas-import-pxe-files'], env=os.environ)
557
558 def test_import_pxe_files_sets_proxy(self):
559 recorder = self.patch(tasks, 'check_call', Mock())
560 proxy = factory.getRandomString()
561 import_pxe_files(http_proxy=proxy)
562 expected_env = dict(os.environ, http_proxy=proxy, https_proxy=proxy)
563 recorder.assert_called_once_with(
564 ['maas-import-pxe-files'], env=expected_env)