Revision b66e4833

b/snf-cyclades-app/synnefo/api/tests.py
249 249
        """Test if a server details are returned."""
250 250
        db_vm = self.vm2
251 251
        user = self.vm2.userid
252
        net = mfactory.NetworkFactory()
253
        nic = mfactory.NetworkInterfaceFactory(machine=self.vm2, network=net)
254

  
252 255
        db_vm_meta = mfactory.VirtualMachineMetadataFactory(vm=db_vm)
253 256

  
254 257
        response = self.get('/api/v1.1/servers/%d' % db_vm.id, user)
......
260 263
        self.assertEqual(server['imageRef'], db_vm.imageid)
261 264
        self.assertEqual(server['name'], db_vm.name)
262 265
        self.assertEqual(server['status'], get_rsapi_state(db_vm))
266
        api_nic = server['attachments']['values'][0]
267
        self.assertEqual(api_nic['network_id'], str(net.id))
268
        self.assertEqual(api_nic['mac_address'], nic.mac)
269
        self.assertEqual(api_nic['firewallProfile'], nic.firewall_profile)
270
        self.assertEqual(api_nic['ipv4'], nic.ipv4)
271
        self.assertEqual(api_nic['ipv6'], nic.ipv6)
272
        self.assertEqual(api_nic['id'], 'nic-%s-%s' % (db_vm.id, nic.index))
263 273

  
264 274
        metadata = server['metadata']['values']
265 275
        self.assertEqual(len(metadata), 1)
......
285 295
        response = self.post('/api/v1.1/servers', params={})
286 296
        self.assertBadRequest(response)
287 297

  
298
    def test_rename_server(self):
299
        vm = self.vm2
300
        request = {'server': {'name': 'new_name'}}
301
        response = self.put('/api/v1.1/servers/%d' % vm.id, vm.userid,
302
                            json.dumps(request), 'json')
303
        self.assertSuccess(response)
304
        self.assertEqual(VirtualMachine.objects.get(id=vm.id).name, "new_name")
305

  
288 306

  
289 307
@patch('synnefo.api.util.get_image')
290 308
@patch('synnefo.logic.rapi_pool.GanetiRapiClient')
......
359 377
        vm = mfactory.VirtualMachineFactory()
360 378
        response = self.delete('/api/v1.1/servers/%d' % 42, vm.userid)
361 379
        self.assertItemNotFound(response)
362
        mrapi().DeleteInstance.assert_not_called()
380
        self.assertFalse(mrapi.mock_calls)
363 381

  
364 382

  
365 383
@patch('synnefo.api.util.get_image')
......
383 401
                self.assertEqual(VirtualMachine.objects.get(id=vm.id).action,
384 402
                                 action.upper())
385 403

  
404
    def test_action_in_building_vm(self, mrapi, mimage):
405
        """Test building in progress"""
406
        vm = mfactory.VirtualMachineFactory()
407
        request = {'start': '{}'}
408
        response = self.post('/api/v1.1/servers/%d/action' % vm.id,
409
                             vm.userid, json.dumps(request), 'json')
410
        self.assertEqual(response.status_code, 409)
411
        self.assertFalse(mrapi.mock_calls)
412

  
413
    def test_destroy_build_vm(self, mrapi, mimage):
414
        """Test building in progress"""
415
        vm = mfactory.VirtualMachineFactory()
416
        response = self.delete('/api/v1.1/servers/%d' % vm.id,
417
                             vm.userid)
418
        self.assertSuccess(response)
419
        mrapi().RemoveInstance.assert_called_once()
420

  
386 421
    def test_firewall(self, mrapi, mimage):
387 422
        vm = mfactory.VirtualMachineFactory()
388 423
        vm.operstate = "STOPPED"
......
393 428
        self.assertEqual(response.status_code, 202)
394 429
        mrapi().ModifyInstance.assert_called_once()
395 430

  
431
    def test_unsupported_firewall(self, mrapi, mimage):
432
        vm = mfactory.VirtualMachineFactory()
433
        vm.operstate = "STOPPED"
434
        vm.save()
435
        request = {'firewallProfile': {'profile': 'FOO'}}
