Exemple #1
0
    def test_shelve(self):
        # Ensure instance can be shelved.
        fake_instance = self._create_fake_instance({'display_name': 'vm01'})
        instance = jsonutils.to_primitive(fake_instance)
        instance_uuid = instance['uuid']
        self.compute.run_instance(self.context, instance, {}, {}, [], None,
                                  None, True, None, False)

        self.assertIsNone(instance['task_state'])

        def fake_init(self2):
            # In original _FakeImageService.__init__(), some fake images are
            # created. To verify the snapshot name of this test only, here
            # sets a fake method.
            self2.images = {}

        def fake_create(self2, ctxt, metadata):
            self.assertEqual(metadata['name'], 'vm01-shelved')
            metadata['id'] = '8b24ed3f-ee57-43bc-bc2e-fb2e9482bc42'
            return metadata

        fake_image.stub_out_image_service(self.stubs)
        self.stubs.Set(fake_image._FakeImageService, '__init__', fake_init)
        self.stubs.Set(fake_image._FakeImageService, 'create', fake_create)

        inst_obj = instance_obj.Instance.get_by_uuid(self.context,
                                                     instance_uuid)
        self.compute_api.shelve(self.context, inst_obj)

        inst_obj.refresh()
        self.assertEqual(inst_obj.task_state, task_states.SHELVING)

        db.instance_destroy(self.context, instance['uuid'])
Exemple #2
0
    def test_shelve(self):
        # Ensure instance can be shelved.
        fake_instance = self._create_fake_instance({'display_name': 'vm01'})
        instance = jsonutils.to_primitive(fake_instance)
        instance_uuid = instance['uuid']
        self.compute.run_instance(self.context, instance=instance)

        self.assertIsNone(instance['task_state'])

        def fake_init(self2):
            # In original _FakeImageService.__init__(), some fake images are
            # created. To verify the snapshot name of this test only, here
            # sets a fake method.
            self2.images = {}

        def fake_create(self2, ctxt, metadata):
            self.assertEqual(metadata['name'], 'vm01-shelved')
            metadata['id'] = '8b24ed3f-ee57-43bc-bc2e-fb2e9482bc42'
            return metadata

        fake_image.stub_out_image_service(self.stubs)
        self.stubs.Set(fake_image._FakeImageService, '__init__', fake_init)
        self.stubs.Set(fake_image._FakeImageService, 'create', fake_create)

        inst_obj = instance_obj.Instance.get_by_uuid(self.context,
                                                     instance_uuid)
        self.compute_api.shelve(self.context, inst_obj)

        inst_obj.refresh()
        self.assertEqual(inst_obj.task_state, task_states.SHELVING)

        db.instance_destroy(self.context, instance['uuid'])
Exemple #3
0
    def setUp(self):
        super(BareMetalTileraTestCase, self).setUp()
        self.flags(**COMMON_FLAGS)
        self.flags(**BAREMETAL_FLAGS)
        self.driver = tilera.Tilera(fake_virt.FakeVirtAPI())

        fake_image.stub_out_image_service(self.stubs)
        self.addCleanup(fake_image.FakeImageService_reset)
        self.context = utils.get_test_admin_context()
        self.test_block_device_info = None,
        self.instance = utils.get_test_instance()
        self.test_network_info = utils.get_test_network_info()
        self.node_info = bm_db_utils.new_bm_node(
            service_host='test_host',
            cpus=4,
            memory_mb=2048,
        )
        self.nic_info = [
            {
                'address': '22:22:22:22:22:22',
                'datapath_id': '0x1',
                'port_no': 1
            },
            {
                'address': '33:33:33:33:33:33',
                'datapath_id': '0x2',
                'port_no': 2
            },
        ]
Exemple #4
0
    def setUp(self):
        super(BareMetalPXETestCase, self).setUp()
        self.flags(**COMMON_FLAGS)
        self.flags(**BAREMETAL_FLAGS)
        self.driver = pxe.PXE()

        fake_image.stub_out_image_service(self.stubs)
        self.addCleanup(fake_image.FakeImageService_reset)
        self.context = utils.get_test_admin_context()
        self.test_block_device_info = None,
        self.instance = utils.get_test_instance()
        self.test_network_info = utils.get_test_network_info(),
        self.node_info = bm_db_utils.new_bm_node(
                id=123,
                service_host='test_host',
                cpus=2,
                memory_mb=2048,
                prov_mac_address='11:11:11:11:11:11',
            )
        self.nic_info = [
                {'address': '22:22:22:22:22:22', 'datapath_id': '0x1',
                    'port_no': 1},
                {'address': '33:33:33:33:33:33', 'datapath_id': '0x2',
                    'port_no': 2},
            ]
    def setUp(self):
        super(ServerActionsControllerTest, self).setUp()

        CONF.set_override('glance_host', 'localhost')
        self.stubs.Set(db, 'instance_get_by_uuid',
                       fakes.fake_instance_get(vm_state=vm_states.ACTIVE,
                                               host='fake_host'))
        self.stubs.Set(db, 'instance_update_and_get_original',
                       instance_update_and_get_original)

        fakes.stub_out_glance(self.stubs)
        fakes.stub_out_nw_api(self.stubs)
        fakes.stub_out_compute_api_snapshot(self.stubs)
        fake.stub_out_image_service(self.stubs)
        service_class = 'nova.image.glance.GlanceImageService'
        self.service = importutils.import_object(service_class)
        self.sent_to_glance = {}
        fakes.stub_out_glanceclient_create(self.stubs, self.sent_to_glance)
        self.flags(allow_instance_snapshots=True,
                   enable_instance_password=True)
        self.uuid = FAKE_UUID
        self.url = '/servers/%s/action' % self.uuid
        self._image_href = '155d900f-4e14-4e4c-a73d-069cbf4541e6'

        ext_info = plugins.LoadedExtensionInfo()
        self.controller = servers.ServersController(extension_info=ext_info)
        self.compute_api = self.controller.compute_api
        self.context = context.RequestContext('fake', 'fake')
        self.app = fakes.wsgi_app_v3(init_only=('servers',),
                                     fake_auth_context=self.context)
