Merge lp:~gmb/maas/enlist-mscm-to-RPC into lp:~maas-committers/maas/trunk

Proposed by Graham Binns
Status: Merged
Approved by: Graham Binns
Approved revision: no longer in the source branch.
Merged at revision: 2956
Proposed branch: lp:~gmb/maas/enlist-mscm-to-RPC
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 284 lines (+130/-32)
8 files modified
src/maasserver/api/tests/test_nodegroup.py (+12/-5)
src/maasserver/models/nodegroup.py (+16/-6)
src/maasserver/models/tests/test_nodegroup.py (+50/-0)
src/provisioningserver/rpc/cluster.py (+14/-0)
src/provisioningserver/rpc/clusterservice.py (+11/-0)
src/provisioningserver/rpc/tests/test_clusterservice.py (+27/-0)
src/provisioningserver/tasks.py (+0/-9)
src/provisioningserver/tests/test_tasks.py (+0/-12)
To merge this branch: bzr merge lp:~gmb/maas/enlist-mscm-to-RPC
Reviewer Review Type Date Requested Status
Gavin Panella (community) Approve
Review via email: mp+234279@code.launchpad.net

Commit message

Convert the enlist_nodes_from_mscm Celery task to an RPC call.

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

On 11 September 2014 11:28, Gavin Panella <email address hidden> wrote:
>
>> +
>> +class EnlistNodesFromMSCM(amp.Command):
>> + """Probe for and enlist mscm machines attached to the cluster.
>> +
>> + :since 1.7:
>> + """
>> + arguments = [
>> + (b"host", amp.Unicode()),
>> + (b"username", amp.Unicode()),
>> + (b"password", amp.Unicode()),
>> + ]
>> + response = []
>> + errors = {}
>
> No errors at all?

probe_and_enlist_mscm() doesn't appear to raise any, so no. This is
one of those cases where we need a catch-all, because I don't know
what might happen further down the stack (this is the one and only
time I've ever been tempted to miss Java's error declarations…)

Revision history for this message
MAAS Lander (maas-lander) wrote :
Download full text (23.7 KiB)

The attempt to merge lp:~gmb/maas/enlist-mscm-to-RPC into lp:maas failed. Below is the output from the failed tests.

Ign http://security.ubuntu.com trusty-security InRelease
Ign http://nova.clouds.archive.ubuntu.com trusty InRelease
Hit http://security.ubuntu.com trusty-security Release.gpg
Ign http://nova.clouds.archive.ubuntu.com trusty-updates InRelease
Hit http://security.ubuntu.com trusty-security Release
Hit http://nova.clouds.archive.ubuntu.com trusty Release.gpg
Hit http://nova.clouds.archive.ubuntu.com trusty-updates Release.gpg
Hit http://nova.clouds.archive.ubuntu.com trusty Release
Hit http://nova.clouds.archive.ubuntu.com trusty-updates Release
Hit http://security.ubuntu.com trusty-security/main Sources
Hit http://security.ubuntu.com trusty-security/universe Sources
Hit http://security.ubuntu.com trusty-security/main amd64 Packages
Hit http://security.ubuntu.com trusty-security/universe amd64 Packages
Hit http://security.ubuntu.com trusty-security/main Translation-en
Hit http://security.ubuntu.com trusty-security/universe Translation-en
Hit http://nova.clouds.archive.ubuntu.com trusty/main Sources
Hit http://nova.clouds.archive.ubuntu.com trusty/universe Sources
Hit http://nova.clouds.archive.ubuntu.com trusty/main amd64 Packages
Hit http://nova.clouds.archive.ubuntu.com trusty/universe amd64 Packages
Hit http://nova.clouds.archive.ubuntu.com trusty/main Translation-en
Hit http://nova.clouds.archive.ubuntu.com trusty/universe Translation-en
Hit http://nova.clouds.archive.ubuntu.com trusty-updates/main Sources
Hit http://nova.clouds.archive.ubuntu.com trusty-updates/universe Sources
Hit http://nova.clouds.archive.ubuntu.com trusty-updates/main amd64 Packages
Hit http://nova.clouds.archive.ubuntu.com trusty-updates/universe amd64 Packages
Hit http://nova.clouds.archive.ubuntu.com trusty-updates/main Translation-en
Hit http://nova.clouds.archive.ubuntu.com trusty-updates/universe Translation-en
Ign http://nova.clouds.archive.ubuntu.com trusty/main Translation-en_US
Ign http://nova.clouds.archive.ubuntu.com trusty/universe Translation-en_US
Reading package lists...
sudo DEBIAN_FRONTEND=noninteractive apt-get -y \
     --no-install-recommends install apache2 authbind bind9 bind9utils build-essential bzr-builddeb curl daemontools debhelper dh-apport distro-info dnsutils firefox freeipmi-tools ipython isc-dhcp-common libjs-raphael libjs-yui3-full libjs-yui3-min libpq-dev make pep8 postgresql pyflakes python-amqplib python-bzrlib python-celery python-convoy python-crochet python-cssselect python-curtin python-dev python-distro-info python-django python-django-piston python-django-south python-djorm-ext-pgarray python-docutils python-extras python-fixtures python-flake8 python-formencode python-hivex python-httplib2 python-jinja2 python-jsonschema python-lockfile python-lxml python-mimeparse python-mock python-netaddr python-netifaces python-nose python-oauth python-oops python-oops-amqp python-oops-datedir-repo python-oops-twisted python-oops-wsgi python-openssl python-paramiko python-pexpect python-pip python-pocket-lint python-psycopg2 python-pyinotify python-seamicroclient python-simplejson python-simplestreams python-sphinx python-s...