436
        response = self.post('/api/v1.1/servers/%d/action' % vm.id,
437
                             vm.userid, json.dumps(request), 'json')
438
        self.assertBadRequest(response)
439
        self.assertFalse(mrapi.mock_calls)
440

  
396 441

  
397 442
class ServerMetadataAPITest(BaseAPITest):
398 443
    def setUp(self):
......
590 635
        response = self.delete('/api/v1.1/networks/%d' % net.id,
591 636
                                self.net2.userid)
592 637
        self.assertFault(response, 403, 'forbidden')
593
        mrapi.DeleteNetwork.assert_not_called()
638
        self.assertFalse(mrapi.mock_calls)
639

  
640
    def test_delete_network_in_use(self, mrapi):
641
        net = mfactory.NetworkFactory(deleted=False)
642
        vm = mfactory.VirtualMachineFactory()
643
        mfactory.NetworkInterfaceFactory(machine=vm, network=net)
644
        response = self.delete('/api/v1.1/networks/%d' % net.id,
645
                                net.userid)
646
        self.assertFault(response, 421, 'networkInUse')
647
        self.assertFalse(mrapi.mock_calls)
594 648

  
595 649
    def test_add_nic(self, mrapi):
596 650
        user = 'userr'
......
601 655
                             net.userid, json.dumps(request), 'json')
602 656
        self.assertEqual(response.status_code, 202)
603 657

  
658
    def test_add_nic_to_public_network(self, mrapi):
659
        user = 'userr'
660
        vm = mfactory.VirtualMachineFactory(name='yo', userid=user)
661
        net = mfactory.NetworkFactory(state='ACTIVE', userid=user, public=True)
662
        request = {'add': {'serverRef': vm.id}}
663
        response = self.post('/api/v1.1/networks/%d/action' % net.id,
664
                             net.userid, json.dumps(request), 'json')
665
        self.assertFault(response, 403, 'forbidden')
666

  
604 667
    def test_add_nic_malformed(self, mrapi):
605 668
        user = 'userr'
606 669
        vm = mfactory.VirtualMachineFactory(name='yo', userid=user)
......
610 673
                             net.userid, json.dumps(request), 'json')
611 674
        self.assertBadRequest(response)
612 675

  
676
    def test_add_nic_not_active(self, mrapi):
677
        """Test connecting VM to non-active network"""
678
        user = 'dummy'
679
        vm = mfactory.VirtualMachineFactory(name='yo', userid=user)
680
        net = mfactory.NetworkFactory(state='PENDING', subnet='10.0.0.0/31',
681
                                      userid=user)
682
        request = {'add': {'serveRef': vm.id}}
683
        response = self.post('/api/v1.1/networks/%d/action' % net.id,
684
                             net.userid, json.dumps(request), 'json')
685
        # Test that returns BuildInProgress
686
        self.assertEqual(response.status_code, 409)
687

  
688
    def test_add_nic_full_network(self, mrapi):
689
        """Test connecting VM to a full network"""
690
        user = 'userr'
691
        vm = mfactory.VirtualMachineFactory(name='yo', userid=user)
692
        net = mfactory.NetworkFactory(state='ACTIVE', subnet='10.0.0.0/30',
693
                                      userid=user, dhcp=True)
694
        pool = net.get_pool()
695
        while not pool.empty():
696
            pool.get()
697
        pool.save()
698
        pool = net.get_pool()
699
        self.assertTrue(pool.empty())
700
        request = {'add': {'serverRef': vm.id}}
701
        response = self.post('/api/v1.1/networks/%d/action' % net.id,
702
                             net.userid, json.dumps(request), 'json')
703
        # Test that returns OverLimit
704
        self.assertEqual(response.status_code, 413)
705

  
613 706
    def test_remove_nic(self, mrapi):
614 707
        user = 'userr'
615 708
        vm = mfactory.VirtualMachineFactory(name='yo', userid=user)
......
637 730
                             net.userid, json.dumps(request), 'json')
638 731
        self.assertBadRequest(response)
639 732

  
733
    def test_remove_nic_malformed_2(self, mrapi):
734
        user = 'userr'
