Beispiel #1
0
    def test_process_exists_with_deleted_at(self):
        launched_str = '2012-12-21 06:34:50.123'
        launched = utils.str_time_to_unix(launched_str)
        deleted_str = '2012-12-21 06:36:50.123'
        deleted = utils.str_time_to_unix(deleted_str)
        values = {
            'instance': INSTANCE_ID_1,
            'request_id': REQUEST_ID_1,
            'instance_type_id': '1',
            'launched_at': launched,
            }
        InstanceUsage(**values).save()

        exists_str = '2012-12-21 23:30:00.000'
        exists_time = utils.str_time_to_unix(exists_str)
        json = test_utils.make_exists_json(launched_str, deleted_at=deleted_str)
        raw = create_raw(self.deployment, exists_time,
            views.INSTANCE_EVENT['exists'], json=json)

        views._process_exists(raw)

        usage = InstanceExists.objects.filter(instance=INSTANCE_ID_1,
            launched_at = launched)[0]
        exists_rows = InstanceExists.objects.all()
        self.assertEqual(len(exists_rows), 1)
        exists = exists_rows[0]
        self.assertEqual(exists.instance, INSTANCE_ID_1)
        self.assertEqual(exists.launched_at, launched)
        self.assertEqual(exists.status, InstanceExists.PENDING)
        self.assertEqual(exists.usage.id, usage.id)
        self.assertEqual(exists.raw.id, raw.id)
        self.assertEqual(exists.message_id, MESSAGE_ID_1)
        self.assertEqual(exists.deleted_at, deleted)
        self.assertEqual(exists.instance_type_id, '1')
Beispiel #2
0
    def test_process_exists(self):
        launched_str = '2012-12-21 06:34:50.123'
        launched = utils.str_time_to_unix(launched_str)
        values = {
            'instance': INSTANCE_ID_1,
            'request_id': REQUEST_ID_1,
            'instance_type_id': '1',
            'launched_at': launched,
        }
        InstanceUsage(**values).save()

        exists_str = '2012-12-21 23:30:00.000'
        exists_time = utils.str_time_to_unix(exists_str)
        json = test_utils.make_exists_json(launched_str)
        raw = create_raw(self.deployment,
                         exists_time,
                         views.INSTANCE_EVENT['exists'],
                         json=json)

        views._process_exists(raw)

        usage = InstanceExists.objects.filter(instance=INSTANCE_ID_1,
                                              launched_at=launched)[0]
        exists_rows = InstanceExists.objects.all()
        self.assertEqual(len(exists_rows), 1)
        exists = exists_rows[0]
        self.assertEqual(exists.instance, INSTANCE_ID_1)
        self.assertEqual(exists.launched_at, launched)
        self.assertEqual(exists.status, InstanceExists.PENDING)
        self.assertEqual(exists.usage.id, usage.id)
        self.assertEqual(exists.raw.id, raw.id)
        self.assertEqual(exists.message_id, MESSAGE_ID_1)
        self.assertIsNone(exists.deleted_at)
        self.assertEqual(exists.instance_type_id, '1')
