Statistics
| Branch: | Tag: | Revision:

root / snf-cyclades-app / synnefo / api / tests / subnets.py @ fef04862

History | View | Annotate | Download (21.5 kB)

1 6a959c73 Dionysis Grigoropoulos
# Copyright 2011-2013 GRNET S.A. All rights reserved.
2 6a959c73 Dionysis Grigoropoulos
#
3 6a959c73 Dionysis Grigoropoulos
# Redistribution and use in source and binary forms, with or without
4 6a959c73 Dionysis Grigoropoulos
# modification, are permitted provided that the following conditions
5 6a959c73 Dionysis Grigoropoulos
# are met:
6 6a959c73 Dionysis Grigoropoulos
#
7 6a959c73 Dionysis Grigoropoulos
#   1. Redistributions of source code must retain the above copyright
8 6a959c73 Dionysis Grigoropoulos
#      notice, this list of conditions and the following disclaimer.
9 6a959c73 Dionysis Grigoropoulos
#
10 6a959c73 Dionysis Grigoropoulos
#  2. Redistributions in binary form must reproduce the above copyright
11 6a959c73 Dionysis Grigoropoulos
#     notice, this list of conditions and the following disclaimer in the
12 6a959c73 Dionysis Grigoropoulos
#     documentation and/or other materials provided with the distribution.
13 6a959c73 Dionysis Grigoropoulos
#
14 6a959c73 Dionysis Grigoropoulos
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
15 6a959c73 Dionysis Grigoropoulos
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 6a959c73 Dionysis Grigoropoulos
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 6a959c73 Dionysis Grigoropoulos
# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
18 6a959c73 Dionysis Grigoropoulos
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 6a959c73 Dionysis Grigoropoulos
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 6a959c73 Dionysis Grigoropoulos
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 6a959c73 Dionysis Grigoropoulos
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 6a959c73 Dionysis Grigoropoulos
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 6a959c73 Dionysis Grigoropoulos
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 6a959c73 Dionysis Grigoropoulos
# SUCH DAMAGE.
25 6a959c73 Dionysis Grigoropoulos
#
26 6a959c73 Dionysis Grigoropoulos
# The views and conclusions contained in the software and documentation are
27 6a959c73 Dionysis Grigoropoulos
# those of the authors and should not be interpreted as representing official
28 6a959c73 Dionysis Grigoropoulos
# policies, either expressed or implied, of GRNET S.A.
29 6a959c73 Dionysis Grigoropoulos
30 6a959c73 Dionysis Grigoropoulos
from snf_django.utils.testing import BaseAPITest
31 6a959c73 Dionysis Grigoropoulos
from django.utils import simplejson as json
32 6a959c73 Dionysis Grigoropoulos
from synnefo.cyclades_settings import cyclades_services
33 6a959c73 Dionysis Grigoropoulos
from synnefo.lib.services import get_service_path
34 6a959c73 Dionysis Grigoropoulos
from synnefo.lib import join_urls
35 6a959c73 Dionysis Grigoropoulos
from ipaddr import IPv4Network
36 6a959c73 Dionysis Grigoropoulos
import json
37 6a959c73 Dionysis Grigoropoulos
import synnefo.db.models_factory as mf
38 6a959c73 Dionysis Grigoropoulos
39 6a959c73 Dionysis Grigoropoulos
40 6a959c73 Dionysis Grigoropoulos
COMPUTE_URL = get_service_path(cyclades_services, 'compute', version='v2.0')
41 6a959c73 Dionysis Grigoropoulos
SUBNETS_URL = join_urls(COMPUTE_URL, "subnets/")
42 6a959c73 Dionysis Grigoropoulos
43 6a959c73 Dionysis Grigoropoulos
44 6a959c73 Dionysis Grigoropoulos
class SubnetTest(BaseAPITest):
45 6a959c73 Dionysis Grigoropoulos
    def test_list_subnets(self):
46 6a959c73 Dionysis Grigoropoulos
        """Test list subnets without data"""
47 6a959c73 Dionysis Grigoropoulos
        response = self.get(SUBNETS_URL)
48 6a959c73 Dionysis Grigoropoulos
        self.assertSuccess(response)
49 6a959c73 Dionysis Grigoropoulos
        subnets = json.loads(response.content)
50 6a959c73 Dionysis Grigoropoulos
        self.assertEqual(subnets, {'subnets': []})
51 6a959c73 Dionysis Grigoropoulos
52 6a959c73 Dionysis Grigoropoulos
    def test_list_subnets_data(self):
53 6a959c73 Dionysis Grigoropoulos
        """Test list subnets with data"""
54 6a959c73 Dionysis Grigoropoulos
        test_net = mf.NetworkFactory()
55 6a959c73 Dionysis Grigoropoulos
        test_subnet_ipv4 = mf.IPv4SubnetFactory(network=test_net)
56 911a1bc1 Dionysis Grigoropoulos
        test_subnet_ipv6 = mf.IPv6SubnetFactory(network=test_net, ipversion=6,
57 6a959c73 Dionysis Grigoropoulos
                                                cidr=
58 6a959c73 Dionysis Grigoropoulos
                                                'fd4b:638e:fd7a:f998::/64')
59 6a959c73 Dionysis Grigoropoulos
        response = self.get(SUBNETS_URL, user=test_net.userid)
60 6a959c73 Dionysis Grigoropoulos
        self.assertSuccess(response)
61 6a959c73 Dionysis Grigoropoulos
62 6a959c73 Dionysis Grigoropoulos
    def test_get_subnet(self):
63 6a959c73 Dionysis Grigoropoulos
        """Test get info of a single subnet"""
64 6a959c73 Dionysis Grigoropoulos
        test_net = mf.NetworkFactory()
65 6a959c73 Dionysis Grigoropoulos
        test_subnet = mf.IPv4SubnetFactory(network=test_net)
66 6a959c73 Dionysis Grigoropoulos
        url = join_urls(SUBNETS_URL, str(test_subnet.id))
67 6a959c73 Dionysis Grigoropoulos
        response = self.get(url, user=test_net.userid)
68 6a959c73 Dionysis Grigoropoulos
        self.assertSuccess(response)
69 6a959c73 Dionysis Grigoropoulos
70 6a959c73 Dionysis Grigoropoulos
    def test_get_subnet_404(self):
