当前位置: 首页>>代码示例>>Python>>正文


Python utils.create_raw函数代码示例

本文整理汇总了Python中utils.create_raw函数的典型用法代码示例。如果您正苦于以下问题:Python create_raw函数的具体用法?Python create_raw怎么用?Python create_raw使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了create_raw函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_process_delete

    def test_process_delete(self):
        delete_time = datetime.datetime.utcnow()
        launch_time = delete_time-datetime.timedelta(days=1)
        launch_decimal = utils.decimal_utc(launch_time)
        delete_decimal = utils.decimal_utc(delete_time)
        notif = utils.create_nova_notif(request_id=REQUEST_ID_1,
                                        launched=str(launch_time),
                                        deleted=str(delete_time))
        json_str = json.dumps(notif)
        event = 'compute.instance.delete.end'
        raw = utils.create_raw(self.mox, delete_decimal, event=event,
                               json_str=json_str)
        delete = self.mox.CreateMockAnything()
        delete.instance = INSTANCE_ID_1
        delete.launched_at = launch_decimal
        delete.deleted_at = delete_decimal
        views.STACKDB.create_instance_delete(instance=INSTANCE_ID_1,
                                             launched_at=launch_decimal,
                                             deleted_at=delete_decimal,
                                             raw=raw)\
                     .AndReturn(delete)
        views.STACKDB.save(delete)
        self.mox.ReplayAll()

        views._process_delete(raw, notif[1])
        self.assertEqual(delete.instance, INSTANCE_ID_1)
        self.assertEqual(delete.launched_at, launch_decimal)
        self.assertEqual(delete.deleted_at, delete_decimal)
        self.mox.VerifyAll()
开发者ID:pperezrubio,项目名称:stacktach,代码行数:29,代码来源:test_stacktach.py

示例2: test_process_exists_with_deleted_at

 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()
开发者ID:swat30,项目名称:stacktach,代码行数:32,代码来源:test_stacktach.py

示例3: test_process_usage_for_updates_revert_end

    def test_process_usage_for_updates_revert_end(self):
        when_time = datetime.datetime.utcnow()
        when_decimal = utils.decimal_utc(when_time)
        notif = utils.create_nova_notif(request_id=REQUEST_ID_1,
                                        launched=str(when_time))
        json_str = json.dumps(notif)
        event = 'compute.instance.resize.revert.end'
        raw = utils.create_raw(self.mox, when_decimal, event=event,
                               json_str=json_str)
        usage = self.mox.CreateMockAnything()
        usage.instance = INSTANCE_ID_1
        usage.request_id = REQUEST_ID_1
        usage.instance_type_id = '1'
        views.STACKDB.get_or_create_instance_usage(instance=INSTANCE_ID_1,
                                                   request_id=REQUEST_ID_1)\
                     .AndReturn((usage, True))
        views.STACKDB.save(usage)
        self.mox.ReplayAll()

        views._process_usage_for_updates(raw, notif[1])
        self.assertEqual(usage.instance, INSTANCE_ID_1)
        self.assertEqual(usage.request_id, REQUEST_ID_1)
        self.assertEqual(usage.instance_type_id, '1')
        self.assertEqual(usage.launched_at, when_decimal)
        self.mox.VerifyAll()
开发者ID:pperezrubio,项目名称:stacktach,代码行数:25,代码来源:test_stacktach.py

示例4: test_aggregate_lifecycle_start

    def test_aggregate_lifecycle_start(self):
        event_name = 'compute.instance.create'
        event = '%s.start' % event_name
        when = datetime.datetime.utcnow()
        raw = utils.create_raw(self.mox, when, event, state='building')

        views.STACKDB.find_lifecycles(instance=INSTANCE_ID_1).AndReturn([])
        lifecycle = self.mox.CreateMockAnything()
        lifecycle.instance = INSTANCE_ID_1
        views.STACKDB.create_lifecycle(instance=INSTANCE_ID_1)\
                     .AndReturn(lifecycle)
        views.STACKDB.save(lifecycle)

        views.STACKDB.find_timings(name=event_name, lifecycle=lifecycle)\
                     .AndReturn([])
        timing = utils.create_timing(self.mox, event_name, lifecycle)
        views.STACKDB.create_timing(lifecycle=lifecycle, name=event_name)\
                     .AndReturn(timing)
        views.STACKDB.save(timing)

        self.mox.ReplayAll()
        views.aggregate_lifecycle(raw)
        self.assertEqual(lifecycle.last_raw, raw)
        self.assertEqual(lifecycle.last_state, 'building')
        self.assertEqual(lifecycle.last_task_state, '')
        self.assertEqual(timing.name, event_name)
        self.assertEqual(timing.lifecycle, lifecycle)
        self.assertEqual(timing.start_raw, raw)
        self.assertEqual(timing.start_when, when)

        self.mox.VerifyAll()