Exemple #6
0
    def test_shelve(self):
        # Ensure instance can be shelved.
        fake_instance = self._create_fake_instance({"display_name": "vm01"})
        instance = jsonutils.to_primitive(fake_instance)
        instance_uuid = instance["uuid"]
        self.compute.run_instance(self.context, instance, {}, {}, [], None, None, True, None, False)

        self.assertIsNone(instance["task_state"])

        def fake_init(self2):
            # In original _FakeImageService.__init__(), some fake images are
            # created. To verify the snapshot name of this test only, here
            # sets a fake method.
            self2.images = {}

        def fake_create(self2, ctxt, metadata):
            self.assertEqual(metadata["name"], "vm01-shelved")
            metadata["id"] = "8b24ed3f-ee57-43bc-bc2e-fb2e9482bc42"
            return metadata

        fake_image.stub_out_image_service(self.stubs)
        self.stubs.Set(fake_image._FakeImageService, "__init__", fake_init)
        self.stubs.Set(fake_image._FakeImageService, "create", fake_create)

        inst_obj = instance_obj.Instance.get_by_uuid(self.context, instance_uuid)
        self.compute_api.shelve(self.context, inst_obj)

        inst_obj.refresh()
        self.assertEqual(inst_obj.task_state, task_states.SHELVING)

        db.instance_destroy(self.context, instance["uuid"])
Exemple #7
0
 def setUp(self):
     super(_FakeDriverBackendTestCase, self).setUp()
     # TODO(sdague): it would be nice to do this in a way that only
     # the relevant backends where replaced for tests, though this
     # should not harm anything by doing it for all backends
     fake_image.stub_out_image_service(self.stubs)
     self._setup_fakelibvirt()
Exemple #8
0
    def setUp(self):
        super(CinderCloudTestCase, self).setUp()
        vol_tmpdir = tempfile.mkdtemp()
        self.flags(compute_driver='nova.virt.fake.FakeDriver',
                   volume_api_class='nova.tests.fake_volume.API')

        def fake_show(meh, context, id):
            return {
                'id': id,
                'name': 'fake_name',
                'container_format': 'ami',
                'status': 'active',
                'properties': {
                    'kernel_id': 'cedef40a-ed67-4d10-800e-17455edce175',
                    'ramdisk_id': 'cedef40a-ed67-4d10-800e-17455edce175',
                    'type': 'machine',
                    'image_state': 'available'
                }
            }

        def fake_detail(_self, context, **kwargs):
            image = fake_show(None, context, None)
            image['name'] = kwargs.get('filters', {}).get('name')
            return [image]

        self.stubs.Set(fake._FakeImageService, 'show', fake_show)
        self.stubs.Set(fake._FakeImageService, 'detail', fake_detail)
        fake.stub_out_image_service(self.stubs)

        def dumb(*args, **kwargs):
            pass

        self.stubs.Set(compute_utils, 'notify_about_instance_usage', dumb)
        fake_network.set_stub_network_methods(self.stubs)

        # set up our cloud
        self.cloud = cloud.CloudController()
        self.flags(scheduler_driver='nova.scheduler.chance.ChanceScheduler')

        # set up services
        self.compute = self.start_service('compute')
        self.scheduler = self.start_service('scheduler')
        self.network = self.start_service('network')

        self.user_id = 'fake'
        self.project_id = 'fake'
        self.context = context.RequestContext(self.user_id,
                                              self.project_id,
                                              is_admin=True)
        self.volume_api = volume.API()

        # NOTE(comstud): Make 'cast' behave like a 'call' which will
        # ensure that operations complete
        self.stubs.Set(rpc, 'cast', rpc.call)

        # make sure we can map ami-00000001/2 to a uuid in FakeImageService
        db.api.s3_image_create(self.context,
                               'cedef40a-ed67-4d10-800e-17455edce175')
        db.api.s3_image_create(self.context,
                               '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6')
Exemple #9
0
    def setUp(self):
        super(SchedulerTestCase, self).setUp()
        self.stubs.Set(compute_api, 'API', fakes.FakeComputeAPI)

        def fake_show(meh, context, id):
            if id:
                return {
                    'id': id,
                    'min_disk': None,
                    'min_ram': None,
                    'name': 'fake_name',
                    'status': 'active',
                    'properties': {
                        'kernel_id': 'fake_kernel_id',
                        'ramdisk_id': 'fake_ramdisk_id',
                        'something_else': 'meow'
                    }
                }
            else:
                raise exception.ImageNotFound(image_id=id)

        fake_image.stub_out_image_service(self.stubs)
        self.stubs.Set(fake_image._FakeImageService, 'show', fake_show)
        self.image_service = glance.get_default_image_service()

        self.driver = self.driver_cls()
        self.context = context.RequestContext('fake_user', 'fake_project')
        self.topic = 'fake_topic'
        self.servicegroup_api = servicegroup.API()
    def setUp(self):
        super(ServerActionsControllerTest, self).setUp()

        CONF.set_override('host', 'localhost', group='glance')
        self.stubs.Set(db, 'instance_get_by_uuid',
                       fakes.fake_instance_get(vm_state=vm_states.ACTIVE,
                                               host='fake_host'))
        self.stubs.Set(db, 'instance_update_and_get_original',
                       instance_update_and_get_original)

        fakes.stub_out_nw_api(self.stubs)
        fakes.stub_out_compute_api_snapshot(self.stubs)
        fake.stub_out_image_service(self.stubs)
        self.flags(allow_instance_snapshots=True,
                   enable_instance_password=True)
        self.uuid = FAKE_UUID
        self.url = '/servers/%s/action' % self.uuid
        self._image_href = '155d900f-4e14-4e4c-a73d-069cbf4541e6'

        ext_info = plugins.LoadedExtensionInfo()
        self.controller = servers.ServersController(extension_info=ext_info)
        self.compute_api = self.controller.compute_api
        self.context = context.RequestContext('fake', 'fake')
        self.app = fakes.wsgi_app_v3(init_only=('servers',),
                                     fake_auth_context=self.context)
Exemple #11
0
    def setUp(self):
        super(BareMetalDriverWithDBTestCase, self).setUp()
        self.flags(**COMMON_FLAGS)
        self.flags(**BAREMETAL_FLAGS)

        fake_image.stub_out_image_service(self.stubs)
        self.context = utils.get_test_admin_context()
        self.driver = bm_driver.BareMetalDriver(None)
        self.node_info = bm_db_utils.new_bm_node(
            id=123,
            service_host='test_host',
            cpus=2,
            memory_mb=2048,
        )
        self.nic_info = [
            {
                'address': '01:23:45:67:89:01',
                'datapath_id': '0x1',
                'port_no': 1
            },
            {
                'address': '01:23:45:67:89:02',
                'datapath_id': '0x2',
                'port_no': 2
            },
        ]
        self.addCleanup(fake_image.FakeImageService_reset)
