Merge "Correct the sorting of datetimes for migrations"

This commit is contained in:
Jenkins
2016-12-12 17:12:04 +00:00
committed by Gerrit Code Review
2 changed files with 11 additions and 7 deletions

View File

@@ -824,9 +824,13 @@ class ResourceTracker(object):
# filter to most recently updated migration for each instance:
other_migration = filtered.get(uuid, None)
# NOTE(claudiub): In Python 3, you cannot compare NoneTypes.
if (not other_migration or (
migration.updated_at and other_migration.updated_at and
migration.updated_at >= other_migration.updated_at)):
if other_migration:
om = other_migration
other_time = om.updated_at or om.created_at
migration_time = migration.updated_at or migration.created_at
if migration_time > other_time:
filtered[uuid] = migration
else:
filtered[uuid] = migration
for migration in filtered.values():

View File

@@ -2054,6 +2054,7 @@ class TestUpdateUsageFromMigrations(BaseTestCase):
instance = objects.Instance(vm_state=vm_states.RESIZED,
task_state=None)
ts1 = timeutils.utcnow()
ts0 = ts1 - datetime.timedelta(seconds=10)
ts2 = ts1 + datetime.timedelta(seconds=10)
migrations = [
@@ -2062,6 +2063,7 @@ class TestUpdateUsageFromMigrations(BaseTestCase):
dest_compute=_HOSTNAME,
dest_node=_NODENAME,
instance_uuid=uuids.instance,
created_at=ts0,
updated_at=ts1,
instance=instance),
objects.Migration(source_compute=_HOSTNAME,
@@ -2069,6 +2071,7 @@ class TestUpdateUsageFromMigrations(BaseTestCase):
dest_compute=_HOSTNAME,
dest_node=_NODENAME,
instance_uuid=uuids.instance,
created_at=ts0,
updated_at=ts2,
instance=instance)
]
@@ -2078,10 +2081,7 @@ class TestUpdateUsageFromMigrations(BaseTestCase):
upd_mock.assert_called_once_with(mock.sentinel.ctx, instance, mig2)
upd_mock.reset_mock()
mig1.updated_at = None
# For some reason, the code thinks None should always take
# precedence over any datetime in the updated_at attribute...
mig2.updated_at = None
self.rt._update_usage_from_migrations(mock.sentinel.ctx, mig_list)
upd_mock.assert_called_once_with(mock.sentinel.ctx, instance, mig1)