예제 #1
0
파일: tests.py 프로젝트: young8/dashboard
 def test_action_queue_delay(self):
     Threshold.objects.create(balance=-50,
                              actions=pickle.dumps(
                                  ['stop_project_instances']),
                              up=False,
                              down=True)
     ServerManager.list(search_opts={
         'all_tenants': True,
         'tenant_id': my_tenant_id,
         'status': 'ACTIVE'
     }).AndReturn([
         instance for instance in instance_list
         if instance.tenant_id == my_tenant_id
     ])
     instance_list[0].stop()
     instance_list[2].stop()
     timezone.now().AndReturn(self.real_now)  # called by user transaction
     timezone.now().AndReturn(self.real_now)  # called by user transaction
     timezone.now().AndReturn(self.real_now +
                              timezone.timedelta(seconds=2 * 24 * 60 * 60))
     timezone.now().AndReturn(self.real_now +
                              timezone.timedelta(seconds=3 * 24 * 60 * 60))
     timezone.now().AndReturn(self.real_now +
                              timezone.timedelta(seconds=5 * 24 * 60 * 60))
     timezone.now().AndReturn(self.real_now +
                              timezone.timedelta(seconds=6 * 24 * 60 * 60))
     self.mox.ReplayAll()
     UserTransactions().consume_user_money(1, 60, 'some consumption')
     ActionQueueProcessor.process()
     ActionQueueProcessor.process()
     ActionQueueProcessor.process()
     ActionQueueProcessor.process()
예제 #2
0
파일: tests.py 프로젝트: kili/dashboard
 def test_action_queue_delay(self):
     Threshold.objects.create(
         balance=-50,
         actions=pickle.dumps(['stop_project_instances']),
         up=False,
         down=True)
     ServerManager.list(
         search_opts={'all_tenants': True,
                      'tenant_id': my_tenant_id,
                      'status': 'ACTIVE'}).AndReturn(
                          [instance for instance in instance_list
                           if instance.tenant_id == my_tenant_id])
     instance_list[0].stop()
     instance_list[2].stop()
     timezone.now().AndReturn(self.real_now)  # called by user transaction
     timezone.now().AndReturn(self.real_now)  # called by user transaction
     timezone.now().AndReturn(
         self.real_now + timezone.timedelta(seconds=2 * 24 * 60 * 60))
     timezone.now().AndReturn(
         self.real_now + timezone.timedelta(seconds=3 * 24 * 60 * 60))
     timezone.now().AndReturn(
         self.real_now + timezone.timedelta(seconds=5 * 24 * 60 * 60))
     timezone.now().AndReturn(
         self.real_now + timezone.timedelta(seconds=6 * 24 * 60 * 60))
     self.mox.ReplayAll()
     UserTransactions().consume_user_money(1, 60, 'some consumption')
     ActionQueueProcessor.process()
     ActionQueueProcessor.process()
     ActionQueueProcessor.process()
     ActionQueueProcessor.process()
예제 #3
0
파일: tests.py 프로젝트: young8/dashboard
 def test_notification_sender_and_instance_stopper_combination(self):
     Notifications.delete_all_notifications()
     Threshold.objects.create(balance=0,
                              actions=pickle.dumps(['send_notification']),
                              up=False,
                              down=True)
     Threshold.objects.create(balance=-50,
                              actions=pickle.dumps([
                                  'send_notification',
                                  'stop_project_instances'
                              ]),
                              up=False,
                              down=True)
     KeystoneClient.get_client().AndReturn(get_stub_keystone_client(3))
     ServerManager.list(search_opts={
         'all_tenants': True,
         'tenant_id': my_tenant_id,
         'status': 'ACTIVE'
     }).AndReturn([
         instance for instance in instance_list
         if instance.tenant_id == my_tenant_id
     ])
     instance_list[0].stop()
     instance_list[2].stop()
     timezone.now().AndReturn(self.real_now)  # called by user transaction
     timezone.now().AndReturn(self.real_now)  # called by user transaction
     timezone.now().AndReturn(self.real_now)  # called by user transaction
     timezone.now().AndReturn(self.real_now +
                              timezone.timedelta(seconds=2 * 24 * 60 * 60))
     timezone.now().AndReturn(self.real_now +
                              timezone.timedelta(seconds=3 * 24 * 60 * 60))
     timezone.now().AndReturn(self.real_now +
                              timezone.timedelta(seconds=5 * 24 * 60 * 60))
     timezone.now().AndReturn(self.real_now +
                              timezone.timedelta(seconds=6 * 24 * 60 * 60))
     self.mox.ReplayAll()
     ut = UserTransactions()
     ut.receive_user_payment(1, 'STRIPE', 6, 'user paid something')
     #import pdb
     #pdb.set_trace()
     ut.consume_user_money(1, 100, 'lot of consumption')
     Notifications.send_all_notifications()
     self.assertEqual(len(mail.outbox), 1)
     self.assertEqual(PassedThreshold.objects.count(), 2)
     ActionQueueProcessor.process()
     ActionQueueProcessor.process()
     self.assertEqual(len(instance_list[0].stop._expected_calls_queue), 1)
     self.assertEqual(len(instance_list[2].stop._expected_calls_queue), 1)
     ActionQueueProcessor.process()
     self.assertEqual(len(instance_list[0].stop._expected_calls_queue), 0)
     self.assertEqual(len(instance_list[2].stop._expected_calls_queue), 0)
     ActionQueueProcessor.process()