Revision history for this message
MAAS Lander (maas-lander) wrote :
Download full text (23.9 KiB)

The attempt to merge lp:~gmb/maas/enlist-mscm-to-RPC into lp:maas failed. Below is the output from the failed tests.

Ign http://security.ubuntu.com trusty-security InRelease
Get:1 http://security.ubuntu.com trusty-security Release.gpg [933 B]
Ign http://nova.clouds.archive.ubuntu.com trusty InRelease
Get:2 http://security.ubuntu.com trusty-security Release [59.7 kB]
Ign http://nova.clouds.archive.ubuntu.com trusty-updates InRelease
Hit http://nova.clouds.archive.ubuntu.com trusty Release.gpg
Get:3 http://nova.clouds.archive.ubuntu.com trusty-updates Release.gpg [933 B]
Hit http://nova.clouds.archive.ubuntu.com trusty Release
Get:4 http://nova.clouds.archive.ubuntu.com trusty-updates Release [59.7 kB]
Hit http://nova.clouds.archive.ubuntu.com trusty/main Sources
Hit http://nova.clouds.archive.ubuntu.com trusty/universe Sources
Hit http://nova.clouds.archive.ubuntu.com trusty/main amd64 Packages
Hit http://nova.clouds.archive.ubuntu.com trusty/universe amd64 Packages
Hit http://nova.clouds.archive.ubuntu.com trusty/main Translation-en
Hit http://nova.clouds.archive.ubuntu.com trusty/universe Translation-en
Get:5 http://security.ubuntu.com trusty-security/main Sources [43.9 kB]
Get:6 http://security.ubuntu.com trusty-security/universe Sources [10.8 kB]
Get:7 http://nova.clouds.archive.ubuntu.com trusty-updates/main Sources [118 kB]
Get:8 http://security.ubuntu.com trusty-security/main amd64 Packages [138 kB]
Get:9 http://security.ubuntu.com trusty-security/universe amd64 Packages [47.2 kB]
Hit http://security.ubuntu.com trusty-security/main Translation-en
Hit http://security.ubuntu.com trusty-security/universe Translation-en
Get:10 http://nova.clouds.archive.ubuntu.com trusty-updates/universe Sources [83.7 kB]
Get:11 http://nova.clouds.archive.ubuntu.com trusty-updates/main amd64 Packages [317 kB]
Get:12 http://nova.clouds.archive.ubuntu.com trusty-updates/universe amd64 Packages [201 kB]
Hit http://nova.clouds.archive.ubuntu.com trusty-updates/main Translation-en
Hit http://nova.clouds.archive.ubuntu.com trusty-updates/universe Translation-en
Ign http://nova.clouds.archive.ubuntu.com trusty/main Translation-en_US
Ign http://nova.clouds.archive.ubuntu.com trusty/universe Translation-en_US
Fetched 1,080 kB in 0s (1,756 kB/s)
Reading package lists...
sudo DEBIAN_FRONTEND=noninteractive apt-get -y \
     --no-install-recommends install apache2 authbind bind9 bind9utils build-essential bzr-builddeb curl daemontools debhelper dh-apport distro-info dnsutils firefox freeipmi-tools ipython isc-dhcp-common libjs-raphael libjs-yui3-full libjs-yui3-min libpq-dev make pep8 postgresql pyflakes python-amqplib python-bzrlib python-celery python-convoy python-crochet python-cssselect python-curtin python-dev python-distro-info python-django python-django-piston python-django-south python-djorm-ext-pgarray python-docutils python-extras python-fixtures python-flake8 python-formencode python-hivex python-httplib2 python-jinja2 python-jsonschema python-lockfile python-lxml python-mimeparse python-mock python-netaddr python-netifaces python-nose python-oauth python-oops python-oops-amqp python-oops-datedir-repo python-oops-twisted python-oops-wsgi python-openssl py...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/api/tests/test_nodegroup.py'