Beispiel #3
0
    def test_resize_workflow_out_of_order(self):
        launched_str = '2012-12-21 06:34:50.123'
        launched = utils.str_time_to_unix(launched_str)
        values = {
            'instance': INSTANCE_ID_1,
            'request_id': REQUEST_ID_1,
            'instance_type_id': '1',
            'launched_at': launched,
        }
        InstanceUsage(**values).save()

        started_str = '2012-12-22 06:34:50.123'
        started_time = utils.str_time_to_unix(started_str)
        pre_end_str = '2012-12-22 06:36:50.123'
        prep_end_time = utils.str_time_to_unix(pre_end_str)
        finish_str = '2012-12-22 06:38:50.123'
        finish_time = utils.str_time_to_unix(finish_str)
        prep_start_json = test_utils\
        .make_resize_prep_start_json(request_id=REQUEST_ID_2)
        prep_end_json = test_utils\
                        .make_resize_prep_end_json(new_instance_type_id='2',
                                                   request_id=REQUEST_ID_2)
        finish_json = test_utils\
                      .make_resize_finish_json(launched_at=finish_str,
                                               request_id=REQUEST_ID_2)
        prep_start_raw = create_raw(self.deployment,
                                    started_time,
                                    views.INSTANCE_EVENT['resize_prep_start'],
                                    request_id=REQUEST_ID_2,
                                    json=prep_start_json)
        prep_end_raw = create_raw(self.deployment,
                                  prep_end_time,
                                  views.INSTANCE_EVENT['resize_prep_end'],
                                  request_id=REQUEST_ID_2,
                                  json=prep_end_json)
        finish_raw = create_raw(self.deployment,
                                finish_time,
                                views.INSTANCE_EVENT['resize_finish_end'],
                                request_id=REQUEST_ID_2,
                                json=finish_json)

        # Resize Started, notification on time
        views.aggregate_usage(prep_start_raw)
        # Received finish_end, prep_end late
        views.aggregate_usage(finish_raw)
        # Finally receive the late prep_end
        views.aggregate_usage(prep_end_raw)

        usages = InstanceUsage.objects.all().order_by('id')
        self.assertEqual(len(usages), 2)
        usage_before = usages[0]
        usage_after = usages[1]
        self.assertOnUsage(usage_before, INSTANCE_ID_1, '1', launched,
                           REQUEST_ID_1)
        self.assertOnUsage(usage_after, INSTANCE_ID_1, '2', finish_time,
                           REQUEST_ID_2)
Beispiel #4
0
    def test_multiple_instance_lifecycles(self):
        when1 = utils.str_time_to_unix('2012-12-21 13:32:50.123')
        when2 = utils.str_time_to_unix('2012-12-21 13:34:50.123')
        when3 = utils.str_time_to_unix('2012-12-21 13:37:50.124')
        update_raw2 = create_raw(self.deployment,
                                 when1,
                                 'compute.instance.update',
                                 instance=INSTANCE_ID_2,
                                 request_id=REQUEST_ID_2,
                                 host='api',
                                 service='api')
        start_raw2 = create_raw(self.deployment,
                                when2,
                                'compute.instance.resize.start',
                                instance=INSTANCE_ID_2,
                                request_id=REQUEST_ID_2)
        end_raw2 = create_raw(self.deployment,
                              when3,
                              'compute.instance.resize.end',
                              old_task='resize',
                              instance=INSTANCE_ID_2,
                              request_id=REQUEST_ID_2)

        views.aggregate_lifecycle(self.update_raw)
        views.aggregate_lifecycle(self.start_raw)
        views.aggregate_lifecycle(update_raw2)
        views.aggregate_lifecycle(start_raw2)

        lifecycles = Lifecycle.objects.all().order_by('id')
        self.assertEqual(len(lifecycles), 2)
        lifecycle1 = lifecycles[0]
        self.assertOnLifecycle(lifecycle1, INSTANCE_ID_1, self.start_raw)
        lifecycle2 = lifecycles[1]
        self.assertOnLifecycle(lifecycle2, INSTANCE_ID_2, start_raw2)

        views.aggregate_lifecycle(end_raw2)
        views.aggregate_lifecycle(self.end_raw)

        lifecycles = Lifecycle.objects.all().order_by('id')
        self.assertEqual(len(lifecycles), 2)
        lifecycle1 = lifecycles[0]
        self.assertOnLifecycle(lifecycle1, INSTANCE_ID_1, self.end_raw)
        lifecycle2 = lifecycles[1]
        self.assertOnLifecycle(lifecycle2, INSTANCE_ID_2, end_raw2)

        timings = Timing.objects.all().order_by('id')
        self.assertEqual(len(timings), 2)
        timing1 = timings[0]
        expected_diff1 = self.end_raw.when - self.start_raw.when
        self.assertOnTiming(timing1, lifecycle1, self.start_raw, self.end_raw,
                            expected_diff1)
        expected_diff2 = end_raw2.when - start_raw2.when
        timing2 = timings[1]
        self.assertOnTiming(timing2, lifecycle2, start_raw2, end_raw2,
                            expected_diff2)
