def fake_compute_get(*args, **kwargs): return fakes.stub_instance(1, task_state="kayaking", vm_state="slightly crunchy", power_state="empowered")
def setUp(self): super(DiskConfigTestCase, self).setUp() self.flags(verbose=True) fakes.stub_out_nw_api(self.stubs) FAKE_INSTANCES = [ fakes.stub_instance(1, uuid=MANUAL_INSTANCE_UUID, auto_disk_config=False), fakes.stub_instance(2, uuid=AUTO_INSTANCE_UUID, auto_disk_config=True) ] def fake_instance_get(context, id_): for instance in FAKE_INSTANCES: if id_ == instance['id']: return instance self.stubs.Set(engine.db, 'instance_get', fake_instance_get) def fake_instance_get_by_uuid(context, uuid): for instance in FAKE_INSTANCES: if uuid == instance['uuid']: return instance self.stubs.Set(engine.db, 'instance_get_by_uuid', fake_instance_get_by_uuid) def fake_instance_get_all(context, *args, **kwargs): return FAKE_INSTANCES self.stubs.Set(engine.db, 'instance_get_all', fake_instance_get_all) self.stubs.Set(engine.db, 'instance_get_all_by_filters', fake_instance_get_all) def fake_instance_create(context, inst_, session=None): class FakeModel(dict): def save(self, session=None): pass inst = FakeModel(**inst_) inst['id'] = 1 inst['uuid'] = AUTO_INSTANCE_UUID inst['created_at'] = datetime.datetime(2010, 10, 10, 12, 0, 0) inst['updated_at'] = datetime.datetime(2010, 10, 10, 12, 0, 0) inst['progress'] = 0 inst['name'] = 'instance-1' # this is a property def fake_instance_get_for_create(context, id_, *args, **kwargs): return inst self.stubs.Set(engine.db, 'instance_get', fake_instance_get_for_create) self.stubs.Set(engine.db, 'instance_update', fake_instance_get_for_create) def fake_instance_get_all_for_create(context, *args, **kwargs): return [inst] self.stubs.Set(engine.db, 'instance_get_all', fake_instance_get_all_for_create) self.stubs.Set(engine.db, 'instance_get_all_by_filters', fake_instance_get_all_for_create) def fake_instance_add_security_group(context, instance_id, security_group_id): pass self.stubs.Set(engine.db, 'instance_add_security_group', fake_instance_add_security_group) return inst self.stubs.Set(engine.db, 'instance_create', fake_instance_create) app = v2.APIRouter() app = extensions.ExtensionMiddleware(app) app = wsgi.LazySerializationMiddleware(app) self.app = app