Revision 1af851fd snf-cyclades-app/synnefo/api/test/servers.py

b/snf-cyclades-app/synnefo/api/test/servers.py
443 443
        self.assertBadRequest(response)
444 444
        self.assertFalse(mrapi.mock_calls)
445 445

  
446
    def test_resize_vm(self, mrapi, mimage):
447
        flavor = mfactory.FlavorFactory(cpu=1, ram=1024)
448
        # Check building VM
449
        vm = self.get_vm(flavor=flavor, operstate="BUILD")
450
        request = {'resize': {'flavorRef': flavor.id}}
451
        response = self.post('/api/v1.1/servers/%d/action' % vm.id,
452
                             vm.userid, json.dumps(request), 'json')
453
        self.assertFault(response, 409, "buildInProgress")
454
        # Check same Flavor
455
        vm = self.get_vm(flavor=flavor, operstate="STOPPED")
456
        request = {'resize': {'flavorRef': flavor.id}}
457
        response = self.post('/api/v1.1/servers/%d/action' % vm.id,
458
                             vm.userid, json.dumps(request), 'json')
459
        self.assertSuccess(response)
460
        # Check flavor with different disk
461
        flavor2 = mfactory.FlavorFactory(disk=1024)
462
        flavor3 = mfactory.FlavorFactory(disk=2048)
463
        vm = self.get_vm(flavor=flavor2, operstate="STOPPED")
464
        request = {'resize': {'flavorRef': flavor3.id}}
465
        response = self.post('/api/v1.1/servers/%d/action' % vm.id,
466
                             vm.userid, json.dumps(request), 'json')
467
        self.assertBadRequest(response)
468
        flavor2 = mfactory.FlavorFactory(disk_template="foo")
469
        flavor3 = mfactory.FlavorFactory(disk_template="baz")
470
        vm = self.get_vm(flavor=flavor2, operstate="STOPPED")
471
        request = {'resize': {'flavorRef': flavor3.id}}
472
        response = self.post('/api/v1.1/servers/%d/action' % vm.id,
473
                             vm.userid, json.dumps(request), 'json')
474
        self.assertBadRequest(response)
475
        # Check success
476
        vm = self.get_vm(flavor=flavor, operstate="STOPPED")
477
        flavor4 = mfactory.FlavorFactory(disk_template=flavor.disk_template,
478
                                         disk=flavor.disk,
479
                                         cpu=4, ram=2048)
480
        request = {'resize': {'flavorRef': flavor4.id}}
481
        mrapi().ModifyInstance.return_value = 42
482
        response = self.post('/api/v1.1/servers/%d/action' % vm.id,
483
                             vm.userid, json.dumps(request), 'json')
484
        self.assertEqual(response.status_code, 202)
485
        vm = VirtualMachine.objects.get(id=vm.id)
486
        self.assertEqual(vm.backendjobid, 42)
487
        name, args, kwargs = mrapi().ModifyInstance.mock_calls[0]
488
        self.assertEqual(kwargs["beparams"]["vcpus"], 4)
489
        self.assertEqual(kwargs["beparams"]["minmem"], 2048)
490
        self.assertEqual(kwargs["beparams"]["maxmem"], 2048)
491

  
492
    def get_vm(self, flavor, operstate):
493
        vm = mfactory.VirtualMachineFactory(flavor=flavor)
494
        vm.operstate = operstate
495
        vm.backendjobstatus = "success"
496
        vm.save()
497
        return vm
498

  
446 499

  
447 500
class ServerVNCConsole(ComputeAPITest):
448 501
    def test_not_active_server(self):

Also available in: Unified diff