'Shared implementation for tests below that create instance.'

def setUp(self):

    super(MultiCreateExtensionTestV21, self).setUp()
    self.flags(enable_instance_password=True, group='api')
    self.instance_cache_num = 0
    self.instance_cache_by_id = {}
    self.instance_cache_by_uuid = {}
    fakes.stub_out_nw_api(self)
    ext_info = extension_info.LoadedExtensionInfo()
    self.controller = servers_v21.ServersController(extension_info=ext_info)
    def instance_get(context, instance_id):
        'Stub    for    compute/api    create()    pulling    in    instance    after\n                                                scheduling\n                                                '
        return self.instance_cache_by_id[instance_id]
    def instance_update(context, uuid, values):
        instance = self.instance_cache_by_uuid[uuid]
        instance.update(values)
        return instance
    def server_update(context, instance_uuid, params, columns_to_join=None):
        inst = self.instance_cache_by_uuid[instance_uuid]
        inst.update(params)
        return (inst, inst)
    def fake_method(*args, **kwargs):
        pass
    def project_get_networks(context, user_id):
        return dict(id='1', host='localhost')
    def create_db_entry_for_new_instance(*args, **kwargs):
        instance = args[4]
        self.instance_cache_by_uuid[instance.uuid] = instance
        return instance
    fakes.stub_out_key_pair_funcs(self)
    fake.stub_out_image_service(self)
    self.stub_out('nova.db.instance_add_security_group', return_security_group)
    self.stub_out('nova.db.project_get_networks', project_get_networks)
    self.stub_out('nova.compute.api.API.create_db_entry_for_new_instance', create_db_entry_for_new_instance)
    self.stub_out('nova.db.instance_system_metadata_update', fake_method)
    self.stub_out('nova.db.instance_get', instance_get)
    self.stub_out('nova.db.instance_update', instance_update)
    self.stub_out('nova.db.instance_update_and_get_original', server_update)
    self.stub_out('nova.network.manager.VlanManager.allocate_fixed_ip', fake_method)
    self.req = fakes.HTTPRequest.blank('')
