Merge lp:~ltrager/maas/allow_short_release_names into lp:~maas-committers/maas/trunk

Proposed by Lee Trager
Status: Merged
Approved by: Blake Rouse
Approved revision: no longer in the source branch.
Merged at revision: 4417
Proposed branch: lp:~ltrager/maas/allow_short_release_names
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 90 lines (+57/-1)
2 files modified
src/maasserver/forms.py (+27/-1)
src/maasserver/tests/test_forms_node.py (+30/-0)
To merge this branch: bzr merge lp:~ltrager/maas/allow_short_release_names
Reviewer Review Type Date Requested Status
Blake Rouse (community) Approve
Andres Rodriguez (community) Needs Fixing
Review via email: mp+275619@code.launchpad.net

Commit message

Accept short hand distro series names

Description of the change

Allow the user to specify short hand distro series names. For example if we have centos65 and centos70 passing distro_series=centos7 will set the distro_series to centos70. If multiple matches are found MAAS will do a reverse sort and pick the first match. This ensures that short hand will versioned series will always pick the latest. e.g with centos65, centos70, centos71 and given centos MAAS will pick centos71.

To post a comment you must log in.
Revision history for this message
Andres Rodriguez (andreserl) wrote :

Hi Lee,

Let me see if I understand this correctly. If we pas centos6 it will pick
centos 65, and if we pass centos7 on a system that has centos70 centos71 it
will pick the latest, centos71

On Saturday, October 24, 2015, Lee Trager <email address hidden> wrote:

> Lee Trager has proposed merging lp:~ltrager/maas/allow_short_release_names
> into lp:maas.
>
> Commit message:
> Accept short hand distro series names
>
> Requested reviews:
> MAAS Maintainers (maas-maintainers)
> Related bugs:
> Bug #1507359 in MAAS: "MAAS 1.9 CentOS image names and Juju streams
> disagree"
> https://bugs.launchpad.net/maas/+bug/1507359
>
> For more details, see:
>
> https://code.launchpad.net/~ltrager/maas/allow_short_release_names/+merge/275619
>
> Allow the user to specify short hand distro series names. For example if
> we have centos65 and centos70 passing distro_series=centos7 will set the
> distro_series to centos70. If multiple matches are found MAAS will do a
> reverse sort and pick the first match. This ensures that short hand will
> versioned series will always pick the latest. e.g with centos65, centos70,
> centos71 and given centos MAAS will pick centos71.
> --
> You are subscribed to branch lp:maas.
>

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

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

Yes, thats correct.

> Hi Lee,
>
> Let me see if I understand this correctly. If we pas centos6 it will pick
> centos 65, and if we pass centos7 on a system that has centos70 centos71 it
> will pick the latest, centos71
>
> On Saturday, October 24, 2015, Lee Trager <email address hidden> wrote:
>
> > Lee Trager has proposed merging lp:~ltrager/maas/allow_short_release_names
> > into lp:maas.
> >
> > Commit message:
> > Accept short hand distro series names
> >
> > Requested reviews:
> > MAAS Maintainers (maas-maintainers)
> > Related bugs:
> > Bug #1507359 in MAAS: "MAAS 1.9 CentOS image names and Juju streams
> > disagree"
> > https://bugs.launchpad.net/maas/+bug/1507359
> >
> > For more details, see:
> >
> > https://code.launchpad.net/~ltrager/maas/allow_short_release_names/+merge/27
> 5619
> >
> > Allow the user to specify short hand distro series names. For example if
> > we have centos65 and centos70 passing distro_series=centos7 will set the
> > distro_series to centos70. If multiple matches are found MAAS will do a
> > reverse sort and pick the first match. This ensures that short hand will
> > versioned series will always pick the latest. e.g with centos65, centos70,
> > centos71 and given centos MAAS will pick centos71.
> > --
> > You are subscribed to branch lp:maas.
> >
>
>
> --
> Andres Rodriguez (RoAkSoAx)
> Ubuntu Server Developer
> MSc. Telecom & Networking
> Systems Engineer

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

Comments inline.

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

I've changed the varialbe name to possible_short_names, let me know if you want something else. I've also modifed the patch to only accept short names for non-Ubuntu OSes. So centos7 will give you centos70 but trust will fail.

