Merge lp:~rvb/maas-test/fix-proxy-usage into lp:maas-test

Proposed by Raphaël Badin
Status: Merged
Merged at revision: 71
Proposed branch: lp:~rvb/maas-test/fix-proxy-usage
Merge into: lp:maas-test
Diff against target: 130 lines (+68/-5)
2 files modified
maastest/maasfixture.py (+14/-5)
maastest/tests/test_maasfixture.py (+54/-0)
To merge this branch: bzr merge lp:~rvb/maas-test/fix-proxy-usage
Reviewer Review Type Date Requested Status
Gavin Panella (community) Approve
Review via email: mp+196745@code.launchpad.net

Commit message

This branch uses the proxy URL in maasfixture: if it is defined, MAAS' http_proxy option is set.

Drive-by fix: add a unit test for configure_default_series (named ­— unexpectedly —test_configure_default_series_configures_series()).

To post a comment you must log in.
Revision history for this message
Gavin Panella (allenap) wrote :

Looks good.

[1]

-    def configure_default_series(self, series):
-        """Set the default series used for enlistment and commissioning."""
+    def configure_maas(self, name, value):
+        """Set a config value in MAAS."""

The name "configure_maas" is somewhat tautological. The full name of
this function is: maastest.maasfixture.MAASFixture.configure_maas. I
think it's safe to call it just "configure".

[2]

         if response.code != httplib.OK:
             # TODO: include the response's content in the exception
             # message, here and in other places in this file.
-            raise Exception("Error configuring the commissiong series")
+            raise Exception("Error configuring '%s'" % name)

As discussed in a previous branch, we really need to do something about
this. It's hiding what might be very useful information that could save
hours of debugging.

[3]

+        self.patch(maas_fixture, 'admin_maas_client', mock.MagicMock())
+        series = self.getUniqueString()
+        call_mock = self.patch_MAASClient(
+            maas_fixture.admin_maas_client, 'post', '')

Do you need the first line here?

[4]

+        self.assertEqual(
+            [mock.call(
+                '/api/1.0/maas/', op='set_config',
+                name='commissioning_distro_series', value=series)],
+            (call_mock.mock_calls))

The braces in the last line are superflous, though harmless.

review: Approve
lp:~rvb/maas-test/fix-proxy-usage updated
70. By Raphaël Badin

Review fixes.

Revision history for this message
Raphaël Badin (rvb) wrote :

> Looks good.
>
>
> [1]
>
> -    def configure_default_series(self, series):
> -        """Set the default series used for enlistment and commissioning."""
> +    def configure_maas(self, name, value):
> +        """Set a config value in MAAS."""
>
> The name "configure_maas" is somewhat tautological. The full name of
> this function is: maastest.maasfixture.MAASFixture.configure_maas. I
> think it's safe to call it just "configure".

Right, fixed.

> [2]
>
>         if response.code != httplib.OK:
>             # TODO: include the response's content in the exception
>             # message, here and in other places in this file.
> -            raise Exception("Error configuring the commissiong series")
> +            raise Exception("Error configuring '%s'" % name)
>
> As discussed in a previous branch, we really need to do something about
> this. It's hiding what might be very useful information that could save
> hours of debugging.

Yeah, I know that's why I added the todo. But let's fix that in another branch.

>
>
> [3]
>
> +        self.patch(maas_fixture, 'admin_maas_client', mock.MagicMock())
> +        series = self.getUniqueString()
> +        call_mock = self.patch_MAASClient(
> +            maas_fixture.admin_maas_client, 'post', '')
>
> Do you need the first line here?

Yes we do, because maas_fixture.admin_maas_client is not created in the context of this test.

> [4]
>
> +        self.assertEqual(
> +            [mock.call(
> +                '/api/1.0/maas/', op='set_config',
> +                name='commissioning_distro_series', value=series)],
> +            (call_mock.mock_calls))
>
> The braces in the last line are superflous, though harmless.

Fixed.

