launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #06516
[Merge] lp:~rvb/maas/maas-network-conf into lp:maas
Raphaël Badin has proposed merging lp:~rvb/maas/maas-network-conf into lp:maas with lp:~rvb/maas/maas-fix-forms-bug-941754 as a prerequisite.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~rvb/maas/maas-network-conf/+merge/94922
This branch adds the "Network Configuration" form to the settings page.
Drive-by fix: create the method get_prefixed_form_data to help format post data for sub-forms (i.e. where all the data keys use a prefix).
--
https://code.launchpad.net/~rvb/maas/maas-network-conf/+merge/94922
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~rvb/maas/maas-network-conf into lp:maas.
=== modified file 'src/maasserver/forms.py'
--- src/maasserver/forms.py 2012-02-27 12:36:55 +0000
+++ src/maasserver/forms.py 2012-02-28 08:46:18 +0000
@@ -146,3 +146,9 @@
for name, value in self.cleaned_data.items():
Config.objects.set_config(name, value)
return True
+
+
+class MaaSAndNetworkForm(ConfigForm):
+ maas_name = forms.CharField(label="MaaS name")
+ provide_dhcp = forms.BooleanField(
+ label="Provide DHCP on this subnet", required=False)
=== modified file 'src/maasserver/templates/maasserver/settings.html'
--- src/maasserver/templates/maasserver/settings.html 2012-02-28 08:46:18 +0000
+++ src/maasserver/templates/maasserver/settings.html 2012-02-28 08:46:18 +0000
@@ -66,6 +66,18 @@
<button class="button right">Add user</button>
</a>
<div class="clear" />
- </div>
+ </div>
+ <div id="maas_and_network">
+ <h2>Network Configuration</h2>
+ <form action="{% url "settings" %}" method="post">
+ <ul>
+ {% for field in maas_and_network_form %}
+ {% include "maasserver/form_field.html" %}
+ {% endfor %}
+ </ul>
+ <input type="hidden" name="maas_and_network_submit" value="1" />
+ <input type="submit" class="button right" value="Save" />
+ </form>
+ </div>
</div>
{% endblock %}
=== modified file 'src/maasserver/testing/factory.py'
--- src/maasserver/testing/factory.py 2012-02-13 16:32:31 +0000
+++ src/maasserver/testing/factory.py 2012-02-28 08:46:18 +0000
@@ -33,6 +33,9 @@
random.choice(string.letters + string.digits)
for x in xrange(size))
+ def getRandomBoolean(self):
+ random.choice((True, False))
+
def make_node(self, hostname='', set_hostname=False, status=None,
**kwargs):
# hostname=None is a valid value, hence the set_hostname trick.
=== modified file 'src/maasserver/tests/test_views.py'
--- src/maasserver/tests/test_views.py 2012-02-28 08:46:18 +0000
+++ src/maasserver/tests/test_views.py 2012-02-28 08:46:18 +0000
@@ -16,13 +16,22 @@
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from lxml.html import fromstring
-from maasserver.models import UserProfile
+from maasserver.models import (
+ Config,
+ UserProfile,
+ )
from maasserver.testing import (
factory,
LoggedInTestCase,
)
+def get_prefixed_form_data(prefix, data):
+ result = {'%s-%s' % (prefix, key): value for key, value in data.items()}
+ result.update({'%s_submit' % prefix: 1})
+ return result
+
+
class UserPrefsViewTest(LoggedInTestCase):
def test_prefs_GET_profile(self):
@@ -66,10 +75,13 @@
# information.
response = self.client.post(
'/account/prefs/',
- {
- 'profile_submit': 1, 'profile-first_name': 'John',
- 'profile-last_name': 'Doe', 'profile-email': 'jon@xxxxxxxxxxx'
- })
+ get_prefixed_form_data(
+ 'profile',
+ {
+ 'first_name': 'John',
+ 'last_name': 'Doe',
+ 'email': 'jon@xxxxxxxxxxx',
+ }))
self.assertEqual(httplib.FOUND, response.status_code)
user = User.objects.get(id=self.logged_in_user.id)
@@ -83,12 +95,14 @@
old_pw = self.logged_in_user.password
response = self.client.post(
'/account/prefs/',
- {
- 'password_submit': 1,
- 'password-old_password': 'test',
- 'password-new_password1': 'new',
- 'password-new_password2': 'new',
- })
+ get_prefixed_form_data(
+ 'password',
+ {
+ 'old_password': 'test',
+ 'new_password1': 'new',
+ 'new_password2': 'new',
+ }))
+
self.assertEqual(httplib.FOUND, response.status_code)
user = User.objects.get(id=self.logged_in_user.id)
# The password is SHA1ized, we just make sure that it has changed.
@@ -145,6 +159,23 @@
self.assertNotIn(
reverse('accounts-del', args=[user.username]), links)
+ def test_settings_maas_and_network_POST(self):
+ new_name = factory.getRandomString()
+ new_provide_dhcp = factory.getRandomBoolean()
+ response = self.client.post(
+ '/settings/',
+ get_prefixed_form_data(
+ prefix='maas_and_network',
+ data={
+ 'maas_name': new_name,
+ 'provide_dhcp': new_provide_dhcp,
+ }))
+
+ 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'))
+
class UserManagementTest(AdminLoggedInTestCase):
=== modified file 'src/maasserver/views.py'
--- src/maasserver/views.py 2012-02-28 08:46:18 +0000
+++ src/maasserver/views.py 2012-02-28 08:46:18 +0000
@@ -36,6 +36,7 @@
from maasserver.exceptions import CannotDeleteUserException
from maasserver.forms import (
EditUserForm,
+ MaaSAndNetworkForm,
NewUserCreationForm,
ProfileForm,
)
@@ -165,9 +166,22 @@
def settings(request):
user_list = UserProfile.objects.all_users().order_by('username')
+ # Process the MaaS & network form.
+ if 'maas_and_network_submit' in request.POST:
+ maas_and_network_form = MaaSAndNetworkForm(
+ request.POST, prefix='maas_and_network')
+ if maas_and_network_form.is_valid():
+ messages.info(request, "Configuration updated.")
+ maas_and_network_form.save()
+ return HttpResponseRedirect(reverse('settings'))
+ else:
+ maas_and_network_form = MaaSAndNetworkForm(
+ prefix='maas_and_network')
+
return render_to_response(
'maasserver/settings.html',
{
'user_list': user_list,
+ 'maas_and_network_form': maas_and_network_form,
},
context_instance=RequestContext(request))