Ejemplo n.º 1
0
 def test_process_exists_with_deleted_at(self):
     launch_time = datetime.datetime.utcnow()-datetime.timedelta(hours=23)
     launch_decimal = utils.decimal_utc(launch_time)
     deleted_time = datetime.datetime.utcnow()-datetime.timedelta(hours=12)
     deleted_decimal = utils.decimal_utc(deleted_time)
     current_time = datetime.datetime.utcnow()
     current_decimal = utils.decimal_utc(current_time)
     notif = utils.create_nova_notif(launched=str(launch_time),
                                     deleted=str(deleted_time))
     json_str = json.dumps(notif)
     event = 'compute.instance.exists'
     raw = utils.create_raw(self.mox, current_decimal, event=event,
                            json_str=json_str)
     usage = self.mox.CreateMockAnything()
     views.STACKDB.get_instance_usage(instance=INSTANCE_ID_1,
                                      launched_at=launch_decimal)\
                  .AndReturn(usage)
     exists_values = {
         'message_id': MESSAGE_ID_1,
         'instance': INSTANCE_ID_1,
         'launched_at': launch_decimal,
         'deleted_at': deleted_decimal,
         'instance_type_id': '1',
         'usage': usage,
         'raw': raw,
     }
     exists = self.mox.CreateMockAnything()
     views.STACKDB.create_instance_exists(**exists_values).AndReturn(exists)
     views.STACKDB.save(exists)
     self.mox.ReplayAll()
     views._process_exists(raw)
     self.mox.VerifyAll()
Ejemplo n.º 2
0
    def test_process_exists_with_deleted_at(self):
        notification = self.mox.CreateMockAnything()
        current_time = datetime.datetime.utcnow()
        launch_time = current_time - datetime.timedelta(hours=23)
        launch_decimal = utils.decimal_utc(launch_time)
        delete_time = datetime.datetime.utcnow()
        deleted_decimal = utils.decimal_utc(delete_time)
        audit_beginning = current_time - datetime.timedelta(hours=20)
        audit_beginning_decimal = utils.decimal_utc(audit_beginning)
        audit_ending_decimal = utils.decimal_utc(current_time)

        notification.launched_at = str(launch_time)
        notification.audit_period_beginning = str(audit_beginning)
        notification.audit_period_ending = str(current_time)
        notification.tenant = TENANT_ID_1
        notification.os_architecture = OS_ARCH_1
        notification.os_version = OS_VERSION_1
        notification.os_distro = OS_DISTRO_1
        notification.rax_options = RAX_OPTIONS_1
        notification.instance = INSTANCE_ID_1
        notification.instance_type_id = INSTANCE_TYPE_ID_1
        notification.message_id = MESSAGE_ID_1
        notification.deleted_at = str(delete_time)
        notification.bandwidth_public_out = BANDWIDTH_PUBLIC_OUTBOUND
        raw = self.mox.CreateMockAnything()
        usage = self.mox.CreateMockAnything()
        launched_range = (launch_decimal, launch_decimal+1)
        views.STACKDB.get_instance_usage(instance=INSTANCE_ID_1,
                                         launched_at__range=launched_range)\
                     .AndReturn(usage)
        delete = self.mox.CreateMockAnything()
        views.STACKDB.get_instance_delete(instance=INSTANCE_ID_1,
                                          launched_at__range=launched_range)\
             .AndReturn(delete)
        exists_values = {
            'message_id': MESSAGE_ID_1,
            'instance': INSTANCE_ID_1,
            'launched_at': launch_decimal,
            'deleted_at': deleted_decimal,
            'audit_period_beginning': audit_beginning_decimal,
            'audit_period_ending': audit_ending_decimal,
            'instance_type_id': INSTANCE_TYPE_ID_1,
            'usage': usage,
            'delete': delete,
            'raw': raw,
            'tenant': TENANT_ID_1,
            'rax_options': RAX_OPTIONS_1,
            'os_architecture': OS_ARCH_1,
            'os_version': OS_VERSION_1,
            'os_distro': OS_DISTRO_1,
            'bandwidth_public_out': BANDWIDTH_PUBLIC_OUTBOUND
        }
        exists = self.mox.CreateMockAnything()
        views.STACKDB.create_instance_exists(**exists_values).AndReturn(exists)
        views.STACKDB.save(exists)
        self.mox.ReplayAll()
        views._process_exists(raw, notification)
        self.mox.VerifyAll()
