Replaces functions in utils.py with openstack/common/timeutils.py
Fixes bug #1008628 1. Edit openstack-common.conf and import nova/openstack/common/timeutils.py 2. Move time related functions from utils.py to timeutils.py 3. Replace following functions in utils.py with timeutils.py - isotime - parse_isotime - strtime - parse_strtime - normalize_time - is_older_than - utcnow_ts - utcnow - set_time_override - advance_time_delta - advance_time_seconds - clear_time_override 4. Remove datetime related functions and datetime related unittests Change-Id: I9a92be286fb071b6237dd39495d88dae106e2ce0
This commit is contained in:
@@ -90,6 +90,7 @@ from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
from nova.openstack.common import importutils
|
||||
from nova.openstack.common import jsonutils
|
||||
from nova.openstack.common import timeutils
|
||||
from nova import quota
|
||||
from nova import rpc
|
||||
from nova.scheduler import rpcapi as scheduler_rpcapi
|
||||
@@ -968,7 +969,7 @@ class ServiceCommands(object):
|
||||
Show a list of all running services. Filter by host & service name.
|
||||
"""
|
||||
ctxt = context.get_admin_context()
|
||||
now = utils.utcnow()
|
||||
now = timeutils.utcnow()
|
||||
services = db.service_get_all(ctxt)
|
||||
if host:
|
||||
services = [s for s in services if s['host'] == host]
|
||||
@@ -1083,7 +1084,7 @@ class HostCommands(object):
|
||||
print "%-25s\t%-15s" % (_('host'),
|
||||
_('zone'))
|
||||
ctxt = context.get_admin_context()
|
||||
now = utils.utcnow()
|
||||
now = timeutils.utcnow()
|
||||
services = db.service_get_all(ctxt)
|
||||
if zone:
|
||||
services = [s for s in services if s['availability_zone'] == zone]
|
||||
|
@@ -18,7 +18,7 @@
|
||||
|
||||
"""Super simple fake memcache client."""
|
||||
|
||||
from nova import utils
|
||||
from nova.openstack.common import timeutils
|
||||
|
||||
|
||||
class Client(object):
|
||||
@@ -35,7 +35,7 @@ class Client(object):
|
||||
|
||||
for k in self.cache.keys():
|
||||
(timeout, _value) = self.cache[k]
|
||||
if timeout and utils.utcnow_ts() >= timeout:
|
||||
if timeout and timeutils.utcnow_ts() >= timeout:
|
||||
del self.cache[k]
|
||||
|
||||
return self.cache.get(key, (0, None))[1]
|
||||
@@ -44,7 +44,7 @@ class Client(object):
|
||||
"""Sets the value for a key."""
|
||||
timeout = 0
|
||||
if time != 0:
|
||||
timeout = utils.utcnow_ts() + time
|
||||
timeout = timeutils.utcnow_ts() + time
|
||||
self.cache[key] = (timeout, value)
|
||||
return True
|
||||
|
||||
|
@@ -21,7 +21,7 @@ from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
from nova.openstack.common import importutils
|
||||
from nova.openstack.common import jsonutils
|
||||
from nova import utils
|
||||
from nova.openstack.common import timeutils
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
@@ -110,7 +110,7 @@ def notify(context, publisher_id, event_type, priority, payload):
|
||||
|
||||
{'message_id': str(uuid.uuid4()),
|
||||
'publisher_id': 'compute.host1',
|
||||
'timestamp': utils.utcnow(),
|
||||
'timestamp': timeutils.utcnow(),
|
||||
'priority': 'WARN',
|
||||
'event_type': 'compute.create_instance',
|
||||
'payload': {'instance_id': 12, ... }}
|
||||
@@ -129,7 +129,7 @@ def notify(context, publisher_id, event_type, priority, payload):
|
||||
event_type=event_type,
|
||||
priority=priority,
|
||||
payload=payload,
|
||||
timestamp=str(utils.utcnow()))
|
||||
timestamp=str(timeutils.utcnow()))
|
||||
try:
|
||||
driver.notify(context, msg)
|
||||
except Exception, e:
|
||||
|
@@ -35,8 +35,8 @@ from nova import block_device
|
||||
from nova import context
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova.openstack.common import timeutils
|
||||
from nova import test
|
||||
from nova import utils
|
||||
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
@@ -252,12 +252,12 @@ class ApiEc2TestCase(test.TestCase):
|
||||
"""
|
||||
conv = apirequest._database_to_isoformat
|
||||
# sqlite database representation with microseconds
|
||||
time_to_convert = utils.parse_strtime("2011-02-21 20:14:10.634276",
|
||||
"%Y-%m-%d %H:%M:%S.%f")
|
||||
time_to_convert = timeutils.parse_strtime("2011-02-21 20:14:10.634276",
|
||||
"%Y-%m-%d %H:%M:%S.%f")
|
||||
self.assertEqual(conv(time_to_convert), '2011-02-21T20:14:10.634Z')
|
||||
# mysqlite database representation
|
||||
time_to_convert = utils.parse_strtime("2011-02-21 19:56:18",
|
||||
"%Y-%m-%d %H:%M:%S")
|
||||
time_to_convert = timeutils.parse_strtime("2011-02-21 19:56:18",
|
||||
"%Y-%m-%d %H:%M:%S")
|
||||
self.assertEqual(conv(time_to_convert), '2011-02-21T19:56:18.000Z')
|
||||
|
||||
def test_xmlns_version_matches_request_version(self):
|
||||
|
@@ -24,6 +24,7 @@ from nova import context
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova.openstack.common import timeutils
|
||||
from nova import test
|
||||
from nova import utils
|
||||
|
||||
@@ -96,7 +97,7 @@ class DbApiTestCase(test.TestCase):
|
||||
db.migration_update(ctxt, migration.id, {"status": "CONFIRMED"})
|
||||
|
||||
# Ensure the new migration is not returned.
|
||||
updated_at = utils.utcnow()
|
||||
updated_at = timeutils.utcnow()
|
||||
values = {"status": "finished", "updated_at": updated_at}
|
||||
migration = db.migration_create(ctxt, values)
|
||||
results = db.migration_get_all_unconfirmed(ctxt, 10)
|
||||
@@ -120,7 +121,7 @@ class DbApiTestCase(test.TestCase):
|
||||
db.instance_update(ctxt, instance['uuid'], {"task_state": None})
|
||||
|
||||
# Ensure the newly rebooted instance is not returned.
|
||||
updated_at = utils.utcnow()
|
||||
updated_at = timeutils.utcnow()
|
||||
values = {"task_state": "rebooting", "updated_at": updated_at}
|
||||
instance = db.instance_create(ctxt, values)
|
||||
results = db.instance_get_all_hung_in_rebooting(ctxt, 10)
|
||||
@@ -383,7 +384,7 @@ class DbApiTestCase(test.TestCase):
|
||||
db.fixed_ip_create(ctxt, values)
|
||||
|
||||
def test_fixed_ip_disassociate_all_by_timeout_single_host(self):
|
||||
now = utils.utcnow()
|
||||
now = timeutils.utcnow()
|
||||
ctxt = context.get_admin_context()
|
||||
self._timeout_test(ctxt, now, False)
|
||||
result = db.fixed_ip_disassociate_all_by_timeout(ctxt, 'foo', now)
|
||||
@@ -392,7 +393,7 @@ class DbApiTestCase(test.TestCase):
|
||||
self.assertEqual(result, 1)
|
||||
|
||||
def test_fixed_ip_disassociate_all_by_timeout_multi_host(self):
|
||||
now = utils.utcnow()
|
||||
now = timeutils.utcnow()
|
||||
ctxt = context.get_admin_context()
|
||||
self._timeout_test(ctxt, now, True)
|
||||
result = db.fixed_ip_disassociate_all_by_timeout(ctxt, 'foo', now)
|
||||
|
@@ -31,13 +31,13 @@ from nova import exception
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import importutils
|
||||
from nova.openstack.common import timeutils
|
||||
from nova import test
|
||||
from nova.tests.db import fakes as db_fakes
|
||||
from nova.tests import fake_network
|
||||
from nova.tests import fake_utils
|
||||
from nova.tests.glance import stubs as glance_stubs
|
||||
from nova.tests.xenapi import stubs
|
||||
from nova import utils
|
||||
from nova.virt.xenapi import connection as xenapi_conn
|
||||
from nova.virt.xenapi import fake as xenapi_fake
|
||||
from nova.virt.xenapi import vm_utils
|
||||
@@ -1316,7 +1316,8 @@ class XenAPIBWUsageTestCase(test.TestCase):
|
||||
self.name = "instance-0001"
|
||||
self.uuid = "1-2-3-4-5"
|
||||
|
||||
result = self.conn.get_all_bw_usage([testinstance()], utils.utcnow())
|
||||
result = self.conn.get_all_bw_usage([testinstance()],
|
||||
timeutils.utcnow())
|
||||
self.assertEqual(result, [])
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user