开发者ID:pperezrubio,项目名称:stacktach,代码行数:31,代码来源:test_stacktach.py

示例5: test_start_kpi_tracking_not_using_host

 def test_start_kpi_tracking_not_using_host(self):
     lifecycle = self.mox.CreateMockAnything()
     tracker = self.mox.CreateMockAnything()
     when = utils.decimal_utc()
     raw = utils.create_raw(self.mox, when, 'compute.instance.update',
                            host='api.example.com', service='compute')
     self.mox.ReplayAll()
     views.start_kpi_tracking(lifecycle, raw)
     self.mox.VerifyAll()
开发者ID:pperezrubio,项目名称:stacktach,代码行数:9,代码来源:test_stacktach.py

示例6: test_process_exists_with_deleted_at

 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()
开发者ID:huangshunping,项目名称:stacktach,代码行数:55,代码来源:test_stacktach.py

示例7: test_aggregate_lifecycle_end

    def test_aggregate_lifecycle_end(self):
        event_name = 'compute.instance.create'
        start_event = '%s.end' % event_name
        end_event = '%s.end' % event_name
        start_when = datetime.datetime.utcnow()
        end_when = datetime.datetime.utcnow()
        start_raw = utils.create_raw(self.mox, start_when, start_event,
                                          state='building')
        end_raw = utils.create_raw(self.mox, end_when, end_event,
                                        old_task='build')

        lifecycle = utils.create_lifecycle(self.mox, INSTANCE_ID_1,
                                                'active', '', start_raw)
        views.STACKDB.find_lifecycles(instance=INSTANCE_ID_1)\
                     .AndReturn([lifecycle])
        views.STACKDB.save(lifecycle)

        timing = utils.create_timing(self.mox, event_name, lifecycle,
                                     start_raw=start_raw,
                                     start_when=start_when)
        views.STACKDB.find_timings(name=event_name, lifecycle=lifecycle)\
                     .AndReturn([timing])

        self.mox.StubOutWithMock(views, "update_kpi")
        views.update_kpi(timing, end_raw)
        views.STACKDB.save(timing)

        self.mox.ReplayAll()
        views.aggregate_lifecycle(end_raw)
        self.assertEqual(lifecycle.last_raw, end_raw)
        self.assertEqual(lifecycle.last_state, 'active')
        self.assertEqual(lifecycle.last_task_state, 'build')
        self.assertEqual(timing.name, event_name)
        self.assertEqual(timing.lifecycle, lifecycle)
        self.assertEqual(timing.start_raw, start_raw)
        self.assertEqual(timing.start_when, start_when)
        self.assertEqual(timing.end_raw, end_raw)
        self.assertEqual(timing.end_when, end_when)
        self.assertEqual(timing.diff, end_when-start_when)

        self.mox.VerifyAll()
开发者ID:pperezrubio,项目名称:stacktach,代码行数:41,代码来源:test_stacktach.py

示例8: _setup_process_usage_mocks

 def _setup_process_usage_mocks(self, event, notification):
     when_time = DUMMY_TIME
     when_decimal = utils.decimal_utc(when_time)
     json_str = json.dumps(notification)
     raw = utils.create_raw(self.mox, when_decimal, event=event,
                            json_str=json_str)
     usage = self.mox.CreateMockAnything()
     views.STACKDB.get_or_create_instance_usage(instance=INSTANCE_ID_1,
                                                request_id=REQUEST_ID_1) \
         .AndReturn((usage, True))
     views.STACKDB.save(usage)
     self.mox.ReplayAll()
     return raw, usage
开发者ID:jeredding,项目名称:stacktach,代码行数:13,代码来源:test_stacktach.py

示例9: test_process_usage_for_new_launch

 def test_process_usage_for_new_launch(self):
     when = utils.decimal_utc()
     notif = utils.create_nova_notif(request_id=REQUEST_ID_1)
     json_str = json.dumps(notif)
     event = 'compute.instance.create.start'
     raw = utils.create_raw(self.mox, when, event=event, json_str=json_str)
     usage = self.mox.CreateMockAnything()
     views.STACKDB.get_or_create_instance_usage(instance=INSTANCE_ID_1,
                                                request_id=REQUEST_ID_1)\
                  .AndReturn((usage, True))
     views.STACKDB.save(usage)
     self.mox.ReplayAll()
     views._process_usage_for_new_launch(raw, notif[1])
     self.assertEquals(usage.instance_type_id, '1')
     self.mox.VerifyAll()
