Merge lp:~mpontillo/maas/spaces-api-backward-compat--bug-1656208 into lp:~maas-committers/maas/trunk

Proposed by Mike Pontillo
Status: Superseded
Proposed branch: lp:~mpontillo/maas/spaces-api-backward-compat--bug-1656208
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 94 lines (+39/-24)
2 files modified
src/maasserver/api/spaces.py (+3/-24)
src/maasserver/api/tests/test_spaces.py (+36/-0)
To merge this branch: bzr merge lp:~mpontillo/maas/spaces-api-backward-compat--bug-1656208
Reviewer Review Type Date Requested Status
Brendan Donegan (community) Needs Fixing
Review via email: mp+314762@code.launchpad.net

This proposal has been superseded by a proposal from 2017-01-17.

Commit message

Fix backward compatibility for spaces endpoint.

Drive-by fix to add the missing `resource_uri`.

To post a comment you must log in.
Revision history for this message
Brendan Donegan (brendan-donegan) wrote :

This CI run using this branch still fails, apparently for the same reason - http://162.213.35.104:8080/job/juju_bootstrap_fix/1

review: Needs Fixing
Revision history for this message
Mike Pontillo (mpontillo) wrote :

Actually, this failure is a separate bug. I filed it here:

https://bugs.launchpad.net/bugs/1656717

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/api/spaces.py'
2--- src/maasserver/api/spaces.py 2017-01-04 19:37:16 +0000
3+++ src/maasserver/api/spaces.py 2017-01-14 02:48:00 +0000
4@@ -18,6 +18,7 @@
5
6
7 DISPLAYED_SPACE_FIELDS = (
8+ 'resource_uri',
9 'id',
10 'name',
11 'vlans',
12@@ -78,33 +79,11 @@
13
14 @classmethod
15 def subnets(cls, space):
16- """Return an abbreviated view of each subnet in the space."""
17- subnets = Subnet.objects.filter(vlan__space=space)
18- return [
19- {
20- "id": subnet.id,
21- "name": subnet.name,
22- "cidr": str(subnet.cidr),
23- "vlan": subnet.vlan_id
24- }
25- for subnet in subnets
26- ]
27+ return Subnet.objects.filter(vlan__space=space)
28
29 @classmethod
30 def vlans(cls, space):
31- """Return an abbreviated view of each VLAN in the space."""
32- return [
33- {
34- "id": vlan.id,
35- "vid": vlan.vid,
36- "name": vlan.name,
37- "fabric": {
38- "id": vlan.fabric.id,
39- "name": vlan.fabric.name,
40- }
41- }
42- for vlan in space.vlan_set.all()
43- ]
44+ return space.vlan_set.all()
45
46 def read(self, request, id):
47 """Read space.
48
49=== modified file 'src/maasserver/api/tests/test_spaces.py'
50--- src/maasserver/api/tests/test_spaces.py 2016-05-24 21:29:53 +0000
51+++ src/maasserver/api/tests/test_spaces.py 2017-01-14 02:48:00 +0000
52@@ -121,6 +121,42 @@
53 ]
54 self.assertItemsEqual(subnet_ids, parsed_subnets)
55
56+ def test_includes_vlan_objects(self):
57+ space = factory.make_Space()
58+ vlan = factory.make_VLAN(space=space)
59+ uri = get_space_uri(space)
60+ response = self.client.get(uri)
61+ self.assertEqual(
62+ http.client.OK, response.status_code, response.content)
63+ parsed_space = json.loads(
64+ response.content.decode(settings.DEFAULT_CHARSET))
65+ parsed_vlan = parsed_space['vlans'][0]
66+ self.assertThat(parsed_vlan, ContainsDict({
67+ "id": Equals(vlan.id),
68+ "vid": Equals(vlan.vid),
69+ "fabric_id": Equals(vlan.fabric_id),
70+ }))
71+
72+ def test_includes_legacy_subnet_objects(self):
73+ space = factory.make_Space()
74+ subnet = factory.make_Subnet(space=space)
75+ uri = get_space_uri(space)
76+ response = self.client.get(uri)
77+ self.assertEqual(
78+ http.client.OK, response.status_code, response.content)
79+ parsed_space = json.loads(
80+ response.content.decode(settings.DEFAULT_CHARSET))
81+ parsed_subnet = parsed_space['subnets'][0]
82+ self.assertThat(parsed_subnet, ContainsDict({
83+ "id": Equals(subnet.id),
84+ "cidr": Equals(str(subnet.cidr)),
85+ }))
86+ self.assertThat(parsed_subnet['vlan'], ContainsDict({
87+ "id": Equals(subnet.vlan.id),
88+ "vid": Equals(subnet.vlan.vid),
89+ "fabric_id": Equals(subnet.vlan.fabric_id),
90+ }))
91+
92 def test_read_404_when_bad_id(self):
93 uri = reverse(
94 'space_handler', args=[random.randint(100, 1000)])