Merge ~ltrager/maas:lp1787621 into maas:master

Proposed by Lee Trager
Status: Merged
Approved by: Lee Trager
Approved revision: 475fd4d11564218a4c599d46f6f1ff7f24f6d3d0
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~ltrager/maas:lp1787621
Merge into: maas:master
Diff against target: 200 lines (+19/-70)
4 files modified
src/maasserver/clusterrpc/osystems.py (+1/-17)
src/maasserver/clusterrpc/tests/test_osystems.py (+1/-42)
src/maasserver/websockets/handlers/bootresource.py (+14/-8)
src/maasserver/websockets/handlers/tests/test_bootresource.py (+3/-3)
Reviewer Review Type Date Requested Status
MAAS Lander Needs Fixing
Blake Rouse (community) Approve
Review via email: mp+354673@code.launchpad.net

Commit message

LP: #1787621 - Retrieve undefined release title directly from OS registry.

MAAS tries to retrieve the resource title from the database. If it has not
been defined in the configured stream or by user during custom image upload
MAAS asks the OS driver to return a release. Each OS driver does this through
string manipulation and does not need on disk access to the OS images. As
such it is safe to call the OS driver directly from the region and not use an
RPC call to all rack controllers.

To post a comment you must log in.
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b lp1787621 lp:~ltrager/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 2f8bf60d361b15e0c442b65fa2f7418a1218cded

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

Looks good, except for the question I have inline.

review: Needs Information
Revision history for this message
Lee Trager (ltrager) wrote :

Thanks for the review, answered your question inline.

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

uhmmm I don't like hardocing this... Why is it only for Ubuntu Core in the
first place? Why not for other OS?

On Tue, Sep 11, 2018 at 11:54 AM, Lee Trager <email address hidden>
wrote:

