launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #12245
[Merge] lp:~rvb/maas/add-api-releases-tests into lp:maas
Raphaël Badin has proposed merging lp:~rvb/maas/add-api-releases-tests into lp:maas.
Commit message:
Add some tests in order to test the changes made to the API in https://code.launchpad.net/~andreserl/maas/add_api_parameter_for_ubuntu_series/+merge/125016.
Requested reviews:
MAAS Maintainers (maas-maintainers)
For more details, see:
https://code.launchpad.net/~rvb/maas/add-api-releases-tests/+merge/125441
This branch adds some tests in order to test the changes made to the API in https://code.launchpad.net/~andreserl/maas/add_api_parameter_for_ubuntu_series/+merge/125016.
= Notes =
- I'd to like fix more things related to the distro_series stuff but improving the test coverage for the existing behavior is a first step.
- I've fixed some lint as well.
--
https://code.launchpad.net/~rvb/maas/add-api-releases-tests/+merge/125441
Your team MAAS Maintainers is requested to review the proposed merge of lp:~rvb/maas/add-api-releases-tests into lp:maas.
=== modified file 'src/maasserver/api.py'
--- src/maasserver/api.py 2012-09-19 13:59:23 +0000
+++ src/maasserver/api.py 2012-09-20 09:42:27 +0000
@@ -515,12 +515,12 @@
def start(self, request, system_id):
"""Power up a node.
- The user_data parameter, if set in the POST data, is taken as
- base64-encoded binary data.
-
- The distro_series parameter, if set in the POST data, is taken as
- clear text. This parameter specifies the Ubuntu Release the node
- will use.
+ :param user_data: If present, this blob of user-data to be made
+ available to the nodes through the metadata service.
+ :type user_data: base64-encoded basestring
+ :param distro_series: If present, this parameter specifies the
+ Ubuntu Release the node will use.
+ :type distro_series: basestring
Ideally we'd have MIME multipart and content-transfer-encoding etc.
deal with the encapsulation of binary data, but couldn't make it work
@@ -533,7 +533,8 @@
user_data = b64decode(user_data)
if series is not None:
node = Node.objects.get_node_or_404(
- system_id=system_id, user=request.user, perm=NODE_PERMISSION.EDIT)
+ system_id=system_id, user=request.user,
+ perm=NODE_PERMISSION.EDIT)
node.set_distro_series(series=series)
nodes = Node.objects.start_nodes(
[system_id], request.user, user_data=user_data)
=== modified file 'src/maasserver/models/node.py'
--- src/maasserver/models/node.py 2012-09-19 17:34:25 +0000
+++ src/maasserver/models/node.py 2012-09-20 09:42:27 +0000
@@ -562,7 +562,10 @@
def get_distro_series(self):
"""Return the distro series to install that node."""
- if not self.distro_series or self.distro_series == DISTRO_SERIES.default:
+ use_default_distro_series = (
+ not self.distro_series or
+ self.distro_series == DISTRO_SERIES.default)
+ if use_default_distro_series:
return Config.objects.get_config('default_distro_series')
else:
return self.distro_series
=== modified file 'src/maasserver/preseed.py'
--- src/maasserver/preseed.py 2012-09-18 18:04:52 +0000
+++ src/maasserver/preseed.py 2012-09-20 09:42:27 +0000
@@ -67,7 +67,7 @@
"""
if node.status == NODE_STATUS.COMMISSIONING:
return render_preseed(
- node, PRESEED_TYPE.COMMISSIONING,
+ node, PRESEED_TYPE.COMMISSIONING,
release=Config.objects.get_config('commissioning_distro_series'))
else:
return render_preseed(node, PRESEED_TYPE.DEFAULT,
=== modified file 'src/maasserver/tests/test_api.py'
--- src/maasserver/tests/test_api.py 2012-09-19 09:50:46 +0000
+++ src/maasserver/tests/test_api.py 2012-09-20 09:42:27 +0000
@@ -49,6 +49,7 @@
from maasserver.enum import (
ARCHITECTURE,
ARCHITECTURE_CHOICES,
+ DISTRO_SERIES,
NODE_AFTER_COMMISSIONING_ACTION,
NODE_STATUS,
NODE_STATUS_CHOICES_DICT,
@@ -881,6 +882,36 @@
self.assertEqual(
node.system_id, json.loads(response.content)['system_id'])
+ def test_POST_start_sets_distro_series(self):
+ node = factory.make_node(
+ owner=self.logged_in_user, mac=True,
+ power_type=POWER_TYPE.WAKE_ON_LAN)
+ distro_series = factory.getRandomEnum(DISTRO_SERIES)
+ response = self.client.post(
+ self.get_node_uri(node),
+ {'op': 'start', 'distro_series': distro_series})
+ self.assertEqual(
+ (httplib.OK, node.system_id),
+ (response.status_code, json.loads(response.content)['system_id']))
+ self.assertEqual(
+ distro_series, reload_object(node).distro_series)
+
+ def test_POST_start_validates_distro_series(self):
+ node = factory.make_node(
+ owner=self.logged_in_user, mac=True,
+ power_type=POWER_TYPE.WAKE_ON_LAN)
+ invalid_distro_series = factory.getRandomString()
+ response = self.client.post(
+ self.get_node_uri(node),
+ {'op': 'start', 'distro_series': invalid_distro_series})
+ self.assertEqual(
+ (
+ httplib.BAD_REQUEST,
+ {'distro_series': ["Value u'%s' is not a valid choice." %
+ invalid_distro_series]}
+ ),
+ (response.status_code, json.loads(response.content)))
+
def test_POST_start_may_be_repeated(self):
node = factory.make_node(
owner=self.logged_in_user, mac=True,
@@ -929,6 +960,13 @@
self.client.post(self.get_node_uri(node), {'op': 'release'})
self.assertTrue(reload_object(node).netboot)
+ def test_POST_release_resets_distro_series(self):
+ node = factory.make_node(
+ status=NODE_STATUS.ALLOCATED, owner=self.logged_in_user,
+ distro_series=factory.getRandomEnum(DISTRO_SERIES))
+ self.client.post(self.get_node_uri(node), {'op': 'release'})
+ self.assertEqual('', reload_object(node).distro_series)
+
def test_POST_release_removes_token_and_user(self):
node = factory.make_node(status=NODE_STATUS.READY)
self.client.post(self.get_uri('nodes/'), {'op': 'acquire'})