Thanks for the review!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'maastest/maasfixture.py'
2--- maastest/maasfixture.py 2013-11-26 13:50:33 +0000
3+++ maastest/maasfixture.py 2013-11-26 22:46:23 +0000
4@@ -181,16 +181,23 @@
5 check_call=True)
6 logging.info("Done importing MAAS PXE Files.")
7
8- def configure_default_series(self, series):
9- """Set the default series used for enlistment and commissioning."""
10+ def configure(self, name, value):
11+ """Set a config value in MAAS."""
12 uri = utils.get_uri('maas/')
13 response = self.admin_maas_client.post(
14- uri, op='set_config', name='commissioning_distro_series',
15- value=series)
16+ uri, op='set_config', name=name, value=value)
17 if response.code != httplib.OK:
18 # TODO: include the response's content in the exception
19 # message, here and in other places in this file.
20- raise Exception("Error configuring the commissiong series")
21+ raise Exception("Error configuring '%s'" % name)
22+
23+ def configure_default_series(self, series):
24+ """Set the default series used for enlistment and commissioning."""
25+ self.configure('commissioning_distro_series', series)
26+
27+ def configure_http_proxy(self, proxy_url):
28+ """Set the proxy to be used by MAAS."""
29+ self.configure('http_proxy', proxy_url)
30
31 def setUp(self):
32 """Install and configure MAAS inside the virtual machine.
33@@ -212,6 +219,8 @@
34 self.admin_api_key = api_key
35 self.admin_maas_client = maas_client
36 # MAAS setup.
37+ if self.proxy_url: # None or '' indicates no proxy.
38+ self.configure_http_proxy(self.proxy_url)
39 self.import_maas_images(
40 series=self.series, architecture=self.architecture)
41 self.configure_default_series(self.series)
42
43=== modified file 'maastest/tests/test_maasfixture.py'
44--- maastest/tests/test_maasfixture.py 2013-11-26 13:20:28 +0000
45+++ maastest/tests/test_maasfixture.py 2013-11-26 22:46:23 +0000
46@@ -423,6 +423,38 @@
47 maas_fixture.collect_logs.mock_calls,
48 ])
49
50+ def test_configure_default_series_configures_series(self):
51+ fixture = self.make_kvm_fixture()
52+ maas_fixture = self.make_maas_fixture(fixture)
53+ self.patch(maas_fixture, 'admin_maas_client', mock.MagicMock())
54+ series = self.getUniqueString()
55+ call_mock = self.patch_MAASClient(
56+ maas_fixture.admin_maas_client, 'post', '')
57+
58+ maas_fixture.configure_default_series(series)
59+
60+ self.assertEqual(
61+ [mock.call(
62+ '/api/1.0/maas/', op='set_config',
63+ name='commissioning_distro_series', value=series)],
64+ call_mock.mock_calls)
65+
66+ def test_configure_http_proxy_configure_http_proxy(self):
67+ fixture = self.make_kvm_fixture()
68+ proxy_url = self.getUniqueString()
69+ maas_fixture = self.make_maas_fixture(fixture, proxy_url=proxy_url)
70+ self.patch(maas_fixture, 'admin_maas_client', mock.MagicMock())
71+ call_mock = self.patch_MAASClient(
72+ maas_fixture.admin_maas_client, 'post', '')
73+
74+ maas_fixture.configure_http_proxy(proxy_url)
75+
76+ self.assertEqual(
77+ [mock.call(
78+ '/api/1.0/maas/', op='set_config',
79+ name='http_proxy', value=proxy_url)],
80+ (call_mock.mock_calls))
81+
82 def test_setUp_calls_methods_if_direct_ip_set(self):
83 fixture = self.make_kvm_fixture()
84 fixture.direct_ip = '127.11.24.38'
85@@ -442,6 +474,8 @@
86 self.patch(
87 maas_fixture, 'configure_cluster', mock.MagicMock())
88 self.patch(
89+ maas_fixture, 'configure_http_proxy', mock.MagicMock())
90+ self.patch(
91 maas_fixture, 'import_maas_images', mock.MagicMock())
92
93 with maas_fixture:
94@@ -452,6 +486,7 @@
95 [mock.call()],
96 [mock.call()],
97 [mock.call()],
98+ [mock.call(maas_fixture.proxy_url)],
99 [mock.call(
100 series=maas_fixture.series,
101 architecture=maas_fixture.architecture)],
102@@ -460,9 +495,28 @@
103 maas_fixture.configure_default_maas_url.mock_calls,
104 maas_fixture.check_cluster_connected.mock_calls,
105 maas_fixture.configure_cluster.mock_calls,
106+ maas_fixture.configure_http_proxy.mock_calls,
107 maas_fixture.import_maas_images.mock_calls,
108 ])
109
110+ def test_setUp_does_not_configure_proxy_if_no_proxy(self):
111+ fixture = self.make_kvm_fixture()
112+ maas_fixture = self.make_maas_fixture(fixture, proxy_url='')
113+ self.patch(
114+ maas_fixture, 'query_api_key',
115+ mock.MagicMock(return_value='fake:api:key'))
116+ self.patch(
117+ maas_fixture, 'configure_http_proxy', mock.MagicMock())
118+
119+ with maas_fixture:
120+ pass
121+
122+ self.assertEqual(
123+ [[]],
124+ [
125+ maas_fixture.configure_http_proxy.mock_calls,
126+ ])
127+
128 def test_setUp_does_not_call_methods_if_direct_ip_unset(self):
129 fixture = self.make_kvm_fixture()
130 maas_fixture = self.make_maas_fixture(fixture)

Subscribers

People subscribed via source and target branches