Merge lp:~vishvananda/nova/consistent-utcnow into lp:~hudson-openstack/nova/trunk

Proposed by Vish Ishaya
Status: Merged
Approved by: Josh Kearney
Approved revision: 1143
Merged at revision: 1147
Proposed branch: lp:~vishvananda/nova/consistent-utcnow
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 905 lines (+77/-95)
31 files modified
bin/nova-manage (+1/-2)
nova/api/ec2/admin.py (+1/-2)
nova/api/ec2/cloud.py (+2/-3)
nova/api/openstack/auth.py (+2/-3)
nova/api/openstack/contrib/__init__.py (+1/-1)
nova/api/openstack/limits.py (+1/-1)
nova/api/openstack/ratelimiting/__init__.py (+1/-1)
nova/compute/api.py (+1/-2)
nova/compute/manager.py (+1/-2)
nova/compute/monitor.py (+1/-1)
nova/context.py (+0/-1)
nova/db/sqlalchemy/api.py (+14/-15)
nova/db/sqlalchemy/migrate_repo/versions/016_make_quotas_key_and_value.py (+5/-5)
nova/db/sqlalchemy/models.py (+4/-5)
nova/network/manager.py (+1/-1)
nova/notifier/api.py (+3/-4)
nova/scheduler/driver.py (+2/-1)
nova/scheduler/simple.py (+5/-6)
nova/scheduler/zone_manager.py (+8/-7)
nova/test.py (+2/-2)
nova/tests/api/openstack/fakes.py (+1/-2)
nova/tests/api/openstack/test_images.py (+0/-1)
nova/tests/api/openstack/test_servers.py (+4/-4)
nova/tests/test_compute.py (+2/-3)
nova/tests/test_console.py (+0/-2)
nova/tests/test_middleware.py (+0/-1)
nova/tests/test_scheduler.py (+8/-8)
nova/utils.py (+1/-1)
nova/virt/xenapi/fake.py (+2/-2)
nova/volume/api.py (+2/-3)
nova/volume/manager.py (+1/-3)
To merge this branch: bzr merge lp:~vishvananda/nova/consistent-utcnow
Reviewer Review Type Date Requested Status
Josh Kearney (community) Approve
Devin Carlen (community) Approve
Review via email: mp+63302@code.launchpad.net

Description of the change

Changes all uses of utcnow to use the version in utils. This is a simple wrapper for datetime.datetime.utcnow that allows us to use fake values for tests.

There are still a few places in the Zone code that is using datetime.now(), I'd prefer to move this to utils.utcnow() as well but I want to chat with sandy first to make sure that there won't be any issues.

To post a comment you must log in.
1143. By Vish Ishaya

switch zones to use utcnow

Revision history for this message
Devin Carlen (devcamcar) wrote :

lgtm

I'm assuming the changes to fake the values in the tests are being treated as a separate issue?

review: Approve
Revision history for this message
Vish Ishaya (vishvananda) wrote :

> I'm assuming the changes to fake the values in the tests are being treated as
> a separate issue?

The only test that is using the time override stuff right now is test_middleware.py. I don't know if this is because other parts of the system aren't time sensitive, or if people just didn't write tests because they didn't know that the time override exists.

Revision history for this message
Josh Kearney (jk0) wrote :