71 6a959c73 Dionysis Grigoropoulos
        """Test get info of a subnet that doesn't exist"""
72 6a959c73 Dionysis Grigoropoulos
        url = join_urls(SUBNETS_URL, '42')
73 6a959c73 Dionysis Grigoropoulos
        response = self.get(url)
74 6a959c73 Dionysis Grigoropoulos
        self.assertItemNotFound(response)
75 6a959c73 Dionysis Grigoropoulos
76 6a959c73 Dionysis Grigoropoulos
    def test_subnet_delete(self):
77 6a959c73 Dionysis Grigoropoulos
        """Test delete a subnet -- not supported"""
78 6a959c73 Dionysis Grigoropoulos
        url = join_urls(SUBNETS_URL, '42')
79 6a959c73 Dionysis Grigoropoulos
        response = self.delete(url)
80 6a959c73 Dionysis Grigoropoulos
        self.assertBadRequest(response)
81 6a959c73 Dionysis Grigoropoulos
82 6a959c73 Dionysis Grigoropoulos
    def test_create_subnet_success_ipv4(self):
83 6a959c73 Dionysis Grigoropoulos
        """Test create a subnet successfully"""
84 6a959c73 Dionysis Grigoropoulos
        test_net = mf.NetworkFactory()
85 6a959c73 Dionysis Grigoropoulos
        request = {
86 6a959c73 Dionysis Grigoropoulos
            'subnet': {
87 6a959c73 Dionysis Grigoropoulos
                'network_id': test_net.id,
88 6a959c73 Dionysis Grigoropoulos
                'cidr': '10.0.3.0/24',
89 6a959c73 Dionysis Grigoropoulos
                'ip_version': 4}
90 6a959c73 Dionysis Grigoropoulos
        }
91 6a959c73 Dionysis Grigoropoulos
        response = self.post(SUBNETS_URL, test_net.userid,
92 6a959c73 Dionysis Grigoropoulos
                             json.dumps(request), "json")
93 6a959c73 Dionysis Grigoropoulos
        self.assertSuccess(response)
94 411e5025 Dionysis Grigoropoulos
        resp = json.loads(response.content)['subnet']
95 411e5025 Dionysis Grigoropoulos
        self.assertEqual("10.0.3.1", resp['gateway_ip'])
96 411e5025 Dionysis Grigoropoulos
        self.assertEqual([{"start": "10.0.3.2", "end": "10.0.3.254"}],
97 411e5025 Dionysis Grigoropoulos
                         resp['allocation_pools'])
98 411e5025 Dionysis Grigoropoulos
        self.assertEqual(True, resp['enable_dhcp'])
99 6a959c73 Dionysis Grigoropoulos
100 b7311f3d Dionysis Grigoropoulos
    def test_create_subnet_success_ipv4_with_slaac(self):
101 b7311f3d Dionysis Grigoropoulos
        """Test create an IPv4 subnet, with a slaac that will be ingored"""
102 97ca522f Dionysis Grigoropoulos
        test_net = mf.NetworkFactory()
103 97ca522f Dionysis Grigoropoulos
        request = {
104 97ca522f Dionysis Grigoropoulos
            'subnet': {
105 97ca522f Dionysis Grigoropoulos
                'network_id': test_net.id,
106 97ca522f Dionysis Grigoropoulos
                'cidr': '10.0.3.0/24',
107 97ca522f Dionysis Grigoropoulos
                'ip_version': 4,
108 b7311f3d Dionysis Grigoropoulos
                'enable_slaac': False}
109 97ca522f Dionysis Grigoropoulos
        }
110 97ca522f Dionysis Grigoropoulos
        response = self.post(SUBNETS_URL, test_net.userid,
111 97ca522f Dionysis Grigoropoulos
                             json.dumps(request), "json")
112 97ca522f Dionysis Grigoropoulos
        self.assertSuccess(response)
113 97ca522f Dionysis Grigoropoulos
114 b7311f3d Dionysis Grigoropoulos
    def test_create_subnet_success_ipv6_with_slaac(self):
115 b7311f3d Dionysis Grigoropoulos
        """Test create a subnet with ipv6 and slaac"""
116 97ca522f Dionysis Grigoropoulos
        test_net = mf.NetworkFactory()
117 97ca522f Dionysis Grigoropoulos
        request = {
118 97ca522f Dionysis Grigoropoulos
            'subnet': {
119 97ca522f Dionysis Grigoropoulos
                'network_id': test_net.id,
120 97ca522f Dionysis Grigoropoulos
                'cidr': 'fdc1:4992:1130:fc0b::/64',
121 97ca522f Dionysis Grigoropoulos
                'ip_version': 6,
122 b7311f3d Dionysis Grigoropoulos
                'enable_slaac': False}
123 97ca522f Dionysis Grigoropoulos
        }
124 97ca522f Dionysis Grigoropoulos
        response = self.post(SUBNETS_URL, test_net.userid,
125 97ca522f Dionysis Grigoropoulos
                             json.dumps(request), "json")
126 97ca522f Dionysis Grigoropoulos
        self.assertSuccess(response)
127 411e5025 Dionysis Grigoropoulos
        resp = json.loads(response.content)['subnet']
128 411e5025 Dionysis Grigoropoulos
        self.assertEqual("fdc1:4992:1130:fc0b::1", resp['gateway_ip'])
129 411e5025 Dionysis Grigoropoulos
        self.assertEqual([], resp['allocation_pools'])
130 b7311f3d Dionysis Grigoropoulos
        self.assertEqual(False, resp['enable_slaac'])
131 97ca522f Dionysis Grigoropoulos
132 b7311f3d Dionysis Grigoropoulos
    def test_create_subnet_with_malformed_slaac(self):
133 b7311f3d Dionysis Grigoropoulos
        """Test create a subnet with ipv6 and a malformed slaac"""
134 97ca522f Dionysis Grigoropoulos
        test_net = mf.NetworkFactory()
135 97ca522f Dionysis Grigoropoulos
        request = {
136 97ca522f Dionysis Grigoropoulos
            'subnet': {
137 97ca522f Dionysis Grigoropoulos
                'network_id': test_net.id,
138 97ca522f Dionysis Grigoropoulos
                'cidr': 'fdc1:4992:1130:fc0b::/64',
139 97ca522f Dionysis Grigoropoulos
                'ip_version': 6,
140 b7311f3d Dionysis Grigoropoulos
                'enable_slaac': 'Random'}
141 97ca522f Dionysis Grigoropoulos
        }
