Merge lp:~rvb/maas/bug-1336709 into lp:~maas-committers/maas/trunk

Proposed by Raphaël Badin
Status: Merged
Approved by: Raphaël Badin
Approved revision: no longer in the source branch.
Merged at revision: 2498
Proposed branch: lp:~rvb/maas/bug-1336709
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 91 lines (+12/-7)
6 files modified
src/maasserver/models/macaddress.py (+1/-0)
src/maasserver/models/staticipaddress.py (+1/-1)
src/maasserver/models/tests/test_macaddress.py (+4/-2)
src/maasserver/models/tests/test_node.py (+2/-1)
src/maasserver/models/tests/test_staticipaddress.py (+2/-2)
src/maasserver/tests/test_api_node.py (+2/-1)
To merge this branch: bzr merge lp:~rvb/maas/bug-1336709
Reviewer Review Type Date Requested Status
Julian Edwards (community) Approve
Review via email: mp+225281@code.launchpad.net

Commit message

MACAddress.claim_static_ip isn't meant to deal with the USER_RESERVED alloc_type.

Description of the change

Drive-by fix: fix lint in src/maasserver/models/tests/test_staticipaddress.py.

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

I also hit the problem in maasserver.tests.test_api_node.TestStickyIP.test_claim_sticky_ip_address_rtns_error_if_clashing_type_exists

Revision history for this message
Julian Edwards (julian-edwards) wrote :

Conditionally approved with some changes, otherwise I'd have landed it already.

review: Approve
Revision history for this message
Raphaël Badin (rvb) :
Revision history for this message
MAAS Lander (maas-lander) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

Another affected test: maasserver.models.tests.test_node.NodeTest.test_delete_node_also_deletes_related_static_IPs

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

> I also hit the problem in maasserver.tests.test_api_node.TestStickyIP.test_cla
> im_sticky_ip_address_rtns_error_if_clashing_type_exists

Done.

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

> Another affected test: maasserver.models.tests.test_node.NodeTest.test_delete_
> node_also_deletes_related_static_IPs

Done.

Revision history for this message
Julian Edwards (julian-edwards) wrote :

Thanks for fixing my upper-decker!