Ejemplo n.º 3
0
 def test_process_exists_with_deleted_at(self):
     current_time = datetime.datetime.utcnow()
     launch_time = current_time - datetime.timedelta(hours=23)
     launch_decimal = utils.decimal_utc(launch_time)
     deleted_time = current_time - datetime.timedelta(hours=12)
     deleted_decimal = utils.decimal_utc(deleted_time)
     current_decimal = utils.decimal_utc(current_time)
     audit_beginning = current_time - datetime.timedelta(hours=20)
     audit_beginning_decimal = utils.decimal_utc(audit_beginning)
     audit_ending_decimal = utils.decimal_utc(current_time)
     notif = utils.create_nova_notif(launched=str(launch_time),
                                     deleted=str(deleted_time),
                                     audit_period_beginning=str(audit_beginning),
                                     audit_period_ending=str(current_time),
                                     tenant_id=TENANT_ID_1,
                                     os_architecture=OS_ARCH_1,
                                     os_version=OS_VERSION_1,
                                     os_distro=OS_DISTRO_1,
                                     rax_options=RAX_OPTIONS_1)
     json_str = json.dumps(notif)
     event = 'compute.instance.exists'
     raw = utils.create_raw(self.mox, current_decimal, event=event,
                            json_str=json_str)
     usage = self.mox.CreateMockAnything()
     launched_range = (launch_decimal, launch_decimal+1)
     views.STACKDB.get_instance_usage(instance=INSTANCE_ID_1,
                                      launched_at__range=launched_range)\
                  .AndReturn(usage)
     delete = self.mox.CreateMockAnything()
     views.STACKDB.get_instance_delete(instance=INSTANCE_ID_1,
                                       launched_at__range=launched_range)\
          .AndReturn(delete)
     exists_values = {
         'message_id': MESSAGE_ID_1,
         'instance': INSTANCE_ID_1,
         'launched_at': launch_decimal,
         'deleted_at': deleted_decimal,
         'audit_period_beginning': audit_beginning_decimal,
         'audit_period_ending': audit_ending_decimal,
         'instance_type_id': '1',
         'usage': usage,
         'delete': delete,
         'raw': raw,
         'tenant': TENANT_ID_1,
         'rax_options': RAX_OPTIONS_1,
         'os_architecture': OS_ARCH_1,
         'os_version': OS_VERSION_1,
         'os_distro': OS_DISTRO_1
     }
     exists = self.mox.CreateMockAnything()
     views.STACKDB.create_instance_exists(**exists_values).AndReturn(exists)
     views.STACKDB.save(exists)
     self.mox.ReplayAll()
     views._process_exists(raw, notif[1])
     self.mox.VerifyAll()
Ejemplo n.º 4
0
 def test_process_exists_no_launched_at(self):
     notification = self.mox.CreateMockAnything()
     notification.instance = INSTANCE_ID_1
     notification.launched_at = None
     raw = self.mox.CreateMockAnything()
     raw.id = '1'
     self.setup_mock_log()
     self.log.warn('Ignoring exists without launched_at. RawData(1)')
     self.mox.ReplayAll()
     views._process_exists(raw, notification)
     self.mox.VerifyAll()
Ejemplo n.º 5
0
 def test_process_exists_no_launched_at(self):
     notification = self.mox.CreateMockAnything()
     notification.instance = INSTANCE_ID_1
     notification.launched_at = None
     raw = self.mox.CreateMockAnything()
     raw.id = '1'
     self.setup_mock_log()
     self.log.warn('Ignoring exists without launched_at. RawData(1)')
     self.mox.ReplayAll()
     views._process_exists(raw, notification)
     self.mox.VerifyAll()
Ejemplo n.º 6
0
 def test_process_exists_with_deleted_at(self):
     current_time = datetime.datetime.utcnow()
     launch_time = current_time - datetime.timedelta(hours=23)
     launch_decimal = utils.decimal_utc(launch_time)
     deleted_time = current_time - datetime.timedelta(hours=12)
     deleted_decimal = utils.decimal_utc(deleted_time)
     current_decimal = utils.decimal_utc(current_time)
     audit_beginning = current_time - datetime.timedelta(hours=20)
     audit_beginning_decimal = utils.decimal_utc(audit_beginning)
     audit_ending_decimal = utils.decimal_utc(current_time)
     notif = utils.create_nova_notif(launched=str(launch_time),
                                     deleted=str(deleted_time),
                                     audit_period_beginning=str(audit_beginning),
                                     audit_period_ending=str(current_time),
                                     tenant_id=TENANT_ID_1)
     json_str = json.dumps(notif)
     event = 'compute.instance.exists'
     raw = utils.create_raw(self.mox, current_decimal, event=event,
                            json_str=json_str)
     usage = self.mox.CreateMockAnything()
     launched_range = (launch_decimal, launch_decimal+1)
     views.STACKDB.get_instance_usage(instance=INSTANCE_ID_1,
                                      launched_at__range=launched_range)\
                  .AndReturn(usage)
     delete = self.mox.CreateMockAnything()
     views.STACKDB.get_instance_delete(instance=INSTANCE_ID_1,
                                       launched_at__range=launched_range)\
          .AndReturn(delete)
     exists_values = {
         'message_id': MESSAGE_ID_1,
         'instance': INSTANCE_ID_1,
         'launched_at': launch_decimal,
         'deleted_at': deleted_decimal,
         'audit_period_beginning': audit_beginning_decimal,
         'audit_period_ending': audit_ending_decimal,
         'instance_type_id': '1',
         'usage': usage,
         'delete': delete,
         'raw': raw,
         'tenant': TENANT_ID_1
     }
     exists = self.mox.CreateMockAnything()
     views.STACKDB.create_instance_exists(**exists_values).AndReturn(exists)
     views.STACKDB.save(exists)
     self.mox.ReplayAll()
     views._process_exists(raw, notif[1])
     self.mox.VerifyAll()