142 97ca522f Dionysis Grigoropoulos
        response = self.post(SUBNETS_URL, test_net.userid,
143 97ca522f Dionysis Grigoropoulos
                             json.dumps(request), "json")
144 97ca522f Dionysis Grigoropoulos
        self.assertBadRequest(response)
145 97ca522f Dionysis Grigoropoulos
146 6a959c73 Dionysis Grigoropoulos
    def test_create_subnet_success_ipv6(self):
147 6a959c73 Dionysis Grigoropoulos
        """Test create an IPv6 subnet successfully"""
148 6a959c73 Dionysis Grigoropoulos
        test_net = mf.NetworkFactory()
149 6a959c73 Dionysis Grigoropoulos
        request = {
150 6a959c73 Dionysis Grigoropoulos
            'subnet': {
151 6a959c73 Dionysis Grigoropoulos
                'network_id': test_net.id,
152 6a959c73 Dionysis Grigoropoulos
                'cidr': 'fdc1:4992:1130:fc0b::/64',
153 6a959c73 Dionysis Grigoropoulos
                'ip_version': 6}
154 6a959c73 Dionysis Grigoropoulos
        }
155 6a959c73 Dionysis Grigoropoulos
        response = self.post(SUBNETS_URL, test_net.userid,
156 6a959c73 Dionysis Grigoropoulos
                             json.dumps(request), "json")
157 6a959c73 Dionysis Grigoropoulos
        self.assertSuccess(response)
158 6a959c73 Dionysis Grigoropoulos
159 6a959c73 Dionysis Grigoropoulos
    def test_create_subnet_with_ip_pool_allocation(self):
160 6a959c73 Dionysis Grigoropoulos
        """Test create a subnet with an IP pool"""
161 6a959c73 Dionysis Grigoropoulos
        test_net = mf.NetworkFactory()
162 6a959c73 Dionysis Grigoropoulos
        request = {
163 6a959c73 Dionysis Grigoropoulos
            'subnet': {
164 6a959c73 Dionysis Grigoropoulos
                'network_id': test_net.id,
165 6a959c73 Dionysis Grigoropoulos
                'cidr': '10.0.3.0/24',
166 6a959c73 Dionysis Grigoropoulos
                'ip_version': 4,
167 6a959c73 Dionysis Grigoropoulos
                'allocation_pools': [{
168 01adca6b Dionysis Grigoropoulos
                    'start': '10.0.3.2',
169 01adca6b Dionysis Grigoropoulos
                    'end': '10.0.3.252'}
170 6a959c73 Dionysis Grigoropoulos
                ]}
171 6a959c73 Dionysis Grigoropoulos
        }
172 6a959c73 Dionysis Grigoropoulos
        response = self.post(SUBNETS_URL, test_net.userid,
173 6a959c73 Dionysis Grigoropoulos
                             json.dumps(request), "json")
174 6a959c73 Dionysis Grigoropoulos
        self.assertSuccess(response)
175 6a959c73 Dionysis Grigoropoulos
176 6a959c73 Dionysis Grigoropoulos
    def test_create_subnet_with_multiple_ip_pools(self):
177 6a959c73 Dionysis Grigoropoulos
        """Test create a subnet with multiple IP pools"""
178 6a959c73 Dionysis Grigoropoulos
        test_net = mf.NetworkFactory()
179 6a959c73 Dionysis Grigoropoulos
        request = {
180 6a959c73 Dionysis Grigoropoulos
            'subnet': {
181 6a959c73 Dionysis Grigoropoulos
                'network_id': test_net.id,
182 6a959c73 Dionysis Grigoropoulos
                'cidr': '10.0.3.0/24',
183 6a959c73 Dionysis Grigoropoulos
                'ip_version': 4,
184 6a959c73 Dionysis Grigoropoulos
                'allocation_pools': [{
185 01adca6b Dionysis Grigoropoulos
                    'start': '10.0.3.2',
186 6a959c73 Dionysis Grigoropoulos
                    'end': '10.0.3.100'}, {
187 6a959c73 Dionysis Grigoropoulos
                    'start': '10.0.3.200',
188 6a959c73 Dionysis Grigoropoulos
                    'end': '10.0.3.220'}
189 6a959c73 Dionysis Grigoropoulos
                ]}
190 6a959c73 Dionysis Grigoropoulos
        }
191 6a959c73 Dionysis Grigoropoulos
        response = self.post(SUBNETS_URL, test_net.userid,
192 6a959c73 Dionysis Grigoropoulos
                             json.dumps(request), "json")
193 6a959c73 Dionysis Grigoropoulos
        self.assertSuccess(response)
194 411e5025 Dionysis Grigoropoulos
        resp = json.loads(response.content)['subnet']
195 411e5025 Dionysis Grigoropoulos
        self.assertEqual([{"start": "10.0.3.2", "end": "10.0.3.100"},
196 411e5025 Dionysis Grigoropoulos
                          {"start": "10.0.3.200", "end": "10.0.3.220"}],
197 411e5025 Dionysis Grigoropoulos
                         resp['allocation_pools'])
198 6a959c73 Dionysis Grigoropoulos
199 fef04862 Dionysis Grigoropoulos
    def test_create_subnet_with_gateway(self):
200 fef04862 Dionysis Grigoropoulos
        """Test create a subnet with a gateway"""
201 fef04862 Dionysis Grigoropoulos
        test_net = mf.NetworkFactory()
202 fef04862 Dionysis Grigoropoulos
        request = {
203 fef04862 Dionysis Grigoropoulos
            'subnet': {
204 fef04862 Dionysis Grigoropoulos
                'network_id': test_net.id,
205 fef04862 Dionysis Grigoropoulos
                'cidr': '10.0.3.0/24',
206 fef04862 Dionysis Grigoropoulos
                'ip_version': 4,
207 fef04862 Dionysis Grigoropoulos
                'gateway_ip': '10.0.3.150'}
208 fef04862 Dionysis Grigoropoulos
        }
209 fef04862 Dionysis Grigoropoulos
        response = self.post(SUBNETS_URL, test_net.userid,
210 fef04862 Dionysis Grigoropoulos
                             json.dumps(request), "json")
