本文整理匯總了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')