Beispiel #5
0
    def test_resize_revert_workflow_start_late(self):
        launched_str = '2012-12-21 06:34:50.123'
        launched = utils.str_time_to_unix(launched_str)
        values = {
            'instance': INSTANCE_ID_1,
            'request_id': REQUEST_ID_1,
            'instance_type_id': '1',
            'launched_at': launched,
        }
        InstanceUsage(**values).save()
        resize_launched_str = '2012-12-22 06:34:50.123'
        resize_launched = utils.str_time_to_unix(resize_launched_str)
        values = {
            'instance': INSTANCE_ID_1,
            'request_id': REQUEST_ID_2,
            'instance_type_id': '2',
            'launched_at': resize_launched,
        }
        InstanceUsage(**values).save()

        started_str = '2012-12-22 06:34:50.123'
        started_time = utils.str_time_to_unix(started_str)
        end_str = '2012-12-22 06:36:50.123'
        end_time = utils.str_time_to_unix(end_str)
        start_json = test_utils\
                     .make_resize_revert_start_json(request_id=REQUEST_ID_3)
        end_json = test_utils\
                   .make_resize_revert_end_json(launched_at=end_str,
                                                request_id=REQUEST_ID_3)
        start_raw = create_raw(self.deployment,
                               started_time,
                               views.INSTANCE_EVENT['resize_revert_start'],
                               request_id=REQUEST_ID_3,
                               json=start_json)
        end_raw = create_raw(self.deployment,
                             started_time,
                             views.INSTANCE_EVENT['resize_revert_end'],
                             request_id=REQUEST_ID_3,
                             json=end_json)

        views.aggregate_usage(end_raw)
        views.aggregate_usage(start_raw)

        usages = InstanceUsage.objects.all().order_by('id')
        self.assertEqual(len(usages), 3)
        usage_before_resize = usages[0]
        usage_after_resize = usages[1]
        usage_after_revert = usages[2]
        self.assertOnUsage(usage_before_resize, INSTANCE_ID_1, '1', launched,
                           REQUEST_ID_1)
        self.assertOnUsage(usage_after_resize, INSTANCE_ID_1, '2',
                           resize_launched, REQUEST_ID_2)
        self.assertOnUsage(usage_after_revert, INSTANCE_ID_1, '1', end_time,
                           REQUEST_ID_3)
Beispiel #6
0
    def test_resize_workflow_out_of_order(self):
        launched_str = '2012-12-21 06:34:50.123'
        launched = utils.str_time_to_unix(launched_str)
        values = {
            'instance': INSTANCE_ID_1,
            'request_id': REQUEST_ID_1,
            'instance_type_id': '1',
            'launched_at': launched,
            }
        InstanceUsage(**values).save()

        started_str = '2012-12-22 06:34:50.123'
        started_time = utils.str_time_to_unix(started_str)
        pre_end_str = '2012-12-22 06:36:50.123'
        prep_end_time = utils.str_time_to_unix(pre_end_str)
        finish_str = '2012-12-22 06:38:50.123'
        finish_time = utils.str_time_to_unix(finish_str)
        prep_start_json = test_utils\
        .make_resize_prep_start_json(request_id=REQUEST_ID_2)
        prep_end_json = test_utils\
                        .make_resize_prep_end_json(new_instance_type_id='2',
                                                   request_id=REQUEST_ID_2)
        finish_json = test_utils\
                      .make_resize_finish_json(launched_at=finish_str,
                                               request_id=REQUEST_ID_2)
        prep_start_raw = create_raw(self.deployment, started_time,
                                    views.INSTANCE_EVENT['resize_prep_start'],
                                    request_id=REQUEST_ID_2,
                                    json=prep_start_json)
        prep_end_raw = create_raw(self.deployment, prep_end_time,
                                  views.INSTANCE_EVENT['resize_prep_end'],
                                  request_id=REQUEST_ID_2,
                                  json=prep_end_json)
        finish_raw = create_raw(self.deployment, finish_time,
                                views.INSTANCE_EVENT['resize_finish_end'],
                                request_id=REQUEST_ID_2,
                                json=finish_json)

        # Resize Started, notification on time
        views.aggregate_usage(prep_start_raw)
        # Received finish_end, prep_end late
        views.aggregate_usage(finish_raw)
        # Finally receive the late prep_end
        views.aggregate_usage(prep_end_raw)

        usages = InstanceUsage.objects.all().order_by('id')
        self.assertEqual(len(usages), 2)
        usage_before = usages[0]
        usage_after = usages[1]
        self.assertOnUsage(usage_before, INSTANCE_ID_1, '1', launched,
                           REQUEST_ID_1)
        self.assertOnUsage(usage_after, INSTANCE_ID_1, '2', finish_time,
                           REQUEST_ID_2)
