launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #06684
[Merge] lp:~jtv/maas/power-type-api into lp:maas
Jeroen T. Vermeulen has proposed merging lp:~jtv/maas/power-type-api into lp:maas.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~jtv/maas/power-type-api/+merge/97355
Whatever script we build for producing a vdenv setup will have to be able to set a node's power type through the API. This change allows that.
In production, for now, we expect only the default wake-on-LAN to make sense.
--
https://code.launchpad.net/~jtv/maas/power-type-api/+merge/97355
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~jtv/maas/power-type-api into lp:maas.
=== modified file 'src/maasserver/forms.py'
--- src/maasserver/forms.py 2012-03-12 07:25:31 +0000
+++ src/maasserver/forms.py 2012-03-14 09:29:19 +0000
@@ -43,10 +43,25 @@
)
-INVALID_ARCHITECTURE_MESSAGE = (
- "%(value)s is not a valid architecture. " +
- "It should be one of: %s." % ", ".join(
- name for name, value in ARCHITECTURE_CHOICES))
+def compose_invalid_choice_text(choice_of_what, valid_choices):
+ """Compose an "invalid choice" string for form error messages.
+
+ :param choice_of_what: The name for what the selected item is supposed
+ to be, to be inserted into the error string.
+ :type choice_of_what: basestring
+ :param valid_choices: Valid choices, in Django choices format:
+ (name, value).
+ :type valid_choices: sequence
+ """
+ return "%s is not a valid %s. It should be one of: %s." % (
+ "%(value)s",
+ choice_of_what,
+ ", ".join(name for name, value in valid_choices),
+ )
+
+
+INVALID_ARCHITECTURE_MESSAGE = compose_invalid_choice_text(
+ 'architecture', ARCHITECTURE_CHOICES)
class NodeForm(ModelForm):
@@ -69,7 +84,7 @@
model = Node
fields = (
'hostname', 'system_id', 'after_commissioning_action',
- 'architecture')
+ 'architecture', 'power_type')
class MACAddressForm(ModelForm):
=== modified file 'src/maasserver/tests/test_api.py'
--- src/maasserver/tests/test_api.py 2012-03-13 05:34:38 +0000
+++ src/maasserver/tests/test_api.py 2012-03-14 09:29:19 +0000
@@ -41,6 +41,7 @@
NodeUserData,
)
from metadataserver.nodeinituser import get_node_init_user
+from provisioningserver.enum import POWER_TYPE
class APIv10TestMixin:
@@ -78,6 +79,27 @@
self.assertEqual(2, diane.after_commissioning_action)
self.assertEqual(ARCHITECTURE.amd64, diane.architecture)
+ def test_POST_new_power_type_defaults_to_asking_config(self):
+ response = self.client.post(
+ self.get_uri('nodes/'), {
+ 'op': 'new',
+ 'mac_addresses': ['00:11:22:33:44:55'],
+ })
+ node = Node.objects.get(
+ system_id=json.loads(response.content)['system_id'])
+ self.assertEqual(POWER_TYPE.DEFAULT, node.power_type)
+
+ def test_POST_new_sets_power_type(self):
+ response = self.client.post(
+ self.get_uri('nodes/'), {
+ 'op': 'new',
+ 'power_type': POWER_TYPE.VIRSH,
+ 'mac_addresses': ['00:11:22:33:44:55'],
+ })
+ node = Node.objects.get(
+ system_id=json.loads(response.content)['system_id'])
+ self.assertEqual(POWER_TYPE.VIRSH, node.power_type)
+
def test_POST_new_associates_mac_addresses(self):
# The API allows a Node to be created and associated with MAC
# Addresses.