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
=== modified file 'src/maasserver/api/spaces.py'
--- src/maasserver/api/spaces.py 2017-01-04 19:37:16 +0000
+++ src/maasserver/api/spaces.py 2017-01-14 02:48:00 +0000
@@ -18,6 +18,7 @@
1818
1919
20DISPLAYED_SPACE_FIELDS = (20DISPLAYED_SPACE_FIELDS = (
21 'resource_uri',
21 'id',22 'id',
22 'name',23 'name',
23 'vlans',24 'vlans',
@@ -78,33 +79,11 @@
7879
79 @classmethod80 @classmethod
80 def subnets(cls, space):81 def subnets(cls, space):
81 """Return an abbreviated view of each subnet in the space."""82 return Subnet.objects.filter(vlan__space=space)
82 subnets = Subnet.objects.filter(vlan__space=space)
83 return [
84 {
85 "id": subnet.id,
86 "name": subnet.name,
87 "cidr": str(subnet.cidr),
88 "vlan": subnet.vlan_id
89 }
90 for subnet in subnets
91 ]
9283
93 @classmethod84 @classmethod
94 def vlans(cls, space):85 def vlans(cls, space):
95 """Return an abbreviated view of each VLAN in the space."""86 return space.vlan_set.all()
96 return [
97 {
98 "id": vlan.id,
99 "vid": vlan.vid,
100 "name": vlan.name,
101 "fabric": {
102 "id": vlan.fabric.id,
103 "name": vlan.fabric.name,
104 }
105 }
106 for vlan in space.vlan_set.all()
107 ]
10887
109 def read(self, request, id):88 def read(self, request, id):
110 """Read space.89 """Read space.
11190
=== modified file 'src/maasserver/api/tests/test_spaces.py'
--- src/maasserver/api/tests/test_spaces.py 2016-05-24 21:29:53 +0000
+++ src/maasserver/api/tests/test_spaces.py 2017-01-14 02:48:00 +0000
@@ -121,6 +121,42 @@
121 ]121 ]
122 self.assertItemsEqual(subnet_ids, parsed_subnets)122 self.assertItemsEqual(subnet_ids, parsed_subnets)
123123
124 def test_includes_vlan_objects(self):
125 space = factory.make_Space()
126 vlan = factory.make_VLAN(space=space)
127 uri = get_space_uri(space)
128 response = self.client.get(uri)
129 self.assertEqual(
130 http.client.OK, response.status_code, response.content)
131 parsed_space = json.loads(
132 response.content.decode(settings.DEFAULT_CHARSET))
133 parsed_vlan = parsed_space['vlans'][0]
134 self.assertThat(parsed_vlan, ContainsDict({
135 "id": Equals(vlan.id),
136 "vid": Equals(vlan.vid),
137 "fabric_id": Equals(vlan.fabric_id),
138 }))
139
140 def test_includes_legacy_subnet_objects(self):
141 space = factory.make_Space()
142 subnet = factory.make_Subnet(space=space)
143 uri = get_space_uri(space)
144 response = self.client.get(uri)
145 self.assertEqual(
146 http.client.OK, response.status_code, response.content)
147 parsed_space = json.loads(
148 response.content.decode(settings.DEFAULT_CHARSET))
149 parsed_subnet = parsed_space['subnets'][0]
150 self.assertThat(parsed_subnet, ContainsDict({
151 "id": Equals(subnet.id),
152 "cidr": Equals(str(subnet.cidr)),
153 }))
154 self.assertThat(parsed_subnet['vlan'], ContainsDict({
155 "id": Equals(subnet.vlan.id),
156 "vid": Equals(subnet.vlan.vid),
157 "fabric_id": Equals(subnet.vlan.fabric_id),
158 }))
159
124 def test_read_404_when_bad_id(self):160 def test_read_404_when_bad_id(self):
125 uri = reverse(161 uri = reverse(
126 'space_handler', args=[random.randint(100, 1000)])162 'space_handler', args=[random.randint(100, 1000)])