Beispiel #7
0
    def test_multiple_instance_lifecycles(self):
        when1 = utils.str_time_to_unix('2012-12-21 13:32:50.123')
        when2 = utils.str_time_to_unix('2012-12-21 13:34:50.123')
        when3 = utils.str_time_to_unix('2012-12-21 13:37:50.124')
        update_raw2 = create_raw(self.deployment, when1,
                                      'compute.instance.update',
                                      instance=INSTANCE_ID_2,
                                      request_id=REQUEST_ID_2,
                                      host='api', service='api')
        start_raw2 = create_raw(self.deployment, when2,
                                     'compute.instance.resize.start',
                                     instance=INSTANCE_ID_2,
                                     request_id=REQUEST_ID_2)
        end_raw2 = create_raw(self.deployment, when3,
                                   'compute.instance.resize.end',
                                   old_task='resize',
                                   instance=INSTANCE_ID_2,
                                   request_id=REQUEST_ID_2)

        views.aggregate_lifecycle(self.update_raw)
        views.aggregate_lifecycle(self.start_raw)
        views.aggregate_lifecycle(update_raw2)
        views.aggregate_lifecycle(start_raw2)

        lifecycles = Lifecycle.objects.all().order_by('id')
        self.assertEqual(len(lifecycles), 2)
        lifecycle1 = lifecycles[0]
        self.assertOnLifecycle(lifecycle1, INSTANCE_ID_1, self.start_raw)
        lifecycle2 = lifecycles[1]
        self.assertOnLifecycle(lifecycle2, INSTANCE_ID_2, start_raw2)

        views.aggregate_lifecycle(end_raw2)
        views.aggregate_lifecycle(self.end_raw)

        lifecycles = Lifecycle.objects.all().order_by('id')
        self.assertEqual(len(lifecycles), 2)
        lifecycle1 = lifecycles[0]
        self.assertOnLifecycle(lifecycle1, INSTANCE_ID_1, self.end_raw)
        lifecycle2 = lifecycles[1]
        self.assertOnLifecycle(lifecycle2, INSTANCE_ID_2, end_raw2)

        timings = Timing.objects.all().order_by('id')
        self.assertEqual(len(timings), 2)
        timing1 = timings[0]
        expected_diff1 = self.end_raw.when - self.start_raw.when
        self.assertOnTiming(timing1, lifecycle1, self.start_raw, self.end_raw,
                            expected_diff1)
        expected_diff2 = end_raw2.when - start_raw2.when
        timing2 = timings[1]
        self.assertOnTiming(timing2, lifecycle2, start_raw2, end_raw2,
            expected_diff2)
Beispiel #8
0
    def test_resize_revert_workflow_start_late(self):
        launched_str = '2012-12-21 06:34:50.123'
        launched = utils.str_time_to_unix(launched_str)
        values = {
            'instance': INSTANCE_ID_1,
            'request_id': REQUEST_ID_1,
            'instance_type_id': '1',
            'launched_at': launched,
            }
        InstanceUsage(**values).save()
        resize_launched_str = '2012-12-22 06:34:50.123'
        resize_launched = utils.str_time_to_unix(resize_launched_str)
        values = {
            'instance': INSTANCE_ID_1,
            'request_id': REQUEST_ID_2,
            'instance_type_id': '2',
            'launched_at': resize_launched,
            }
        InstanceUsage(**values).save()

        started_str = '2012-12-22 06:34:50.123'
        started_time = utils.str_time_to_unix(started_str)
        end_str = '2012-12-22 06:36:50.123'
        end_time = utils.str_time_to_unix(end_str)
        start_json = test_utils\
                     .make_resize_revert_start_json(request_id=REQUEST_ID_3)
        end_json = test_utils\
                   .make_resize_revert_end_json(launched_at=end_str,
                                                request_id=REQUEST_ID_3)
        start_raw = create_raw(self.deployment, started_time,
                               views.INSTANCE_EVENT['resize_revert_start'],
                               request_id=REQUEST_ID_3, json=start_json)
        end_raw = create_raw(self.deployment, started_time,
                             views.INSTANCE_EVENT['resize_revert_end'],
                             request_id=REQUEST_ID_3, json=end_json)

        views.aggregate_usage(end_raw)
        views.aggregate_usage(start_raw)

        usages = InstanceUsage.objects.all().order_by('id')
        self.assertEqual(len(usages), 3)
        usage_before_resize = usages[0]
        usage_after_resize = usages[1]
        usage_after_revert = usages[2]
        self.assertOnUsage(usage_before_resize, INSTANCE_ID_1, '1', launched,
                           REQUEST_ID_1)
        self.assertOnUsage(usage_after_resize, INSTANCE_ID_1, '2',
                           resize_launched, REQUEST_ID_2)
        self.assertOnUsage(usage_after_revert, INSTANCE_ID_1, '1', end_time,
                           REQUEST_ID_3)