I changed series to release['name'] because if you look in set_distro_series(src/maasserver/forms.py:681) it accepts the argument series then passes that to find_osystem_and_release_from_release_name which validates the given release is available and returns two dictionaries describing the osystem and release. Previously all we were really doing was finding the osystem name and the series name never changed. Now we're allowing the series name to change so we need to use the found value, not the value passed in.

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

You should add a unit test for the ubuntu code, to make sure that it doesn't accept the startswith for Ubuntu releases.

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

I've added a test to ensure that short names can't be used with Ubuntu releases.

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

Thanks for adding that test.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/forms.py'
2--- src/maasserver/forms.py 2015-10-23 22:06:42 +0000
3+++ src/maasserver/forms.py 2015-10-27 02:41:10 +0000
4@@ -364,10 +364,36 @@
5 def find_osystem_and_release_from_release_name(name):
6 """Return os and release for the given release name."""
7 osystems = list_all_usable_osystems()
8+ possible_short_names = []
9 for osystem in osystems:
10 for release in osystem['releases']:
11 if release['name'] == name:
12 return osystem, release
13+ elif osystem['name'] == name:
14+ # If the given release matches the osystem name add it to
15+ # our list of possibilities. This allows a user to specify
16+ # Ubuntu and get the latest release available.
17+ possible_short_names.append({
18+ 'osystem': osystem,
19+ 'release': release})
20+ elif (osystem['name'] != "ubuntu"
21+ and release['name'].startswith(name)):
22+ # Check if the given name is a shortened version of a known
23+ # name. e.g centos7 for centos70. We don't allow short names
24+ # for Ubuntu releases
25+ possible_short_names.append({
26+ 'osystem': osystem,
27+ 'release': release})
28+ if len(possible_short_names) > 0:
29+ # Do a reverse sort of all the possibilities and pick the top one.
30+ # This allows a user to do a short hand with versioning to pick the
31+ # latest release. e.g we have centos70, centos71 given centos7 this
32+ # will pick centos71
33+ sorted_list = sorted(
34+ possible_short_names,
35+ key=lambda os_release: os_release['release']['name'],
36+ reverse=True)
37+ return sorted_list[0]['osystem'], sorted_list[0]['release']
38 return None, None
39
40
41@@ -671,7 +697,7 @@
42 self.data['osystem'] = osystem['name']
43 self.data['distro_series'] = '%s/%s%s' % (
44 osystem['name'],
45- series,
46+ release['name'],
47 key_required,
48 )
49 else:
50
51=== modified file 'src/maasserver/tests/test_forms_node.py'
52--- src/maasserver/tests/test_forms_node.py 2015-10-21 23:36:45 +0000
53+++ src/maasserver/tests/test_forms_node.py 2015-10-27 02:41:10 +0000
54@@ -205,6 +205,36 @@
55 self.assertFalse(form.is_valid())
56 self.assertItemsEqual(['distro_series'], form._errors.keys())
57
58+ def test_set_distro_series_accepts_short_distro_series(self):
59+ self.client_log_in()
60+ node = factory.make_Node(owner=self.logged_in_user)
61+ release = factory.make_name('release')
62+ make_usable_osystem(
63+ self, releases=[release + '6', release + '0', release + '3'])
64+ form = NodeForm(data={
65+ 'hostname': factory.make_name('host'),
66+ 'architecture': make_usable_architecture(self),
67+ },
68+ instance=node)
69+ form.set_distro_series(release)
70+ form.save()
71+ self.assertEquals(release + '6', node.distro_series)
72+
73+ def test_set_distro_series_doesnt_allow_short_ubuntu_series(self):
74+ self.client_log_in()
75+ node = factory.make_Node(owner=self.logged_in_user)
76+ make_usable_osystem(
77+ self,
78+ osystem_name='ubuntu',
79+ releases=['trusty'])
80+ form = NodeForm(data={
81+ 'hostname': factory.make_name('host'),
82+ 'architecture': make_usable_architecture(self),
83+ },
84+ instance=node)
85+ form.set_distro_series('trust')
86+ self.assertFalse(form.is_valid())
87+
88 def test_starts_with_default_distro_series(self):
89 self.client_log_in()
90 node = factory.make_Node(owner=self.logged_in_user)