Revision 10d9cd27

b/snf-cyclades-app/synnefo/logic/tests.py
68 68

  
69 69
    def test_missing_attribute(self, client):
70 70
        update_db(client, json.dumps({'body': {}}))
71
        client.basic_nack.assert_called_once()
71
        self.assertTrue(client.basic_reject.called)
72 72

  
73 73
    def test_unhandled_exception(self, client):
74 74
        update_db(client, {})
......
78 78
        msg = self.create_msg(operation='OP_INSTANCE_STARTUP',
79 79
                              instance='foo')
80 80
        update_db(client, msg)
81
        client.basic_nack.assert_called_once()
81
        self.assertTrue(client.basic_ack.called)
82 82

  
83 83
    def test_wrong_type(self, client):
84 84
        msg = self.create_msg(type="WRONG_TYPE")
85 85
        update_db(client, msg)
86
        client.basic_ack.assert_called_once()
86
        self.assertTrue(client.basic_nack.called)
87 87

  
88 88
    def test_old_msg(self, client):
89 89
        from time import sleep
......
98 98
                              event_time=split_time(old_time),
99 99
                              instance=vm.backend_vm_id)
100 100
        update_db(client, msg)
101
        client.basic_ack.assert_called_once()
101
        self.assertTrue(client.basic_ack.called)
102 102
        db_vm = VirtualMachine.objects.get(id=vm.id)
103 103
        self.assertEquals(db_vm.operstate, "STOPPED")
104 104
        self.assertEquals(db_vm.backendtime, new_time)
......
108 108
        msg = self.create_msg(operation='OP_INSTANCE_STARTUP',
109 109
                              instance=vm.backend_vm_id)
110 110
        update_db(client, msg)
111
        client.basic_ack.assert_called_once()
111
        self.assertTrue(client.basic_ack.called)
112 112
        db_vm = VirtualMachine.objects.get(id=vm.id)
113 113
        self.assertEqual(db_vm.operstate, 'STARTED')
114 114

  
......
117 117
        msg = self.create_msg(operation='OP_INSTANCE_SHUTDOWN',
118 118
                              instance=vm.backend_vm_id)
119 119
        update_db(client, msg)
120
        client.basic_ack.assert_called_once()
120
        self.assertTrue(client.basic_ack.called)
121 121
        db_vm = VirtualMachine.objects.get(id=vm.id)
122 122
        self.assertEqual(db_vm.operstate, 'STOPPED')
123 123

  
......
126 126
        msg = self.create_msg(operation='OP_INSTANCE_REBOOT',
127 127
                              instance=vm.backend_vm_id)
128 128
        update_db(client, msg)
129
        client.basic_ack.assert_called_once()
129
        self.assertTrue(client.basic_ack.called)
130 130
        db_vm = VirtualMachine.objects.get(id=vm.id)
131 131
        self.assertEqual(db_vm.operstate, 'STARTED')
132 132

  
......
138 138
                              instance=vm.backend_vm_id)
139 139
        with mocked_quotaholder():
140 140
            update_db(client, msg)
141
        client.basic_ack.assert_called_once()
141
        self.assertTrue(client.basic_ack.called)
142 142
        db_vm = VirtualMachine.objects.get(id=vm.id)
143 143
        self.assertEqual(db_vm.operstate, 'DESTROYED')
144 144
        self.assertTrue(db_vm.deleted)
......
150 150
        msg = self.create_msg(operation='OP_INSTANCE_CREATE',
151 151
                              instance=vm.backend_vm_id)
152 152
        update_db(client, msg)
153
        client.basic_ack.assert_called_once()
153
        self.assertTrue(client.basic_ack.called)
154 154
        db_vm = VirtualMachine.objects.get(id=vm.id)
155 155
        self.assertEqual(db_vm.operstate, 'STARTED')
156 156

  
......
161 161
                              instance=vm.backend_vm_id,
162 162
                              status='error')
163 163
        update_db(client, msg)
164
        client.basic_ack.assert_called_once()
164
        self.assertTrue(client.basic_ack.called)
165 165
        db_vm = VirtualMachine.objects.get(id=vm.id)
166 166
        self.assertEqual(db_vm.operstate, 'ERROR')
167 167

  
......
174 174
                              instance=vm.backend_vm_id)
175 175
        with mocked_quotaholder():
176 176
            update_db(client, msg)
177
        client.basic_ack.assert_called_once()
177
        self.assertTrue(client.basic_ack.called)
178 178
        db_vm = VirtualMachine.objects.get(id=vm.id)
179 179
        self.assertEqual(db_vm.operstate, 'DESTROYED')
180 180
        self.assertTrue(db_vm.deleted)
......
188 188
                              instance=vm.backend_vm_id,
189 189
                              status='error')
190 190
        update_db(client, msg)