Beispiel #9
0
    def setUp(self):
        self.deployment = Deployment(name='TestDeployment')
        self.deployment.save()

        when1 = utils.str_time_to_unix('2012-12-21 12:34:50.123')
        when2 = utils.str_time_to_unix('2012-12-21 12:34:56.123')
        when3 = utils.str_time_to_unix('2012-12-21 12:36:56.124')
        self.update_raw = create_raw(self.deployment, when1,
                                          'compute.instance.update',
                                          host='api', service='api')
        self.start_raw = create_raw(self.deployment, when2,
                                         'compute.instance.reboot.start')
        self.end_raw = create_raw(self.deployment, when3,
                                       'compute.instance.reboot.end',
                                       old_task='reboot')
Beispiel #10
0
    def test_single_instance_multiple_kpi_out_of_order(self):
        when1 = utils.str_time_to_unix('2012-12-21 13:32:50.123')
        when2 = utils.str_time_to_unix('2012-12-21 13:34:50.123')
        when3 = utils.str_time_to_unix('2012-12-21 13:37:50.124')
        update_raw2 = create_raw(self.deployment,
                                 when1,
                                 'compute.instance.update',
                                 request_id=REQUEST_ID_2,
                                 host='api',
                                 service='api')
        start_raw2 = create_raw(self.deployment,
                                when2,
                                'compute.instance.resize.start',
                                request_id=REQUEST_ID_2)
        end_raw2 = create_raw(self.deployment,
                              when3,
                              'compute.instance.resize.end',
                              old_task='resize',
                              request_id=REQUEST_ID_2)

        # First action started
        views.aggregate_lifecycle(self.update_raw)
        views.aggregate_lifecycle(self.start_raw)
        # Second action started, first end is late
        views.aggregate_lifecycle(update_raw2)
        views.aggregate_lifecycle(start_raw2)
        # Finally get first end
        views.aggregate_lifecycle(self.end_raw)
        # Second end
        views.aggregate_lifecycle(end_raw2)

        lifecycles = Lifecycle.objects.all().order_by('id')
        self.assertEqual(len(lifecycles), 1)
        lifecycle1 = lifecycles[0]
        self.assertOnLifecycle(lifecycle1, INSTANCE_ID_1, end_raw2)

        trackers = RequestTracker.objects.all().order_by('id')
        self.assertEqual(len(trackers), 2)
        tracker1 = trackers[0]
        expected_diff1 = self.end_raw.when - self.update_raw.when
        self.assertOnTracker(tracker1, REQUEST_ID_1, lifecycle1,
                             self.update_raw.when, expected_diff1)
        tracker2 = trackers[1]
        expected_diff2 = end_raw2.when - update_raw2.when
        self.assertOnTracker(tracker2, REQUEST_ID_2, lifecycle1,
                             update_raw2.when, expected_diff2)
