Revision f2080d16 snf-cyclades-app/synnefo/api/test/servers.py
b/snf-cyclades-app/synnefo/api/test/servers.py | ||
---|---|---|
40 | 40 |
from synnefo.cyclades_settings import cyclades_services |
41 | 41 |
from synnefo.lib.services import get_service_path |
42 | 42 |
from synnefo.lib import join_urls |
43 |
from synnefo.logic.rapi import GanetiApiError |
|
43 | 44 |
|
44 | 45 |
from mock import patch |
45 | 46 |
|
... | ... | |
303 | 304 |
json.dumps(request), 'json') |
304 | 305 |
self.assertItemNotFound(response) |
305 | 306 |
|
307 |
def test_create_server_error(self, mrapi, mimage): |
|
308 |
"""Test if the create server call returns the expected response |
|
309 |
if a valid request has been speficied.""" |
|
310 |
mimage.return_value = {'location': 'pithos://foo', |
|
311 |
'checksum': '1234', |
|
312 |
"id": 1, |
|
313 |
"name": "test_image", |
|
314 |
'disk_format': 'diskdump'} |
|
315 |
mrapi().CreateInstance.side_effect = GanetiApiError("..ganeti is down") |
|
316 |
flavor = mfactory.FlavorFactory() |
|
317 |
# Create public network and backend |
|
318 |
network = mfactory.NetworkFactory(public=True) |
|
319 |
backend = mfactory.BackendFactory() |
|
320 |
mfactory.BackendNetworkFactory(network=network, backend=backend) |
|
321 |
|
|
322 |
request = { |
|
323 |
"server": { |
|
324 |
"name": "new-server-test", |
|
325 |
"userid": "test_user", |
|
326 |
"imageRef": 1, |
|
327 |
"flavorRef": flavor.id, |
|
328 |
"metadata": { |
|
329 |
"My Server Name": "Apache1" |
|
330 |
}, |
|
331 |
"personality": [] |
|
332 |
} |
|
333 |
} |
|
334 |
with mocked_quotaholder(): |
|
335 |
response = self.mypost('servers', 'test_user', |
|
336 |
json.dumps(request), 'json') |
|
337 |
self.assertEqual(response.status_code, 500) |
|
338 |
mrapi().CreateInstance.assert_called_once() |
|
339 |
vm = VirtualMachine.objects.get() |
|
340 |
# The VM has been deleted |
|
341 |
self.assertTrue(vm.deleted) |
|
342 |
# and it has no nics |
|
343 |
self.assertEqual(len(vm.nics.all()), 0) |
|
344 |
self.assertEqual(vm.backendjobid, 0) |
|
345 |
|
|
306 | 346 |
|
307 | 347 |
@patch('synnefo.logic.rapi_pool.GanetiRapiClient') |
308 | 348 |
class ServerDestroyAPITest(ComputeAPITest): |
Also available in: Unified diff