735
        vm = mfactory.VirtualMachineFactory(name='yo', userid=user)
736
        net = mfactory.NetworkFactory(state='ACTIVE', userid=user)
737
        request = {'remove':
738
                    {'attachment': 'nic-%s' % vm.id}
739
                  }
740
        response = self.post('/api/v1.1/networks/%d/action' % net.id,
741
                             net.userid, json.dumps(request), 'json')
742
        self.assertBadRequest(response)
743

  
640 744

  
641 745
class ServerVNCConsole(BaseAPITest):
642 746

  
......
665 769
        self.assertEqual(set(console.keys()),
666 770
                         set(['type', 'host', 'port', 'password']))
667 771

  
772
    def test_wrong_console_type(self):
773
        """Test console req for ACTIVE server"""
774
        vm = mfactory.VirtualMachineFactory()
775
        vm.operstate = 'STARTED'
776
        vm.save()
777

  
778
        data = json.dumps({'console': {'type': 'foo'}})
779
        response = self.post('/api/v1.1/servers/%d/action' % vm.id,
780
                             vm.userid, data, 'json')
781
        self.assertBadRequest(response)
668 782

  
669 783
def assert_backend_closed(func):
670 784
    @wraps(func)
......
846 960
                            {'foo': 'bar', 'foo2': 'bar2', 'foo3': 'bar3'}})
847 961

  
848 962
    @assert_backend_closed
963
    def test_create_metadata_malformed_1(self, backend):
964
        backend.return_value.get_image.return_value = self.image
965
        with patch("synnefo.api.images.ImageBackend"):
966
                request = {'met': {'foo3': 'bar3'}}
967
                response = self.put('/api/v1.1/images/42/meta/foo3', 'user',
968
                                    json.dumps(request), 'json')
969
                self.assertBadRequest(response)
970

  
971
    @assert_backend_closed
972
    def test_create_metadata_malformed_2(self, backend):
973
        backend.return_value.get_image.return_value = self.image
974
        with patch("synnefo.api.images.ImageBackend"):
975
                request = {'meta': [('foo3', 'bar3')]}
976
                response = self.put('/api/v1.1/images/42/meta/foo3', 'user',
977
                                    json.dumps(request), 'json')
978
                self.assertBadRequest(response)
979

  
980
    @assert_backend_closed
981
    def test_create_metadata_malformed_3(self, backend):
982
        backend.return_value.get_image.return_value = self.image
983
        with patch("synnefo.api.images.ImageBackend"):
984
            request = {'met': {'foo3': 'bar3', 'foo4': 'bar4'}}
985
            response = self.put('/api/v1.1/images/42/meta/foo3', 'user',
986
                                    json.dumps(request), 'json')
987
            self.assertBadRequest(response)
988

  
989
    @assert_backend_closed
990
    def test_create_metadata_malformed_4(self, backend):
991
        backend.return_value.get_image.return_value = self.image
992
        with patch("synnefo.api.images.ImageBackend"):
993
            request = {'met': {'foo3': 'bar3'}}
994
            response = self.put('/api/v1.1/images/42/meta/foo4', 'user',
995
                                    json.dumps(request), 'json')
996
            self.assertBadRequest(response)
997

  
998
    @assert_backend_closed
849 999
    def test_update_metadata_item(self, backend):
850 1000
        backend.return_value.get_image.return_value = self.image
851 1001
        with patch("synnefo.api.images.ImageBackend") as m:
......
858 1008
                            {'foo': 'bar_new', 'foo2': 'bar2', 'foo4': 'bar4'}
859 1009
                        })
860 1010

  
1011
    @assert_backend_closed
1012
    def test_update_metadata_malformed(self, backend):
1013
        backend.return_value.get_image.return_value = self.image
1014
        with patch("synnefo.api.images.ImageBackend"):
1015
                request = {'meta': {'foo': 'bar_new', 'foo4': 'bar4'}}
1016
                response = self.post('/api/v1.1/images/42/meta', 'user',
1017
                                    json.dumps(request), 'json')
1018
                self.assertBadRequest(response)
1019

  
861 1020

  
862 1021
class APITest(TestCase):
863 1022
    def test_api_version(self):