Beispiel #11
0
    def test_process_delete(self):
        launched_str = '2012-12-21 06:34:50.123'
        launched = utils.str_time_to_unix(launched_str)
        deleted_str = '2012-12-21 12:34:50.123'
        deleted = utils.str_time_to_unix(deleted_str)
        json = test_utils.make_delete_end_json(launched_str, deleted_str)
        raw = create_raw(self.deployment, deleted,
                         views.INSTANCE_EVENT['delete_end'], json=json)

        views._process_delete(raw)

        delete = InstanceDeletes.objects.all()
        self.assertEqual(len(delete), 1)
        delete = delete[0]
        self.assertEqual(delete.instance, INSTANCE_ID_1)
        self.assertEqual(delete.launched_at, launched)
        self.assertEqual(delete.deleted_at, deleted)
        self.assertEqual(delete.raw.id, raw.id)
Beispiel #12
0
    def setUp(self):
        self.deployment = Deployment(name='TestDeployment')
        self.deployment.save()

        when1 = utils.str_time_to_unix('2012-12-21 12:34:50.123')
        when2 = utils.str_time_to_unix('2012-12-21 12:34:56.123')
        when3 = utils.str_time_to_unix('2012-12-21 12:36:56.124')
        self.update_raw = create_raw(self.deployment,
                                     when1,
                                     'compute.instance.update',
                                     host='api',
                                     service='api')
        self.start_raw = create_raw(self.deployment, when2,
                                    'compute.instance.reboot.start')
        self.end_raw = create_raw(self.deployment,
                                  when3,
                                  'compute.instance.reboot.end',
                                  old_task='reboot')
Beispiel #13
0
    def test_single_instance_multiple_kpi_out_of_order(self):
        when1 = utils.str_time_to_unix('2012-12-21 13:32:50.123')
        when2 = utils.str_time_to_unix('2012-12-21 13:34:50.123')
        when3 = utils.str_time_to_unix('2012-12-21 13:37:50.124')
        update_raw2 = create_raw(self.deployment, when1,
                                      'compute.instance.update',
                                      request_id=REQUEST_ID_2,
                                      host='api', service='api')
        start_raw2 = create_raw(self.deployment, when2,
                                     'compute.instance.resize.start',
                                     request_id=REQUEST_ID_2)
        end_raw2 = create_raw(self.deployment, when3,
                                   'compute.instance.resize.end',
                                   old_task='resize',
                                   request_id=REQUEST_ID_2)

        # First action started
        views.aggregate_lifecycle(self.update_raw)
        views.aggregate_lifecycle(self.start_raw)
        # Second action started, first end is late
        views.aggregate_lifecycle(update_raw2)
        views.aggregate_lifecycle(start_raw2)
        # Finally get first end
        views.aggregate_lifecycle(self.end_raw)
        # Second end
        views.aggregate_lifecycle(end_raw2)

        lifecycles = Lifecycle.objects.all().order_by('id')
        self.assertEqual(len(lifecycles), 1)
        lifecycle1 = lifecycles[0]
        self.assertOnLifecycle(lifecycle1, INSTANCE_ID_1, end_raw2)

        trackers = RequestTracker.objects.all().order_by('id')
        self.assertEqual(len(trackers), 2)
        tracker1 = trackers[0]
        expected_diff1 = self.end_raw.when-self.update_raw.when
        self.assertOnTracker(tracker1, REQUEST_ID_1, lifecycle1,
                             self.update_raw.when, expected_diff1)
        tracker2 = trackers[1]
        expected_diff2 = end_raw2.when-update_raw2.when
        self.assertOnTracker(tracker2, REQUEST_ID_2, lifecycle1,
                             update_raw2.when, expected_diff2)
Beispiel #14
0
    def test_process_delete(self):
        launched_str = '2012-12-21 06:34:50.123'
        launched = utils.str_time_to_unix(launched_str)
        deleted_str = '2012-12-21 12:34:50.123'
        deleted = utils.str_time_to_unix(deleted_str)
        json = test_utils.make_delete_end_json(launched_str, deleted_str)
        raw = create_raw(self.deployment,
                         deleted,
                         views.INSTANCE_EVENT['delete_end'],
                         json=json)

        views._process_delete(raw)

        delete = InstanceDeletes.objects.all()
        self.assertEqual(len(delete), 1)
        delete = delete[0]
        self.assertEqual(delete.instance, INSTANCE_ID_1)
        self.assertEqual(delete.launched_at, launched)
        self.assertEqual(delete.deleted_at, deleted)
        self.assertEqual(delete.raw.id, raw.id)
