Merge lp:~julian-edwards/maas/network-gateway-ui into lp:~maas-committers/maas/trunk

Proposed by Julian Edwards
Status: Merged
Approved by: Julian Edwards
Approved revision: no longer in the source branch.
Merged at revision: 2904
Proposed branch: lp:~julian-edwards/maas/network-gateway-ui
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 170 lines (+25/-4)
8 files modified
src/maasserver/api/networks.py (+2/-1)
src/maasserver/api/tests/test_network.py (+3/-0)
src/maasserver/api/tests/test_networks.py (+3/-1)
src/maasserver/forms.py (+1/-0)
src/maasserver/templates/maasserver/network_detail.html (+4/-0)
src/maasserver/templates/maasserver/network_list.html (+2/-0)
src/maasserver/testing/factory.py (+4/-2)
src/maasserver/views/tests/test_networks.py (+6/-0)
To merge this branch: bzr merge lp:~julian-edwards/maas/network-gateway-ui
Reviewer Review Type Date Requested Status
Jeroen T. Vermeulen (community) Approve
Review via email: mp+233445@code.launchpad.net

Commit message

Trivial changes to add default_gateway to the web UI pages for viewing, editing and adding Networks. Also ensure default_gateway can be edited in the API.

To post a comment you must log in.
Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

Two nitpicks about this bit you're adding in the factory:

        if default_gateway is None and random.choice((True, False)):
            default_gateway = unicode(IPAddress(network.first + 1))

The factory has a helper for random.choice((True, False)): pick_bool().

Why are you forcing the gateway to be network.first + 1? I'd use self.pick_ip_in_network(network).

review: Approve
Revision history for this message
Julian Edwards (julian-edwards) wrote :

On Friday 05 September 2014 03:20:51 you wrote:
> Review: Approve
>
> Two nitpicks about this bit you're adding in the factory:
>
> if default_gateway is None and random.choice((True, False)):
> default_gateway = unicode(IPAddress(network.first + 1))
>
> The factory has a helper for random.choice((True, False)): pick_bool().
>
> Why are you forcing the gateway to be network.first + 1? I'd use
> self.pick_ip_in_network(network).

Both good points, I'll change things, thank you!

Revision history for this message
MAAS Lander (maas-lander) wrote :
Download full text (47.1 KiB)

The attempt to merge lp:~julian-edwards/maas/network-gateway-ui into lp:maas failed. Below is the output from the failed tests.

Ign http://security.ubuntu.com trusty-security InRelease
Get:1 http://security.ubuntu.com trusty-security Release.gpg [933 B]
Ign http://nova.clouds.archive.ubuntu.com trusty InRelease
Get:2 http://security.ubuntu.com trusty-security Release [59.7 kB]
Ign http://nova.clouds.archive.ubuntu.com trusty-updates InRelease
Hit http://nova.clouds.archive.ubuntu.com trusty Release.gpg
Get:3 http://nova.clouds.archive.ubuntu.com trusty-updates Release.gpg [933 B]
Hit http://nova.clouds.archive.ubuntu.com trusty Release
Get:4 http://nova.clouds.archive.ubuntu.com trusty-updates Release [59.7 kB]
Hit http://nova.clouds.archive.ubuntu.com trusty/main Sources
Hit http://nova.clouds.archive.ubuntu.com trusty/universe Sources
Hit http://nova.clouds.archive.ubuntu.com trusty/main amd64 Packages
Hit http://nova.clouds.archive.ubuntu.com trusty/universe amd64 Packages
Hit http://nova.clouds.archive.ubuntu.com trusty/main Translation-en
Hit http://nova.clouds.archive.ubuntu.com trusty/universe Translation-en
Get:5 http://security.ubuntu.com trusty-security/main Sources [43.5 kB]
Get:6 http://security.ubuntu.com trusty-security/universe Sources [10.8 kB]
Get:7 http://security.ubuntu.com trusty-security/main amd64 Packages [136 kB]
Get:8 http://security.ubuntu.com trusty-security/universe amd64 Packages [47.1 kB]
Hit http://security.ubuntu.com trusty-security/main Translation-en
Hit http://security.ubuntu.com trusty-security/universe Translation-en
Get:9 http://nova.clouds.archive.ubuntu.com trusty-updates/main Sources [116 kB]
Get:10 http://nova.clouds.archive.ubuntu.com trusty-updates/universe Sources [82.6 kB]
Get:11 http://nova.clouds.archive.ubuntu.com trusty-updates/main amd64 Packages [311 kB]
Get:12 http://nova.clouds.archive.ubuntu.com trusty-updates/universe amd64 Packages [199 kB]
Hit http://nova.clouds.archive.ubuntu.com trusty-updates/main Translation-en
Hit http://nova.clouds.archive.ubuntu.com trusty-updates/universe Translation-en
Ign http://nova.clouds.archive.ubuntu.com trusty/main Translation-en_US
Ign http://nova.clouds.archive.ubuntu.com trusty/universe Translation-en_US
Fetched 1,068 kB in 0s (1,619 kB/s)
Reading package lists...
sudo DEBIAN_FRONTEND=noninteractive apt-get -y \
     --no-install-recommends install apache2 authbind bind9 bind9utils build-essential bzr-builddeb curl daemontools debhelper dh-apport distro-info dnsutils firefox freeipmi-tools ipython isc-dhcp-common libjs-raphael libjs-yui3-full libjs-yui3-min libpq-dev make pep8 postgresql pyflakes python-amqplib python-bzrlib python-celery python-convoy python-crochet python-cssselect python-curtin python-dev python-distro-info python-django python-django-piston python-django-south python-djorm-ext-pgarray python-docutils python-extras python-fixtures python-flake8 python-formencode python-hivex python-httplib2 python-jinja2 python-jsonschema python-lockfile python-lxml python-mimeparse python-mock python-netaddr python-netifaces python-nose python-oauth python-oops python-oops-amqp python-oops-datedir-repo python-oops-twisted python-oops-wsgi python...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/api/networks.py'