On 02/07/14 20:41, Raphaël Badin wrote:
>
>
> Diff comments:
>
>> === modified file 'src/maasserver/models/macaddress.py'
>> --- src/maasserver/models/macaddress.py 2014-06-12 10:08:51 +0000
>> +++ src/maasserver/models/macaddress.py 2014-07-02 10:18:44 +0000
>> @@ -106,6 +106,9 @@
>> :raises: StaticIPAddressTypeClash if an IP already exists with a
>> different type.
>> """
>> + if alloc_type == IPADDRESS_TYPE.USER_RESERVED:
>> + raise AssertionError(
>> + "Can't claim a static IP for USER_RESERVED alloc_type")
>> # Avoid circular import.
>
>> Did you write and run the test before adding this code?
>
> Yes I did.
>
>> Because the test would have passed
>
> No it would not. That's precisely why I added a check for the exception message.

Well done on chopping out context from my original statement to make me
look stupid here. ;)

My actual words were:
"Because the test would have passed (with the exception of the exception
text)"

meaning, all this is doing is raising the same exception with different
text. As I said on IRC:

> Anyway, I agree that it's probably not worth bothering with adding a new assertion because it's a programming error and so the only really important information would be the stacktrace.

This is the more important thing here, the new assertion is not adding
any value.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/models/macaddress.py'
2--- src/maasserver/models/macaddress.py 2014-06-12 10:08:51 +0000
3+++ src/maasserver/models/macaddress.py 2014-07-02 10:47:59 +0000
4@@ -97,6 +97,7 @@
5 the host boots it is too late.
6
7 :param alloc_type: See :class:`StaticIPAddress`.alloc_type.
8+ This parameter musn't be IPADDRESS_TYPE.USER_RESERVED.
9 :return: A :class:`StaticIPAddress` object. Returns None if
10 the cluster_interface is not yet known, or the
11 static_ip_range_low/high values values are not set on the
12
13=== modified file 'src/maasserver/models/staticipaddress.py'
14--- src/maasserver/models/staticipaddress.py 2014-07-02 03:47:43 +0000
15+++ src/maasserver/models/staticipaddress.py 2014-07-02 10:47:59 +0000
16@@ -68,7 +68,7 @@
17 """
18 if alloc_type == IPADDRESS_TYPE.USER_RESERVED and user is None:
19 raise AssertionError(
20- "Must provide user for USER_RESERVED alloc_type")
21+ "Must provide user for USER_RESERVED alloc_type.")
22 if user is not None and alloc_type != IPADDRESS_TYPE.USER_RESERVED:
23 raise AssertionError(
24 "Must not provide user for USER_RESERVED alloc_type.")
25
26=== modified file 'src/maasserver/models/tests/test_macaddress.py'
27--- src/maasserver/models/tests/test_macaddress.py 2014-06-17 01:14:36 +0000
28+++ src/maasserver/models/tests/test_macaddress.py 2014-07-02 10:47:59 +0000
29@@ -115,7 +115,8 @@
30 def test_claim_static_ip_raises_if_clashing_type(self):
31 node = factory.make_node_with_mac_attached_to_nodegroupinterface()
32 mac = node.get_primary_mac()
33- iptype = factory.getRandomEnum(IPADDRESS_TYPE)
34+ iptype = factory.getRandomEnum(
35+ IPADDRESS_TYPE, but_not=[IPADDRESS_TYPE.USER_RESERVED])
36 iptype2 = factory.getRandomEnum(IPADDRESS_TYPE, but_not=[iptype])
37 mac.claim_static_ip(alloc_type=iptype)
38 self.assertRaises(
39@@ -125,7 +126,8 @@
40 def test_claim_static_ip_returns_existing_if_claiming_same_type(self):
41 node = factory.make_node_with_mac_attached_to_nodegroupinterface()
42 mac = node.get_primary_mac()
43- iptype = factory.getRandomEnum(IPADDRESS_TYPE)
44+ iptype = factory.getRandomEnum(
45+ IPADDRESS_TYPE, but_not=[IPADDRESS_TYPE.USER_RESERVED])
46 ip = mac.claim_static_ip(alloc_type=iptype)
47 self.assertEqual(
48 ip, mac.claim_static_ip(alloc_type=iptype))
49
50=== modified file 'src/maasserver/models/tests/test_node.py'
51--- src/maasserver/models/tests/test_node.py 2014-07-02 07:05:24 +0000
52+++ src/maasserver/models/tests/test_node.py 2014-07-02 10:47:59 +0000
53@@ -339,7 +339,8 @@
54 self.patch(Omshell, 'remove')
55 node = factory.make_node_with_mac_attached_to_nodegroupinterface()
56 primary_mac = node.get_primary_mac()
57- random_alloc_type = factory.getRandomEnum(IPADDRESS_TYPE)
58+ random_alloc_type = factory.getRandomEnum(
59+ IPADDRESS_TYPE, but_not=[IPADDRESS_TYPE.USER_RESERVED])
60 primary_mac.claim_static_ip(alloc_type=random_alloc_type)
61 node.delete()
62 self.assertItemsEqual([], StaticIPAddress.objects.all())
63
64=== modified file 'src/maasserver/models/tests/test_staticipaddress.py'
65--- src/maasserver/models/tests/test_staticipaddress.py 2014-07-02 03:42:42 +0000
66+++ src/maasserver/models/tests/test_staticipaddress.py 2014-07-02 10:47:59 +0000
67@@ -61,8 +61,8 @@
68 user=user, alloc_type=alloc_type)
69
70 def test_allocate_new_with_reserved_type_requires_a_user(self):
71- low, high = factory.make_ip_range()
72- self.assertRaises(
73+ low, high = factory.make_ip_range()
74+ self.assertRaises(
75 AssertionError, StaticIPAddress.objects.allocate_new, low, high,
76 alloc_type=IPADDRESS_TYPE.USER_RESERVED)
77
78
79=== modified file 'src/maasserver/tests/test_api_node.py'
80--- src/maasserver/tests/test_api_node.py 2014-06-27 03:48:14 +0000
81+++ src/maasserver/tests/test_api_node.py 2014-07-02 10:47:59 +0000
82@@ -972,7 +972,8 @@
83 self.become_admin()
84 node = factory.make_node_with_mac_attached_to_nodegroupinterface()
85 random_alloc_type = factory.getRandomEnum(
86- IPADDRESS_TYPE, but_not=[IPADDRESS_TYPE.STICKY])
87+ IPADDRESS_TYPE,
88+ but_not=[IPADDRESS_TYPE.STICKY, IPADDRESS_TYPE.USER_RESERVED])
89 node.get_primary_mac().claim_static_ip(alloc_type=random_alloc_type)
90 response = self.client.post(
91 self.get_node_uri(node), {'op': 'claim_sticky_ip_address'})