191
        client.basic_ack.assert_called_once()
191
        self.assertTrue(client.basic_ack.called)
192 192
        db_vm = VirtualMachine.objects.get(id=vm.id)
193 193
        self.assertEqual(db_vm.operstate, vm.operstate)
194 194
        self.assertEqual(db_vm.backendtime, vm.backendtime)
......
211 211

  
212 212
    def test_missing_attribute(self, client):
213 213
        update_db(client, json.dumps({'body': {}}))
214
        client.basic_nack.assert_called_once()
214
        self.assertTrue(client.basic_reject.called)
215 215

  
216 216
    def test_unhandled_exception(self, client):
217 217
        update_db(client, {})
......
220 220
    def test_wrong_type(self, client):
221 221
        msg = self.create_msg(type="WRONG_TYPE")
222 222
        update_db(client, msg)
223
        client.basic_ack.assert_called_once()
223
        self.assertTrue(client.basic_nack.called)
224 224

  
225 225
    def test_missing_instance(self, client):
226 226
        msg = self.create_msg(operation='OP_INSTANCE_STARTUP',
227 227
                              instance='foo')
228 228
        update_db(client, msg)
229
        client.basic_nack.assert_called_once()
229
        self.assertTrue(client.basic_ack.called)
230 230

  
231 231
    def test_no_nics(self, client):
232 232
        vm = mfactory.VirtualMachineFactory(operstate='ERROR')
......
237 237
        msg = self.create_msg(nics=[],
238 238
                              instance=vm.backend_vm_id)
239 239
        update_db(client, msg)
240
        client.basic_ack.assert_called_once()
240
        self.assertTrue(client.basic_ack.called)
241 241
        db_vm = VirtualMachine.objects.get(id=vm.id)
242 242
        self.assertEqual(len(db_vm.nics.all()), 0)
243 243

  
......
248 248
            msg = self.create_msg(nics=[{'network': net.backend_id}],
249 249
                                  instance=vm.backend_vm_id)
250 250
            update_db(client, msg)
251
            client.basic_ack.assert_called_once()
251
            self.assertTrue(client.basic_ack.called)
252 252
            db_vm = VirtualMachine.objects.get(id=vm.id)
253 253
            nics = db_vm.nics.all()
254 254
            self.assertEqual(len(nics), 1)
......
273 273
                                     'mac': 'aa:bb:cc:00:11:22'}],
274 274
                              instance=vm.backend_vm_id)
275 275
        update_db(client, msg)
276
        client.basic_ack.assert_called_once()
276
        self.assertTrue(client.basic_ack.called)
277 277
        db_vm = VirtualMachine.objects.get(id=vm.id)
278 278
        nics = db_vm.nics.all()
279 279
        self.assertEqual(len(nics), 1)
......
302 302

  
303 303
    def test_missing_attribute(self, client):
304 304
        update_network(client, json.dumps({'body': {}}))
305
        client.basic_nack.assert_called_once()
305
        self.assertTrue(client.basic_reject.called)
306 306

  
307 307
    def test_unhandled_exception(self, client):
308 308
        update_network(client, {})
......
311 311
    def test_wrong_type(self, client):
312 312
        msg = self.create_msg(type="WRONG_TYPE")
313 313
        update_network(client, msg)
314
        client.basic_ack.assert_called_once()
314
        self.assertTrue(client.basic_nack.called)
315 315

  
316 316
    def test_missing_network(self, client):
317 317
        msg = self.create_msg(operation='OP_NETWORK_CREATE',
318 318
                              network='foo')
319 319
        update_network(client, msg)
320
        client.basic_nack.assert_called_once()
320
        self.assertTrue(client.basic_ack.called)
321 321

  
322 322
    def test_create(self, client):
323 323
        back_network = mfactory.BackendNetworkFactory(operstate='PENDING')
......
334 334
                              network=net.backend_id,
335 335
                              cluster=back1.clustername)
336 336
        update_network(client, msg)
337
        client.basic_ack.assert_called_once()
337
        self.assertTrue(client.basic_ack.called)
338 338

  
339 339
        back_net = BackendNetwork.objects.get(id=back_network.id)
340 340
        self.assertEqual(back_net.operstate, 'ACTIVE')
......
345 345
                              network=net.backend_id,
346 346
                              cluster=back2.clustername)
347 347
        update_network(client, msg)
348
        client.basic_ack.assert_called_once()
348
        self.assertTrue(client.basic_ack.called)
349 349

  
350 350
        db_net = Network.objects.get(id=net.id)
351 351
        self.assertEqual(db_net.state, 'ACTIVE')
......
362 362
                              network=net.backend_id,
363 363
                              cluster=bn1.backend.clustername)
364 364
        update_network(client, msg)
365
        client.basic_ack.assert_called_once()