2--- src/maasserver/api/networks.py 2014-08-16 12:04:25 +0000
3+++ src/maasserver/api/networks.py 2014-09-05 05:05:52 +0000
4@@ -45,7 +45,8 @@
5 api_doc_section_name = "Network"
6
7 model = Network
8- fields = ('name', 'ip', 'netmask', 'vlan_tag', 'description')
9+ fields = (
10+ 'name', 'ip', 'netmask', 'vlan_tag', 'description', 'default_gateway')
11
12 # Creation happens on the NetworksHandler.
13 create = None
14
15=== modified file 'src/maasserver/api/tests/test_network.py'
16--- src/maasserver/api/tests/test_network.py 2014-08-16 05:43:33 +0000
17+++ src/maasserver/api/tests/test_network.py 2014-09-05 05:05:52 +0000
18@@ -55,6 +55,7 @@
19 network.netmask,
20 network.vlan_tag,
21 network.description,
22+ network.default_gateway,
23 ),
24 (
25 parsed_result['name'],
26@@ -62,6 +63,7 @@
27 parsed_result['netmask'],
28 parsed_result['vlan_tag'],
29 parsed_result['description'],
30+ parsed_result['default_gateway'],
31 ))
32
33 def test_GET_returns_404_for_unknown_network(self):
34@@ -79,6 +81,7 @@
35 'netmask': '%s' % new_net.netmask,
36 'vlan_tag': factory.make_vlan_tag(),
37 'description': "Changed description",
38+ 'default_gateway': factory.getRandomIPAddress(),
39 }
40
41 response = self.client_put(self.get_url(network.name), new_values)
42
43=== modified file 'src/maasserver/api/tests/test_networks.py'
44--- src/maasserver/api/tests/test_networks.py 2014-08-16 05:43:33 +0000
45+++ src/maasserver/api/tests/test_networks.py 2014-09-05 05:05:52 +0000
46@@ -61,7 +61,9 @@
47 parsed_result = json.loads(response.content)
48 self.assertEqual(1, len(parsed_result))
49 [returned_network] = parsed_result
50- fields = {'name', 'ip', 'netmask', 'vlan_tag', 'description'}
51+ fields = {
52+ 'name', 'ip', 'netmask', 'vlan_tag', 'description',
53+ 'default_gateway'}
54 self.assertEqual(
55 fields.union({'resource_uri'}),
56 set(returned_network.keys()))
57
58=== modified file 'src/maasserver/forms.py'
59--- src/maasserver/forms.py 2014-09-04 08:14:17 +0000
60+++ src/maasserver/forms.py 2014-09-05 05:05:52 +0000
61@@ -1914,6 +1914,7 @@
62 'ip',
63 'netmask',
64 'vlan_tag',
65+ 'default_gateway',
66 )
67
68 mac_addresses = NodeMACAddressChoiceField(
69
70=== modified file 'src/maasserver/templates/maasserver/network_detail.html'
71--- src/maasserver/templates/maasserver/network_detail.html 2014-02-24 07:48:20 +0000
72+++ src/maasserver/templates/maasserver/network_detail.html 2014-09-05 05:05:52 +0000
73@@ -40,6 +40,10 @@
74 <span>{{ network.vlan_tag|default_if_none:"" }}</span>
75 </li>
76 <li class="block size2">
77+ <h4>Default Gateway</h4>
78+ <span>{{ network.default_gateway|default_if_none:"" }}</span>
79+ </li>
80+ <li class="block size2">
81 <h4>Attached nodes</h4>
82 <span id="nodecount">
83 <a title="View nodes attached to network {{ network.name }}"
84
85=== modified file 'src/maasserver/templates/maasserver/network_list.html'
86--- src/maasserver/templates/maasserver/network_list.html 2014-03-25 11:03:39 +0000
87+++ src/maasserver/templates/maasserver/network_list.html 2014-09-05 05:05:52 +0000
88@@ -23,6 +23,7 @@
89 <th>Description</th>
90 <th>Network</th>
91 <th>VLAN tag</th>
92+ <th>Default gateway</th>
93 <th>Attached nodes</th>
94 {% if user.is_superuser %}
95 {% comment %} Action buttons {% endcomment %}
96@@ -41,6 +42,7 @@
97 <td>{{ network_item.description|truncatechars:40 }}</td>
98 <td>{{ network_item.get_network }}</td>
99 <td>{{ network_item.vlan_tag|default_if_none:"" }}</td>
100+ <td>{{ network_item.default_gateway|default_if_none:"" }}</td>
101 <td>
102 <a title="View nodes attached to network {{ network_item.name }}"
103 href="{% url 'node-list' %}?query=networks%3D{{ network_item.name }}">
104
105=== modified file 'src/maasserver/testing/factory.py'
106--- src/maasserver/testing/factory.py 2014-08-29 12:49:20 +0000
107+++ src/maasserver/testing/factory.py 2014-09-05 05:05:52 +0000
108@@ -834,7 +834,7 @@
109
110 def make_network(self, name=None, network=None, vlan_tag=NO_VALUE,
111 description=None, sortable_name=False,
112- disjoint_from=None):
113+ disjoint_from=None, default_gateway=None):
114 """Create a `Network`.
115
116 :param network: An `IPNetwork`. If given, the `ip` and `netmask`
117@@ -867,6 +867,8 @@
118 ]
119 if network is None:
120 network = self.getRandomNetwork(disjoint_from=disjoint_from)
121+ if default_gateway is None and self.pick_bool():
122+ default_gateway = self.pick_ip_in_network(network)
123 ip = unicode(network.ip)
124 netmask = unicode(network.netmask)
125 if description is None:
126@@ -875,7 +877,7 @@
127 vlan_tag = self.make_vlan_tag()
128 network = Network(
129 name=name, ip=ip, netmask=netmask, vlan_tag=vlan_tag,
130- description=description)
131+ description=description, default_gateway=default_gateway)
132 network.save()
133 return network
134
135
136=== modified file 'src/maasserver/views/tests/test_networks.py'
137--- src/maasserver/views/tests/test_networks.py 2014-08-13 21:49:35 +0000
138+++ src/maasserver/views/tests/test_networks.py 2014-09-05 05:05:52 +0000
139@@ -68,6 +68,9 @@
140 network.description[:20],
141 '%s' % network.get_network(),
142 '%s' % network.vlan_tag if network.vlan_tag else '',
143+ '%s' % (
144+ network.default_gateway if network.default_gateway
145+ else ''),
146 '%d' % network.get_connected_nodes().count(),
147 ]
148 for network in networks]
149@@ -196,6 +199,7 @@
150 'ip': "%s" % network.cidr.ip,
151 'netmask': "%s" % network.netmask,
152 'vlan_tag': factory.make_vlan_tag(),
153+ 'default_gateway': factory.getRandomIPAddress(),
154 }
155 response = self.client.post(reverse('network-add'), definition)
156 self.assertEqual(httplib.FOUND, response.status_code)
157@@ -310,11 +314,13 @@
158 new_macs = [
159 factory.make_mac_address()
160 for _ in range(3)]
161+ new_gateway = factory.getRandomIPAddress()
162 response = self.client.post(
163 reverse('network-edit', args=[network.name]),
164 data={
165 'name': new_name,
166 'description': new_description,
167+ 'default_gateway': new_gateway,
168 'mac_addresses': new_macs,
169 })
170 self.assertEqual(