Exemple #12
0
    def setUp(self):
        super(CinderCloudTestCase, self).setUp()
        vol_tmpdir = tempfile.mkdtemp()
        self.flags(compute_driver='nova.virt.fake.FakeDriver',
                   volume_api_class='nova.tests.fake_volume.API')

        def fake_show(meh, context, id):
            return {'id': id,
                    'name': 'fake_name',
                    'container_format': 'ami',
                    'status': 'active',
                    'properties': {
                        'kernel_id': 'cedef40a-ed67-4d10-800e-17455edce175',
                        'ramdisk_id': 'cedef40a-ed67-4d10-800e-17455edce175',
                        'type': 'machine',
                        'image_state': 'available'}}

        def fake_detail(_self, context, **kwargs):
            image = fake_show(None, context, None)
            image['name'] = kwargs.get('filters', {}).get('name')
            return [image]

        self.stubs.Set(fake._FakeImageService, 'show', fake_show)
        self.stubs.Set(fake._FakeImageService, 'detail', fake_detail)
        fake.stub_out_image_service(self.stubs)

        def dumb(*args, **kwargs):
            pass

        self.stubs.Set(compute_utils, 'notify_about_instance_usage', dumb)
        fake_network.set_stub_network_methods(self.stubs)

        # set up our cloud
        self.cloud = cloud.CloudController()
        self.flags(scheduler_driver='nova.scheduler.chance.ChanceScheduler')

        # Short-circuit the conductor service
        self.flags(use_local=True, group='conductor')

        # set up services
        self.compute = self.start_service('compute')
        self.scheduler = self.start_service('scheduler')
        self.network = self.start_service('network')

        self.user_id = 'fake'
        self.project_id = 'fake'
        self.context = context.RequestContext(self.user_id,
                                              self.project_id,
                                              is_admin=True)
        self.volume_api = volume.API()

        # NOTE(comstud): Make 'cast' behave like a 'call' which will
        # ensure that operations complete
        self.stubs.Set(rpc, 'cast', rpc.call)

        # make sure we can map ami-00000001/2 to a uuid in FakeImageService
        db.api.s3_image_create(self.context,
                               'cedef40a-ed67-4d10-800e-17455edce175')
        db.api.s3_image_create(self.context,
                               '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6')
    def setUp(self):
        super(ServerActionsControllerTest, self).setUp()

        self.stubs.Set(db, 'instance_get_by_uuid',
                       fakes.fake_instance_get(vm_state=vm_states.ACTIVE,
                                               host='fake_host'))
        self.stubs.Set(db, 'instance_update_and_get_original',
                       instance_update)

        fakes.stub_out_glance(self.stubs)
        fakes.stub_out_nw_api(self.stubs)
        fakes.stub_out_rate_limiting(self.stubs)
        fakes.stub_out_compute_api_snapshot(self.stubs)
        fake.stub_out_image_service(self.stubs)
        service_class = 'nova.image.glance.GlanceImageService'
        self.service = importutils.import_object(service_class)
        self.sent_to_glance = {}
        fakes.stub_out_glanceclient_create(self.stubs, self.sent_to_glance)
        self.flags(allow_instance_snapshots=True,
                   enable_instance_password=True)
        self.uuid = FAKE_UUID
        self.url = '/v2/fake/servers/%s/action' % self.uuid
        self._image_href = '155d900f-4e14-4e4c-a73d-069cbf4541e6'

        self.controller = servers.Controller()
 def setUp(self):
     super(ConfigDriveTestV21, self).setUp()
     self.Controller = self._get_config_drive_controller()
     fakes.stub_out_networking(self.stubs)
     fakes.stub_out_rate_limiting(self.stubs)
     fake.stub_out_image_service(self.stubs)
     self._setup_wsgi()
Exemple #15
0
    def setUp(self):
        super(ServerActionsControllerTest, self).setUp()

        self.stubs.Set(
            db, 'instance_get_by_uuid',
            fakes.fake_instance_get(vm_state=vm_states.ACTIVE,
                                    host='fake_host'))
        self.stubs.Set(db, 'instance_update_and_get_original', instance_update)

        fakes.stub_out_glance(self.stubs)
        fakes.stub_out_nw_api(self.stubs)
        fakes.stub_out_rate_limiting(self.stubs)
        fakes.stub_out_compute_api_snapshot(self.stubs)
        fake.stub_out_image_service(self.stubs)
        service_class = 'nova.image.glance.GlanceImageService'
        self.service = importutils.import_object(service_class)
        self.sent_to_glance = {}
        fakes.stub_out_glanceclient_create(self.stubs, self.sent_to_glance)
        self.flags(allow_instance_snapshots=True,
                   enable_instance_password=True)
        self.uuid = FAKE_UUID
        self.url = '/v2/fake/servers/%s/action' % self.uuid
        self._image_href = '155d900f-4e14-4e4c-a73d-069cbf4541e6'

        self.controller = servers.Controller()
Exemple #16
0
 def setUp(self):
     super(ConfigDriveTestV21, self).setUp()
     self.Controller = self._get_config_drive_controller()
     fakes.stub_out_networking(self.stubs)
     fakes.stub_out_rate_limiting(self.stubs)
     fake.stub_out_image_service(self.stubs)
     self._setup_wsgi()