365
        self.assertTrue(client.basic_ack.called)
366 366
        new_net = Network.objects.get(id=net.id)
367 367
        self.assertEqual(new_net.state, 'ACTIVE')
368 368

  
......
378 378
                              network=net1.backend_id,
379 379
                              cluster=bn2.backend.clustername)
380 380
        update_network(client, msg)
381
        client.basic_ack.assert_called_once()
381
        self.assertTrue(client.basic_ack.called)
382 382
        self.assertEqual(Network.objects.get(id=net1.id).state, 'ACTIVE')
383 383
        self.assertEqual(BackendNetwork.objects.get(id=bn2.id).operstate,
384 384
                         'PENDING')
......
404 404
                                      cluster=bn.backend.clustername)
405 405
                with mocked_quotaholder():
406 406
                    update_network(client, msg)
407
                client.basic_ack.assert_called_once()
407
                self.assertTrue(client.basic_ack.called)
408 408
                db_bnet = BackendNetwork.objects.get(id=bn.id)
409 409
                self.assertEqual(db_bnet.operstate,
410 410
                                 'DELETED')
......
433 433
                              cluster=bn1.backend.clustername)
434 434
        with mocked_quotaholder():
435 435
            update_network(client, msg)
436
        client.basic_ack.assert_called_once()
436
        self.assertTrue(client.basic_ack.called)
437 437
        new_net = Network.objects.get(id=net.id)
438 438
        self.assertEqual(new_net.state, 'ACTIVE')
439 439
        self.assertFalse(new_net.deleted)
......
459 459
                                      cluster=bn.backend.clustername)
460 460
                with mocked_quotaholder():
461 461
                    update_network(client, msg)
462
                client.basic_ack.assert_called_once()
462
                self.assertTrue(client.basic_ack.called)
463 463
                db_bnet = BackendNetwork.objects.get(id=bn.id)
464 464
                self.assertEqual(bn.operstate, db_bnet.operstate)
465 465
                self.assertEqual(bn.network.state, db_bnet.network.state)
......
474 474
                              add_reserved_ips=['10.0.0.10', '10.0.0.20'],
475 475
                              remove_reserved_ips=[])
476 476
        update_network(client, msg)
477
        client.basic_ack.assert_called_once()
477
        self.assertTrue(client.basic_ack.called)
478 478
        pool = network.get_pool()
479 479
        self.assertTrue(pool.is_reserved('10.0.0.10'))
480 480
        self.assertTrue(pool.is_reserved('10.0.0.20'))
......
486 486
                              add_reserved_ips=[],
487 487
                              remove_reserved_ips=['10.0.0.10', '10.0.0.20'])
488 488
        update_network(client, msg)
489
        client.basic_ack.assert_called_once()
489
        self.assertTrue(client.basic_ack.called)
490 490
        pool = network.get_pool()
491 491
        self.assertFalse(pool.is_reserved('10.0.0.10'))
492 492
        self.assertFalse(pool.is_reserved('10.0.0.20'))
......
512 512

  
513 513
    def test_missing_attribute(self, client):
514 514
        update_build_progress(client, json.dumps({'body': {}}))
515
        client.basic_nack.assert_called_once()
515
        self.assertTrue(client.basic_reject.called)
516 516

  
517 517
    def test_unhandled_exception(self, client):
518 518
        update_build_progress(client, {})
......
521 521
    def test_missing_instance(self, client):
522 522
        msg = self.create_msg(instance='foo')
523 523
        update_build_progress(client, msg)
524
        client.basic_nack.assert_called_once()
524
        self.assertTrue(client.basic_ack.called)
525 525

  
526 526
    def test_wrong_type(self, client):
527 527
        msg = self.create_msg(type="WRONG_TYPE")
528 528
        update_build_progress(client, msg)
529
        client.basic_ack.assert_called_once()
529
        self.assertTrue(client.basic_nack.called)
530 530

  
531 531
    def test_progress_update(self, client):
532 532
        rprogress = randint(10, 100)
533 533
        msg = self.create_msg(progress=rprogress,
534 534
                              instance=self.vm.backend_vm_id)
535 535
        update_build_progress(client, msg)
536
        client.basic_ack.assert_called_once()
536
        self.assertTrue(client.basic_ack.called)
537 537
        vm = self.get_db_vm()
538 538
        self.assertEqual(vm.buildpercentage, rprogress)
539 539

  
......
543 543
            msg = self.create_msg(progress=rprogress,
544 544
                                  instance=self.vm.backend_vm_id)
545 545
            update_build_progress(client, msg)
546
            client.basic_ack.assert_called_once()
546
            self.assertTrue(client.basic_ack.called)
547 547
            vm = self.get_db_vm()
548 548
            self.assertEqual(vm.buildpercentage, old)
549 549

  

Also available in: Unified diff