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
=== modified file 'src/maasserver/api.py'
--- src/maasserver/api.py 2012-10-02 10:12:12 +0000
+++ src/maasserver/api.py 2012-10-02 15:55:25 +0000
@@ -1128,6 +1128,14 @@
1128 {ip: leases[ip] for ip in new_leases if ip in leases})1128 {ip: leases[ip] for ip in new_leases if ip in leases})
1129 return HttpResponse("Leases updated.", status=httplib.OK)1129 return HttpResponse("Leases updated.", status=httplib.OK)
11301130
1131 @operation(idempotent=True)
1132 def list_nodes(self, request, uuid):
1133 """Get the list of node ids that are part of this group."""
1134 nodegroup = get_object_or_404(NodeGroup, uuid=uuid)
1135 check_nodegroup_access(request, nodegroup)
1136 return [node.system_id
1137 for node in Node.objects.filter(nodegroup=nodegroup)]
1138
11311139
1132DISPLAYED_NODEGROUP_FIELDS = (1140DISPLAYED_NODEGROUP_FIELDS = (
1133 'ip', 'management', 'interface', 'subnet_mask',1141 'ip', 'management', 'interface', 'subnet_mask',
11341142
=== modified file 'src/maasserver/tests/test_api.py'
--- src/maasserver/tests/test_api.py 2012-10-02 13:55:22 +0000
+++ src/maasserver/tests/test_api.py 2012-10-02 15:55:25 +0000
@@ -3452,6 +3452,36 @@
3452 httplib.FORBIDDEN, response.status_code,3452 httplib.FORBIDDEN, response.status_code,
3453 explain_unexpected_response(httplib.FORBIDDEN, response))3453 explain_unexpected_response(httplib.FORBIDDEN, response))
34543454
3455 def test_nodegroup_list_nodes_requires_authentication(self):
3456 nodegroup = factory.make_node_group()
3457 response = self.client.get(
3458 reverse('nodegroup_handler', args=[nodegroup.uuid]),
3459 {'op': 'list_nodes'})
3460 self.assertEqual(httplib.UNAUTHORIZED, response.status_code)
3461
3462 def test_nodegroup_list_nodes_does_not_work_for_normal_user(self):
3463 nodegroup = factory.make_node_group()
3464 log_in_as_normal_user(self.client)
3465 response = self.client.get(
3466 reverse('nodegroup_handler', args=[nodegroup.uuid]),
3467 {'op': 'list_nodes'})
3468 self.assertEqual(
3469 httplib.FORBIDDEN, response.status_code,
3470 explain_unexpected_response(httplib.FORBIDDEN, response))
3471
3472 def test_nodegroup_list_works_for_nodegroup_worker(self):
3473 nodegroup = factory.make_node_group()
3474 node = factory.make_node(nodegroup=nodegroup)
3475 client = make_worker_client(nodegroup)
3476 response = client.get(
3477 reverse('nodegroup_handler', args=[nodegroup.uuid]),
3478 {'op': 'list_nodes'})
3479 self.assertEqual(
3480 httplib.OK, response.status_code,
3481 explain_unexpected_response(httplib.OK, response))
3482 parsed_result = json.loads(response.content)
3483 self.assertItemsEqual([node.system_id], parsed_result)
3484
34553485
3456class TestBootImagesAPI(APITestCase):3486class TestBootImagesAPI(APITestCase):
34573487