Exemple #17
0
    def setUp(self):
        super(SchedulerTestCase, self).setUp()
        self.stubs.Set(compute_api, "API", fakes.FakeComputeAPI)

        def fake_show(meh, context, id):
            if id:
                return {
                    "id": id,
                    "min_disk": None,
                    "min_ram": None,
                    "name": "fake_name",
                    "status": "active",
                    "properties": {
                        "kernel_id": "fake_kernel_id",
                        "ramdisk_id": "fake_ramdisk_id",
                        "something_else": "meow",
                    },
                }
            else:
                raise exception.ImageNotFound(image_id=id)

        fake_image.stub_out_image_service(self.stubs)
        self.stubs.Set(fake_image._FakeImageService, "show", fake_show)
        self.image_service = glance.get_default_image_service()

        self.driver = self.driver_cls()
        self.context = context.RequestContext("fake_user", "fake_project")
        self.topic = "fake_topic"
        self.servicegroup_api = servicegroup.API()
 def setUp(self):
     super(ConfigDriveTest, self).setUp()
     ext_info = plugins.LoadedExtensionInfo()
     self.Controller = config_drive.ConfigDriveController(extension_info=ext_info)
     fakes.stub_out_networking(self.stubs)
     fakes.stub_out_rate_limiting(self.stubs)
     fake.stub_out_image_service(self.stubs)
    def setUp(self):
        super(ServerActionsControllerTest, self).setUp()

        self.stubs.Set(db, "instance_get_by_uuid", fakes.fake_instance_get(vm_state=vm_states.ACTIVE, host="fake_host"))
        self.stubs.Set(db, "instance_update_and_get_original", instance_update_and_get_original)

        fakes.stub_out_glance(self.stubs)
        fakes.stub_out_nw_api(self.stubs)
        fakes.stub_out_compute_api_snapshot(self.stubs)
        fake.stub_out_image_service(self.stubs)
        service_class = "nova.image.glance.GlanceImageService"
        self.service = importutils.import_object(service_class)
        self.sent_to_glance = {}
        fakes.stub_out_glanceclient_create(self.stubs, self.sent_to_glance)
        self.flags(allow_instance_snapshots=True, enable_instance_password=True)
        self.uuid = FAKE_UUID
        self.url = "/v2/fake/servers/%s/action" % self.uuid
        self._image_href = "155d900f-4e14-4e4c-a73d-069cbf4541e6"

        class FakeExtManager(object):
            def is_loaded(self, ext):
                return False

        self.controller = servers.Controller(ext_mgr=FakeExtManager())
        self.compute_api = self.controller.compute_api
        self.context = context.RequestContext("fake", "fake")
        self.app = fakes.wsgi_app(init_only=("servers",), fake_auth_context=self.context)
    def setUp(self):
        super(BareMetalVPDTestCase, self).setUp()
        self.flags(**COMMON_FLAGS)
        self.flags(**BAREMETAL_FLAGS)

        fake_image.stub_out_image_service(self.stubs)
        self.context = utils.get_test_admin_context()
        self.test_block_device_info = None,
        self.instance = utils.get_test_instance()
        self.test_network_info = utils.get_test_network_info(),
        self.node_info = bm_db_utils.new_bm_node(
            id=123,
            service_host='test_host',
            cpus=2,
            memory_mb=2048,
            prov_mac_address='aa:bb:cc:dd:ee:ff',
        )
        self.nic_info = [
            {
                'address': '11:11:11:11:11:11',
                'datapath_id': '0x1',
                'port_no': 1
            },
            {
                'address': '22:22:22:22:22:22',
                'datapath_id': '0x2',
                'port_no': 2
            },
        ]
        self.addCleanup(fake_image.FakeImageService_reset)
Exemple #21
0
 def setUp(self):
     super(_FakeDriverBackendTestCase, self).setUp()
     # TODO(sdague): it would be nice to do this in a way that only
     # the relevant backends where replaced for tests, though this
     # should not harm anything by doing it for all backends
     fake_image.stub_out_image_service(self.stubs)
     self._setup_fakelibvirt()
Exemple #22
0
    def setUp(self):
        super(CinderCloudTestCase, self).setUp()
        vol_tmpdir = tempfile.mkdtemp()
        self.flags(
            compute_driver="nova.virt.fake.FakeDriver",
            volume_api_class="nova.tests.fake_volume.API",
            volumes_dir=vol_tmpdir,
        )

        def fake_show(meh, context, id):
            return {
                "id": id,
                "name": "fake_name",
                "container_format": "ami",
                "properties": {
                    "kernel_id": "cedef40a-ed67-4d10-800e-17455edce175",
                    "ramdisk_id": "cedef40a-ed67-4d10-800e-17455edce175",
                    "type": "machine",
                    "image_state": "available",
                },
            }

        def fake_detail(_self, context, **kwargs):
            image = fake_show(None, context, None)
            image["name"] = kwargs.get("filters", {}).get("name")
            return [image]

        self.stubs.Set(fake._FakeImageService, "show", fake_show)
        self.stubs.Set(fake._FakeImageService, "detail", fake_detail)
        fake.stub_out_image_service(self.stubs)

        def dumb(*args, **kwargs):
            pass

        self.stubs.Set(compute_utils, "notify_about_instance_usage", dumb)
        fake_network.set_stub_network_methods(self.stubs)

        # set up our cloud
        self.cloud = cloud.CloudController()
        self.flags(compute_scheduler_driver="nova.scheduler." "chance.ChanceScheduler")

        # set up services
        self.compute = self.start_service("compute")
        self.scheduler = self.start_service("scheduler")
        self.network = self.start_service("network")
        self.volume = self.start_service("volume")

        self.user_id = "fake"
        self.project_id = "fake"
        self.context = context.RequestContext(self.user_id, self.project_id, is_admin=True)
        self.volume_api = volume.API()

        # NOTE(comstud): Make 'cast' behave like a 'call' which will
        # ensure that operations complete
        self.stubs.Set(rpc, "cast", rpc.call)

        # make sure we can map ami-00000001/2 to a uuid in FakeImageService
        db.api.s3_image_create(self.context, "cedef40a-ed67-4d10-800e-17455edce175")
        db.api.s3_image_create(self.context, "76fa36fc-c930-4bf3-8c8a-ea2a2420deb6")
Exemple #23
0
 def setUp(self):
     super(BaremetalDriverTestCase, self).setUp()
     self.driver_module = 'nova.virt.baremetal.BareMetalDriver'
     self.flags(**COMMON_FLAGS)
     self.node = _create_baremetal_stuff()
     self.node_id = self.node['id']
     fake_image.stub_out_image_service(self.stubs)
     self.addCleanup(fake_image.FakeImageService_reset)
Exemple #24
0
 def setUp(self):
     super(ConfigDriveTest, self).setUp()
     ext_info = plugins.LoadedExtensionInfo()
     self.Controller = config_drive.ConfigDriveController(
         extension_info=ext_info)
     fakes.stub_out_networking(self.stubs)
     fakes.stub_out_rate_limiting(self.stubs)
     fake.stub_out_image_service(self.stubs)