211 fef04862 Dionysis Grigoropoulos
        self.assertSuccess(response)
212 fef04862 Dionysis Grigoropoulos
        resp = json.loads(response.content)['subnet']
213 fef04862 Dionysis Grigoropoulos
        self.assertEqual("10.0.3.150", resp['gateway_ip'])
214 fef04862 Dionysis Grigoropoulos
        self.assertEqual([{"start": "10.0.3.1", "end": "10.0.3.149"},
215 fef04862 Dionysis Grigoropoulos
                          {"start": "10.0.3.151", "end": "10.0.3.254"}],
216 fef04862 Dionysis Grigoropoulos
                         resp['allocation_pools'])
217 fef04862 Dionysis Grigoropoulos
218 01adca6b Dionysis Grigoropoulos
    def test_create_subnet_with_gateway_inside_of_ip_pool_range(self):
219 fef04862 Dionysis Grigoropoulos
        """Test create a subnet with a gateway IP inside the IP pool range"""
220 01adca6b Dionysis Grigoropoulos
        test_net = mf.NetworkFactory()
221 01adca6b Dionysis Grigoropoulos
        request = {
222 01adca6b Dionysis Grigoropoulos
            'subnet': {
223 01adca6b Dionysis Grigoropoulos
                'network_id': test_net.id,
224 01adca6b Dionysis Grigoropoulos
                'cidr': '10.0.3.0/24',
225 01adca6b Dionysis Grigoropoulos
                'ip_version': 4,
226 01adca6b Dionysis Grigoropoulos
                'gateway_ip': '10.0.3.1',
227 01adca6b Dionysis Grigoropoulos
                'allocation_pools': [{
228 01adca6b Dionysis Grigoropoulos
                    'start': '10.0.3.0',
229 01adca6b Dionysis Grigoropoulos
                    'end': '10.0.3.255'}
230 01adca6b Dionysis Grigoropoulos
                ]}
231 01adca6b Dionysis Grigoropoulos
        }
232 01adca6b Dionysis Grigoropoulos
        response = self.post(SUBNETS_URL, test_net.userid,
233 01adca6b Dionysis Grigoropoulos
                             json.dumps(request), "json")
234 01adca6b Dionysis Grigoropoulos
        self.assertConflict(response)
235 01adca6b Dionysis Grigoropoulos
236 6a959c73 Dionysis Grigoropoulos
    def test_create_subnet_with_ip_pool_outside_of_network_range(self):
237 6a959c73 Dionysis Grigoropoulos
        """Test create a subnet with an IP pool outside of network range"""
238 6a959c73 Dionysis Grigoropoulos
        test_net = mf.NetworkFactory()
239 6a959c73 Dionysis Grigoropoulos
        request = {
240 6a959c73 Dionysis Grigoropoulos
            'subnet': {
241 6a959c73 Dionysis Grigoropoulos
                'network_id': test_net.id,
242 6a959c73 Dionysis Grigoropoulos
                'cidr': '10.0.3.0/24',
243 6a959c73 Dionysis Grigoropoulos
                'ip_version': 4,
244 6a959c73 Dionysis Grigoropoulos
                'allocation_pools': [{
245 6a959c73 Dionysis Grigoropoulos
                    'start': '10.0.8.0',
246 01adca6b Dionysis Grigoropoulos
                    'end': '10.0.1.250'}
247 6a959c73 Dionysis Grigoropoulos
                ]}
248 6a959c73 Dionysis Grigoropoulos
        }
249 6a959c73 Dionysis Grigoropoulos
        response = self.post(SUBNETS_URL, test_net.userid,
250 6a959c73 Dionysis Grigoropoulos
                             json.dumps(request), "json")
251 01adca6b Dionysis Grigoropoulos
        self.assertConflict(response)
252 6a959c73 Dionysis Grigoropoulos
253 6a959c73 Dionysis Grigoropoulos
    def test_create_subnet_with_ip_pool_end_lower_than_start(self):
254 6a959c73 Dionysis Grigoropoulos
        """Test create a subnet with a pool where end is lower than start"""
255 6a959c73 Dionysis Grigoropoulos
        test_net = mf.NetworkFactory()
256 6a959c73 Dionysis Grigoropoulos
        request = {
257 6a959c73 Dionysis Grigoropoulos
            'subnet': {
258 6a959c73 Dionysis Grigoropoulos
                'network_id': test_net.id,
259 6a959c73 Dionysis Grigoropoulos
                'cidr': '10.0.3.0/24',
260 6a959c73 Dionysis Grigoropoulos
                'ip_version': 4,
261 6a959c73 Dionysis Grigoropoulos
                'allocation_pools': [{
262 6a959c73 Dionysis Grigoropoulos
                    'start': '10.0.1.10',
263 6a959c73 Dionysis Grigoropoulos
                    'end': '10.0.1.5'}
264 6a959c73 Dionysis Grigoropoulos
                ]}
265 6a959c73 Dionysis Grigoropoulos
        }
266 6a959c73 Dionysis Grigoropoulos
        response = self.post(SUBNETS_URL, test_net.userid,
267 6a959c73 Dionysis Grigoropoulos
                             json.dumps(request), "json")
268 01adca6b Dionysis Grigoropoulos
        self.assertConflict(response)
269 6a959c73 Dionysis Grigoropoulos
270 6a959c73 Dionysis Grigoropoulos
    def test_create_subnet_with_ip_pool_in_a_ipv6_subnet(self):
271 6a959c73 Dionysis Grigoropoulos
        """Test create a subnet with an ip pool, in an IPv6 subnet """
272 6a959c73 Dionysis Grigoropoulos
        test_net = mf.NetworkFactory()
273 6a959c73 Dionysis Grigoropoulos
        request = {
274 6a959c73 Dionysis Grigoropoulos
            'subnet': {
275 6a959c73 Dionysis Grigoropoulos
                'network_id': test_net.id,
276 6a959c73 Dionysis Grigoropoulos
                'cidr': 'fd4b:638e:fd7a:f998::/64',
277 6a959c73 Dionysis Grigoropoulos
                'ip_version': 6,
278 6a959c73 Dionysis Grigoropoulos
                'allocation_pools': [{
279 6a959c73 Dionysis Grigoropoulos
                    'start': '10.0.1.10',
280 6a959c73 Dionysis Grigoropoulos
                    'end': '10.0.1.5'}
281 6a959c73 Dionysis Grigoropoulos
                ]}
282 6a959c73 Dionysis Grigoropoulos
        }