Ejemplo n.º 7
0
 def test_process_exists_with_deleted_at(self):
     current_time = datetime.datetime.utcnow()
     launch_time = current_time - datetime.timedelta(hours=23)
     launch_decimal = utils.decimal_utc(launch_time)
     delete_time = datetime.datetime.utcnow()
     deleted_decimal = utils.decimal_utc(delete_time)
     audit_beginning = current_time - datetime.timedelta(hours=20)
     audit_beginning_decimal = utils.decimal_utc(audit_beginning)
     audit_ending_decimal = utils.decimal_utc(current_time)
     notification = self._create_exists_notification(
         audit_beginning, current_time, launch_time, delete_time)
     raw = self.mox.CreateMockAnything()
     usage = self.mox.CreateMockAnything()
     launched_range = (launch_decimal, launch_decimal + 1)
     views.STACKDB.get_instance_usage(instance=INSTANCE_ID_1,
                                      launched_at__range=launched_range)\
                  .AndReturn(usage)
     delete = self.mox.CreateMockAnything()
     views.STACKDB.get_instance_delete(instance=INSTANCE_ID_1,
                                       launched_at__range=launched_range)\
          .AndReturn(delete)
     exists_values = {
         'message_id': MESSAGE_ID_1,
         'instance': INSTANCE_ID_1,
         'launched_at': launch_decimal,
         'deleted_at': deleted_decimal,
         'audit_period_beginning': audit_beginning_decimal,
         'audit_period_ending': audit_ending_decimal,
         'instance_type_id': INSTANCE_TYPE_ID_1,
         'instance_flavor_id': INSTANCE_FLAVOR_ID_1,
         'usage': usage,
         'delete': delete,
         'raw': raw,
         'tenant': TENANT_ID_1,
         'rax_options': RAX_OPTIONS_1,
         'os_architecture': OS_ARCH_1,
         'os_version': OS_VERSION_1,
         'os_distro': OS_DISTRO_1,
         'bandwidth_public_out': BANDWIDTH_PUBLIC_OUTBOUND
     }
     exists = self.mox.CreateMockAnything()
     views.STACKDB.create_instance_exists(**exists_values).AndReturn(exists)
     views.STACKDB.save(exists)
     self.mox.ReplayAll()
     views._process_exists(raw, notification)
     self.mox.VerifyAll()
Ejemplo n.º 8
0
 def test_process_exists_no_launched_at(self):
     current_time = datetime.datetime.utcnow()
     current_decimal = utils.decimal_utc(current_time)
     audit_beginning = current_time - datetime.timedelta(hours=20)
     notif = utils.create_nova_notif(audit_period_beginning=str(audit_beginning),
                                     audit_period_ending=str(current_time),
                                     tenant_id=TENANT_ID_1)
     json_str = json.dumps(notif)
     event = 'compute.instance.exists'
     raw = utils.create_raw(self.mox, current_decimal, event=event,
                            json_str=json_str)
     raw.id = 1
     self.setup_mock_log()
     self.log.warn('Ignoring exists without launched_at. RawData(1)')
     self.mox.ReplayAll()
     views._process_exists(raw, notif[1])
     self.mox.VerifyAll()
Ejemplo n.º 9
0
 def test_process_exists(self):
     current_time = datetime.datetime.utcnow()
     launch_time = current_time - datetime.timedelta(hours=23)
     launch_decimal = utils.decimal_utc(launch_time)
     current_decimal = utils.decimal_utc(current_time)
     audit_beginning = current_time - datetime.timedelta(hours=20)
     audit_beginning_decimal = utils.decimal_utc(audit_beginning)
     audit_ending_decimal = utils.decimal_utc(current_time)
     notif = utils.create_nova_notif(launched=str(launch_time),
                                     audit_period_beginning=str(audit_beginning),
                                     audit_period_ending=str(current_time))
     json_str = json.dumps(notif)
     event = 'compute.instance.exists'
     raw = utils.create_raw(self.mox, current_decimal, event=event,
                            json_str=json_str)
     usage = self.mox.CreateMockAnything()
     launched_range = (launch_decimal, launch_decimal+1)
     views.STACKDB.get_instance_usage(instance=INSTANCE_ID_1,
                                      launched_at__range=launched_range)\
                  .AndReturn(usage)
     views.STACKDB.get_instance_delete(instance=INSTANCE_ID_1,
                                       launched_at__range=launched_range)\
          .AndReturn(None)
     exists_values = {
         'message_id': MESSAGE_ID_1,
         'instance': INSTANCE_ID_1,
         'launched_at': launch_decimal,
         'audit_period_beginning': audit_beginning_decimal,
         'audit_period_ending': audit_ending_decimal,
         'instance_type_id': '1',
         'usage': usage,
         'raw': raw,
     }
     exists = self.mox.CreateMockAnything()
     views.STACKDB.create_instance_exists(**exists_values).AndReturn(exists)
     views.STACKDB.save(exists)
     self.mox.ReplayAll()
     views._process_exists(raw, notif[1])
     self.mox.VerifyAll()