本文整理汇总了Python中oslo_utils.timeutils方法的典型用法代码示例。如果您正苦于以下问题:Python oslo_utils.timeutils方法的具体用法?Python oslo_utils.timeutils怎么用?Python oslo_utils.timeutils使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oslo_utils
的用法示例。
在下文中一共展示了oslo_utils.timeutils方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: import oslo_utils [as 别名]
# 或者: from oslo_utils import timeutils [as 别名]
def setUp(self):
super(ServicesTest, self).setUp()
self.mock_object(db, "service_get_all", fake_service_get_all)
self.mock_object(timeutils, "utcnow", fake_utcnow)
self.mock_object(db, "service_get_by_args",
fake_service_get_by_host_binary)
self.mock_object(db, "service_update", fake_service_update)
self.context = context.get_admin_context()
self.controller = services.ServiceController()
self.controller_legacy = services.ServiceControllerLegacy()
self.resource_name = self.controller.resource_name
self.mock_policy_check = self.mock_object(
policy, 'check_policy', mock.Mock(return_value=True))
示例2: test_share_host_update_db
# 需要导入模块: import oslo_utils [as 别名]
# 或者: from oslo_utils import timeutils [as 别名]
def test_share_host_update_db(self):
with mock.patch.object(timeutils, 'utcnow',
mock.Mock(return_value='fake-now')):
base.share_update_db(self.context, 31337, 'fake_host')
db.share_update.assert_called_once_with(
self.context, 31337,
{'host': 'fake_host', 'scheduled_at': 'fake-now'})
示例3: test_service_is_up
# 需要导入模块: import oslo_utils [as 别名]
# 或者: from oslo_utils import timeutils [as 别名]
def test_service_is_up(self):
fts_func = datetime.datetime.fromtimestamp
fake_now = 1000
down_time = 5
self.flags(service_down_time=down_time)
with mock.patch.object(timeutils, 'utcnow',
mock.Mock(return_value=fts_func(fake_now))):
# Up (equal)
service = {'updated_at': fts_func(fake_now - down_time),
'created_at': fts_func(fake_now - down_time)}
result = utils.service_is_up(service)
self.assertTrue(result)
timeutils.utcnow.assert_called_once_with()
with mock.patch.object(timeutils, 'utcnow',
mock.Mock(return_value=fts_func(fake_now))):
# Up
service = {'updated_at': fts_func(fake_now - down_time + 1),
'created_at': fts_func(fake_now - down_time + 1)}
result = utils.service_is_up(service)
self.assertTrue(result)
timeutils.utcnow.assert_called_once_with()
with mock.patch.object(timeutils, 'utcnow',
mock.Mock(return_value=fts_func(fake_now))):
# Down
service = {'updated_at': fts_func(fake_now - down_time - 1),
'created_at': fts_func(fake_now - down_time - 1)}
result = utils.service_is_up(service)
self.assertFalse(result)
timeutils.utcnow.assert_called_once_with()
示例4: setUp
# 需要导入模块: import oslo_utils [as 别名]
# 或者: from oslo_utils import timeutils [as 别名]
def setUp(self):
super(DBTestBase, self).setUp()
patcher = mock.patch.object(timeutils, 'utcnow')
self.addCleanup(patcher.stop)
self.mock_utcnow = patcher.start()
self.mock_utcnow.return_value = datetime.datetime(2015, 7, 2, 10, 39)
示例5: setUp
# 需要导入模块: import oslo_utils [as 别名]
# 或者: from oslo_utils import timeutils [as 别名]
def setUp(self):
super(ShareGroupsAPITestCase, self).setUp()
self.user_id = 'fake_user_id'
self.project_id = 'fake_project_id'
self.context = context.RequestContext(
user_id=self.user_id, project_id=self.project_id, is_admin=True)
self.scheduler_rpcapi = mock.Mock()
self.share_rpcapi = mock.Mock()
self.share_api = mock.Mock()
self.api = share_group_api.API()
self.mock_object(self.api, 'share_rpcapi', self.share_rpcapi)
self.mock_object(self.api, 'share_api', self.share_api)
self.mock_object(self.api, 'scheduler_rpcapi', self.scheduler_rpcapi)
dt_utc = datetime.datetime.utcnow()
self.mock_object(timeutils, 'utcnow', mock.Mock(return_value=dt_utc))
self.fake_share_type = {
'name': 'default',
'extra_specs': {'driver_handles_share_servers': 'False'},
'is_public': True,
'id': 'c01990c1-448f-435a-9de6-c7c894bb6df9'
}
self.fake_share_type_2 = {
'name': 'default2',
'extra_specs': {'driver_handles_share_servers': 'False'},
'is_public': True,
'id': 'c01990c1-448f-435a-9de6-c7c894bb7dfd'
}
self.fake_share_group_type = {
'share_types': [
{'share_type_id': self.fake_share_type['id']},
{'share_type_id': self.fake_share_type_2['id']},
]
}
self.mock_object(share_types, 'get_share_type',
mock.Mock(return_value=self.fake_share_type))
self.mock_object(
db_driver, 'share_group_type_get',
mock.Mock(return_value=self.fake_share_group_type))
self.mock_object(share_group_api.QUOTAS, 'reserve')
self.mock_object(share_group_api.QUOTAS, 'commit')
self.mock_object(share_group_api.QUOTAS, 'rollback')