283 6a959c73 Dionysis Grigoropoulos
        response = self.post(SUBNETS_URL, test_net.userid,
284 6a959c73 Dionysis Grigoropoulos
                             json.dumps(request), "json")
285 01adca6b Dionysis Grigoropoulos
        self.assertConflict(response)
286 6a959c73 Dionysis Grigoropoulos
287 6a959c73 Dionysis Grigoropoulos
    def test_create_subnet_with_invalid_network_id(self):
288 6a959c73 Dionysis Grigoropoulos
        """Test create a subnet with a network id that doesn't exist"""
289 6a959c73 Dionysis Grigoropoulos
        test_net = mf.NetworkFactory()
290 6a959c73 Dionysis Grigoropoulos
        request = {
291 6a959c73 Dionysis Grigoropoulos
            'subnet': {
292 6a959c73 Dionysis Grigoropoulos
                'network_id': '420000',
293 6a959c73 Dionysis Grigoropoulos
                'cidr': '10.0.3.0/24',
294 6a959c73 Dionysis Grigoropoulos
                'ip_version': 4}
295 6a959c73 Dionysis Grigoropoulos
        }
296 6a959c73 Dionysis Grigoropoulos
        response = self.post(SUBNETS_URL, test_net.userid, json.dumps(request),
297 6a959c73 Dionysis Grigoropoulos
                             "json")
298 6a959c73 Dionysis Grigoropoulos
        self.assertItemNotFound(response)
299 6a959c73 Dionysis Grigoropoulos
300 6a959c73 Dionysis Grigoropoulos
    def test_create_subnet_with_malformed_ipversion(self):
301 6a959c73 Dionysis Grigoropoulos
        """Create a subnet with a malformed ip_version type"""
302 6a959c73 Dionysis Grigoropoulos
        test_net = mf.NetworkFactory()
303 6a959c73 Dionysis Grigoropoulos
        request = {
304 6a959c73 Dionysis Grigoropoulos
            'subnet': {
305 6a959c73 Dionysis Grigoropoulos
                'network_id': test_net.id,
306 6a959c73 Dionysis Grigoropoulos
                'cidr': '10.0.3.0/24',
307 6a959c73 Dionysis Grigoropoulos
                'ip_version': 8}
308 6a959c73 Dionysis Grigoropoulos
        }
309 6a959c73 Dionysis Grigoropoulos
        response = self.post(SUBNETS_URL, test_net.userid, json.dumps(request),
310 6a959c73 Dionysis Grigoropoulos
                             "json")
311 6a959c73 Dionysis Grigoropoulos
        self.assertBadRequest(response)
312 6a959c73 Dionysis Grigoropoulos
313 6a959c73 Dionysis Grigoropoulos
    def test_create_subnet_with_invalid_cidr(self):
314 6a959c73 Dionysis Grigoropoulos
        """Create a subnet with an invalid cidr"""
315 6a959c73 Dionysis Grigoropoulos
        test_net = mf.NetworkFactory()
316 6a959c73 Dionysis Grigoropoulos
        request = {
317 6a959c73 Dionysis Grigoropoulos
            'subnet': {
318 6a959c73 Dionysis Grigoropoulos
                'network_id': test_net.id,
319 6a959c73 Dionysis Grigoropoulos
                'cidr': '192.168.3.0/8'}
320 6a959c73 Dionysis Grigoropoulos
        }
321 6a959c73 Dionysis Grigoropoulos
        response = self.post(SUBNETS_URL, test_net.userid, json.dumps(request),
322 6a959c73 Dionysis Grigoropoulos
                             "json")
323 6a959c73 Dionysis Grigoropoulos
        self.assertBadRequest(response)
324 6a959c73 Dionysis Grigoropoulos
325 6a959c73 Dionysis Grigoropoulos
    def test_create_subnet_with_invalid_gateway(self):
326 6a959c73 Dionysis Grigoropoulos
        """Create a subnet with a gateway outside of the subnet range"""
327 6a959c73 Dionysis Grigoropoulos
        test_net = mf.NetworkFactory()
328 6a959c73 Dionysis Grigoropoulos
        request = {
329 6a959c73 Dionysis Grigoropoulos
            'subnet': {
330 6a959c73 Dionysis Grigoropoulos
                'network_id': test_net.id,
331 6a959c73 Dionysis Grigoropoulos
                'cidr': '192.168.3.0/24',
332 6a959c73 Dionysis Grigoropoulos
                'gateway_ip': '192.168.0.1'}
333 6a959c73 Dionysis Grigoropoulos
        }
334 6a959c73 Dionysis Grigoropoulos
        response = self.post(SUBNETS_URL, test_net.userid, json.dumps(request),
335 6a959c73 Dionysis Grigoropoulos
                             "json")
336 6a959c73 Dionysis Grigoropoulos
        self.assertBadRequest(response)
337 6a959c73 Dionysis Grigoropoulos
338 6a959c73 Dionysis Grigoropoulos
    def test_create_subnet_with_invalid_name(self):
339 6a959c73 Dionysis Grigoropoulos
        """Create a subnet with an invalid subnet name"""
340 6a959c73 Dionysis Grigoropoulos
        test_net = mf.NetworkFactory()
341 6a959c73 Dionysis Grigoropoulos
        request = {
342 6a959c73 Dionysis Grigoropoulos
            'subnet': {
343 6a959c73 Dionysis Grigoropoulos
                'network_id': test_net.id,
344 6a959c73 Dionysis Grigoropoulos
                'cidr': '192.168.3.0/24',
345 6a959c73 Dionysis Grigoropoulos
                'name': 'a' * 300}
346 6a959c73 Dionysis Grigoropoulos
        }
347 6a959c73 Dionysis Grigoropoulos
        response = self.post(SUBNETS_URL, test_net.userid, json.dumps(request),
348 6a959c73 Dionysis Grigoropoulos
                             "json")
349 6a959c73 Dionysis Grigoropoulos
        self.assertBadRequest(response)
350 6a959c73 Dionysis Grigoropoulos
351 6a959c73 Dionysis Grigoropoulos
    def test_create_subnet_with_invalid_dhcp(self):