Exemple #25
0
    def setUp(self):
        super(EC2ValidateTestCase, self).setUp()
        self.flags(compute_driver="nova.virt.fake.FakeDriver")

        def dumb(*args, **kwargs):
            pass

        self.stubs.Set(compute_utils, "notify_about_instance_usage", dumb)
        fake_network.set_stub_network_methods(self.stubs)

        # set up our cloud
        self.cloud = cloud.CloudController()

        # set up services
        self.conductor = self.start_service("conductor", manager=CONF.conductor.manager)
        self.compute = self.start_service("compute")
        self.scheduter = self.start_service("scheduler")
        self.network = self.start_service("network")
        self.image_service = fake.FakeImageService()

        self.user_id = "fake"
        self.project_id = "fake"
        self.context = context.RequestContext(self.user_id, self.project_id, is_admin=True)

        self.EC2_MALFORMED_IDS = ["foobar", "", 123]
        self.EC2_VALID__IDS = ["i-284f3a41", "i-001", "i-deadbeef"]

        self.ec2_id_exception_map = [(x, exception.InvalidInstanceIDMalformedEC2) for x in self.EC2_MALFORMED_IDS]
        self.ec2_id_exception_map.extend([(x, exception.InstanceNotFound) for x in self.EC2_VALID__IDS])
        self.volume_id_exception_map = [(x, exception.InvalidInstanceIDMalformedEC2) for x in self.EC2_MALFORMED_IDS]
        self.volume_id_exception_map.extend([(x, exception.VolumeNotFound) for x in self.EC2_VALID__IDS])

        def fake_show(meh, context, id):
            return {
                "id": id,
                "container_format": "ami",
                "properties": {
                    "kernel_id": "cedef40a-ed67-4d10-800e-17455edce175",
                    "ramdisk_id": "cedef40a-ed67-4d10-800e-17455edce175",
                    "type": "machine",
                    "image_state": "available",
                },
            }

        def fake_detail(self, context, **kwargs):
            image = fake_show(self, context, None)
            image["name"] = kwargs.get("name")
            return [image]

        fake.stub_out_image_service(self.stubs)
        self.stubs.Set(fake._FakeImageService, "show", fake_show)
        self.stubs.Set(fake._FakeImageService, "detail", fake_detail)

        self.useFixture(cast_as_call.CastAsCall(self.stubs))

        # make sure we can map ami-00000001/2 to a uuid in FakeImageService
        db.s3_image_create(self.context, "cedef40a-ed67-4d10-800e-17455edce175")
        db.s3_image_create(self.context, "76fa36fc-c930-4bf3-8c8a-ea2a2420deb6")
Exemple #26
0
 def setUp(self):
     # Point _VirtDriverTestCase at the right module
     self.driver_module = 'nova.virt.baremetal.BareMetalDriver'
     self.flags(**COMMON_FLAGS)
     utils.clear_tables()
     self.node = _create_baremetal_stuff()
     self.node_id = self.node['id']
     super(BaremetalDriverTestCase, self).setUp()
     fake_image.stub_out_image_service(self.stubs)
Exemple #27
0
    def setUp(self):
        super(BareMetalDriverWithDBTestCase, self).setUp()
        self.config(**COMMON_CONFIG)
        self.config(**BAREMETAL_CONFIG)

        fake_image.stub_out_image_service(self.stubs)
        self.context = utils.get_test_admin_context()
        self.driver = bm_driver.BareMetalDriver(None)
        self.addCleanup(fake_image.FakeImageService_reset)
Exemple #28
0
 def setUp(self):
     # Point _VirtDriverTestCase at the right module
     self.driver_module = 'nova.virt.baremetal.BareMetalDriver'
     self.flags(**COMMON_FLAGS)
     utils.clear_tables()
     self.node = _create_baremetal_stuff()
     self.node_id = self.node['id']
     super(BaremetalDriverTestCase, self).setUp()
     fake_image.stub_out_image_service(self.stubs)
Exemple #29
0
    def setUp(self):
        super(BareMetalDriverWithDBTestCase, self).setUp()
        self.config(**COMMON_CONFIG)
        self.config(**BAREMETAL_CONFIG)

        fake_image.stub_out_image_service(self.stubs)
        self.context = utils.get_test_admin_context()
        self.driver = bm_driver.BareMetalDriver(None)
        self.addCleanup(fake_image.FakeImageService_reset)
Exemple #30
0
 def _create_instance(self):
     fake.stub_out_image_service(self.stubs)
     return db.instance_create(context.get_admin_context(),
                     {'user_id': 'fake',
                     'project_id': 'fake',
                     'instance_type_id': 1,
                     'memory_mb': 1024,
                     'image_ref': '155d900f-4e14-4e4c-a73d-069cbf4541e6',
                     'vcpus': 2})
Exemple #31
0
    def setUp(self):
        super(BareMetalDriverWithDBTestCase, self).setUp()
        self.flags(**COMMON_FLAGS)
        self.flags(**BAREMETAL_FLAGS)

        fake_image.stub_out_image_service(self.stubs)
        self.context = utils.get_test_admin_context()
        self.driver = bm_driver.BareMetalDriver(fake_virt.FakeVirtAPI())
        self.addCleanup(fake_image.FakeImageService_reset)
Exemple #32
0
    def setUp(self):
        super(BareMetalDriverWithDBTestCase, self).setUp()
        self.flags(**COMMON_FLAGS)
        self.flags(**BAREMETAL_FLAGS)

        fake_image.stub_out_image_service(self.stubs)
        self.context = utils.get_test_admin_context()
        self.driver = bm_driver.BareMetalDriver(fake_virt.FakeVirtAPI())
        self.addCleanup(fake_image.FakeImageService_reset)
Exemple #33
0
    def setUp(self):
        super(TestS3ImageService, self).setUp()
        self.context = context.RequestContext(None, None)

        # set up one fixture to test shows, should have id '1'
        nova.db.api.s3_image_create(self.context,
                                    '155d900f-4e14-4e4c-a73d-069cbf4541e6')

        fake.stub_out_image_service(self.stubs)
        self.image_service = s3.S3ImageService()
Exemple #34
0
    def setUp(self):
        super(TestS3ImageService, self).setUp()
        self.context = context.RequestContext(None, None)

        # set up one fixture to test shows, should have id '1'
        nova.db.api.s3_image_create(self.context,
                                    '155d900f-4e14-4e4c-a73d-069cbf4541e6')

        fake.stub_out_image_service(self.stubs)
        self.image_service = s3.S3ImageService()
Exemple #35
0
    def setUp(self):
        super(TestS3ImageService, self).setUp()
        self.context = context.RequestContext(None, None)
        self.useFixture(fixtures.FakeLogger('boto'))

        # set up one fixture to test shows, should have id '1'
        nova.db.api.s3_image_create(self.context,
                                    '155d900f-4e14-4e4c-a73d-069cbf4541e6')

        fake.stub_out_image_service(self.stubs)
        self.image_service = s3.S3ImageService()
        self.addCleanup(ec2utils.reset_cache)
    def setUp(self):
        super(BlockDeviceMappingTestV21, self).setUp()
        self._setup_controller()
        fake.stub_out_image_service(self.stubs)

        self.bdm = [{
            'no_device': None,
            'source_type': 'volume',
            'destination_type': 'volume',
            'uuid': 'fake',
            'device_name': 'vda',
            'delete_on_termination': False,
        }]
