Merge lp:~allenap/maas/zone-sort-by-name--bug-1262160 into lp:~maas-committers/maas/trunk

Proposed by Gavin Panella
Status: Merged
Approved by: Gavin Panella
Approved revision: no longer in the source branch.
Merged at revision: 1801
Proposed branch: lp:~allenap/maas/zone-sort-by-name--bug-1262160
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 30 lines (+2/-7)
2 files modified
src/maasserver/models/zone.py (+1/-0)
src/maasserver/tests/test_views_nodes.py (+1/-7)
To merge this branch: bzr merge lp:~allenap/maas/zone-sort-by-name--bug-1262160
Reviewer Review Type Date Requested Status
Jeroen T. Vermeulen (community) Approve
Review via email: mp+199460@code.launchpad.net

Commit message

Sort nodes by zone name instead of zone ID.

To post a comment you must log in.
Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

That easy? What a relief! Django has its good sides, eh?

Instead of hard-coding zone names in the test, I'd just create a slightly longer list and let factory.make_zone() come up with names...

    zones = [factory.make_zone() for _ in range(5)]

The longer list will make it most likely that failures to sort will be exposed.

review: Approve
Revision history for this message
Gavin Panella (allenap) wrote :

> That easy? What a relief! Django has its good sides, eh?
>
> Instead of hard-coding zone names in the test, I'd just create a slightly
> longer list and let factory.make_zone() come up with names...
>
> zones = [factory.make_zone() for _ in range(5)]
>
> The longer list will make it most likely that failures to sort will be
> exposed.

Okay, I'll do that. There's the possibility of false success, but it's low.

I'll also remove the TODO you added about this; I missed that.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/maasserver/models/zone.py'
--- src/maasserver/models/zone.py 2013-12-18 12:27:33 +0000
+++ src/maasserver/models/zone.py 2013-12-18 13:46:10 +0000
@@ -41,6 +41,7 @@
41 """Needed for South to recognize this model."""41 """Needed for South to recognize this model."""
42 verbose_name = "Availability zone"42 verbose_name = "Availability zone"
43 verbose_name_plural = "Availability zones"43 verbose_name_plural = "Availability zones"
44 ordering = ["name"]
4445
45 name = CharField(46 name = CharField(
46 max_length=256, unique=True, editable=True,47 max_length=256, unique=True, editable=True,
4748
=== modified file 'src/maasserver/tests/test_views_nodes.py'
--- src/maasserver/tests/test_views_nodes.py 2013-12-18 11:16:29 +0000
+++ src/maasserver/tests/test_views_nodes.py 2013-12-18 13:46:10 +0000
@@ -181,13 +181,7 @@
181 if link.startswith('/nodes/node')])181 if link.startswith('/nodes/node')])
182182
183 def test_node_list_sorts_by_zone(self):183 def test_node_list_sorts_by_zone(self):
184 # TODO JeroenVermeulen 2013-12-18, bug=1262160: This is cheating.184 zones = [factory.make_zone() for _ in range(5)]
185 # Sorting by zone should sort by zone name, but it actually sorts
186 # by zone ID. Make this test pass with the default random names!
187 zones = [
188 factory.make_zone(name='z-%d' % counter)
189 for counter in range(3)
190 ]
191 nodes = [factory.make_node(zone=zone) for zone in zones]185 nodes = [factory.make_node(zone=zone) for zone in zones]
192186
193 # First check the ascending sort order187 # First check the ascending sort order