def test_migration_get_unconfirmed_by_dest_compute(self): ctxt = context.get_admin_context() # Ensure no migrations are returned. results = db.migration_get_unconfirmed_by_dest_compute(ctxt, 10, "fake_host") self.assertEqual(0, len(results)) # Ensure no migrations are returned. results = db.migration_get_unconfirmed_by_dest_compute(ctxt, 10, "fake_host2") self.assertEqual(0, len(results)) updated_at = datetime.datetime(2000, 01, 01, 12, 00, 00) values = {"status": "finished", "updated_at": updated_at, "dest_compute": "fake_host2"} migration = db.migration_create(ctxt, values) # Ensure different host is not returned results = db.migration_get_unconfirmed_by_dest_compute(ctxt, 10, "fake_host") self.assertEqual(0, len(results)) # Ensure one migration older than 10 seconds is returned. results = db.migration_get_unconfirmed_by_dest_compute(ctxt, 10, "fake_host2") self.assertEqual(1, len(results)) db.migration_update(ctxt, migration.id, {"status": "CONFIRMED"}) # Ensure the new migration is not returned. updated_at = timeutils.utcnow() values = {"status": "finished", "updated_at": updated_at, "dest_compute": "fake_host2"} migration = db.migration_create(ctxt, values) results = db.migration_get_unconfirmed_by_dest_compute(ctxt, 10, "fake_host2") self.assertEqual(0, len(results)) db.migration_update(ctxt, migration.id, {"status": "CONFIRMED"})
def test_save(self): ctxt = context.get_admin_context() self.mox.StubOutWithMock(db, 'migration_update') db.migration_update(ctxt, 123, {'source_compute': 'foo'} ).AndReturn(fake_migration) self.mox.ReplayAll() mig = migration.Migration() mig.id = 123 mig.source_compute = 'foo' mig.save(ctxt) self.assertEqual(fake_migration['dest_compute'], mig.dest_compute)
def test_save(self): ctxt = context.get_admin_context() fake_migration = fake_db_migration() self.mox.StubOutWithMock(db, 'migration_update') db.migration_update(ctxt, 123, {'source_compute': 'foo'} ).AndReturn(fake_migration) self.mox.ReplayAll() mig = migration.Migration(context=ctxt) mig.id = 123 mig.source_compute = 'foo' mig.save() self.assertEqual(fake_migration['dest_compute'], mig.dest_compute)
def save(self, context): updates = {} for key in self.obj_what_changed(): updates[key] = self[key] updates.pop('id', None) db_migration = db.migration_update(context, self.id, updates) self._from_db_object(context, self, db_migration) self.obj_reset_changes()
def test_migration_get_all_unconfirmed(self): ctxt = context.get_admin_context() # Ensure no migrations are returned. results = db.migration_get_all_unconfirmed(ctxt, 10) self.assertEqual(0, len(results)) # Ensure one migration older than 10 seconds is returned. updated_at = datetime.datetime(2000, 01, 01, 12, 00, 00) values = {"status": "FINISHED", "updated_at": updated_at} migration = db.migration_create(ctxt, values) results = db.migration_get_all_unconfirmed(ctxt, 10) self.assertEqual(1, len(results)) db.migration_update(ctxt, migration.id, {"status": "CONFIRMED"}) # Ensure the new migration is not returned. updated_at = datetime.datetime.utcnow() values = {"status": "FINISHED", "updated_at": updated_at} migration = db.migration_create(ctxt, values) results = db.migration_get_all_unconfirmed(ctxt, 10) self.assertEqual(0, len(results)) db.migration_update(ctxt, migration.id, {"status": "CONFIRMED"})
def save(self, context): updates = self.obj_get_changes() updates.pop('id', None) db_migration = db.migration_update(context, self.id, updates) self._from_db_object(context, self, db_migration) self.obj_reset_changes()
def save(self): updates = self.obj_get_changes() updates.pop('id', None) db_migration = db.migration_update(self._context, self.id, updates) self._from_db_object(self._context, self, db_migration) self.obj_reset_changes()
def confirm_resize(self, context, migration, status='confirmed'): """Cleanup usage for a confirmed resize""" elevated = context.elevated() db.migration_update(elevated, migration['id'], {'status': status}) self.update_available_resource(elevated)
def confirm_resize(self, context, migration, status='confirmed'): """Cleanup usage for a confirmed resize.""" elevated = context.elevated() db.migration_update(elevated, migration['id'], {'status': status}) self.update_available_resource(elevated)
def confirm_resize(self, context, migration, status="confirmed"): """Cleanup usage for a confirmed resize""" elevated = context.elevated() db.migration_update(elevated, migration["id"], {"status": status}) self.update_available_resource(elevated)