Exemple #37
0
def create_instance(testcase):
    fake.stub_out_image_service(testcase.stubs)
    ctxt = context.get_admin_context()
    instance_type = db.instance_type_get(ctxt, 1)
    sys_meta = flavors.save_flavor_info({}, instance_type)
    return db.instance_create(ctxt,
                    {'user_id': 'fake',
                     'project_id': 'fake',
                     'instance_type_id': 1,
                     'memory_mb': 1024,
                     'vcpus': 2,
                     'image_ref': '155d900f-4e14-4e4c-a73d-069cbf4541e6',
                     'system_metadata': sys_meta})
Exemple #38
0
    def setUp(self):
        super(BlockDeviceMappingTestV21, self).setUp()
        self._setup_controller()
        fake.stub_out_image_service(self.stubs)

        self.bdm = [{
            'no_device': None,
            'source_type': 'volume',
            'destination_type': 'volume',
            'uuid': 'fake',
            'device_name': 'vda',
            'delete_on_termination': False,
        }]
Exemple #39
0
def create_instance(testcase):
    fake.stub_out_image_service(testcase.stubs)
    ctxt = context.get_admin_context()
    instance_type = db.instance_type_get(ctxt, 1)
    sys_meta = flavors.save_instance_type_info({}, instance_type)
    return db.instance_create(ctxt,
                    {'user_id': 'fake',
                     'project_id': 'fake',
                     'instance_type_id': 1,
                     'memory_mb': 1024,
                     'vcpus': 2,
                     'image_ref': '155d900f-4e14-4e4c-a73d-069cbf4541e6',
                     'system_metadata': sys_meta})
Exemple #40
0
    def setUp(self):
        super(AccessIPsExtAPIValidationTest, self).setUp()

        def fake_save(context, **kwargs):
            pass

        def fake_rebuild(*args, **kwargs):
            pass

        ext_info = plugins.LoadedExtensionInfo()
        self.controller = servers.ServersController(extension_info=ext_info)
        fake.stub_out_image_service(self.stubs)
        self.stubs.Set(db, 'instance_get_by_uuid', fakes.fake_instance_get())
        self.stubs.Set(instance_obj.Instance, 'save', fake_save)
        self.stubs.Set(compute_api.API, 'rebuild', fake_rebuild)
Exemple #41
0
    def setUp(self):
        super(AccessIPsExtAPIValidationTest, self).setUp()

        def fake_save(context, **kwargs):
            pass

        def fake_rebuild(*args, **kwargs):
            pass

        ext_info = plugins.LoadedExtensionInfo()
        self.controller = servers.ServersController(extension_info=ext_info)
        fake.stub_out_image_service(self.stubs)
        self.stubs.Set(db, 'instance_get_by_uuid', fakes.fake_instance_get())
        self.stubs.Set(instance_obj.Instance, 'save', fake_save)
        self.stubs.Set(compute_api.API, 'rebuild', fake_rebuild)
Exemple #42
0
 def setUp(self):
     super(VolumeTestCase, self).setUp()
     self.compute = importutils.import_object(FLAGS.compute_manager)
     vol_tmpdir = tempfile.mkdtemp()
     self.flags(compute_driver='nova.virt.fake.FakeDriver',
                volumes_dir=vol_tmpdir,
                notification_driver=[test_notifier.__name__])
     self.stubs.Set(iscsi.TgtAdm, '_get_target', self.fake_get_target)
     self.volume = importutils.import_object(FLAGS.volume_manager)
     self.context = context.get_admin_context()
     instance = db.instance_create(self.context, {})
     self.instance_id = instance['id']
     self.instance_uuid = instance['uuid']
     test_notifier.NOTIFICATIONS = []
     fake_image.stub_out_image_service(self.stubs)
Exemple #43
0
 def setUp(self):
     super(ImageHandlerTestCase, self).setUp()
     self.fake_driver = mock.MagicMock()
     self.context = context.get_admin_context()
     self.image_service = fake_image.stub_out_image_service(self.stubs)
     imagehandler._IMAGE_HANDLERS = []
     imagehandler._IMAGE_HANDLERS_ASSO = {}
Exemple #44
0
    def setUp(self):
        super(TestS3ImageService, self).setUp()
        self.context = context.RequestContext(None, None)
        self.useFixture(fixtures.FakeLogger('boto'))

        # set up 3 fixtures to test shows, should have id '1', '2', and '3'
        db.s3_image_create(self.context,
                           '155d900f-4e14-4e4c-a73d-069cbf4541e6')
        db.s3_image_create(self.context,
                           'a2459075-d96c-40d5-893e-577ff92e721c')
        db.s3_image_create(self.context,
                           '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6')

        fake.stub_out_image_service(self.stubs)
        self.image_service = s3.S3ImageService()
        ec2utils.reset_cache()
Exemple #45
0
def create_instance(testcase):
    fake.stub_out_image_service(testcase.stubs)
    ctxt = context.get_admin_context()
    instance_type = db.flavor_get(ctxt, 1)
    sys_meta = flavors.save_flavor_info({}, instance_type)
    return db.instance_create(
        ctxt,
        {
            "user_id": "fake",
            "project_id": "fake",
            "instance_type_id": 1,
            "memory_mb": 1024,
            "vcpus": 2,
            "image_ref": "155d900f-4e14-4e4c-a73d-069cbf4541e6",
            "system_metadata": sys_meta,
        },
    )
Exemple #46
0
    def setUp(self):
        super(BareMetalTileraTestCase, self).setUp()
        self.flags(**COMMON_FLAGS)
        self.flags(**BAREMETAL_FLAGS)
        self.driver = tilera.Tilera(fake_virt.FakeVirtAPI())

        fake_image.stub_out_image_service(self.stubs)
        self.addCleanup(fake_image.FakeImageService_reset)
        self.context = utils.get_test_admin_context()
        self.test_block_device_info = (None,)
        self.instance = utils.get_test_instance()
        self.test_network_info = utils.get_test_network_info()
        self.node_info = bm_db_utils.new_bm_node(service_host="test_host", cpus=4, memory_mb=2048)
        self.nic_info = [
            {"address": "22:22:22:22:22:22", "datapath_id": "0x1", "port_no": 1},
            {"address": "33:33:33:33:33:33", "datapath_id": "0x2", "port_no": 2},
        ]
 def setUp(self):
     super(BlockDeviceMappingTestV21, self).setUp()
     self._setup_controller()
     fake.stub_out_image_service(self.stubs)
     self.volume_id = fakes.FAKE_UUID
     self.bdm = [{
         'id': 1,
         'no_device': None,
         'virtual_name': None,
         'snapshot_id': None,
         'volume_id': self.volume_id,
         'status': 'active',
         'device_name': 'vda',
         'delete_on_termination': False,
         'volume_image_metadata':
             {'test_key': 'test_value'}
     }]