예제 #4
0
파일: tests.py 프로젝트: kili/dashboard
 def test_notification_sender_and_instance_stopper_combination(self):
     Notifications.delete_all_notifications()
     Threshold.objects.create(
         balance=0,
         actions=pickle.dumps(['send_notification']),
         up=False,
         down=True)
     Threshold.objects.create(
         balance=-50,
         actions=pickle.dumps(['send_notification',
                               'stop_project_instances']),
         up=False,
         down=True)
     KeystoneClient.get_client().AndReturn(
         get_stub_keystone_client(3))
     ServerManager.list(
         search_opts={'all_tenants': True,
                      'tenant_id': my_tenant_id,
                      'status': 'ACTIVE'}).AndReturn(
                          [instance for instance in instance_list
                           if instance.tenant_id == my_tenant_id])
     instance_list[0].stop()
     instance_list[2].stop()
     timezone.now().AndReturn(self.real_now)  # called by user transaction
     timezone.now().AndReturn(self.real_now)  # called by user transaction
     timezone.now().AndReturn(self.real_now)  # called by user transaction
     timezone.now().AndReturn(
         self.real_now + timezone.timedelta(seconds=2 * 24 * 60 * 60))
     timezone.now().AndReturn(
         self.real_now + timezone.timedelta(seconds=3 * 24 * 60 * 60))
     timezone.now().AndReturn(
         self.real_now + timezone.timedelta(seconds=5 * 24 * 60 * 60))
     timezone.now().AndReturn(
         self.real_now + timezone.timedelta(seconds=6 * 24 * 60 * 60))
     self.mox.ReplayAll()
     ut = UserTransactions()
     ut.receive_user_payment(1, 'STRIPE', 6, 'user paid something')
     #import pdb
     #pdb.set_trace()
     ut.consume_user_money(1, 100, 'lot of consumption')
     Notifications.send_all_notifications()
     self.assertEqual(len(mail.outbox), 1)
     self.assertEqual(PassedThreshold.objects.count(), 2)
     ActionQueueProcessor.process()
     ActionQueueProcessor.process()
     self.assertEqual(len(instance_list[0].stop._expected_calls_queue), 1)
     self.assertEqual(len(instance_list[2].stop._expected_calls_queue), 1)
     ActionQueueProcessor.process()
     self.assertEqual(len(instance_list[0].stop._expected_calls_queue), 0)
     self.assertEqual(len(instance_list[2].stop._expected_calls_queue), 0)
     ActionQueueProcessor.process()
예제 #5
0
파일: tests.py 프로젝트: kili/dashboard
 def test_instance_stopper(self):
     Threshold.objects.create(
         balance=-50,
         actions=pickle.dumps(['stop_project_instances']),
         up=False,
         down=True)
     ServerManager.list(
         search_opts={'all_tenants': True,
                      'tenant_id': my_tenant_id,
                      'status': 'ACTIVE'}).AndReturn(
                          [instance for instance in instance_list
                           if instance.tenant_id == my_tenant_id])
     instance_list[0].stop()
     instance_list[2].stop()
     StopProjectInstancesThresholdAction._get_due_datetime().AndReturn(
         timezone.now())
     self.mox.ReplayAll()
     UserTransactions().consume_user_money(1, 60, 'some consumption')
     ActionQueueProcessor.process()
예제 #6
0
def get_fake_instances_data(request):
    import json
    from novaclient.v1_1.servers import Server, ServerManager
    from horizon.api.nova import Server as HServer
    instances = [HServer(Server(ServerManager(None), i), request)
                 for i in json.loads(test_json)]
    for i in instances:
        i._loaded = True
    instances += instances
    return instances
예제 #7
0
파일: tests.py 프로젝트: young8/dashboard
 def test_instance_stopper(self):
     Threshold.objects.create(balance=-50,
                              actions=pickle.dumps(
                                  ['stop_project_instances']),
                              up=False,
                              down=True)
     ServerManager.list(search_opts={
         'all_tenants': True,
         'tenant_id': my_tenant_id,
         'status': 'ACTIVE'
     }).AndReturn([
         instance for instance in instance_list
         if instance.tenant_id == my_tenant_id
     ])
     instance_list[0].stop()
     instance_list[2].stop()
     StopProjectInstancesThresholdAction._get_due_datetime().AndReturn(
         timezone.now())
     self.mox.ReplayAll()
     UserTransactions().consume_user_money(1, 60, 'some consumption')
     ActionQueueProcessor.process()