352 6a959c73 Dionysis Grigoropoulos
        """Create a subnet with an invalid dhcp value"""
353 6a959c73 Dionysis Grigoropoulos
        test_net = mf.NetworkFactory()
354 6a959c73 Dionysis Grigoropoulos
        request = {
355 6a959c73 Dionysis Grigoropoulos
            'subnet': {
356 6a959c73 Dionysis Grigoropoulos
                'network_id': test_net.id,
357 6a959c73 Dionysis Grigoropoulos
                'cidr': '192.168.3.0/24',
358 6a959c73 Dionysis Grigoropoulos
                'enable_dhcp': 'None'}
359 6a959c73 Dionysis Grigoropoulos
        }
360 6a959c73 Dionysis Grigoropoulos
        response = self.post(SUBNETS_URL, test_net.userid, json.dumps(request),
361 6a959c73 Dionysis Grigoropoulos
                             "json")
362 6a959c73 Dionysis Grigoropoulos
        self.assertBadRequest(response)
363 6a959c73 Dionysis Grigoropoulos
364 97ca522f Dionysis Grigoropoulos
    def test_create_subnet_with_dhcp_set_to_false(self):
365 97ca522f Dionysis Grigoropoulos
        """Create a subnet with a dhcp set to false"""
366 97ca522f Dionysis Grigoropoulos
        test_net = mf.NetworkFactory()
367 97ca522f Dionysis Grigoropoulos
        request = {
368 97ca522f Dionysis Grigoropoulos
            'subnet': {
369 97ca522f Dionysis Grigoropoulos
                'network_id': test_net.id,
370 97ca522f Dionysis Grigoropoulos
                'cidr': '192.168.3.0/24',
371 97ca522f Dionysis Grigoropoulos
                'enable_dhcp': False}
372 97ca522f Dionysis Grigoropoulos
        }
373 97ca522f Dionysis Grigoropoulos
        response = self.post(SUBNETS_URL, test_net.userid, json.dumps(request),
374 97ca522f Dionysis Grigoropoulos
                             "json")
375 97ca522f Dionysis Grigoropoulos
        self.assertSuccess(response)
376 97ca522f Dionysis Grigoropoulos
377 6a959c73 Dionysis Grigoropoulos
    def test_create_subnet_with_dns_nameservers(self):
378 6a959c73 Dionysis Grigoropoulos
        """Create a subnet with dns nameservers"""
379 6a959c73 Dionysis Grigoropoulos
        test_net = mf.NetworkFactory()
380 6a959c73 Dionysis Grigoropoulos
        request = {
381 6a959c73 Dionysis Grigoropoulos
            'subnet': {
382 6a959c73 Dionysis Grigoropoulos
                'network_id': test_net.id,
383 6a959c73 Dionysis Grigoropoulos
                'cidr': '192.168.3.0/24',
384 6a959c73 Dionysis Grigoropoulos
                'dns_nameservers': ['8.8.8.8', '1.1.1.1']}
385 6a959c73 Dionysis Grigoropoulos
        }
386 6a959c73 Dionysis Grigoropoulos
        response = self.post(SUBNETS_URL, test_net.userid, json.dumps(request),
387 6a959c73 Dionysis Grigoropoulos
                             "json")
388 6a959c73 Dionysis Grigoropoulos
        self.assertSuccess(response)
389 6a959c73 Dionysis Grigoropoulos
390 6a959c73 Dionysis Grigoropoulos
    def test_create_subnet_with_host_routes(self):
391 6a959c73 Dionysis Grigoropoulos
        """Create a subnet with dns nameservers"""
392 6a959c73 Dionysis Grigoropoulos
        test_net = mf.NetworkFactory()
393 6a959c73 Dionysis Grigoropoulos
        request = {
394 6a959c73 Dionysis Grigoropoulos
            'subnet': {
395 6a959c73 Dionysis Grigoropoulos
                'network_id': test_net.id,
396 6a959c73 Dionysis Grigoropoulos
                'cidr': '192.168.3.0/24',
397 6a959c73 Dionysis Grigoropoulos
                'host_routes': ['8.8.8.8', '1.1.1.1']}
398 6a959c73 Dionysis Grigoropoulos
        }
399 6a959c73 Dionysis Grigoropoulos
        response = self.post(SUBNETS_URL, test_net.userid, json.dumps(request),
400 6a959c73 Dionysis Grigoropoulos
                             "json")
401 6a959c73 Dionysis Grigoropoulos
        self.assertSuccess(response)
402 411e5025 Dionysis Grigoropoulos
        resp = json.loads(response.content)['subnet']
403 411e5025 Dionysis Grigoropoulos
        self.assertEqual(["8.8.8.8", "1.1.1.1"], resp["host_routes"])
404 6a959c73 Dionysis Grigoropoulos
405 6a959c73 Dionysis Grigoropoulos
    def test_create_subnet_with_same_ipversion(self):
406 6a959c73 Dionysis Grigoropoulos
        """
407 6a959c73 Dionysis Grigoropoulos
        Create a subnet in a network with another subnet of the same
408 6a959c73 Dionysis Grigoropoulos
        ipversion type
409 6a959c73 Dionysis Grigoropoulos
        """
410 6a959c73 Dionysis Grigoropoulos
        test_net = mf.NetworkFactory()
411 6a959c73 Dionysis Grigoropoulos
        test_sub = mf.IPv4SubnetFactory(network=test_net)
412 6a959c73 Dionysis Grigoropoulos
        request = {
413 6a959c73 Dionysis Grigoropoulos
            'subnet': {
414 6a959c73 Dionysis Grigoropoulos
                'network_id': test_net.id,
415 6a959c73 Dionysis Grigoropoulos
                'cidr': '192.168.3.0/24'}
416 6a959c73 Dionysis Grigoropoulos
        }
417 6a959c73 Dionysis Grigoropoulos
        response = self.post(SUBNETS_URL, test_net.userid, json.dumps(request),
418 6a959c73 Dionysis Grigoropoulos
                             "json")
419 6a959c73 Dionysis Grigoropoulos
        self.assertBadRequest(response)
420 6a959c73 Dionysis Grigoropoulos
421 6a959c73 Dionysis Grigoropoulos
    def test_update_subnet_ip_version(self):