b/snf-cyclades-app/synnefo/db/pools/tests.py
34 34

  
35 35
from django.test import TestCase
36 36
from synnefo.db.pools import (PoolManager, EmptyPool, BridgePool,
37
                              MacPrefixPool, IPPool)
37
                              MacPrefixPool, IPPool, find_padding,
38
                              bitarray_to_map)
38 39
from bitarray import bitarray
39 40

  
40 41

  
......
136 137
        self.assertEqual(pool.available, bitarray('1' * 39 + '0' * 1))
137 138
        self.assertEqual(pool.reserved, bitarray('1' * 39 + '0' * 1))
138 139

  
140
    def test_shrink_in_use(self):
141
        obj = DummyObject(8)
142
        pool = DummyPool(obj)
143
        pool._reserve(6)
144
        self.assertRaises(Exception, pool.shrink, 3)
145

  
146
    def test_count(self):
147
        obj = DummyObject(10)
148
        pool = DummyPool(obj)
149
        pool._reserve(1)
150
        pool._reserve(3)
151
        pool._reserve(4)
152
        pool._reserve(2, external=True)
153
        self.assertEqual(pool.count_available(), 6)
154
        self.assertEqual(pool.count_unavailable(), 4)
155
        self.assertEqual(pool.count_reserved(), 1)
156
        self.assertEqual(pool.count_unreserved(), 9)
157

  
158

  
159
class HelpersTestCase(TestCase):
160
    def test_find_padding(self):
161
        self.assertEqual(find_padding(1), 7)
162
        self.assertEqual(find_padding(8), 0)
163
        self.assertEqual(find_padding(12), 4)
164
        self.assertEqual(find_padding(16), 0)
165

  
166
    def test_bitarray_to_map(self):
167
        bt = bitarray('01001100101')
168
        map_ = bitarray_to_map(bt)
169
        self.assertEqual(map_, 'X.XX..XX.X.')
170

  
139 171

  
140 172
class BridgePoolTestCase(TestCase):
141 173
    def test_bridge_conversion(self):
......
159 191
        for i in range(0, 65536):
160 192
            self.assertEqual(pool.is_available(i, index=True), False)
161 193

  
194
    def test_mac_prefix_conversion(self):
195
        obj = DummyObject(13)
196
        obj.base = 'aa:00:0'
197
        pool = MacPrefixPool(obj)
198
        for i in range(1, 9):
199
            self.assertEqual("aa:00:%s" % i, pool.get())
200

  
201
    def test_value_to_index(self):
202
        obj = DummyObject(13)
203
        obj.base = 'aa:00:0'
204
        pool = MacPrefixPool(obj)
205
        index = pool.value_to_index('aa:bc:ee')
206
        val = pool.index_to_value(index)
207
        self.assertEqual(val, 'aa:bc:ee')
208

  
162 209

  
163 210
class IPPoolTestCase(TestCase):
164 211
    def test_auto_reservations(self):
b/snf-cyclades-app/synnefo/db/tests.py
192 192
        self.assertTrue(backend.index < 10)
193 193
        self.assertEqual(bnet.mac_prefix, 'aa:bb:c%s' % backend.index)
194 194

  
195
    def test_invalid_mac(self):
196
        network = mfact.NetworkFactory(mac_prefix='zz:bb:c')
197
        backend = mfact.BackendFactory()
198
        self.assertRaises(utils.InvalidMacAddress,
199
                mfact.BackendNetworkFactory, network=network, backend=backend)
200

  
195 201

  
196 202
class BridgePoolTest(TestCase):
197 203
    def test_no_pool(self):