Exemple #48
0
 def setUp(self):
     super(BlockDeviceMappingTestV21, self).setUp()
     self._setup_controller()
     fake.stub_out_image_service(self.stubs)
     self.volume_id = fakes.FAKE_UUID
     self.bdm = [{
         'id': 1,
         'no_device': None,
         'virtual_name': None,
         'snapshot_id': None,
         'volume_id': self.volume_id,
         'status': 'active',
         'device_name': 'vda',
         'delete_on_termination': False,
         'volume_image_metadata':
             {'test_key': 'test_value'}
     }]
 def setUp(self):
     super(BlockDeviceMappingTestV21, self).setUp()
     self._setup_controller()
     fake.stub_out_image_service(self.stubs)
     self.volume_id = fakes.FAKE_UUID
     self.bdm = [
         {
             "id": 1,
             "no_device": None,
             "virtual_name": None,
             "snapshot_id": None,
             "volume_id": self.volume_id,
             "status": "active",
             "device_name": "vda",
             "delete_on_termination": False,
             "volume_image_metadata": {"test_key": "test_value"},
         }
     ]
    def setUp(self):
        """Shared implementation for tests below that create instance."""
        super(ServersControllerCreateTest, self).setUp()

        self.flags(verbose=True,
                   enable_instance_password=True)
        self.instance_cache_num = 0

        self.ext_mgr = extensions.ExtensionManager()
        self.ext_mgr.extensions = {}
        self.controller = servers.Controller(self.ext_mgr)

        def instance_create(context, inst):
            inst_type = flavors.get_flavor_by_flavor_id(3)
            image_uuid = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6'
            def_image_ref = 'http://localhost/images/%s' % image_uuid
            self.instance_cache_num += 1
            instance = fake_instance.fake_db_instance(**{
                'id': self.instance_cache_num,
                'display_name': inst['display_name'] or 'test',
                'uuid': FAKE_UUID,
                'instance_type': dict(inst_type),
                'access_ip_v4': '1.2.3.4',
                'access_ip_v6': 'fead::1234',
                'image_ref': inst.get('image_ref', def_image_ref),
                'user_id': 'fake',
                'project_id': 'fake',
                'reservation_id': inst['reservation_id'],
                "created_at": datetime.datetime(2010, 10, 10, 12, 0, 0),
                "updated_at": datetime.datetime(2010, 11, 11, 11, 0, 0),
                "progress": 0,
                "fixed_ips": [],
                "task_state": "",
                "vm_state": "",
                "root_device_name": inst.get('root_device_name', 'vda'),
            })
            return instance

        fake.stub_out_image_service(self.stubs)
        self.stubs.Set(db, 'instance_create', instance_create)
Exemple #51
0
    def setUp(self):
        self.flags(**COMMON_FLAGS)
        utils.clear_tables()
        super(BaremetalDriverSpawnTestCase, self).setUp()
        fake_image.stub_out_image_service(self.stubs)

        self.context = test_utils.get_test_admin_context()
        self.instance = test_utils.get_test_instance()
        self.instance['uuid'] = '12345'
        self.network_info = test_utils.get_test_network_info()
        self.block_device_info = None
        self.image_meta = test_utils.get_test_image_info(None, self.instance)
        self.node = _create_baremetal_stuff()
        self.node_id = self.node['id']
        self.driver = bm_driver.BareMetalDriver()
        self.kwargs = dict(context=self.context,
                           instance=self.instance,
                           image_meta=self.image_meta,
                           injected_files=[('/foo', 'bar'), ('/abc', 'xyz')],
                           admin_password='******',
                           network_info=self.network_info,
                           block_device_info=self.block_device_info)
Exemple #52
0
 def setUp(self):
     super(BaremetalDriverTestCase, self).setUp()
     self.flags(baremetal_sql_connection='sqlite:///:memory:',
                host=NODE['service_host'],
                baremetal_driver='nova.virt.baremetal.fake.Fake',
                power_manager='nova.virt.baremetal.ipmi.DummyIpmi',
                baremetal_vif_driver=class_path(FakeVifDriver),
                baremetal_firewall_driver=class_path(FakeFirewallDriver),
                baremetal_volume_driver=class_path(FakeVolumeDriver),
                instance_type_extra_specs=['cpu_arch:test']
                )
     bmdb_utils.clear_tables()
     context = test_utils.get_test_admin_context()
     node = bmdb.bm_node_create(context, NODE)
     self.node_id = node['id']
     for nic in NICS:
         bmdb.bm_interface_create(context,
                                   node['id'],
                                   nic['address'],
                                   nic['datapath_id'],
                                   nic['port_no'])
     fake_image.stub_out_image_service(self.stubs)
    def setUp(self):
        super(BlockDeviceMappingTest, self).setUp()

        ext_info = plugins.LoadedExtensionInfo()
        self.controller = servers.ServersController(extension_info=ext_info)

        CONF.set_override('extensions_blacklist', 'os-block-device-mapping',
                          'osapi_v3')
        self.no_volumes_controller = servers.ServersController(
            extension_info=ext_info)
        CONF.set_override('extensions_blacklist', '', 'osapi_v3')

        fake.stub_out_image_service(self.stubs)

        self.bdm = [{
            'no_device': None,
            'source_type': 'volume',
            'destination_type': 'volume',
            'uuid': 'fake',
            'device_name': 'vda',
            'delete_on_termination': False,
        }]