> Thanks for the review, answered your question inline.
>
> Diff comments:
>
> > diff --git a/src/maasserver/websockets/handlers/bootresource.py
> b/src/maasserver/websockets/handlers/bootresource.py
> > index 4183f22..78315b2 100644
> > --- a/src/maasserver/websockets/handlers/bootresource.py
> > +++ b/src/maasserver/websockets/handlers/bootresource.py
> > @@ -286,7 +286,8 @@ class BootResourceHandler(Handler):
> > if 'title' in image.extra and image.extra != '':
> > title = image.extra['title']
> > else:
> > - title = get_os_release_title(image.os, image.release)
> > + osystem = OperatingSystemRegistry['ubuntu-core']
>
> This is a method only for Ubuntu Core(format_ubuntu_core-images) It
> iterates over BootSourceCache.objects.filter(os='ubuntu-core') so we know
> it will always be ubuntu-core.
>
> > + title = osystem.get_release_title(image.release)
> > if title is None:
> > title = '%s/%s' % (image.os, image.release)
> > images.append({
>
>
> --
> https://code.launchpad.net/~ltrager/maas/+git/maas/+merge/354673
> You are reviewing the proposed merge of ~ltrager/maas:lp1787621 into
> maas:master.
>

--
Andres Rodriguez
Engineering Manager, MAAS
Canonical USA, Inc.

Revision history for this message
Lee Trager (ltrager) wrote :

Ubuntu Core is hard coded as its used in a method specifically for Ubuntu Core. The images that method processes comes from BootSourceCache.objects.filter(os='ubuntu-core').

As discussed in stand up I've removed the unused RPC code on the region.

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

Thanks for the explanation, and for the removal of the unused code.

review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b lp1787621 lp:~ltrager/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci-jenkins.internal:8080/job/maas/job/branch-tester/3898/console
COMMIT: d6f0c9c02fae4706352d5e20482d1cc7c8a33909

review: Needs Fixing
Revision history for this message
MAAS Lander (maas-lander) wrote :
Revision history for this message
Andres Rodriguez (andreserl) wrote :

Can you please fix this for landing?

+ cd /run/build/maas
+ sudo -u ubuntu -E -H make lint
src/maasserver/clusterrpc/osystems.py:24:1: F401 'provisioningserver.rpc.cluster.GetOSReleaseTitle' imported but unused
Makefile:356: recipe for target 'lint-py' failed
make: *** [lint-py] Error 123
[Pipeline] }

~ltrager/maas:lp1787621 updated
475fd4d... by Lee Trager

Fix lint

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/clusterrpc/osystems.py b/src/maasserver/clusterrpc/osystems.py
2index 9ae6af6..e126af4 100644
3--- a/src/maasserver/clusterrpc/osystems.py
4+++ b/src/maasserver/clusterrpc/osystems.py
5@@ -1,4 +1,4 @@
6-# Copyright 2014-2016 Canonical Ltd. This software is licensed under the
7+# Copyright 2014-2018 Canonical Ltd. This software is licensed under the
8 # GNU Affero General Public License version 3 (see the file LICENSE).
9
10 """Obtain OS information from clusters."""
11@@ -22,7 +22,6 @@ from maasserver.rpc import (
12 from maasserver.utils import async
13 from maasserver.utils.orm import get_one
14 from provisioningserver.rpc.cluster import (
15- GetOSReleaseTitle,
16 GetPreseedData,
17 ListOperatingSystems,
18 ValidateLicenseKey,
19@@ -82,21 +81,6 @@ def gen_all_known_operating_systems():
20
21
22 @synchronous
23-def get_os_release_title(osystem, release):
24- """Get the title for the operating systems release."""
25- title = ""
26- responses = async.gather(
27- partial(client, GetOSReleaseTitle, osystem=osystem, release=release)
28- for client in getAllClients())
29- for response in suppress_failures(responses):
30- if response["title"] != "":
31- title = response["title"]
32- if title == "":
33- return None
34- return title
35-
36-
37-@synchronous
38 def get_preseed_data(preseed_type, node, token, metadata_url):
39 """Obtain optional preseed data for this OS, preseed type, and node.
40
41diff --git a/src/maasserver/clusterrpc/tests/test_osystems.py b/src/maasserver/clusterrpc/tests/test_osystems.py
42index e07d6ad..c2ad218 100644
43--- a/src/maasserver/clusterrpc/tests/test_osystems.py
44+++ b/src/maasserver/clusterrpc/tests/test_osystems.py
45@@ -1,4 +1,4 @@
46-# Copyright 2014-2016 Canonical Ltd. This software is licensed under the
47+# Copyright 2014-2018 Canonical Ltd. This software is licensed under the
48 # GNU Affero General Public License version 3 (see the file LICENSE).
49
50 """Tests for the `osystems` module."""
51@@ -12,7 +12,6 @@ from collections import (
52
53 from maasserver.clusterrpc.osystems import (
54 gen_all_known_operating_systems,
55- get_os_release_title,
56 get_preseed_data,
57 validate_license_key,
58 )
59@@ -155,46 +154,6 @@ class TestGenAllKnownOperatingSystems(MAASServerTestCase):
60 gen_all_known_operating_systems())
61
62
63-class TestGetOSReleaseTitle(MAASServerTestCase):
64- """Tests for `get_os_release_title`."""
65-
66- def test_ignores_failures_when_talking_to_clusters(self):
67- factory.make_RackController()
68- factory.make_RackController()
69- factory.make_RackController()
70- self.useFixture(RunningClusterRPCFixture())
71-
72- title = factory.make_name('title')
73- clients = getAllClients()
74- for index, client in enumerate(clients):
75- callRemote = self.patch(client._conn, "callRemote")
76- if index == 0:
77- # The first client found returns dummy title.
78- example = {"title": title}
79- callRemote.return_value = succeed(example)
80- else:
81- # All clients but the first raise an exception.
82- callRemote.side_effect = ZeroDivisionError()
83-
84- # The only title to get through is that from the first. The
85- # failures arising from communicating with the other clusters have all
86- # been suppressed.
87- self.assertEqual(
88- title,
89- get_os_release_title("bogus-os", "bogus-release"))
90-
91- def test_returns_None_if_title_is_blank(self):
92- factory.make_RackController()
93- self.useFixture(RunningClusterRPCFixture())
94-
95- clients = getAllClients()
96- for index, client in enumerate(clients):
97- callRemote = self.patch(client._conn, "callRemote")
98- example = {"title": ""}
99- callRemote.return_value = succeed(example)
100- self.assertIsNone(get_os_release_title("bogus-os", "bogus-release"))
101-
102-
103 class TestGetPreseedData(MAASServerTestCase):
104 """Tests for `get_preseed_data`."""
105
106diff --git a/src/maasserver/websockets/handlers/bootresource.py b/src/maasserver/websockets/handlers/bootresource.py
107index 4183f22..78315b2 100644
108--- a/src/maasserver/websockets/handlers/bootresource.py
109+++ b/src/maasserver/websockets/handlers/bootresource.py
110@@ -1,4 +1,4 @@
111-# Copyright 2016-2017 Canonical Ltd. This software is licensed under the
112+# Copyright 2016-2018 Canonical Ltd. This software is licensed under the
113 # GNU Affero General Public License version 3 (see the file LICENSE).
114
115 """The BootResource handler for the WebSocket connection."""
116@@ -26,7 +26,6 @@ from maasserver.clusterrpc.boot_images import (
117 get_common_available_boot_images,
118 is_import_boot_images_running,
119 )
120-from maasserver.clusterrpc.osystems import get_os_release_title
121 from maasserver.enum import (
122 BOOT_RESOURCE_TYPE,
123 NODE_STATUS,
124@@ -53,6 +52,7 @@ from provisioningserver.config import (
125 DEFAULT_IMAGES_URL,
126 DEFAULT_KEYRINGS_PATH,
127 )
128+from provisioningserver.drivers.osystem import OperatingSystemRegistry
129 from provisioningserver.import_images.download_descriptions import (
130 download_all_image_descriptions,
131 image_passes_filter,
132@@ -286,7 +286,8 @@ class BootResourceHandler(Handler):
133 if 'title' in image.extra and image.extra != '':
134 title = image.extra['title']
135 else:
136- title = get_os_release_title(image.os, image.release)
137+ osystem = OperatingSystemRegistry['ubuntu-core']
138+ title = osystem.get_release_title(image.release)
139 if title is None:
140 title = '%s/%s' % (image.os, image.release)
141 images.append({
142@@ -306,11 +307,13 @@ class BootResourceHandler(Handler):
143 Q(os='ubuntu') | Q(os='ubuntu-core')).filter(bootloader_type=None)
144 for image in qs:
145 resource = self.get_matching_resource_for_image(resources, image)
146+ title = None
147 if 'title' in image.extra and image.extra != '':
148 title = image.extra['title']
149- else:
150- title = get_os_release_title(image.os, image.release)
151- if title is None:
152+ elif image.os in OperatingSystemRegistry:
153+ osystem = OperatingSystemRegistry[image.os]
154+ title = osystem.get_release_title(image.release)
155+ if not title:
156 title = '%s/%s' % (image.os, image.release)
157 images.append({
158 'name': '%s/%s/%s/%s' % (
159@@ -432,8 +435,11 @@ class BootResourceHandler(Handler):
160 if resource.name.startswith('ubuntu/'):
161 return format_ubuntu_distro_series(series)
162 else:
163- title = get_os_release_title(os, series)
164- if title is None:
165+ title = None
166+ if os in OperatingSystemRegistry:
167+ osystem = OperatingSystemRegistry[os]
168+ title = osystem.get_release_title(series)
169+ if not title:
170 return resource.name
171 else:
172 return title
173diff --git a/src/maasserver/websockets/handlers/tests/test_bootresource.py b/src/maasserver/websockets/handlers/tests/test_bootresource.py
174index fa71918..ebaefe8 100644
175--- a/src/maasserver/websockets/handlers/tests/test_bootresource.py
176+++ b/src/maasserver/websockets/handlers/tests/test_bootresource.py
177@@ -1,4 +1,4 @@
178-# Copyright 2016-2017 Canonical Ltd. This software is licensed under the
179+# Copyright 2016-2018 Canonical Ltd. This software is licensed under the
180 # GNU Affero General Public License version 3 (see the file LICENSE).
181
182 """Tests for `maasserver.websockets.handlers.bootresource`"""
183@@ -629,7 +629,7 @@ class TestBootResourcePoll(MAASServerTestCase, PatchOSInfoMixin):
184 self.assertEquals([{
185 'name': '%s/%s/%s/%s' % (
186 cache.os, cache.arch, cache.subarch, cache.release),
187- 'title': '%s/%s' % (cache.os, cache.release),
188+ 'title': cache.release,
189 'checked': False,
190 'deleted': False,
191 }], ubuntu_core_images)
192@@ -647,7 +647,7 @@ class TestBootResourcePoll(MAASServerTestCase, PatchOSInfoMixin):
193 self.assertEquals([{
194 'name': '%s/%s/%s/%s' % (
195 cache.os, cache.arch, cache.subarch, cache.release),
196- 'title': '%s/%s' % (cache.os, cache.release),
197+ 'title': cache.release,
198 'checked': True,
199 'deleted': False,
200 }], ubuntu_core_images)

Subscribers

People subscribed via source and target branches