Merge lp:~blake-rouse/maas/fix-1364062 into lp:~maas-committers/maas/trunk

Proposed by Blake Rouse
Status: Merged
Approved by: Blake Rouse
Approved revision: no longer in the source branch.
Merged at revision: 2879
Proposed branch: lp:~blake-rouse/maas/fix-1364062
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 94 lines (+37/-11)
2 files modified
src/maasserver/bootresources.py (+5/-0)
src/maasserver/tests/test_bootresources.py (+32/-11)
To merge this branch: bzr merge lp:~blake-rouse/maas/fix-1364062
Reviewer Review Type Date Requested Status
Raphaël Badin (community) Approve
Review via email: mp+233070@code.launchpad.net

Commit message

Set http_proxy and https_proxy when importing boot resources on the region.

To post a comment you must log in.
Revision history for this message
Raphaël Badin (rvb) wrote :

Looks good!

review: Approve
Revision history for this message
Andres Rodriguez (andreserl) wrote :

we really need to test this and how things are affected...

On Tue, Sep 2, 2014 at 11:40 AM, <email address hidden> wrote:

> The proposal to merge lp:~blake-rouse/maas/fix-1364062 into lp:maas has
> been updated.
>
> Status: Approved => Merged
>
> For more details, see:
> https://code.launchpad.net/~blake-rouse/maas/fix-1364062/+merge/233070
> --
> https://code.launchpad.net/~blake-rouse/maas/fix-1364062/+merge/233070
> You are subscribed to branch lp:maas.
>

--
Andres Rodriguez (RoAkSoAx)
Ubuntu Server Developer
MSc. Telecom & Networking
Systems Engineer

Revision history for this message
Blake Rouse (blake-rouse) wrote :

Are you saying the config value is only for the clusters and the nodes, not for the region?

I could see that assumption. In that case the server should just be setup to use that proxy. I have nothing against either.

Revision history for this message
Julian Edwards (julian-edwards) wrote :

On Tuesday 02 September 2014 14:46:11 you wrote:
> You can probably do the check in one go:
> self.assertEqual(
> (proxy_address, proxy_address),
> (capture.env['http_proxy'], capture.env['http_proxys']))

ARGH. Please stop doing this, it makes test errors almost unreadable.

Use self.expectThat, which delays errors until the test is finished.

In this instance you can also use MatchesAll as you have the same predicate:

self.assertThat(
    proxy_address, MatchesAll(
        Equals(capture.env['http_proxy']),
        Equals(capture.env['https_proxy'])
    ))

Revision history for this message
Julian Edwards (julian-edwards) wrote :

On Tuesday 02 September 2014 16:12:40 you wrote:
> we really need to test this and how things are affected...

Ideally, before landing run the branch through the CI using the instructions
that rvb provided.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/bootresources.py'
2--- src/maasserver/bootresources.py 2014-09-02 08:36:29 +0000
3+++ src/maasserver/bootresources.py 2014-09-02 15:28:52 +0000
4@@ -43,6 +43,7 @@
5 BootResourceSet,
6 BootSource,
7 BootSourceSelection,
8+ Config,
9 LargeFile,
10 NodeGroup,
11 )
12@@ -880,6 +881,10 @@
13 variables = {
14 'GNUPGHOME': get_maas_user_gpghome(),
15 }
16+ http_proxy = Config.objects.get_config('http_proxy')
17+ if http_proxy is not None:
18+ variables['http_proxy'] = http_proxy
19+ variables['https_proxy'] = http_proxy
20 with environment_variables(variables):
21 maaslog.info("Started importing of boot resources.")
22 sources = [source.to_dict() for source in BootSource.objects.all()]
23
24=== modified file 'src/maasserver/tests/test_bootresources.py'
25--- src/maasserver/tests/test_bootresources.py 2014-09-02 06:21:04 +0000
26+++ src/maasserver/tests/test_bootresources.py 2014-09-02 15:28:52 +0000
27@@ -45,6 +45,7 @@
28 BootResourceSet,
29 BootSource,
30 BootSourceSelection,
31+ Config,
32 LargeFile,
33 )
34 from maasserver.testing.factory import factory
35@@ -975,6 +976,18 @@
36
37 class TestImportImages(MAASTestCase):
38
39+ def patch_and_capture_env_for_download_all_boot_resources(self):
40+ class CaptureEnv:
41+ """Fake function; records a copy of the environment."""
42+
43+ def __call__(self, *args, **kwargs):
44+ self.args = args
45+ self.env = environ.copy()
46+
47+ capture = self.patch(
48+ bootresources, 'download_all_boot_resources', CaptureEnv())
49+ return capture
50+
51 def test_download_boot_resources_syncs_repo(self):
52 fake_sync = self.patch(bootresources.BootResourceRepoWriter, 'sync')
53 store = BootResourceStore()
54@@ -1082,21 +1095,29 @@
55 descriptions.is_empty.return_value = False
56 fake_image_descriptions.return_value = descriptions
57 self.patch(bootresources, 'map_products')
58-
59- class CaptureEnv:
60- """Fake function; records a copy of the environment."""
61-
62- def __call__(self, *args, **kwargs):
63- self.args = args
64- self.env = environ.copy()
65-
66- fake_download = self.patch(
67- bootresources, 'download_all_boot_resources', CaptureEnv())
68+ capture = self.patch_and_capture_env_for_download_all_boot_resources()
69
70 bootresources._import_resources(force=True)
71 self.assertEqual(
72 bootresources.get_maas_user_gpghome(),
73- fake_download.env['GNUPGHOME'])
74+ capture.env['GNUPGHOME'])
75+
76+ def test__import_resources_has_env_http_and_https_proxy_set(self):
77+ proxy_address = factory.make_name('proxy')
78+ Config.objects.set_config('http_proxy', proxy_address)
79+
80+ fake_image_descriptions = self.patch(
81+ bootresources, 'download_all_image_descriptions')
82+ descriptions = Mock()
83+ descriptions.is_empty.return_value = False
84+ fake_image_descriptions.return_value = descriptions
85+ self.patch(bootresources, 'map_products')
86+ capture = self.patch_and_capture_env_for_download_all_boot_resources()
87+
88+ bootresources._import_resources(force=True)
89+ self.assertEqual(
90+ (proxy_address, proxy_address),
91+ (capture.env['http_proxy'], capture.env['http_proxy']))
92
93 def test__import_resources_calls_import_boot_images_on_clusters(self):
94 nodegroup = MagicMock()