def create(self): if self.obj_attr_is_set('id'): raise exception.ObjectActionError(action='create', reason='already created') if 'uuid' not in self: self.uuid = uuidutils.generate_uuid() updates = self.obj_get_changes() if 'migration_type' not in updates: raise exception.ObjectActionError( action="create", reason=_("cannot create a Migration object without a " "migration_type set")) db_migration = db.migration_create(self._context, updates) self._from_db_object(self._context, self, db_migration)
def test_create_uuid_on_load(self): values = {'source_compute': 'src', 'dest_compute': 'dst', 'source_node': 'srcnode', 'dest_node': 'dstnode', 'instance_uuid': 'fake', 'status': 'faking', 'migration_type': 'migration', 'created_at': None, 'deleted_at': None, 'updated_at': None} db_mig = db.migration_create(self.context, values) mig = objects.Migration.get_by_id(self.context, db_mig.id) self.assertIn('uuid', mig) uuid = mig.uuid # Make sure that it was saved and we get the same one back mig = objects.Migration.get_by_id(self.context, db_mig.id) self.assertEqual(uuid, mig.uuid)
def test_create_uuid_on_load(self): values = {'source_compute': 'src', 'dest_compute': 'dst', 'source_node': 'srcnode', 'dest_node': 'dstnode', 'instance_uuid': 'fake', 'status': 'faking', 'migration_type': 'migration', 'created_at': None, 'deleted_at': None, 'updated_at': None} db_mig = db.migration_create(self.context, values) mig = objects.Migration.get_by_id(self.context, db_mig.id) self.assertIn('uuid', mig) uuid = mig.uuid # Make sure that it was saved and we get the same one back mig = objects.Migration.get_by_id(self.context, db_mig.id) self.assertEqual(uuid, mig.uuid)
def create(self): if self.obj_attr_is_set('id'): raise exception.ObjectActionError(action='create', reason='already created') if 'uuid' not in self: self.uuid = uuidutils.generate_uuid() # Record who is initiating the migration which is # not necessarily the owner of the instance. if 'user_id' not in self: self.user_id = self._context.user_id if 'project_id' not in self: self.project_id = self._context.project_id updates = self.obj_get_changes() if 'migration_type' not in updates: raise exception.ObjectActionError( action="create", reason=_("cannot create a Migration object without a " "migration_type set")) db_migration = db.migration_create(self._context, updates) self._from_db_object(self._context, self, db_migration)