开发者ID:pperezrubio,项目名称:stacktach,代码行数:15,代码来源:test_stacktach.py

示例10: test_process_usage_for_updates_create_end_error_message

    def test_process_usage_for_updates_create_end_error_message(self):
        kwargs = {'launched': str(DUMMY_TIME), 'tenant_id': TENANT_ID_1}
        notification = utils.create_nova_notif(request_id=REQUEST_ID_1, **kwargs)
        notification[1]['payload']['message'] = "Error"
        event = 'compute.instance.create.end'
        when_time = DUMMY_TIME
        when_decimal = utils.decimal_utc(when_time)
        json_str = json.dumps(notification)
        raw = utils.create_raw(self.mox, when_decimal, event=event,
                               json_str=json_str)
        self.mox.ReplayAll()

        views._process_usage_for_updates(raw, notification[1])

        self.mox.VerifyAll()
开发者ID:jeredding,项目名称:stacktach,代码行数:15,代码来源:test_stacktach.py

示例11: test_start_kpi_tracking

 def test_start_kpi_tracking(self):
     lifecycle = self.mox.CreateMockAnything()
     tracker = self.mox.CreateMockAnything()
     when = utils.decimal_utc()
     raw = utils.create_raw(self.mox, when, 'compute.instance.update',
                            host='nova.example.com', service='api')
     views.STACKDB.create_request_tracker(lifecycle=lifecycle,
                                          request_id=REQUEST_ID_1,
                                          start=when,
                                          last_timing=None,
                                          duration=str(0.0))\
                                          .AndReturn(tracker)
     views.STACKDB.save(tracker)
     self.mox.ReplayAll()
     views.start_kpi_tracking(lifecycle, raw)
     self.mox.VerifyAll()
开发者ID:pperezrubio,项目名称:stacktach,代码行数:16,代码来源:test_stacktach.py

示例12: test_process_exists_no_launched_at

 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()
开发者ID:jeredding,项目名称:stacktach,代码行数:17,代码来源:test_stacktach.py

示例13: test_process_usage_for_new_launch_resize_no_launched_at_in_db

 def test_process_usage_for_new_launch_resize_no_launched_at_in_db(self):
     now = datetime.datetime.utcnow()
     when = utils.decimal_utc(now)
     notif = utils.create_nova_notif(request_id=REQUEST_ID_1,
                                     launched=str(now))
     json_str = json.dumps(notif)
     event = 'compute.instance.resize.prep.start'
     raw = utils.create_raw(self.mox, when, event=event, json_str=json_str)
     usage = self.mox.CreateMockAnything()
     usage.launched_at = None
     views.STACKDB.get_or_create_instance_usage(instance=INSTANCE_ID_1,
                                                request_id=REQUEST_ID_1) \
          .AndReturn((usage, True))
     views.STACKDB.save(usage)
     self.mox.ReplayAll()
     views._process_usage_for_new_launch(raw, notif[1])
     self.assertEqual(usage.launched_at, when)
     self.mox.VerifyAll()
开发者ID:mendeni,项目名称:stacktach,代码行数:18,代码来源:test_stacktach.py

示例14: test_aggregate_lifecycle_update

    def test_aggregate_lifecycle_update(self):
        event = 'compute.instance.update'
        when = datetime.datetime.utcnow()
        raw = utils.create_raw(self.mox, when, event, old_task='reboot')

        views.STACKDB.find_lifecycles(instance=INSTANCE_ID_1).AndReturn([])
        lifecycle = self.mox.CreateMockAnything()
        lifecycle.instance = INSTANCE_ID_1
        views.STACKDB.create_lifecycle(instance=INSTANCE_ID_1).AndReturn(lifecycle)
        views.STACKDB.save(lifecycle)

        self.mox.StubOutWithMock(views, "start_kpi_tracking")
        views.start_kpi_tracking(lifecycle, raw)

        self.mox.ReplayAll()
        views.aggregate_lifecycle(raw)
        self.assertEqual(lifecycle.last_raw, raw)
        self.assertEqual(lifecycle.last_state, 'active')
        self.assertEqual(lifecycle.last_task_state, 'reboot')

        self.mox.VerifyAll()
开发者ID:pperezrubio,项目名称:stacktach,代码行数:21,代码来源:test_stacktach.py

示例15: test_process_exists

 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()
开发者ID:pperezrubio,项目名称:stacktach,代码行数:39,代码来源:test_stacktach.py


注:本文中的utils.create_raw函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。