\o/

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/nova-manage'
2--- bin/nova-manage 2011-06-01 23:01:41 +0000
3+++ bin/nova-manage 2011-06-02 21:52:56 +0000
4@@ -53,7 +53,6 @@
5 CLI interface for nova management.
6 """
7
8-import datetime
9 import gettext
10 import glob
11 import json
12@@ -689,7 +688,7 @@
13 """Show a list of all running services. Filter by host & service name.
14 args: [host] [service]"""
15 ctxt = context.get_admin_context()
16- now = datetime.datetime.utcnow()
17+ now = utils.utcnow()
18 services = db.service_get_all(ctxt)
19 if host:
20 services = [s for s in services if s['host'] == host]
21
22=== modified file 'nova/api/ec2/admin.py'
23--- nova/api/ec2/admin.py 2011-04-19 16:19:52 +0000
24+++ nova/api/ec2/admin.py 2011-06-02 21:52:56 +0000
25@@ -21,7 +21,6 @@
26 """
27
28 import base64
29-import datetime
30
31 from nova import db
32 from nova import exception
33@@ -305,7 +304,7 @@
34 * Volume Count
35 """
36 services = db.service_get_all(context, False)
37- now = datetime.datetime.utcnow()
38+ now = utils.utcnow()
39 hosts = []
40 rv = []
41 for host in [service['host'] for service in services]:
42
43=== modified file 'nova/api/ec2/cloud.py'
44--- nova/api/ec2/cloud.py 2011-05-27 05:13:17 +0000
45+++ nova/api/ec2/cloud.py 2011-06-02 21:52:56 +0000
46@@ -23,7 +23,6 @@
47 """
48
49 import base64
50-import datetime
51 import IPy
52 import os
53 import urllib
54@@ -235,7 +234,7 @@
55 'zoneState': 'available'}]}
56
57 services = db.service_get_all(context, False)
58- now = datetime.datetime.utcnow()
59+ now = utils.utcnow()
60 hosts = []
61 for host in [service['host'] for service in services]:
62 if not host in hosts:
63@@ -595,7 +594,7 @@
64 instance_id = ec2utils.ec2_id_to_id(ec2_id)
65 output = self.compute_api.get_console_output(
66 context, instance_id=instance_id)
67- now = datetime.datetime.utcnow()
68+ now = utils.utcnow()
69 return {"InstanceId": ec2_id,
70 "Timestamp": now,
71 "output": base64.b64encode(output)}
72
73=== modified file 'nova/api/openstack/auth.py'
74--- nova/api/openstack/auth.py 2011-05-17 19:12:48 +0000
75+++ nova/api/openstack/auth.py 2011-06-02 21:52:56 +0000
76@@ -13,9 +13,8 @@
77 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
78 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
79 # License for the specific language governing permissions and limitations
80-# under the License.import datetime
81+# under the License.
82
83-import datetime
84 import hashlib
85 import time
86
87@@ -127,7 +126,7 @@
88 except exception.NotFound:
89 return None
90 if token:
91- delta = datetime.datetime.utcnow() - token['created_at']
92+ delta = utils.utcnow() - token['created_at']
93 if delta.days >= 2:
94 self.db.auth_token_destroy(ctxt, token['token_hash'])
95 else:
96
97=== modified file 'nova/api/openstack/contrib/__init__.py'
98--- nova/api/openstack/contrib/__init__.py 2011-03-30 01:16:09 +0000
99+++ nova/api/openstack/contrib/__init__.py 2011-06-02 21:52:56 +0000
100@@ -13,7 +13,7 @@
101 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
102 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
103 # License for the specific language governing permissions and limitations
104-# under the License.import datetime
105+# under the License.
106
107 """Contrib contains extensions that are shipped with nova.
108
109
110=== modified file 'nova/api/openstack/limits.py'
111--- nova/api/openstack/limits.py 2011-05-26 16:06:54 +0000
112+++ nova/api/openstack/limits.py 2011-06-02 21:52:56 +0000
113@@ -11,7 +11,7 @@
114 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
115 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
116 # License for the specific language governing permissions and limitations
117-# under the License.import datetime
118+# under the License.
119
120 """
121 Module dedicated functions/classes dealing with rate limiting requests.
122
123=== modified file 'nova/api/openstack/ratelimiting/__init__.py'
124--- nova/api/openstack/ratelimiting/__init__.py 2011-03-03 16:04:33 +0000
125+++ nova/api/openstack/ratelimiting/__init__.py 2011-06-02 21:52:56 +0000
126@@ -13,7 +13,7 @@
127 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
128 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
129 # License for the specific language governing permissions and limitations
130-# under the License.import datetime
131+# under the License.
132
133 """Rate limiting of arbitrary actions."""
134
135
136=== modified file 'nova/compute/api.py'
137--- nova/compute/api.py 2011-06-02 17:16:06 +0000
138+++ nova/compute/api.py 2011-06-02 21:52:56 +0000
139@@ -18,7 +18,6 @@
140
141 """Handles all requests relating to instances (guest vms)."""
142
143-import datetime
144 import eventlet
145 import re
146 import time
147@@ -405,7 +404,7 @@
148 instance['id'],
149 state_description='terminating',
150 state=0,
151- terminated_at=datetime.datetime.utcnow())
152+ terminated_at=utils.utcnow())
153
154 host = instance['host']
155 if host:
156
157=== modified file 'nova/compute/manager.py'
158--- nova/compute/manager.py 2011-05-29 03:10:42 +0000
159+++ nova/compute/manager.py 2011-06-02 21:52:56 +0000
160@@ -35,7 +35,6 @@
161
162 """
163
164-import datetime
165 import os
166 import socket
167 import sys
168@@ -159,7 +158,7 @@
169
170 def _update_launched_at(self, context, instance_id, launched_at=None):
171 """Update the launched_at parameter of the given instance."""
172- data = {'launched_at': launched_at or datetime.datetime.utcnow()}
173+ data = {'launched_at': launched_at or utils.utcnow()}
174 self.db.instance_update(context, instance_id, data)
175
176 def _update_image_id(self, context, instance_id, image_id):
177
178=== modified file 'nova/compute/monitor.py'
179--- nova/compute/monitor.py 2011-04-18 23:40:03 +0000
180+++ nova/compute/monitor.py 2011-06-02 21:52:56 +0000
181@@ -86,7 +86,7 @@
182 ]}
183
184
185-utcnow = datetime.datetime.utcnow
186+utcnow = utils.utcnow
187
188
189 LOG = logging.getLogger('nova.compute.monitor')
190
191=== modified file 'nova/context.py'
192--- nova/context.py 2011-04-20 19:08:22 +0000
193+++ nova/context.py 2011-06-02 21:52:56 +0000
194@@ -18,7 +18,6 @@
195
196 """RequestContext: context for requests that persist through all of nova."""
197
198-import datetime
199 import random
200
201 from nova import exception
202
203=== modified file 'nova/db/sqlalchemy/api.py'
204--- nova/db/sqlalchemy/api.py 2011-05-31 20:15:52 +0000
205+++ nova/db/sqlalchemy/api.py 2011-06-02 21:52:56 +0000
206@@ -19,7 +19,6 @@
207 Implementation of SQLAlchemy backend.
208 """
209
210-import datetime
211 import warnings
212
213 from nova import db
214@@ -674,7 +673,7 @@
215 filter_by(allocated=0).\
216 update({'instance_id': None,
217 'leased': 0,
218- 'updated_at': datetime.datetime.utcnow()},
219+ 'updated_at': utils.utcnow()},
220 synchronize_session='fetch')
221 return result
222
223@@ -820,17 +819,17 @@
224 session.query(models.Instance).\
225 filter_by(id=instance_id).\
226 update({'deleted': True,
227- 'deleted_at': datetime.datetime.utcnow(),
228+ 'deleted_at': utils.utcnow(),
229 'updated_at': literal_column('updated_at')})
230 session.query(models.SecurityGroupInstanceAssociation).\
231 filter_by(instance_id=instance_id).\
232 update({'deleted': True,
233- 'deleted_at': datetime.datetime.utcnow(),
234+ 'deleted_at': utils.utcnow(),
235 'updated_at': literal_column('updated_at')})
236 session.query(models.InstanceMetadata).\
237 filter_by(instance_id=instance_id).\
238 update({'deleted': True,
239- 'deleted_at': datetime.datetime.utcnow(),
240+ 'deleted_at': utils.utcnow(),
241 'updated_at': literal_column('updated_at')})
242
243
244@@ -1123,7 +1122,7 @@
245 session.query(models.KeyPair).\
246 filter_by(user_id=user_id).\
247 update({'deleted': 1,
248- 'deleted_at': datetime.datetime.utcnow(),
249+ 'deleted_at': utils.utcnow(),
250 'updated_at': literal_column('updated_at')})
251
252
253@@ -1655,7 +1654,7 @@
254 session.query(models.Volume).\
255 filter_by(id=volume_id).\
256 update({'deleted': 1,
257- 'deleted_at': datetime.datetime.utcnow(),
258+ 'deleted_at': utils.utcnow(),
259 'updated_at': literal_column('updated_at')})
260 session.query(models.ExportDevice).\
261 filter_by(volume_id=volume_id).\
262@@ -1813,7 +1812,7 @@
263 session.query(models.Snapshot).\
264 filter_by(id=snapshot_id).\
265 update({'deleted': 1,
266- 'deleted_at': datetime.datetime.utcnow(),
267+ 'deleted_at': utils.utcnow(),
268 'updated_at': literal_column('updated_at')})
269
270
271@@ -1968,17 +1967,17 @@
272 session.query(models.SecurityGroup).\
273 filter_by(id=security_group_id).\
274 update({'deleted': 1,
275- 'deleted_at': datetime.datetime.utcnow(),
276+ 'deleted_at': utils.utcnow(),
277 'updated_at': literal_column('updated_at')})
278 session.query(models.SecurityGroupInstanceAssociation).\
279 filter_by(security_group_id=security_group_id).\
280 update({'deleted': 1,
281- 'deleted_at': datetime.datetime.utcnow(),
282+ 'deleted_at': utils.utcnow(),
283 'updated_at': literal_column('updated_at')})
284 session.query(models.SecurityGroupIngressRule).\
285 filter_by(group_id=security_group_id).\
286 update({'deleted': 1,
287- 'deleted_at': datetime.datetime.utcnow(),
288+ 'deleted_at': utils.utcnow(),
289 'updated_at': literal_column('updated_at')})
290
291
292@@ -1989,11 +1988,11 @@
293 with session.begin():
294 session.query(models.SecurityGroup).\
295 update({'deleted': 1,
296- 'deleted_at': datetime.datetime.utcnow(),
297+ 'deleted_at': utils.utcnow(),
298 'updated_at': literal_column('updated_at')})
299 session.query(models.SecurityGroupIngressRule).\
300 update({'deleted': 1,
301- 'deleted_at': datetime.datetime.utcnow(),
302+ 'deleted_at': utils.utcnow(),
303 'updated_at': literal_column('updated_at')})
304
305
306@@ -2627,7 +2626,7 @@
307 filter_by(key=key).\
308 filter_by(deleted=False).\
309 update({'deleted': True,
310- 'deleted_at': datetime.datetime.utcnow(),
311+ 'deleted_at': utils.utcnow(),
312 'updated_at': literal_column('updated_at')})
313
314
315@@ -2638,7 +2637,7 @@
316 filter_by(instance_id=instance_id).\
317 filter_by(deleted=False).\
318 update({'deleted': True,
319- 'deleted_at': datetime.datetime.utcnow(),
320+ 'deleted_at': utils.utcnow(),
321 'updated_at': literal_column('updated_at')})
322
323
324
325=== modified file 'nova/db/sqlalchemy/migrate_repo/versions/016_make_quotas_key_and_value.py'
326--- nova/db/sqlalchemy/migrate_repo/versions/016_make_quotas_key_and_value.py 2011-06-01 14:58:17 +0000
327+++ nova/db/sqlalchemy/migrate_repo/versions/016_make_quotas_key_and_value.py 2011-06-02 21:52:56 +0000
328@@ -17,7 +17,7 @@
329 from sqlalchemy import Boolean, Column, DateTime, Integer
330 from sqlalchemy import MetaData, String, Table
331
332-import datetime
333+from nova import utils
334
335 meta = MetaData()
336
337@@ -35,9 +35,9 @@
338 return Table(name, meta,
339 Column('id', Integer(), primary_key=True),
340 Column('created_at', DateTime(),
341- default=datetime.datetime.utcnow),
342+ default=utils.utcnow),
343 Column('updated_at', DateTime(),
344- onupdate=datetime.datetime.utcnow),
345+ onupdate=utils.utcnow),
346 Column('deleted_at', DateTime()),
347 Column('deleted', Boolean(), default=False),
348 Column('project_id',
349@@ -57,9 +57,9 @@
350 return Table(name, meta,
351 Column('id', Integer(), primary_key=True),
352 Column('created_at', DateTime(),
353- default=datetime.datetime.utcnow),
354+ default=utils.utcnow),
355 Column('updated_at', DateTime(),
356- onupdate=datetime.datetime.utcnow),
357+ onupdate=utils.utcnow),
358 Column('deleted_at', DateTime()),
359 Column('deleted', Boolean(), default=False),
360 Column('project_id',
361
362=== modified file 'nova/db/sqlalchemy/models.py'
363--- nova/db/sqlalchemy/models.py 2011-05-27 04:50:20 +0000
364+++ nova/db/sqlalchemy/models.py 2011-06-02 21:52:56 +0000
365@@ -19,8 +19,6 @@
366 SQLAlchemy models for nova data.
367 """
368
369-import datetime
370-
371 from sqlalchemy.orm import relationship, backref, object_mapper
372 from sqlalchemy import Column, Integer, String, schema
373 from sqlalchemy import ForeignKey, DateTime, Boolean, Text
374@@ -33,6 +31,7 @@
375 from nova import auth
376 from nova import exception
377 from nova import flags
378+from nova import utils
379
380
381 FLAGS = flags.FLAGS
382@@ -43,8 +42,8 @@
383 """Base class for Nova Models."""
384 __table_args__ = {'mysql_engine': 'InnoDB'}
385 __table_initialized__ = False
386- created_at = Column(DateTime, default=datetime.datetime.utcnow)
387- updated_at = Column(DateTime, onupdate=datetime.datetime.utcnow)
388+ created_at = Column(DateTime, default=utils.utcnow)
389+ updated_at = Column(DateTime, onupdate=utils.utcnow)
390 deleted_at = Column(DateTime)
391 deleted = Column(Boolean, default=False)
392
393@@ -64,7 +63,7 @@
394 def delete(self, session=None):
395 """Delete this object."""
396 self.deleted = True
397- self.deleted_at = datetime.datetime.utcnow()
398+ self.deleted_at = utils.utcnow()
399 self.save(session=session)
400
401 def __setitem__(self, key, value):
402
403=== modified file 'nova/network/manager.py'
404--- nova/network/manager.py 2011-05-11 19:24:01 +0000
405+++ nova/network/manager.py 2011-06-02 21:52:56 +0000
406@@ -235,7 +235,7 @@
407 inst_addr = instance_ref['mac_address']
408 raise exception.Error(_('IP %(address)s leased to bad mac'
409 ' %(inst_addr)s vs %(mac)s') % locals())
410- now = datetime.datetime.utcnow()
411+ now = utils.utcnow()
412 self.db.fixed_ip_update(context,
413 fixed_ip_ref['address'],
414 {'leased': True,
415
416=== modified file 'nova/notifier/api.py'
417--- nova/notifier/api.py 2011-05-18 17:55:17 +0000
418+++ nova/notifier/api.py 2011-06-02 21:52:56 +0000
419@@ -11,9 +11,8 @@
420 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
421 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
422 # License for the specific language governing permissions and limitations
423-# under the License.import datetime
424+# under the License.
425
426-import datetime
427 import uuid
428
429 from nova import flags
430@@ -64,7 +63,7 @@
431
432 {'message_id': str(uuid.uuid4()),
433 'publisher_id': 'compute.host1',
434- 'timestamp': datetime.datetime.utcnow(),
435+ 'timestamp': utils.utcnow(),
436 'priority': 'WARN',
437 'event_type': 'compute.create_instance',
438 'payload': {'instance_id': 12, ... }}
439@@ -79,5 +78,5 @@
440 event_type=event_type,
441 priority=priority,
442 payload=payload,
443- timestamp=str(datetime.datetime.utcnow()))
444+ timestamp=str(utils.utcnow()))
445 driver.notify(msg)
446
447=== modified file 'nova/scheduler/driver.py'
448--- nova/scheduler/driver.py 2011-04-27 21:03:05 +0000
449+++ nova/scheduler/driver.py 2011-06-02 21:52:56 +0000
450@@ -28,6 +28,7 @@
451 from nova import flags
452 from nova import log as logging
453 from nova import rpc
454+from nova import utils
455 from nova.compute import power_state
456
457 FLAGS = flags.FLAGS
458@@ -61,7 +62,7 @@
459 """Check whether a service is up based on last heartbeat."""
460 last_heartbeat = service['updated_at'] or service['created_at']
461 # Timestamps in DB are UTC.
462- elapsed = datetime.datetime.utcnow() - last_heartbeat
463+ elapsed = utils.utcnow() - last_heartbeat
464 return elapsed < datetime.timedelta(seconds=FLAGS.service_down_time)
465
466 def hosts_up(self, context, topic):
467
468=== modified file 'nova/scheduler/simple.py'
469--- nova/scheduler/simple.py 2011-03-31 19:29:16 +0000
470+++ nova/scheduler/simple.py 2011-06-02 21:52:56 +0000
471@@ -21,10 +21,9 @@
472 Simple Scheduler
473 """
474
475-import datetime
476-
477 from nova import db
478 from nova import flags
479+from nova import utils
480 from nova.scheduler import driver
481 from nova.scheduler import chance
482
483@@ -54,7 +53,7 @@
484
485 # TODO(vish): this probably belongs in the manager, if we
486 # can generalize this somehow
487- now = datetime.datetime.utcnow()
488+ now = utils.utcnow()
489 db.instance_update(context, instance_id, {'host': host,
490 'scheduled_at': now})
491 return host
492@@ -66,7 +65,7 @@
493 if self.service_is_up(service):
494 # NOTE(vish): this probably belongs in the manager, if we
495 # can generalize this somehow
496- now = datetime.datetime.utcnow()
497+ now = utils.utcnow()
498 db.instance_update(context,
499 instance_id,
500 {'host': service['host'],
501@@ -90,7 +89,7 @@
502
503 # TODO(vish): this probably belongs in the manager, if we
504 # can generalize this somehow
505- now = datetime.datetime.utcnow()
506+ now = utils.utcnow()
507 db.volume_update(context, volume_id, {'host': host,
508 'scheduled_at': now})
509 return host
510@@ -103,7 +102,7 @@
511 if self.service_is_up(service):
512 # NOTE(vish): this probably belongs in the manager, if we
513 # can generalize this somehow
514- now = datetime.datetime.utcnow()
515+ now = utils.utcnow()
516 db.volume_update(context,
517 volume_id,
518 {'host': service['host'],
519
520=== modified file 'nova/scheduler/zone_manager.py'
521--- nova/scheduler/zone_manager.py 2011-05-05 14:35:44 +0000
522+++ nova/scheduler/zone_manager.py 2011-06-02 21:52:56 +0000
523@@ -17,16 +17,17 @@
524 ZoneManager oversees all communications with child Zones.
525 """
526
527+import datetime
528 import novaclient
529 import thread
530 import traceback
531
532-from datetime import datetime
533 from eventlet import greenpool
534
535 from nova import db
536 from nova import flags
537 from nova import log as logging
538+from nova import utils
539
540 FLAGS = flags.FLAGS
541 flags.DEFINE_integer('zone_db_check_interval', 60,
542@@ -42,7 +43,7 @@
543 self.name = None
544 self.capabilities = None
545 self.attempt = 0
546- self.last_seen = datetime.min
547+ self.last_seen = datetime.datetime.min
548 self.last_exception = None
549 self.last_exception_time = None
550
551@@ -56,7 +57,7 @@
552 def update_metadata(self, zone_metadata):
553 """Update zone metadata after successful communications with
554 child zone."""
555- self.last_seen = datetime.now()
556+ self.last_seen = utils.utcnow()
557 self.attempt = 0
558 self.name = zone_metadata.get("name", "n/a")
559 self.capabilities = ", ".join(["%s=%s" % (k, v)
560@@ -72,7 +73,7 @@
561 """Something went wrong. Check to see if zone should be
562 marked as offline."""
563 self.last_exception = exception
564- self.last_exception_time = datetime.now()
565+ self.last_exception_time = utils.utcnow()
566 api_url = self.api_url
567 logging.warning(_("'%(exception)s' error talking to "
568 "zone %(api_url)s") % locals())
569@@ -104,7 +105,7 @@
570 class ZoneManager(object):
571 """Keeps the zone states updated."""
572 def __init__(self):
573- self.last_zone_db_check = datetime.min
574+ self.last_zone_db_check = datetime.datetime.min
575 self.zone_states = {} # { <zone_id> : ZoneState }
576 self.service_states = {} # { <host> : { <service> : { cap k : v }}}
577 self.green_pool = greenpool.GreenPool()
578@@ -158,10 +159,10 @@
579
580 def ping(self, context=None):
581 """Ping should be called periodically to update zone status."""
582- diff = datetime.now() - self.last_zone_db_check
583+ diff = utils.utcnow() - self.last_zone_db_check
584 if diff.seconds >= FLAGS.zone_db_check_interval:
585 logging.debug(_("Updating zone cache from db."))
586- self.last_zone_db_check = datetime.now()
587+ self.last_zone_db_check = utils.utcnow()
588 self._refresh_from_db(context)
589 self._poll_zones(context)
590
591
592=== modified file 'nova/test.py'
593--- nova/test.py 2011-05-25 22:42:49 +0000
594+++ nova/test.py 2011-06-02 21:52:56 +0000
595@@ -23,7 +23,6 @@
596
597 """
598
599-import datetime
600 import functools
601 import os
602 import shutil
603@@ -37,6 +36,7 @@
604 from nova import fakerabbit
605 from nova import flags
606 from nova import rpc
607+from nova import utils
608 from nova import service
609 from nova import wsgi
610 from nova.virt import fake
611@@ -69,7 +69,7 @@
612 # NOTE(vish): We need a better method for creating fixtures for tests
613 # now that we have some required db setup for the system
614 # to work properly.
615- self.start = datetime.datetime.utcnow()
616+ self.start = utils.utcnow()
617 shutil.copyfile(os.path.join(FLAGS.state_path, FLAGS.sqlite_clean_db),
618 os.path.join(FLAGS.state_path, FLAGS.sqlite_db))
619
620
621=== modified file 'nova/tests/api/openstack/fakes.py'
622--- nova/tests/api/openstack/fakes.py 2011-05-24 20:44:28 +0000
623+++ nova/tests/api/openstack/fakes.py 2011-06-02 21:52:56 +0000
624@@ -16,7 +16,6 @@
625 # under the License.
626
627 import copy
628-import datetime
629 import json
630 import random
631 import string
632@@ -253,7 +252,7 @@
633
634 @staticmethod
635 def auth_token_create(context, token):
636- fake_token = FakeToken(created_at=datetime.datetime.now(), **token)
637+ fake_token = FakeToken(created_at=utils.utcnow(), **token)
638 FakeAuthDatabase.data[fake_token.token_hash] = fake_token
639 FakeAuthDatabase.data['id_%i' % fake_token.id] = fake_token
640 return fake_token
641
642=== modified file 'nova/tests/api/openstack/test_images.py'
643--- nova/tests/api/openstack/test_images.py 2011-05-26 17:59:25 +0000
644+++ nova/tests/api/openstack/test_images.py 2011-06-02 21:52:56 +0000
645@@ -22,7 +22,6 @@
646
647 import copy
648 import json
649-import datetime
650 import os
651 import shutil
652 import tempfile
653
654=== modified file 'nova/tests/api/openstack/test_servers.py'
655--- nova/tests/api/openstack/test_servers.py 2011-06-01 22:46:01 +0000
656+++ nova/tests/api/openstack/test_servers.py 2011-06-02 21:52:56 +0000
657@@ -16,7 +16,6 @@
658 # under the License.
659
660 import base64
661-import datetime
662 import json
663 import unittest
664 from xml.dom import minidom
665@@ -29,6 +28,7 @@
666 from nova import exception
667 from nova import flags
668 from nova import test
669+from nova import utils
670 import nova.api.openstack
671 from nova.api.openstack import servers
672 import nova.compute.api
673@@ -114,9 +114,9 @@
674 "user_data": "",
675 "reservation_id": "",
676 "mac_address": "",
677- "scheduled_at": datetime.datetime.now(),
678- "launched_at": datetime.datetime.now(),
679- "terminated_at": datetime.datetime.now(),
680+ "scheduled_at": utils.utcnow(),
681+ "launched_at": utils.utcnow(),
682+ "terminated_at": utils.utcnow(),
683 "availability_zone": "",
684 "display_name": "server%s" % id,
685 "display_description": "",
686
687=== modified file 'nova/tests/test_compute.py'
688--- nova/tests/test_compute.py 2011-05-11 19:41:39 +0000
689+++ nova/tests/test_compute.py 2011-06-02 21:52:56 +0000
690@@ -19,7 +19,6 @@
691 Tests For Compute
692 """
693
694-import datetime
695 import mox
696 import stubout
697
698@@ -217,12 +216,12 @@
699 instance_ref = db.instance_get(self.context, instance_id)
700 self.assertEqual(instance_ref['launched_at'], None)
701 self.assertEqual(instance_ref['deleted_at'], None)
702- launch = datetime.datetime.utcnow()
703+ launch = utils.utcnow()
704 self.compute.run_instance(self.context, instance_id)
705 instance_ref = db.instance_get(self.context, instance_id)
706 self.assert_(instance_ref['launched_at'] > launch)
707 self.assertEqual(instance_ref['deleted_at'], None)
708- terminate = datetime.datetime.utcnow()
709+ terminate = utils.utcnow()
710 self.compute.terminate_instance(self.context, instance_id)
711 self.context = self.context.elevated(True)
712 instance_ref = db.instance_get(self.context, instance_id)
713
714=== modified file 'nova/tests/test_console.py'
715--- nova/tests/test_console.py 2011-04-04 20:17:04 +0000
716+++ nova/tests/test_console.py 2011-06-02 21:52:56 +0000
717@@ -20,8 +20,6 @@
718 Tests For Console proxy.
719 """
720
721-import datetime
722-
723 from nova import context
724 from nova import db
725 from nova import exception
726
727=== modified file 'nova/tests/test_middleware.py'
728--- nova/tests/test_middleware.py 2011-03-18 13:56:05 +0000
729+++ nova/tests/test_middleware.py 2011-06-02 21:52:56 +0000
730@@ -16,7 +16,6 @@
731 # License for the specific language governing permissions and limitations
732 # under the License.
733
734-import datetime
735 import webob
736 import webob.dec
737 import webob.exc
738
739=== modified file 'nova/tests/test_scheduler.py'
740--- nova/tests/test_scheduler.py 2011-05-13 01:07:54 +0000
741+++ nova/tests/test_scheduler.py 2011-06-02 21:52:56 +0000
742@@ -196,7 +196,7 @@
743 service.topic = 'compute'
744 service.id = kwargs['id']
745 service.availability_zone = kwargs['zone']
746- service.created_at = datetime.datetime.utcnow()
747+ service.created_at = utils.utcnow()
748 return service
749
750 def test_with_two_zones(self):
751@@ -290,7 +290,7 @@
752 dic['host'] = kwargs.get('host', 'dummy')
753 s_ref = db.service_create(self.context, dic)
754 if 'created_at' in kwargs.keys() or 'updated_at' in kwargs.keys():
755- t = datetime.datetime.utcnow() - datetime.timedelta(0)
756+ t = utils.utcnow() - datetime.timedelta(0)
757 dic['created_at'] = kwargs.get('created_at', t)
758 dic['updated_at'] = kwargs.get('updated_at', t)
759 db.service_update(self.context, s_ref['id'], dic)
760@@ -401,7 +401,7 @@
761 FLAGS.compute_manager)
762 compute1.start()
763 s1 = db.service_get_by_args(self.context, 'host1', 'nova-compute')
764- now = datetime.datetime.utcnow()
765+ now = utils.utcnow()
766 delta = datetime.timedelta(seconds=FLAGS.service_down_time * 2)
767 past = now - delta
768 db.service_update(self.context, s1['id'], {'updated_at': past})
769@@ -542,7 +542,7 @@
770 def test_wont_sechedule_if_specified_host_is_down(self):
771 compute1 = self.start_service('compute', host='host1')
772 s1 = db.service_get_by_args(self.context, 'host1', 'nova-compute')
773- now = datetime.datetime.utcnow()
774+ now = utils.utcnow()
775 delta = datetime.timedelta(seconds=FLAGS.service_down_time * 2)
776 past = now - delta
777 db.service_update(self.context, s1['id'], {'updated_at': past})
778@@ -692,7 +692,7 @@
779 dic = {'instance_id': instance_id, 'size': 1}
780 v_ref = db.volume_create(self.context, {'instance_id': instance_id,
781 'size': 1})
782- t1 = datetime.datetime.utcnow() - datetime.timedelta(1)
783+ t1 = utils.utcnow() - datetime.timedelta(1)
784 dic = {'created_at': t1, 'updated_at': t1, 'binary': 'nova-volume',
785 'topic': 'volume', 'report_count': 0}
786 s_ref = db.service_create(self.context, dic)
787@@ -709,7 +709,7 @@
788 """Confirms src-compute node is alive."""
789 instance_id = self._create_instance()
790 i_ref = db.instance_get(self.context, instance_id)
791- t = datetime.datetime.utcnow() - datetime.timedelta(10)
792+ t = utils.utcnow() - datetime.timedelta(10)
793 s_ref = self._create_compute_service(created_at=t, updated_at=t,
794 host=i_ref['host'])
795
796@@ -737,7 +737,7 @@
797 """Confirms exception raises in case dest host does not exist."""
798 instance_id = self._create_instance()
799 i_ref = db.instance_get(self.context, instance_id)
800- t = datetime.datetime.utcnow() - datetime.timedelta(10)
801+ t = utils.utcnow() - datetime.timedelta(10)
802 s_ref = self._create_compute_service(created_at=t, updated_at=t,
803 host=i_ref['host'])
804
805@@ -796,7 +796,7 @@
806 # mocks for live_migration_common_check()
807 instance_id = self._create_instance()
808 i_ref = db.instance_get(self.context, instance_id)
809- t1 = datetime.datetime.utcnow() - datetime.timedelta(10)
810+ t1 = utils.utcnow() - datetime.timedelta(10)
811 s_ref = self._create_compute_service(created_at=t1, updated_at=t1,
812 host=dest)
813
814
815=== modified file 'nova/utils.py'
816--- nova/utils.py 2011-05-16 18:14:03 +0000
817+++ nova/utils.py 2011-06-02 21:52:56 +0000
818@@ -307,7 +307,7 @@
819
820
821 def utcnow():
822- """Overridable version of datetime.datetime.utcnow."""
823+ """Overridable version of utils.utcnow."""
824 if utcnow.override_time:
825 return utcnow.override_time
826 return datetime.datetime.utcnow()
827
828=== modified file 'nova/virt/xenapi/fake.py'
829--- nova/virt/xenapi/fake.py 2011-05-26 19:27:27 +0000
830+++ nova/virt/xenapi/fake.py 2011-06-02 21:52:56 +0000
831@@ -51,13 +51,13 @@
832 """
833
834
835-import datetime
836 import uuid
837
838 from pprint import pformat
839
840 from nova import exception
841 from nova import log as logging
842+from nova import utils
843
844
845 _CLASSES = ['host', 'network', 'session', 'SR', 'VBD',
846@@ -540,7 +540,7 @@
847 except Failure, exc:
848 task['error_info'] = exc.details
849 task['status'] = 'failed'
850- task['finished'] = datetime.datetime.now()
851+ task['finished'] = utils.utcnow()
852 return task_ref
853
854 def _check_session(self, params):
855
856=== modified file 'nova/volume/api.py'
857--- nova/volume/api.py 2011-05-27 05:13:17 +0000
858+++ nova/volume/api.py 2011-06-02 21:52:56 +0000
859@@ -20,14 +20,13 @@
860 Handles all requests relating to volumes.
861 """
862
863-import datetime
864
865-from nova import db
866 from nova import exception
867 from nova import flags
868 from nova import log as logging
869 from nova import quota
870 from nova import rpc
871+from nova import utils
872 from nova.db import base
873
874 FLAGS = flags.FLAGS
875@@ -78,7 +77,7 @@
876 volume = self.get(context, volume_id)
877 if volume['status'] != "available":
878 raise exception.ApiError(_("Volume status must be available"))
879- now = datetime.datetime.utcnow()
880+ now = utils.utcnow()
881 self.db.volume_update(context, volume_id, {'status': 'deleting',
882 'terminated_at': now})
883 host = volume['host']
884
885=== modified file 'nova/volume/manager.py'
886--- nova/volume/manager.py 2011-05-27 05:13:17 +0000
887+++ nova/volume/manager.py 2011-06-02 21:52:56 +0000
888@@ -42,8 +42,6 @@
889
890 """
891
892-import datetime
893-
894
895 from nova import context
896 from nova import exception
897@@ -127,7 +125,7 @@
898 volume_ref['id'], {'status': 'error'})
899 raise
900
901- now = datetime.datetime.utcnow()
902+ now = utils.utcnow()
903 self.db.volume_update(context,
904 volume_ref['id'], {'status': 'available',
905 'launched_at': now})