422 6a959c73 Dionysis Grigoropoulos
        """Update the IP version of a subnet, raises 400 BadRequest"""
423 6a959c73 Dionysis Grigoropoulos
        test_net = mf.NetworkFactory()
424 6a959c73 Dionysis Grigoropoulos
        test_sub = mf.IPv4SubnetFactory(network=test_net)
425 6a959c73 Dionysis Grigoropoulos
        request = {
426 6a959c73 Dionysis Grigoropoulos
            'subnet': {
427 6a959c73 Dionysis Grigoropoulos
                'ip_version': '6'}
428 6a959c73 Dionysis Grigoropoulos
        }
429 6a959c73 Dionysis Grigoropoulos
        url = join_urls(SUBNETS_URL, str(test_sub.id))
430 6a959c73 Dionysis Grigoropoulos
        response = self.put(url, test_net.userid, json.dumps(request), "json")
431 6a959c73 Dionysis Grigoropoulos
        self.assertBadRequest(response)
432 6a959c73 Dionysis Grigoropoulos
433 6a959c73 Dionysis Grigoropoulos
    def test_update_subnet_cidr(self):
434 6a959c73 Dionysis Grigoropoulos
        """Update the cidr of a subnet, raises 400 BadRequest"""
435 6a959c73 Dionysis Grigoropoulos
        test_net = mf.NetworkFactory()
436 6a959c73 Dionysis Grigoropoulos
        test_sub = mf.IPv4SubnetFactory(network=test_net)
437 6a959c73 Dionysis Grigoropoulos
        request = {
438 6a959c73 Dionysis Grigoropoulos
            'subnet': {
439 6a959c73 Dionysis Grigoropoulos
                'cidr': '192.168.42.0/24'}
440 6a959c73 Dionysis Grigoropoulos
        }
441 6a959c73 Dionysis Grigoropoulos
        url = join_urls(SUBNETS_URL, str(test_sub.id))
442 6a959c73 Dionysis Grigoropoulos
        response = self.put(url, test_net.userid, json.dumps(request), "json")
443 6a959c73 Dionysis Grigoropoulos
        self.assertBadRequest(response)
444 6a959c73 Dionysis Grigoropoulos
445 6a959c73 Dionysis Grigoropoulos
    def test_update_subnet_allocation_pools(self):
446 6a959c73 Dionysis Grigoropoulos
        """Update the allocation pools of a subnet, raises 400 BadRequest"""
447 6a959c73 Dionysis Grigoropoulos
        test_net = mf.NetworkFactory()
448 6a959c73 Dionysis Grigoropoulos
        test_sub = mf.IPv4SubnetFactory(network=test_net)
449 6a959c73 Dionysis Grigoropoulos
        request = {
450 6a959c73 Dionysis Grigoropoulos
            'subnet': {
451 6a959c73 Dionysis Grigoropoulos
                'allocation_pools': [{
452 6a959c73 Dionysis Grigoropoulos
                    'start': '10.0.3.0',
453 6a959c73 Dionysis Grigoropoulos
                    'end': '10.0.3.255'}
454 6a959c73 Dionysis Grigoropoulos
                ]}
455 6a959c73 Dionysis Grigoropoulos
        }
456 6a959c73 Dionysis Grigoropoulos
        url = join_urls(SUBNETS_URL, str(test_sub.id))
457 6a959c73 Dionysis Grigoropoulos
        response = self.put(url, test_net.userid, json.dumps(request), "json")
458 6a959c73 Dionysis Grigoropoulos
        self.assertBadRequest(response)
459 6a959c73 Dionysis Grigoropoulos
460 6a959c73 Dionysis Grigoropoulos
    def test_update_subnet_add_dns(self):
461 6a959c73 Dionysis Grigoropoulos
        """Update the dns nameservers of a subnet, raises 400 BadRequest"""
462 6a959c73 Dionysis Grigoropoulos
        test_net = mf.NetworkFactory()
463 6a959c73 Dionysis Grigoropoulos
        test_sub = mf.IPv4SubnetFactory(network=test_net)
464 6a959c73 Dionysis Grigoropoulos
        request = {
465 6a959c73 Dionysis Grigoropoulos
            'subnet': {
466 6a959c73 Dionysis Grigoropoulos
                'dns_nameservers': ['8.8.8.8']}
467 6a959c73 Dionysis Grigoropoulos
        }
468 6a959c73 Dionysis Grigoropoulos
        url = join_urls(SUBNETS_URL, str(test_sub.id))
469 6a959c73 Dionysis Grigoropoulos
        response = self.put(url, test_net.userid, json.dumps(request), "json")
470 6a959c73 Dionysis Grigoropoulos
        self.assertBadRequest(response)
471 6a959c73 Dionysis Grigoropoulos
472 6a959c73 Dionysis Grigoropoulos
    def test_update_subnet_add_host_routes(self):
473 6a959c73 Dionysis Grigoropoulos
        """Update the host routes of a subnet, raises 400 BadRequest"""
474 6a959c73 Dionysis Grigoropoulos
        test_net = mf.NetworkFactory()
475 6a959c73 Dionysis Grigoropoulos
        test_sub = mf.IPv4SubnetFactory(network=test_net)
476 6a959c73 Dionysis Grigoropoulos
        request = {
477 6a959c73 Dionysis Grigoropoulos
            'subnet': {
478 6a959c73 Dionysis Grigoropoulos
                'host_routes': ['8.8.8.8']}
479 6a959c73 Dionysis Grigoropoulos
        }
480 6a959c73 Dionysis Grigoropoulos
        url = join_urls(SUBNETS_URL, str(test_sub.id))
481 6a959c73 Dionysis Grigoropoulos
        response = self.put(url, test_net.userid, json.dumps(request), "json")
482 6a959c73 Dionysis Grigoropoulos
        self.assertBadRequest(response)
483 6a959c73 Dionysis Grigoropoulos
484 6a959c73 Dionysis Grigoropoulos
    def test_update_subnet_with_invalid_dhcp_value(self):
485 6a959c73 Dionysis Grigoropoulos
        """Update a subnet with an invalid dhcp value"""
486 6a959c73 Dionysis Grigoropoulos
        test_net = mf.NetworkFactory()
487 6a959c73 Dionysis Grigoropoulos
        test_sub = mf.IPv4SubnetFactory(network=test_net)
