← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~rvb/maas/maas-settings-commi into lp:maas

 

Raphaël Badin has proposed merging lp:~rvb/maas/maas-settings-commi into lp:maas.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~rvb/maas/maas-settings-commi/+merge/95122

This branch adds the "Commissioning" section to the "settings" page.

Drive-by fixes:
- add MaaSAndNetworkForm to src/maasserver/forms.py:__all__
- fix factory.getRandomBoolean and related test test_settings_maas_and_network_POST (line 88 in the diff).  This test passed only because of the wrong getRandomBoolean method.
-- 
https://code.launchpad.net/~rvb/maas/maas-settings-commi/+merge/95122
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~rvb/maas/maas-settings-commi into lp:maas.
=== modified file 'src/maasserver/forms.py'
--- src/maasserver/forms.py	2012-02-28 13:33:42 +0000
+++ src/maasserver/forms.py	2012-02-29 08:03:17 +0000
@@ -10,8 +10,10 @@
 
 __metaclass__ = type
 __all__ = [
+    "CommissioningForm",
     "NodeForm",
     "MACAddressForm",
+    "MaaSAndNetworkForm",
     ]
 
 from django import forms
@@ -163,3 +165,12 @@
     maas_name = forms.CharField(label="MaaS name")
     provide_dhcp = forms.BooleanField(
         label="Provide DHCP on this subnet", required=False)
+
+
+class CommissioningForm(ConfigForm):
+    after_commissioning = forms.ChoiceField(
+        choices=NODE_AFTER_COMMISSIONING_ACTION_CHOICES,
+        label="After commissioning")
+    check_compatibility = forms.BooleanField(
+        label="Check component compatibility and certification",
+        required=False)

=== modified file 'src/maasserver/templates/maasserver/settings.html'
--- src/maasserver/templates/maasserver/settings.html	2012-02-28 13:33:42 +0000
+++ src/maasserver/templates/maasserver/settings.html	2012-02-29 08:03:17 +0000
@@ -67,6 +67,19 @@
       </a>
       <div class="clear"></div>
     </div>
+    <div id="commissioning">
+      <h2>Commissioning</h2>
+      <form action="{% url "settings" %}" method="post">
+        <ul>
+        {% for field in commissioning_form %}
+          {% include "maasserver/form_field.html" %}
+        {% endfor %}
+        </ul>
+        <input type="hidden" name="commissioning_submit" value="1" />
+        <input type="submit" class="button right" value="Save" />
+        <div class="clear"></div>
+      </form>
+    </div>
     <div id="maas_and_network">
       <h2>Network Configuration</h2>
       <form action="{% url "settings" %}" method="post">

=== modified file 'src/maasserver/testing/factory.py'
--- src/maasserver/testing/factory.py	2012-02-28 13:33:42 +0000
+++ src/maasserver/testing/factory.py	2012-02-29 08:03:17 +0000
@@ -34,7 +34,13 @@
             for x in xrange(size))
 
     def getRandomBoolean(self):
-        random.choice((True, False))
+        return random.choice((True, False))
+
+    def getRandomEnum(self, enum):
+        enum_choices = [
+            value for key, value in vars(enum).items()
+            if not key.startswith('__')]
+        return random.choice(enum_choices)
 
     def make_node(self, hostname='', set_hostname=False, status=None,
                   **kwargs):

=== modified file 'src/maasserver/tests/test_views.py'
--- src/maasserver/tests/test_views.py	2012-02-28 13:33:42 +0000
+++ src/maasserver/tests/test_views.py	2012-02-29 08:03:17 +0000
@@ -18,6 +18,7 @@
 from lxml.html import fromstring
 from maasserver.models import (
     Config,
+    NODE_AFTER_COMMISSIONING_ACTION,
     UserProfile,
     )
 from maasserver.testing import (
@@ -174,7 +175,28 @@
         self.assertEqual(httplib.FOUND, response.status_code)
         self.assertEqual(new_name, Config.objects.get_config('maas_name'))
         self.assertEqual(
-            new_provide_dhcp, Config.objects.get_config('new_provide_dhcp'))
+            new_provide_dhcp, Config.objects.get_config('provide_dhcp'))
+
+    def test_settings_commissioning_POST(self):
+        new_after_commissioning = factory.getRandomEnum(
+            NODE_AFTER_COMMISSIONING_ACTION)
+        new_check_compatibility = factory.getRandomBoolean()
+        response = self.client.post(
+            '/settings/',
+            get_prefixed_form_data(
+                prefix='commissioning',
+                data={
+                    'after_commissioning': new_after_commissioning,
+                    'check_compatibility': new_check_compatibility,
+                }))
+
+        self.assertEqual(httplib.FOUND, response.status_code)
+        self.assertEqual(
+            new_after_commissioning,
+            Config.objects.get_config('after_commissioning'))
+        self.assertEqual(
+            new_check_compatibility,
+            Config.objects.get_config('check_compatibility'))
 
 
 class UserManagementTest(AdminLoggedInTestCase):

=== modified file 'src/maasserver/views.py'
--- src/maasserver/views.py	2012-02-28 13:33:42 +0000
+++ src/maasserver/views.py	2012-02-29 08:03:17 +0000
@@ -35,6 +35,7 @@
     )
 from maasserver.exceptions import CannotDeleteUserException
 from maasserver.forms import (
+    CommissioningForm,
     EditUserForm,
     MaaSAndNetworkForm,
     NewUserCreationForm,
@@ -175,13 +176,24 @@
             maas_and_network_form.save()
             return HttpResponseRedirect(reverse('settings'))
     else:
-        maas_and_network_form = MaaSAndNetworkForm(
-            prefix='maas_and_network')
+        maas_and_network_form = MaaSAndNetworkForm(prefix='maas_and_network')
+
+    # Process the Commissioning form.
+    if 'commissioning_submit' in request.POST:
+        commissioning_form = CommissioningForm(
+            request.POST, prefix='commissioning')
+        if commissioning_form.is_valid():
+            messages.info(request, "Configuration updated.")
+            commissioning_form.save()
+            return HttpResponseRedirect(reverse('settings'))
+    else:
+        commissioning_form = CommissioningForm(prefix='commissioning')
 
     return render_to_response(
         'maasserver/settings.html',
         {
             'user_list': user_list,
             'maas_and_network_form': maas_and_network_form,
+            'commissioning_form': commissioning_form,
         },
         context_instance=RequestContext(request))