2--- src/maasserver/api/tests/test_nodegroup.py 2014-09-10 06:35:46 +0000
3+++ src/maasserver/api/tests/test_nodegroup.py 2014-09-11 11:22:16 +0000
4@@ -55,7 +55,10 @@
5 )
6 from mock import Mock
7 from provisioningserver.auth import get_recorded_nodegroup_uuid
8-from provisioningserver.rpc.cluster import ImportBootImages
9+from provisioningserver.rpc.cluster import (
10+ EnlistNodesFromMSCM,
11+ ImportBootImages,
12+ )
13 from testresources import FixtureResource
14 from testtools.matchers import (
15 AllMatch,
16@@ -370,7 +373,9 @@
17 password = factory.make_name('password')
18 self.become_admin()
19
20- mock = self.patch(nodegroup_module, 'enlist_nodes_from_mscm')
21+ getClientFor = self.patch(nodegroup_module, 'getClientFor')
22+ client = getClientFor.return_value
23+ nodegroup = factory.make_NodeGroup()
24
25 response = self.client.post(
26 reverse('nodegroup_handler', args=[nodegroup.uuid]),
27@@ -385,9 +390,11 @@
28 httplib.OK, response.status_code,
29 explain_unexpected_response(httplib.OK, response))
30
31- args = (host, username, password)
32- matcher = MockCalledOnceWith(queue=nodegroup.uuid, args=args)
33- self.assertThat(mock.apply_async, matcher)
34+ self.expectThat(
35+ client,
36+ MockCalledOnceWith(
37+ EnlistNodesFromMSCM, host=host, username=username,
38+ password=password))
39
40
41 class TestNodeGroupAPIAuth(MAASServerTestCase):
42
43=== modified file 'src/maasserver/models/nodegroup.py'
44--- src/maasserver/models/nodegroup.py 2014-09-10 16:01:38 +0000
45+++ src/maasserver/models/nodegroup.py 2014-09-11 11:22:16 +0000
46@@ -41,13 +41,11 @@
47 from provisioningserver.rpc.cluster import (
48 AddSeaMicro15k,
49 AddVirsh,
50+ EnlistNodesFromMSCM,
51 ImportBootImages,
52 )
53 from provisioningserver.rpc.exceptions import NoConnectionsAvailable
54-from provisioningserver.tasks import (
55- enlist_nodes_from_mscm,
56- enlist_nodes_from_ucsm,
57- )
58+from provisioningserver.tasks import enlist_nodes_from_ucsm
59
60
61 class NodeGroupManager(Manager):
62@@ -314,6 +312,18 @@
63 :param host: IP address for the MSCM.
64 :param username: username for MSCM.
65 :param password: password for MSCM.
66+
67+ :raises NoConnectionsAvailable: If no connections to the cluster
68+ are available.
69 """
70- args = (host, username, password)
71- enlist_nodes_from_mscm.apply_async(queue=self.uuid, args=args)
72+ try:
73+ client = getClientFor(self.uuid, timeout=1)
74+ except NoConnectionsAvailable:
75+ # No connection to the cluster so we can't do anything. We
76+ # let the caller handle the error, since we don't want to
77+ # just drop it.
78+ raise
79+ else:
80+ return client(
81+ EnlistNodesFromMSCM, host=host, username=username,
82+ password=password)
83
84=== modified file 'src/maasserver/models/tests/test_nodegroup.py'
85--- src/maasserver/models/tests/test_nodegroup.py 2014-09-10 16:01:38 +0000
86+++ src/maasserver/models/tests/test_nodegroup.py 2014-09-11 11:22:16 +0000
87@@ -49,6 +49,7 @@
88 from provisioningserver.rpc.cluster import (
89 AddSeaMicro15k,
90 AddVirsh,
91+ EnlistNodesFromMSCM,
92 ImportBootImages,
93 )
94 from provisioningserver.rpc.exceptions import NoConnectionsAvailable
95@@ -513,3 +514,52 @@
96 self.assertRaises(
97 NoConnectionsAvailable, nodegroup.add_seamicro15k,
98 mac, username, password, power_control)
99+
100+ def test_enlist_nodes_from_mscm_end_to_end(self):
101+ nodegroup = factory.make_NodeGroup(status=NODEGROUP_STATUS.ACCEPTED)
102+
103+ self.useFixture(RegionEventLoopFixture("rpc"))
104+ self.useFixture(RunningEventLoopFixture())
105+ fixture = self.useFixture(MockLiveRegionToClusterRPCFixture())
106+ protocol = fixture.makeCluster(nodegroup, EnlistNodesFromMSCM)
107+ protocol.EnlistNodesFromMSCM.return_value = defer.succeed({})
108+
109+ host = factory.make_name('host')
110+ username = factory.make_name('user')
111+ password = factory.make_name('password')
112+ nodegroup.enlist_nodes_from_mscm(
113+ host, username, password).wait(10)
114+
115+ self.expectThat(
116+ protocol.EnlistNodesFromMSCM,
117+ MockCalledOnceWith(
118+ ANY, host=host, username=username, password=password))
119+
120+ def test_enlist_nodes_from_mscm_calls_client_with_resource_endpoint(self):
121+ getClientFor = self.patch(nodegroup_module, 'getClientFor')
122+ client = getClientFor.return_value
123+ nodegroup = factory.make_NodeGroup()
124+
125+ host = factory.make_name('host')
126+ username = factory.make_name('user')
127+ password = factory.make_name('password')
128+ nodegroup.enlist_nodes_from_mscm(
129+ host, username, password).wait(10)
130+
131+ self.expectThat(
132+ client,
133+ MockCalledOnceWith(
134+ EnlistNodesFromMSCM, host=host, username=username,
135+ password=password))
136+
137+ def test_enlist_nodes_from_mscm_raises_if_no_connection_to_cluster(self):
138+ getClientFor = self.patch(nodegroup_module, 'getClientFor')
139+ getClientFor.side_effect = NoConnectionsAvailable()
140+ nodegroup = factory.make_NodeGroup()
141+
142+ host = factory.make_name('host')
143+ username = factory.make_name('user')
144+ password = factory.make_name('password')
145+ self.assertRaises(
146+ NoConnectionsAvailable, nodegroup.enlist_nodes_from_mscm,
147+ host, username, password)
148
149=== modified file 'src/provisioningserver/rpc/cluster.py'
150--- src/provisioningserver/rpc/cluster.py 2014-09-10 16:44:28 +0000
151+++ src/provisioningserver/rpc/cluster.py 2014-09-11 11:22:16 +0000
152@@ -377,3 +377,17 @@
153 errors = {
154 exceptions.NoIPFoundForMACAddress: b"NoIPFoundForMACAddress",
155 }
156+
157+
158+class EnlistNodesFromMSCM(amp.Command):
159+ """Probe for and enlist mscm machines attached to the cluster.
160+
161+ :since: 1.7
162+ """
163+ arguments = [
164+ (b"host", amp.Unicode()),
165+ (b"username", amp.Unicode()),
166+ (b"password", amp.Unicode()),
167+ ]
168+ response = []
169+ errors = {}
170
171=== modified file 'src/provisioningserver/rpc/clusterservice.py'
172--- src/provisioningserver/rpc/clusterservice.py 2014-09-10 23:00:52 +0000
173+++ src/provisioningserver/rpc/clusterservice.py 2014-09-11 11:22:16 +0000
174@@ -29,6 +29,7 @@
175 ArchitectureRegistry,
176 PowerTypeRegistry,
177 )
178+from provisioningserver.drivers.hardware.mscm import probe_and_enlist_mscm
179 from provisioningserver.drivers.hardware.seamicro import (
180 probe_seamicro15k_and_enlist,
181 )
182@@ -266,6 +267,16 @@
183 raise exceptions.NoIPFoundForMACAddress(message)
184 return {}
185
186+ @cluster.EnlistNodesFromMSCM.responder
187+ def enlist_nodes_from_mscm(self, host, username, password):
188+ """enlist_nodes_from_mscm()
189+
190+ Implemention of
191+ :py:class:`~provisioningserver.rpc.cluster.EnlistNodesFromMSCM`.
192+ """
193+ probe_and_enlist_mscm(host, username, password)
194+ return {}
195+
196
197 @implementer(IConnection)
198 class ClusterClient(Cluster):
199
200=== modified file 'src/provisioningserver/rpc/tests/test_clusterservice.py'
201--- src/provisioningserver/rpc/tests/test_clusterservice.py 2014-09-10 23:00:52 +0000
202+++ src/provisioningserver/rpc/tests/test_clusterservice.py 2014-09-11 11:22:16 +0000
203@@ -1256,3 +1256,30 @@
204 probe_seamicro15k_and_enlist, MockCalledOnceWith(
205 find_ip_via_arp.return_value, username, password,
206 power_control=power_control))
207+
208+
209+class TestClusterProtocol_EnlistNodesFromMSCM(MAASTestCase):
210+
211+ def test__is_registered(self):
212+ protocol = Cluster()
213+ responder = protocol.locateResponder(
214+ cluster.EnlistNodesFromMSCM.commandName)
215+ self.assertIsNot(responder, None)
216+
217+ def test__calls_probe_and_enlist_mscm(self):
218+ probe_and_enlist_mscm = self.patch_autospec(
219+ clusterservice, 'probe_and_enlist_mscm')
220+
221+ host = factory.make_name('host')
222+ username = factory.make_name('user')
223+ password = factory.make_name('password')
224+
225+ call_responder(Cluster(), cluster.EnlistNodesFromMSCM, {
226+ 'host': host,
227+ 'username': username,
228+ 'password': password,
229+ })
230+
231+ self.assertThat(
232+ probe_and_enlist_mscm, MockCalledOnceWith(
233+ host, username, password))
234
235=== modified file 'src/provisioningserver/tasks.py'
236--- src/provisioningserver/tasks.py 2014-09-10 17:00:43 +0000
237+++ src/provisioningserver/tasks.py 2014-09-11 11:22:16 +0000
238@@ -42,7 +42,6 @@
239 set_up_options_conf,
240 setup_rndc,
241 )
242-from provisioningserver.drivers.hardware.mscm import probe_and_enlist_mscm
243 from provisioningserver.drivers.hardware.ucsm import probe_and_enlist_ucsm
244 from provisioningserver.logger import get_maas_logger
245
246@@ -309,11 +308,3 @@
247 def enlist_nodes_from_ucsm(url, username, password):
248 """ See `maasserver.api.NodeGroupHandler.enlist_nodes_from_ucsm`. """
249 probe_and_enlist_ucsm(url, username, password)
250-
251-
252-@task
253-@log_task_events()
254-@log_exception_text
255-def enlist_nodes_from_mscm(host, username, password):
256- """ See `maasserver.api.NodeGroupHandler.enlist_nodes_from_mscm`. """
257- probe_and_enlist_mscm(host, username, password)
258
259=== modified file 'src/provisioningserver/tests/test_tasks.py'
260--- src/provisioningserver/tests/test_tasks.py 2014-09-10 17:00:43 +0000
261+++ src/provisioningserver/tests/test_tasks.py 2014-09-11 11:22:16 +0000
262@@ -55,7 +55,6 @@
263 )
264 from provisioningserver.tags import MissingCredentials
265 from provisioningserver.tasks import (
266- enlist_nodes_from_mscm,
267 enlist_nodes_from_ucsm,
268 refresh_secrets,
269 report_boot_images,
270@@ -403,14 +402,3 @@
271 mock = self.patch(tasks, 'probe_and_enlist_ucsm')
272 enlist_nodes_from_ucsm(url, username, password)
273 self.assertThat(mock, MockCalledOnceWith(url, username, password))
274-
275-
276-class TestAddMSCM(PservTestCase):
277-
278- def test_enlist_nodes_from_mscm(self):
279- host = 'host'
280- username = 'username'
281- password = 'password'
282- mock = self.patch(tasks, 'probe_and_enlist_mscm')
283- enlist_nodes_from_mscm(host, username, password)
284- self.assertThat(mock, MockCalledOnceWith(host, username, password))