Beispiel #15
0
    def test_create_workflow_start_late(self):
        created_str = '2012-12-21 06:30:50.123'
        created = utils.str_time_to_unix(created_str)
        launched_str = '2012-12-21 06:34:50.123'
        launched = utils.str_time_to_unix(launched_str)
        create_start_json = test_utils.make_create_start_json()
        create_end_json = test_utils.make_create_end_json(launched_str)
        create_start_raw = create_raw(self.deployment, created,
                                      views.INSTANCE_EVENT['create_start'],
                                      json=create_start_json)
        create_end_raw = create_raw(self.deployment, launched,
                                    views.INSTANCE_EVENT['create_end'],
                                    json=create_end_json)

        views.aggregate_usage(create_end_raw)
        views.aggregate_usage(create_start_raw)

        usages = InstanceUsage.objects.all()
        self.assertEqual(len(usages), 1)
        usage = usages[0]
        self.assertOnUsage(usage, INSTANCE_ID_1, '1', launched, REQUEST_ID_1)
Beispiel #16
0
    def test_create_workflow_start_late(self):
        created_str = '2012-12-21 06:30:50.123'
        created = utils.str_time_to_unix(created_str)
        launched_str = '2012-12-21 06:34:50.123'
        launched = utils.str_time_to_unix(launched_str)
        create_start_json = test_utils.make_create_start_json()
        create_end_json = test_utils.make_create_end_json(launched_str)
        create_start_raw = create_raw(self.deployment,
                                      created,
                                      views.INSTANCE_EVENT['create_start'],
                                      json=create_start_json)
        create_end_raw = create_raw(self.deployment,
                                    launched,
                                    views.INSTANCE_EVENT['create_end'],
                                    json=create_end_json)

        views.aggregate_usage(create_end_raw)
        views.aggregate_usage(create_start_raw)

        usages = InstanceUsage.objects.all()
        self.assertEqual(len(usages), 1)
        usage = usages[0]
        self.assertOnUsage(usage, INSTANCE_ID_1, '1', launched, REQUEST_ID_1)
Beispiel #17
0
    def test_process_new_launch_create_start(self):
        when = utils.str_time_to_unix('2012-12-21 12:34:50.123')
        json = test_utils.make_create_start_json()
        raw = create_raw(self.deployment, when,
                         views.INSTANCE_EVENT['create_start'], json=json)

        views._process_usage_for_new_launch(raw)

        usages = InstanceUsage.objects.all()
        self.assertEqual(len(usages), 1)
        usage = usages[0]
        self.assertEqual(usage.instance, INSTANCE_ID_1)
        self.assertEqual(usage.instance_type_id, '1')
        self.assertEqual(usage.request_id, REQUEST_ID_1)
Beispiel #18
0
    def test_process_new_launch_resize_prep_start(self):
        when = utils.str_time_to_unix('2012-12-21 12:34:50.123')
        json = test_utils.make_resize_prep_start_json()
        raw = create_raw(self.deployment, when,
                         views.INSTANCE_EVENT['resize_prep_start'], json=json)

        views._process_usage_for_new_launch(raw)

        usages = InstanceUsage.objects.all()
        self.assertEqual(len(usages), 1)
        usage = usages[0]
        self.assertEqual(usage.instance, INSTANCE_ID_1)
        self.assertEqual(usage.request_id, REQUEST_ID_1)
        # The instance_type_id from resize prep notifications is the old one,
        #       thus we ignore it.
        self.assertIsNone(usage.instance_type_id)
Beispiel #19
0
    def test_process_new_launch_create_start(self):
        when = utils.str_time_to_unix('2012-12-21 12:34:50.123')
        json = test_utils.make_create_start_json()
        raw = create_raw(self.deployment,
                         when,
                         views.INSTANCE_EVENT['create_start'],
                         json=json)

        views._process_usage_for_new_launch(raw)

        usages = InstanceUsage.objects.all()
        self.assertEqual(len(usages), 1)
        usage = usages[0]
        self.assertEqual(usage.instance, INSTANCE_ID_1)
        self.assertEqual(usage.instance_type_id, '1')
        self.assertEqual(usage.request_id, REQUEST_ID_1)
