Merge lp:~jameinel/maas/get-nodes-for-group into lp:~maas-committers/maas/trunk

Proposed by John A Meinel
Status: Merged
Approved by: John A Meinel
Approved revision: no longer in the source branch.
Merged at revision: 1135
Proposed branch: lp:~jameinel/maas/get-nodes-for-group
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 58 lines (+38/-0)
2 files modified
src/maasserver/api.py (+8/-0)
src/maasserver/tests/test_api.py (+30/-0)
To merge this branch: bzr merge lp:~jameinel/maas/get-nodes-for-group
Reviewer Review Type Date Requested Status
Martin Packman (community) Approve
Review via email: mp+127484@code.launchpad.net

Commit message

Add nodegroups/UUID/?op=list_nodes to get the system_ids for all nodes that are part of the group.
The permissions for this is restricted to the worker for the nodegroup, so it shouldn't be visible to users.

Description of the change

This exposes a '/nodegroups/UUID/?op=list_nodes' that returns the list of system_ids for a given nodegroup.

The use case for this is the new Tag changes to allow the nodegroups to process the tag definitions themselves. We will spawn a 'start processing' request, which will then need to come back and determine what nodes need to be updated for this group.

This is the first step along that path.

To post a comment you must log in.
Revision history for this message
Martin Packman (gz) wrote :

Looks good in general.

+ def test_GET_list_with_nodegroup(self):

This test has no assertions? It wants some, or documentation as to what it's testing.

review: Approve
Revision history for this message
John A Meinel (jameinel) wrote :

Actually, it just needs to be removed. Originally I was going to to
GET /nodes?op=list&nodegroup=UUID

However I switched to:

GET /nodegroups/UUID/?op=list_nodes

Since it made more sense to hang it off of the nodegroup api rather than the nodes api. (Especially, as it turned out, because the nodegroup already had good code for restricting requests to the worker task that is processing that nodegroup.)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/api.py'
2--- src/maasserver/api.py 2012-10-02 10:12:12 +0000
3+++ src/maasserver/api.py 2012-10-02 15:55:25 +0000
4@@ -1128,6 +1128,14 @@
5 {ip: leases[ip] for ip in new_leases if ip in leases})
6 return HttpResponse("Leases updated.", status=httplib.OK)
7
8+ @operation(idempotent=True)
9+ def list_nodes(self, request, uuid):
10+ """Get the list of node ids that are part of this group."""
11+ nodegroup = get_object_or_404(NodeGroup, uuid=uuid)
12+ check_nodegroup_access(request, nodegroup)
13+ return [node.system_id
14+ for node in Node.objects.filter(nodegroup=nodegroup)]
15+
16
17 DISPLAYED_NODEGROUP_FIELDS = (
18 'ip', 'management', 'interface', 'subnet_mask',
19
20=== modified file 'src/maasserver/tests/test_api.py'
21--- src/maasserver/tests/test_api.py 2012-10-02 13:55:22 +0000
22+++ src/maasserver/tests/test_api.py 2012-10-02 15:55:25 +0000
23@@ -3452,6 +3452,36 @@
24 httplib.FORBIDDEN, response.status_code,
25 explain_unexpected_response(httplib.FORBIDDEN, response))
26
27+ def test_nodegroup_list_nodes_requires_authentication(self):
28+ nodegroup = factory.make_node_group()
29+ response = self.client.get(
30+ reverse('nodegroup_handler', args=[nodegroup.uuid]),
31+ {'op': 'list_nodes'})
32+ self.assertEqual(httplib.UNAUTHORIZED, response.status_code)
33+
34+ def test_nodegroup_list_nodes_does_not_work_for_normal_user(self):
35+ nodegroup = factory.make_node_group()
36+ log_in_as_normal_user(self.client)
37+ response = self.client.get(
38+ reverse('nodegroup_handler', args=[nodegroup.uuid]),
39+ {'op': 'list_nodes'})
40+ self.assertEqual(
41+ httplib.FORBIDDEN, response.status_code,
42+ explain_unexpected_response(httplib.FORBIDDEN, response))
43+
44+ def test_nodegroup_list_works_for_nodegroup_worker(self):
45+ nodegroup = factory.make_node_group()
46+ node = factory.make_node(nodegroup=nodegroup)
47+ client = make_worker_client(nodegroup)
48+ response = client.get(
49+ reverse('nodegroup_handler', args=[nodegroup.uuid]),
50+ {'op': 'list_nodes'})
51+ self.assertEqual(
52+ httplib.OK, response.status_code,
53+ explain_unexpected_response(httplib.OK, response))
54+ parsed_result = json.loads(response.content)
55+ self.assertItemsEqual([node.system_id], parsed_result)
56+
57
58 class TestBootImagesAPI(APITestCase):
59