b/snf-cyclades-app/synnefo/logic/test/rapi_pool_tests.py
1
# Copyright 2011-2012 GRNET S.A. All rights reserved.
2
#
3
# Redistribution and use in source and binary forms, with or
4
# without modification, are permitted provided that the following
5
# conditions are met:
6
#
7
#   1. Redistributions of source code must retain the above
8
#      copyright notice, this list of conditions and the following
9
#      disclaimer.
10
#
11
#   2. Redistributions in binary form must reproduce the above
12
#      copyright notice, this list of conditions and the following
13
#      disclaimer in the documentation and/or other materials
14
#      provided with the distribution.
15
#
16
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
# POSSIBILITY OF SUCH DAMAGE.
28
#
29
# The views and conclusions contained in the software and
30
# documentation are those of the authors and should not be
31
# interpreted as representing official policies, either expressed
32
# or implied, of GRNET S.A.
33

  
34
from django.test import TestCase
35

  
36
from synnefo.logic import rapi_pool
37

  
38
from mock import patch
39

  
40

  
41
@patch('synnefo.logic.rapi_pool.GanetiRapiClient', spec=True)
42
class GanetiRapiPoolTest(TestCase):
43
    def test_new_client(self, rclient):
44
        cl = rapi_pool.get_rapi_client(1, 'amxixa', 'cluster0', '5080', 'user',
45
                                       'pass')
46
        rclient.assert_called_once_with("cluster0", "5080", "user", "pass")
47
        self.assertTrue('amxixa' in rapi_pool._pools)
48
        self.assertTrue(cl._pool is rapi_pool._pools[rapi_pool._hashes[1]])
49

  
50
    def test_invalid_get(self, rclient):
51
        self.assertRaises(ValueError, rapi_pool.get_rapi_client, 1, 'amxixa',
52
                         None, '5080', 'user', 'pass')
53
        self.assertRaises(ValueError, rapi_pool.get_rapi_client, 1, 'amxixa',
54
                         'Foo', None, 'user', 'pass')
55

  
56
    def test_get_from_pool(self, rclient):
57
        cl = rapi_pool.get_rapi_client(1, 'dummyhash', 'cluster1', '5080',
58
                                       'user', 'pass')
59
        rclient.assert_called_once_with("cluster1", "5080", "user", "pass")
60
        rapi_pool.put_rapi_client(cl)
61
        rclient.reset_mock()
62
        cl2 = rapi_pool.get_rapi_client(1, 'dummyhash', 'cluster1', '5080',
63
                                        'user', 'pass')
64
        self.assertTrue(cl is cl2)
65
        self.assertFalse(rclient.mock_calls)
66

  
67
    def test_changed_credentials(self, rclient):
68
        cl = rapi_pool.get_rapi_client(1, 'dummyhash2', 'cluster2', '5080',
69
                                       'user', 'pass')
70
        rclient.assert_called_once_with("cluster2", "5080", "user", "pass")
71
        rapi_pool.put_rapi_client(cl)
72
        rclient.reset_mock()
73
        rapi_pool.get_rapi_client(1, 'dummyhash3', 'cluster2', '5080',
74
                                        'user', 'new_pass')
75
        rclient.assert_called_once_with("cluster2", "5080", "user", "new_pass")
76
        self.assertFalse('dummyhash2' in rapi_pool._pools)
77

  
78
    def test_no_pool(self, rclient):
79
        cl = rapi_pool.get_rapi_client(1, 'dummyhash2', 'cluster2', '5080',
80
                                       'user', 'pass')
81
        cl._pool = None
82
        rapi_pool.put_rapi_client(cl)
83
        self.assertTrue(cl not in rapi_pool._pools.values())
b/snf-cyclades-app/synnefo/logic/test/utils_tests.py
1
# Copyright 2011-2012 GRNET S.A. All rights reserved.
2
#
3
# Redistribution and use in source and binary forms, with or
4
# without modification, are permitted provided that the following
5
# conditions are met:
6
#
7
#   1. Redistributions of source code must retain the above
8
#      copyright notice, this list of conditions and the following
9
#      disclaimer.
10
#
11
#   2. Redistributions in binary form must reproduce the above
12
#      copyright notice, this list of conditions and the following
13
#      disclaimer in the documentation and/or other materials
14
#      provided with the distribution.
15
#
16
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
# POSSIBILITY OF SUCH DAMAGE.
28
#
29
# The views and conclusions contained in the software and
30
# documentation are those of the authors and should not be
31
# interpreted as representing official policies, either expressed
32
# or implied, of GRNET S.A.
33

  
34
from django.test import TestCase
35

  
36
from synnefo.logic import utils
37
from django.conf import settings
38
from synnefo.db.models import VirtualMachine, Network
39
from synnefo.db.models_factory import VirtualMachineFactory
40

  
41

  
42
class NameConversionTest(TestCase):
43
    def setUp(self):
