Revision a3b8aaf6 snf-cyclades-app/synnefo/api/tests/ports.py

b/snf-cyclades-app/synnefo/api/tests/ports.py
69 69
        response = self.delete(url, user=nic.network.userid)
70 70
        self.assertEqual(response.status_code, 204)
71 71

  
72
    def test_remove_nic_malformed(self):
73
        url = join_urls(PORTS_URL, "123")
74
        response = self.delete(url)
75
        self.assertItemNotFound(response)
76

  
72 77
    def test_update_port_name(self):
73 78
        nic = dbmf.NetworkInterfaceFactory.create(device_owner='vm')
74 79
        url = join_urls(PORTS_URL, str(nic.id))
......
134 139
        response = self.post(PORTS_URL, params=json.dumps(request),
135 140
                             user=net.userid)
136 141
        self.assertEqual(response.status_code, 201)
142

  
143
    def test_add_nic_to_deleted_network(self):
144
        user = 'userr'
145
        vm = dbmf.VirtualMachineFactory(name='yo', userid=user,
146
                                            operstate="ACTIVE")
147
        net = dbmf.NetworkFactory(state='ACTIVE', userid=user,
148
                                      deleted=True)
149
        request = {
150
            "port": {
151
                "device_id": str(vm.id),
152
                "name": "port1",
153
                "network_id": str(net.id)
154
            }
155
        }
156
        response = self.post(PORTS_URL, params=json.dumps(request),
157
                             user=net.userid)
158
        self.assertBadRequest(response)
159

  
160
    def test_add_nic_to_public_network(self):
161
        user = 'userr'
162
        vm = dbmf.VirtualMachineFactory(name='yo', userid=user)
163
        net = dbmf.NetworkFactory(state='ACTIVE', userid=user, public=True)
164
        request = {
165
            "port": {
166
                "device_id": str(vm.id),
167
                "name": "port1",
168
                "network_id": str(net.id)
169
            }
170
        }
171
        response = self.post(PORTS_URL, params=json.dumps(request),
172
                             user=net.userid)
173
        self.assertFault(response, 403, 'forbidden')
174

  
175
    def test_add_nic_malformed_1(self):
176
        user = 'userr'
177
        vm = dbmf.VirtualMachineFactory(name='yo', userid=user)
178
        net = dbmf.NetworkFactory(state='ACTIVE', userid=user)
179
        request = {
180
            "port": {
181
                "name": "port1",
182
                "network_id": str(net.id)
183
            }
184
        }
185
        response = self.post(PORTS_URL, params=json.dumps(request),
186
                             user=net.userid)
187
        self.assertBadRequest(response)
188

  
189
    def test_add_nic_malformed_2(self):
190
        user = 'userr'
191
        vm = dbmf.VirtualMachineFactory(name='yo', userid=user)
192
        net = dbmf.NetworkFactory(state='ACTIVE', userid=user)
193
        request = {
194
            "port": {
195
                "device_id": str(vm.id),
196
                "name": "port1"
197
            }
198
        }
199
        response = self.post(PORTS_URL, params=json.dumps(request),
200
                             user=net.userid)
201
        self.assertBadRequest(response)
202

  
203
    def test_add_nic_not_active(self):
204
        """Test connecting VM to non-active network"""
205
        user = 'dummy'
206
        vm = dbmf.VirtualMachineFactory(name='yo', userid=user)
207
        net = dbmf.NetworkFactory(state='PENDING', userid=user)
208
        request = {
209
            "port": {
210
                "device_id": str(vm.id),
211
                "name": "port1",
212
                "network_id": str(net.id)
213
            }
214
        }
215
        response = self.post(PORTS_URL, params=json.dumps(request),
216
                             user=net.userid)
217
        # Test that returns BuildInProgress
218
        self.assertEqual(response.status_code, 409)
219

  
220
#    def test_add_nic_full_network(self, mrapi):
221
#        """Test connecting VM to a full network"""
222
#        user = 'userr'
223
#        vm = dbmf.VirtualMachineFactory(name='yo', userid=user,
224
#                                            operstate="STARTED")
225
#        net = dbmf.NetworkFactory(state='ACTIVE', subnet='10.0.0.0/30',
226
#                                      userid=user, dhcp=True)
227
#        pool = net.get_pool()
228
#        while not pool.empty():
229
#            pool.get()
230
#        pool.save()
231
#        pool = net.get_pool()
232
#        self.assertTrue(pool.empty())
233
#        request = {'add': {'serverRef': vm.id}}
234
#        response = self.mypost('networks/%d/action' % net.id,
235
#                               net.userid, json.dumps(request), 'json')
236
#        # Test that returns OverLimit
237
#        self.assertEqual(response.status_code, 413)
238
#        self.assertFalse(mrapi.called)

Also available in: Unified diff