Exemple #54
0
    def test_unshelve(self):
        db_instance = jsonutils.to_primitive(self._create_fake_instance())
        self.compute.run_instance(self.context, db_instance, {}, {}, [], None,
                                  None, True, None, False)
        instance = instance_obj.Instance.get_by_uuid(
            self.context,
            db_instance['uuid'],
            expected_attrs=['metadata', 'system_metadata'])
        instance.task_state = task_states.UNSHELVING
        instance.save()
        image = {'id': 'fake_id'}
        host = 'fake-mini'
        cur_time = timeutils.utcnow()
        cur_time_tz = cur_time.replace(tzinfo=iso8601.iso8601.Utc())
        timeutils.set_time_override(cur_time)
        sys_meta = dict(instance.system_metadata)
        sys_meta['shelved_at'] = timeutils.strtime(at=cur_time)
        sys_meta['shelved_image_id'] = image['id']
        sys_meta['shelved_host'] = host
        hypervisor_hostname = 'fake_hypervisor_hostname'
        fake_compute_info = {'hypervisor_hostname': hypervisor_hostname}

        self.mox.StubOutWithMock(self.compute, '_notify_about_instance_usage')
        self.mox.StubOutWithMock(self.compute, '_prep_block_device')
        self.mox.StubOutWithMock(self.compute.driver, 'spawn')
        self.mox.StubOutWithMock(self.compute, '_get_power_state')
        self.mox.StubOutWithMock(self.compute, '_get_compute_info')
        self.mox.StubOutWithMock(db, 'instance_update_and_get_original')

        self.deleted_image_id = None

        def fake_delete(self2, ctxt, image_id):
            self.deleted_image_id = image_id

        fake_image.stub_out_image_service(self.stubs)
        self.stubs.Set(fake_image._FakeImageService, 'delete', fake_delete)

        self.compute._notify_about_instance_usage(self.context, instance,
                                                  'unshelve.start')
        self.compute._get_compute_info(
            mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(fake_compute_info)
        db.instance_update_and_get_original(
            self.context,
            instance['uuid'],
            {
                'task_state': task_states.SPAWNING,
                'host': host,
                'node': hypervisor_hostname
            },
            update_cells=False,
            columns_to_join=['metadata', 'system_metadata'],
        ).AndReturn((db_instance, db_instance))
        self.compute._prep_block_device(self.context, instance,
                                        []).AndReturn('fake_bdm')
        db_instance['key_data'] = None
        db_instance['auto_disk_config'] = None
        self.compute.driver.spawn(self.context,
                                  instance,
                                  image,
                                  injected_files=[],
                                  admin_password=None,
                                  network_info=[],
                                  block_device_info='fake_bdm')
        self.compute._get_power_state(self.context, instance).AndReturn(123)
        db.instance_update_and_get_original(
            self.context,
            instance['uuid'], {
                'power_state': 123,
                'vm_state': vm_states.ACTIVE,
                'task_state': None,
                'key_data': None,
                'auto_disk_config': False,
                'expected_task_state': task_states.SPAWNING,
                'launched_at': cur_time_tz
            },
            update_cells=False,
            columns_to_join=['metadata', 'system_metadata']).AndReturn(
                (db_instance, db_instance))
        self.compute._notify_about_instance_usage(self.context, instance,
                                                  'unshelve.end')
        self.mox.ReplayAll()

        self.compute.unshelve_instance(self.context, instance, image=image)
        self.assertEqual(image['id'], self.deleted_image_id)
        self.assertEqual(instance.host, self.compute.host)
Exemple #55
0
 def setUp(self):
     super(ConfigDriveTest, self).setUp()
     fakes.stub_out_networking(self.stubs)
     fakes.stub_out_rate_limiting(self.stubs)
     fake.stub_out_image_service(self.stubs)
Exemple #56
0
 def setUp(self):
     super(ManagedRBDTestCase, self).setUp()
     fake_image.stub_out_image_service(self.stubs)
Exemple #57
0
    def setUp(self):
        """Shared implementation for tests below that create instance."""
        super(ServersControllerCreateTest, self).setUp()

        self.flags(verbose=True, enable_instance_password=True)
        self.instance_cache_num = 0
        self.instance_cache_by_id = {}
        self.instance_cache_by_uuid = {}

        ext_info = plugins.LoadedExtensionInfo()
        self.controller = servers.ServersController(extension_info=ext_info)
        CONF.set_override('extensions_blacklist', 'os-personality', 'osapi_v3')
        self.no_personality_controller = servers.ServersController(
            extension_info=ext_info)

        def instance_create(context, inst):
            inst_type = flavors.get_flavor_by_flavor_id(3)
            image_uuid = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6'
            def_image_ref = 'http://localhost/images/%s' % image_uuid
            self.instance_cache_num += 1
            instance = fake_instance.fake_db_instance(
                **{
                    'id': self.instance_cache_num,
                    'display_name': inst['display_name'] or 'test',
                    'uuid': FAKE_UUID,
                    'instance_type': dict(inst_type),
                    'access_ip_v4': '1.2.3.4',
                    'access_ip_v6': 'fead::1234',
                    'image_ref': inst.get('image_ref', def_image_ref),
                    'user_id': 'fake',
                    'project_id': 'fake',
                    'reservation_id': inst['reservation_id'],
                    "created_at": datetime.datetime(2010, 10, 10, 12, 0, 0),
                    "updated_at": datetime.datetime(2010, 11, 11, 11, 0, 0),
                    "config_drive": None,
                    "progress": 0,
                    "fixed_ips": [],
                    "task_state": "",
                    "vm_state": "",
                    "security_groups": inst['security_groups'],
                })

            self.instance_cache_by_id[instance['id']] = instance
            self.instance_cache_by_uuid[instance['uuid']] = instance
            return instance

        def instance_get(context, instance_id):
            """Stub for compute/api create() pulling in instance after
            scheduling
            """
            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):
            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 queue_get_for(context, *args):
            return 'network_topic'

        fakes.stub_out_rate_limiting(self.stubs)
        fakes.stub_out_key_pair_funcs(self.stubs)
        fake.stub_out_image_service(self.stubs)
        fakes.stub_out_nw_api(self.stubs)
        self.stubs.Set(uuid, 'uuid4', fake_gen_uuid)
        self.stubs.Set(db, 'instance_add_security_group',
                       return_security_group)
        self.stubs.Set(db, 'project_get_networks', project_get_networks)
        self.stubs.Set(db, 'instance_create', instance_create)
        self.stubs.Set(db, 'instance_system_metadata_update', fake_method)
        self.stubs.Set(db, 'instance_get', instance_get)
        self.stubs.Set(db, 'instance_update', instance_update)
        self.stubs.Set(rpc, 'cast', fake_method)
        self.stubs.Set(db, 'instance_update_and_get_original', server_update)
        self.stubs.Set(rpc, 'queue_get_for', queue_get_for)
        self.stubs.Set(manager.VlanManager, 'allocate_fixed_ip', fake_method)

        return_server = fakes.fake_instance_get()
        return_servers = fakes.fake_instance_get_all_by_filters()
        self.stubs.Set(db, 'instance_get_all_by_filters', return_servers)
        self.stubs.Set(db, 'instance_get_by_uuid', return_server)
        self.stubs.Set(db, 'instance_add_security_group',
                       return_security_group)
        self.stubs.Set(db, 'instance_update_and_get_original', instance_update)