44
        settings.BACKEND_PREFIX_ID = 'snf-'
45

  
46
    def test_id_from_iname(self):
47
        self.assertEqual(utils.id_from_instance_name('snf-42'), 42)
48
        for name in [None, 'foo', 'snf42', 'snf-a', 'snf-snf-42', 1234]:
49
            self.assertRaises(VirtualMachine.InvalidBackendIdError,
50
                              utils.id_from_instance_name, '')
51

  
52
    def test_iname_from_id(self):
53
        self.assertEqual(utils.id_to_instance_name(42), 'snf-42')
54

  
55
    def test_id_from_net_name(self):
56
        self.assertEqual(utils.id_from_network_name('snf-net-42'), 42)
57
        for name in [None, 'foo', 'snf42', 'snf-net-a', 'snf-snf-42', 1234]:
58
            self.assertRaises(Network.InvalidBackendIdError,
59
                              utils.id_from_network_name, '')
60

  
61
    def test_net_name_from_id(self):
62
            self.assertEqual(utils.id_to_network_name(42), 'snf-net-42')
63

  
64

  
65
class APIStateTest(TestCase):
66
    def test_correct_state(self):
67
        vm = VirtualMachineFactory()
68
        vm.operstate = 'foo'
69
        self.assertEqual(utils.get_rsapi_state(vm), "UNKNOWN")
70
        vm.operstate = "STARTED"
71
        vm.deleted = True
72
        self.assertEqual(utils.get_rsapi_state(vm), "DELETED")
73
        vm.deleted = False
74
        vm.backendopcode = "OP_INSTANCE_REBOOT"
75
        vm.backendjobstatus = "waiting"
76
        self.assertEqual(utils.get_rsapi_state(vm), "REBOOT")
77

  
78

  
79
class HidePass(TestCase):
80
    def test_no_osparams(self):
81
        foo = {'foo': 'bar'}
82
        self.assertTrue(foo is utils.hide_pass(foo))
83
        foo = {'osparams': {}, 'bar': 'foo'}
84
        self.assertTrue(foo is utils.hide_pass(foo))
85

  
86
    def test_hidden_pass(self):
87
        foo = {'osparams': {'img_passwd': 'pass'}, 'bar': 'foo'}
88
        after = {'osparams': {'img_passwd': 'xxxxxxxx'}, 'bar': 'foo'}
89
        self.assertEqual(after, utils.hide_pass(foo))
b/snf-cyclades-app/synnefo/logic/tests.py
84 84
        update_db(client, msg)
85 85
        client.basic_ack.assert_called_once()
86 86

  
87
    def test_old_msg(self, client):
88
        from time import sleep
89
        from datetime import datetime
90
        old_time = time()
91
        sleep(0.01)
92
        new_time = datetime.fromtimestamp(time())
93
        vm = mfactory.VirtualMachineFactory(backendtime=new_time)
94
        vm.operstate = 'STOPPED'
95
        vm.save()
96
        msg = self.create_msg(operation='OP_INSTANCE_STARTUP',
97
                              event_time=split_time(old_time),
98
                              instance=vm.backend_vm_id)
99
        update_db(client, msg)
100
        client.basic_ack.assert_called_once()
101
        db_vm = VirtualMachine.objects.get(id=vm.id)
102
        self.assertEquals(db_vm.operstate, "STOPPED")
103
        self.assertEquals(db_vm.backendtime, new_time)
104

  
87 105
    def test_start(self, client):
88 106
        vm = mfactory.VirtualMachineFactory()
89 107
        msg = self.create_msg(operation='OP_INSTANCE_STARTUP',
......
541 559
                          set([(2, 'STARTED', False),
542 560
                           (3, 'BUILD', True), (4, 'STARTED', False),
543 561
                           (50, 'BUILD', True)]))
562

  
563
from synnefo.logic.test.rapi_pool_tests import *
564
from synnefo.logic.test.utils_tests import *

Also available in: Unified diff