Beispiel #20
0
    def test_process_new_launch_resize_revert_start(self):
        when = utils.str_time_to_unix('2012-12-21 12:34:50.123')
        json = test_utils.make_resize_revert_start_json()
        raw = create_raw(self.deployment,
                         when,
                         views.INSTANCE_EVENT['resize_revert_start'],
                         json=json)

        views._process_usage_for_new_launch(raw)

        usages = InstanceUsage.objects.all()
        self.assertEqual(len(usages), 1)
        usage = usages[0]
        self.assertEqual(usage.instance, INSTANCE_ID_1)
        self.assertEqual(usage.request_id, REQUEST_ID_1)
        # The instance_type_id from resize revert notifications is the old one,
        #       thus we ignore it.
        self.assertIsNone(usage.instance_type_id)
Beispiel #21
0
    def test_process_updates_resize_prep_end(self):
        values = {
            'instance': INSTANCE_ID_1,
            'request_id': REQUEST_ID_1,
            }
        InstanceUsage(**values).save()

        sent = '2012-12-21 12:34:50.123'
        when = utils.str_time_to_unix(sent)
        json = test_utils.make_resize_prep_end_json(sent)
        raw = create_raw(self.deployment, when,
                         views.INSTANCE_EVENT['resize_prep_end'], json=json)

        views._process_usage_for_updates(raw)

        usages = InstanceUsage.objects.all()
        self.assertEqual(len(usages), 1)
        usage = usages[0]
        self.assertEqual(usage.instance_type_id, '2')
Beispiel #22
0
    def test_process_updates_resize_prep_end(self):
        values = {
            'instance': INSTANCE_ID_1,
            'request_id': REQUEST_ID_1,
        }
        InstanceUsage(**values).save()

        sent = '2012-12-21 12:34:50.123'
        when = utils.str_time_to_unix(sent)
        json = test_utils.make_resize_prep_end_json(sent)
        raw = create_raw(self.deployment,
                         when,
                         views.INSTANCE_EVENT['resize_prep_end'],
                         json=json)

        views._process_usage_for_updates(raw)

        usages = InstanceUsage.objects.all()
        self.assertEqual(len(usages), 1)
        usage = usages[0]
        self.assertEqual(usage.instance_type_id, '2')
Beispiel #23
0
f.close()
ThisRunTime = datetime.now()
if os.path.isfile(LastRunFile):
    with open(LastRunFile) as infile:
        LastRunTime = infile.readline().strip()
else:
    LastRunTime = "2015-01-01 00:00:00.0"

try:
    con = mdb.connect(conf.STACKTACH_DB_HOST, conf.STACKTACH_DB_USERNAME,
                      conf.STACKTACH_DB_PASSWORD, conf.STACKTACH_DB_NAME)
    with con:

        cur = con.cursor(mdb.cursors.DictCursor)
        sqlQuery = "Select tenant,service,json,`when` from stacktach_rawdata \
            where `when` > " + str(utils.str_time_to_unix(str(LastRunTime))) + \
            " and `when` <= " + str(utils.str_time_to_unix(str(ThisRunTime))) + \
            " order by tenant,service,`when`;"
        cur.execute(sqlQuery)
        rows = cur.fetchall()
        for row in rows:
            # print row["tenant"], rename_service(row["service"]), datetime.date(dt.dt_from_decimal(row['when']))
            exportDir = LogDir + row['tenant'] + '/' + rename_service(row['service'])
            exportFile = exportDir + '/' + str(datetime.date(dt.dt_from_decimal(row['when']))) + '.log'
            if not os.path.exists(exportDir):
                os.makedirs(exportDir)
            with open(exportFile, 'a+') as outfile:
                outfile.write(row['json'])
        with open(LastRunFile, 'w+') as outfile:
            outfile.write(str(ThisRunTime))
except mdb.Error, e:
Beispiel #24
0
 def test_srt_time_to_unix(self):
     unix = utils.str_time_to_unix('2012-12-21 12:34:56.123')
     self.assertEqual(unix, decimal.Decimal('1356093296.123'))
Beispiel #25
0
 def test_srt_time_to_unix(self):
     unix = utils.str_time_to_unix('2012-12-21 12:34:56.123')
     self.assertEqual(unix, decimal.Decimal('1356093296.123'))