488 6a959c73 Dionysis Grigoropoulos
        request = {
489 6a959c73 Dionysis Grigoropoulos
            'subnet': {
490 6a959c73 Dionysis Grigoropoulos
                'enable_dhcp': 'Random'}
491 6a959c73 Dionysis Grigoropoulos
        }
492 6a959c73 Dionysis Grigoropoulos
        url = join_urls(SUBNETS_URL, str(test_sub.id))
493 6a959c73 Dionysis Grigoropoulos
        response = self.put(url, test_net.userid, json.dumps(request), "json")
494 6a959c73 Dionysis Grigoropoulos
        self.assertBadRequest(response)
495 6a959c73 Dionysis Grigoropoulos
496 6a959c73 Dionysis Grigoropoulos
    def test_update_subnet_with_invalid_name(self):
497 6a959c73 Dionysis Grigoropoulos
        """Update a subnet with an invalid name value"""
498 6a959c73 Dionysis Grigoropoulos
        test_net = mf.NetworkFactory()
499 6a959c73 Dionysis Grigoropoulos
        test_sub = mf.IPv4SubnetFactory(network=test_net)
500 6a959c73 Dionysis Grigoropoulos
        request = {
501 6a959c73 Dionysis Grigoropoulos
            'subnet': {
502 6a959c73 Dionysis Grigoropoulos
                'name': 'a' * 300}
503 6a959c73 Dionysis Grigoropoulos
        }
504 6a959c73 Dionysis Grigoropoulos
        url = join_urls(SUBNETS_URL, str(test_sub.id))
505 6a959c73 Dionysis Grigoropoulos
        response = self.put(url, test_net.userid, json.dumps(request), "json")
506 6a959c73 Dionysis Grigoropoulos
        self.assertBadRequest(response)
507 6a959c73 Dionysis Grigoropoulos
508 6a959c73 Dionysis Grigoropoulos
    def test_update_subnet_with_invalid_gateway(self):
509 6a959c73 Dionysis Grigoropoulos
        """Update a subnet with an invalid gateway value"""
510 6a959c73 Dionysis Grigoropoulos
        test_net = mf.NetworkFactory()
511 6a959c73 Dionysis Grigoropoulos
        test_sub = mf.IPv4SubnetFactory(network=test_net)
512 6a959c73 Dionysis Grigoropoulos
        request = {
513 6a959c73 Dionysis Grigoropoulos
            'subnet': {
514 6a959c73 Dionysis Grigoropoulos
                'gateway_ip': '192.168.200.0/24'}
515 6a959c73 Dionysis Grigoropoulos
        }
516 6a959c73 Dionysis Grigoropoulos
        url = join_urls(SUBNETS_URL, str(test_sub.id))
517 6a959c73 Dionysis Grigoropoulos
        response = self.put(url, test_net.userid, json.dumps(request), "json")
518 6a959c73 Dionysis Grigoropoulos
        self.assertBadRequest(response)
519 6a959c73 Dionysis Grigoropoulos
520 6a959c73 Dionysis Grigoropoulos
    def test_update_subnet_gateway(self):
521 6a959c73 Dionysis Grigoropoulos
        """Update the gateway of a subnet"""
522 6a959c73 Dionysis Grigoropoulos
        test_net = mf.NetworkFactory()
523 6a959c73 Dionysis Grigoropoulos
        test_sub = mf.IPv4SubnetFactory(network=test_net)
524 6a959c73 Dionysis Grigoropoulos
        request = {
525 6a959c73 Dionysis Grigoropoulos
            'subnet': {
526 6a959c73 Dionysis Grigoropoulos
                'gateway_ip': str(IPv4Network(test_sub.gateway).network + 1)}
527 6a959c73 Dionysis Grigoropoulos
        }
528 6a959c73 Dionysis Grigoropoulos
        url = join_urls(SUBNETS_URL, str(test_sub.id))
529 6a959c73 Dionysis Grigoropoulos
        response = self.put(url, test_net.userid, json.dumps(request), "json")
530 6a959c73 Dionysis Grigoropoulos
        self.assertBadRequest(response)
531 6a959c73 Dionysis Grigoropoulos
532 6a959c73 Dionysis Grigoropoulos
    def test_update_subnet_name(self):
533 6a959c73 Dionysis Grigoropoulos
        """Update the name of a subnet"""
534 6a959c73 Dionysis Grigoropoulos
        test_net = mf.NetworkFactory()
535 6a959c73 Dionysis Grigoropoulos
        test_sub = mf.IPv4SubnetFactory(network=test_net)
536 6a959c73 Dionysis Grigoropoulos
        request = {
537 6a959c73 Dionysis Grigoropoulos
            'subnet': {
538 6a959c73 Dionysis Grigoropoulos
                'name': 'Updated Name'}
539 6a959c73 Dionysis Grigoropoulos
        }
540 6a959c73 Dionysis Grigoropoulos
        url = join_urls(SUBNETS_URL, str(test_sub.id))
541 6a959c73 Dionysis Grigoropoulos
        response = self.put(url, test_net.userid, json.dumps(request), "json")
542 6a959c73 Dionysis Grigoropoulos
        self.assertSuccess(response)
543 6a959c73 Dionysis Grigoropoulos
544 6a959c73 Dionysis Grigoropoulos
    def test_update_subnet_dhcp(self):
545 6a959c73 Dionysis Grigoropoulos
        """Update the dhcp flag of a subnet"""
546 6a959c73 Dionysis Grigoropoulos
        test_net = mf.NetworkFactory()
547 6a959c73 Dionysis Grigoropoulos
        test_sub = mf.IPv4SubnetFactory(network=test_net)
548 6a959c73 Dionysis Grigoropoulos
        request = {
549 6a959c73 Dionysis Grigoropoulos
            'subnet': {
550 6a959c73 Dionysis Grigoropoulos
                'enable_dhcp': False}
551 6a959c73 Dionysis Grigoropoulos
        }
552 6a959c73 Dionysis Grigoropoulos
        url = join_urls(SUBNETS_URL, str(test_sub.id))
553 6a959c73 Dionysis Grigoropoulos
        response = self.put(url, test_net.userid, json.dumps(request), "json")
554 6a959c73 Dionysis Grigoropoulos
        self.assertBadRequest(response)