Example #1
0
 def setUp(self):
     super(ServerUsageTest, self).setUp()
     fakes.stub_out_nw_api(self.stubs)
     self.stubs.Set(compute.api.API, 'get', fake_compute_get)
     self.stubs.Set(compute.api.API, 'get_all', fake_compute_get_all)
     return_server = fakes.fake_instance_get()
     self.stubs.Set(db, 'instance_get_by_uuid', return_server)
Example #2
0
    def setUp(self):
        super(ServerActionsControllerTest, self).setUp()

        self.stubs.Set(nova.db, 'instance_get_by_uuid',
                       fakes.fake_instance_get(vm_state=vm_states.ACTIVE,
                                               host='fake_host'))
        self.stubs.Set(nova.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)
        nova.tests.image.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()
Example #3
0
    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)
Example #4
0
    def setUp(self):
        self.maxDiff = None
        super(ServerActionsControllerTest, self).setUp()

        self.stubs = stubout.StubOutForTesting()
        fakes.stub_out_auth(self.stubs)
        self.stubs.Set(nova.db, 'instance_get_by_uuid',
                fakes.fake_instance_get(vm_state=vm_states.ACTIVE,
                        host='fake_host'))
        self.stubs.Set(nova.db, 'instance_update', 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)
        fakes.stub_out_image_service(self.stubs)
        service_class = 'nova.image.glance.GlanceImageService'
        self.service = utils.import_object(service_class)
        self.context = context.RequestContext(1, None)
        self.service.delete_all()
        self.sent_to_glance = {}
        fakes.stub_out_glance_add_image(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()
Example #5
0
    def setUp(self):
        super(ServerPasswordTest, self).setUp()
        fakes.stub_out_nw_api(self.stubs)
        self.stubs.Set(
            compute.api.API, 'get',
            lambda self, ctxt, *a, **kw:
                fake_instance.fake_instance_obj(
                ctxt,
                system_metadata={},
                expected_attrs=['system_metadata']))
        self.password = '******'

        def fake_extract_password(instance):
            return self.password

        def fake_convert_password(context, password):
            self.password = password
            return {}

        self.stubs.Set(password, 'extract_password', fake_extract_password)
        self.stubs.Set(password, 'convert_password', fake_convert_password)
        self.flags(
            osapi_compute_extension=[
                'nova.api.openstack.compute.contrib.select_extensions'],
            osapi_compute_ext_list=['Server_password'])
Example #6
0
 def setUp(self):
     super(FlavorRxtxTestV21, self).setUp()
     ext = "nova.api.openstack.compute.contrib" ".flavor_rxtx.Flavor_rxtx"
     self.flags(osapi_compute_extension=[ext])
     fakes.stub_out_nw_api(self.stubs)
     self.stubs.Set(flavors, "get_all_flavors_sorted_list", fake_get_all_flavors_sorted_list)
     self.stubs.Set(flavors, "get_flavor_by_flavor_id", fake_flavor_get_by_flavor_id)
Example #7
0
 def setUp(self):
     super(FlavorDisabledTest, self).setUp()
     ext = "nova.api.openstack.compute.contrib" ".flavor_disabled.Flavor_disabled"
     self.flags(osapi_compute_extension=[ext])
     fakes.stub_out_nw_api(self.stubs)
     self.stubs.Set(flavors, "get_all_flavors", fake_flavor_get_all)
     self.stubs.Set(flavors, "get_flavor_by_flavor_id", fake_flavor_get_by_flavor_id)
Example #8
0
 def setUp(self):
     super(ExtendedHostIpTest, self).setUp()
     fakes.stub_out_nw_api(self.stubs)
     self.stubs.Set(compute.api.API, 'get', fake_compute_get)
     self.stubs.Set(db, 'compute_node_get_by_host', fake_cn_get)
     self.stubs.Set(db, 'service_get_all_by_host',
                    fake_service_get_all_by_host)
Example #9
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_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(ExtendedServerAttributesTest, self).setUp()
     fakes.stub_out_nw_api(self.stubs)
     self.stubs.Set(compute.api.API, 'get', fake_compute_get)
     self.stubs.Set(compute.api.API, 'get_all', fake_compute_get_all)
     self.stubs.Set(db, 'compute_node_get_by_host', fake_cn_get)
     self.stubs.Set(db, 'compute_node_get_all', fake_compute_node_get_all)
Example #11
0
 def setUp(self):
     super(ExtendedStatusTest, self).setUp()
     fakes.stub_out_nw_api(self.stubs)
     self.stubs.Set(compute.api.API, "get", fake_compute_get)
     self.stubs.Set(compute.api.API, "get_all", fake_compute_get_all)
     return_server = fakes.fake_instance_get()
     self.stubs.Set(db, "instance_get_by_uuid", return_server)
Example #12
0
 def setUp(self):
     super(ExtendedStatusTest, self).setUp()
     self.uuid = '70f6db34-de8d-4fbd-aafb-4065bdfa6114'
     self.url = '/v2/fake/servers/%s' % self.uuid
     fakes.stub_out_nw_api(self.stubs)
     self.flags(allow_admin_api=True)
     self.stubs.Set(compute.api.API, 'routing_get', fake_compute_get)
Example #13
0
    def setUp(self):
        self.maxDiff = None
        super(ServerActionsControllerTest, self).setUp()

        self.stubs = stubout.StubOutForTesting()
        fakes.stub_out_auth(self.stubs)
        self.stubs.Set(nova.db, 'instance_get', return_server_by_id)
        self.stubs.Set(nova.db, 'instance_get_by_uuid', return_server_by_uuid)
        self.stubs.Set(nova.db, 'instance_update', instance_update)

        fakes.stub_out_glance(self.stubs)
        fakes.stub_out_nw_api(self.stubs)
        fakes.stub_out_rate_limiting(self.stubs)
        self.snapshot = fakes.stub_out_compute_api_snapshot(self.stubs)
        self.backup = fakes.stub_out_compute_api_backup(self.stubs)
        service_class = 'nova.image.glance.GlanceImageService'
        self.service = utils.import_object(service_class)
        self.context = context.RequestContext(1, None)
        self.service.delete_all()
        self.sent_to_glance = {}
        fakes.stub_out_glance_add_image(self.stubs, self.sent_to_glance)
        self.flags(allow_instance_snapshots=True)
        self.uuid = FAKE_UUID
        self.url = '/v1.1/fake/servers/%s/action' % self.uuid

        self.controller = servers.Controller()
 def setUp(self):
     super(HideServerAddressesTest, self).setUp()
     fakes.stub_out_nw_api(self.stubs)
     self.flags(
         osapi_compute_extension=[
             'nova.api.openstack.compute.contrib.select_extensions'],
         osapi_compute_ext_list=['Hide_server_addresses'])
Example #15
0
 def setUp(self):
     super(SecurityGroupsOutputTest, self).setUp()
     CONF.set_override("security_group_api", "nova")
     fakes.stub_out_nw_api(self.stubs)
     self.stubs.Set(compute.api.API, "get", fake_compute_get)
     self.stubs.Set(compute.api.API, "get_all", fake_compute_get_all)
     self.stubs.Set(compute.api.API, "create", fake_compute_create)
     self.app = fakes.wsgi_app_v3(init_only=("servers", "os-security-groups"))
 def setUp(self):
     super(ExtendedAvailabilityZoneTest, self).setUp()
     fakes.stub_out_nw_api(self.stubs)
     self.stubs.Set(compute.api.API, 'get', fake_compute_get)
     self.stubs.Set(compute.api.API, 'get_all', fake_compute_get_all)
     self.stubs.Set(db, 'service_get_all', fake_service_get_all)
     self.stubs.Set(db, 'service_get_all_by_host',
                    fake_service_get_all_by_host)
 def setUp(self):
     super(FlavorDisabledTest, self).setUp()
     fakes.stub_out_nw_api(self.stubs)
     self.stubs.Set(flavors, "get_all_flavors",
                    fake_flavor_get_all)
     self.stubs.Set(flavors,
                    "get_flavor_by_flavor_id",
                    fake_flavor_get_by_flavor_id)
Example #18
0
 def setUp(self):
     super(BootFromVolumeTest, self).setUp()
     self.stubs.Set(compute_api.API, 'create', fake_compute_api_create)
     fakes.stub_out_nw_api(self.stubs)
     self.flags(
         osapi_compute_extension=[
             'nova.api.openstack.compute.contrib.select_extensions'],
         osapi_compute_ext_list=['Volumes'])
Example #19
0
 def setUp(self):
     super(SecurityGroupsOutputTest, self).setUp()
     fakes.stub_out_nw_api(self.stubs)
     self.stubs.Set(compute.api.API, 'get', fake_compute_get)
     self.stubs.Set(compute.api.API, 'get_all', fake_compute_get_all)
     self.stubs.Set(compute.api.API, 'create', fake_compute_create)
     self.app = fakes.wsgi_app_v3(init_only=('servers',
                                             'os-security-groups'))
Example #20
0
 def setUp(self):
     super(FlavorRxtxTest, self).setUp()
     fakes.stub_out_nw_api(self.stubs)
     self.stubs.Set(flavors, "get_all_flavors_sorted_list",
                    fake_get_all_flavors_sorted_list)
     self.stubs.Set(flavors,
                    "get_flavor_by_flavor_id",
                    fake_flavor_get_by_flavor_id)
 def setUp(self):
     super(ExtendedServerAttributesTest, self).setUp()
     availability_zones._reset_cache()
     fakes.stub_out_nw_api(self.stubs)
     self.stubs.Set(compute.api.API, 'get', fake_compute_get)
     self.stubs.Set(compute.api.API, 'get_all', fake_compute_get_all)
     self.stubs.Set(availability_zones, 'get_host_availability_zone',
                    fake_get_host_availability_zone)
Example #22
0
 def setUp(self):
     super(ExtendedStatusTestV21, self).setUp()
     fakes.stub_out_nw_api(self.stubs)
     self.stubs.Set(compute.api.API, 'get', fake_compute_get)
     self.stubs.Set(compute.api.API, 'get_all', fake_compute_get_all)
     self._set_flags()
     return_server = fakes.fake_instance_get()
     self.stubs.Set(db, 'instance_get_by_uuid', return_server)
Example #23
0
 def setUp(self):
     super(ExtendedIpsTest, self).setUp()
     fakes.stub_out_nw_api(self.stubs)
     self.stubs.Set(compute.api.API, 'get', fake_compute_get)
     self.stubs.Set(compute.api.API, 'get_all', fake_compute_get_all)
     self.flags(
         osapi_compute_extension=[
             'nova.api.openstack.compute.contrib.select_extensions'],
         osapi_compute_ext_list=['Extended_ips'])
Example #24
0
    def setUp(self):
        super(FlavorDisabledTest, self).setUp()
        fakes.stub_out_nw_api(self.stubs)

        self.stubs.Set(nova.compute.flavors, "get_all_flavors_sorted_list",
                       fake_get_all_flavors_sorted_list)
        self.stubs.Set(nova.compute.flavors,
                       "get_flavor_by_flavor_id",
                       fake_flavor_get_by_flavor_id)
 def setUp(self):
     super(ExtendedServerAttributesTest, self).setUp()
     availability_zones.reset_cache()
     fakes.stub_out_nw_api(self.stubs)
     self.stubs.Set(compute.api.API, "get", fake_compute_get)
     self.stubs.Set(compute.api.API, "get_all", fake_compute_get_all)
     self.stubs.Set(availability_zones, "get_host_availability_zone", fake_get_host_availability_zone)
     return_server = fakes.fake_instance_get()
     self.stubs.Set(db, "instance_get_by_uuid", return_server)
Example #26
0
    def setUp(self):
        super(FlavorDisabledTest, self).setUp()
        fakes.stub_out_nw_api(self.stubs)

        # def fake_flavor_get_all(*args, **kwargs):
        #    return FAKE_FLAVORS
        #
        self.stubs.Set(nova.compute.flavors, "get_all_flavors_sorted_list", fake_get_all_flavors_sorted_list)
        self.stubs.Set(nova.compute.flavors, "get_flavor_by_flavor_id", fake_flavor_get_by_flavor_id)
 def setUp(self):
     super(HideServerAddressesTest, self).setUp()
     fakes.stub_out_nw_api(self.stubs)
     self.flags(
         osapi_compute_extension=[
             'nova.api.openstack.compute.contrib.select_extensions'],
         osapi_compute_ext_list=['Hide_server_addresses'])
     return_server = fakes.fake_instance_get()
     self.stubs.Set(db, 'instance_get_by_uuid', return_server)
Example #28
0
 def setUp(self):
     super(ExtendedStatusTest, self).setUp()
     fakes.stub_out_nw_api(self.stubs)
     self.stubs.Set(compute.api.API, "get", fake_compute_get)
     self.stubs.Set(compute.api.API, "get_all", fake_compute_get_all)
     self.flags(
         osapi_compute_extension=["nova.api.openstack.compute.contrib.select_extensions"],
         osapi_compute_ext_list=["Extended_status"],
     )
 def setUp(self):
     super(ExtendedAvailabilityZoneTestV21, self).setUp()
     availability_zones.reset_cache()
     fakes.stub_out_nw_api(self.stubs)
     self.stubs.Set(compute.api.API, 'get', fake_compute_get)
     self.stubs.Set(compute.api.API, 'get_all', fake_compute_get_all)
     self.stubs.Set(availability_zones, 'get_host_availability_zone',
                    fake_get_host_availability_zone)
     return_server = fakes.fake_instance_get()
     self.stubs.Set(db, 'instance_get_by_uuid', return_server)
 def setUp(self):
     super(ExtendedServerAttributesTest, self).setUp()
     fakes.stub_out_nw_api(self.stubs)
     self.stubs.Set(compute.api.API, 'get', fake_compute_get)
     self.stubs.Set(compute.api.API, 'get_all', fake_compute_get_all)
     self.stubs.Set(db, 'compute_node_get_by_host', fake_cn_get)
     self.flags(
         osapi_compute_extension=[
             'nova.api.openstack.compute.contrib.select_extensions'],
         osapi_compute_ext_list=['Extended_server_attributes'])
Example #31
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-scheduler-hints',
                          'osapi_v3')
        self.no_scheduler_hints_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 = {
                '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": "",
            }

            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 rpc_call_wrapper(context, topic, msg, timeout=None):
            """Stub out the scheduler creating the instance entry."""
            if (topic == CONF.scheduler_topic
                    and msg['method'] == 'run_instance'):
                request_spec = msg['args']['request_spec']
                num_instances = request_spec.get('num_instances', 1)
                instances = []
                for x in xrange(num_instances):
                    instances.append(
                        instance_create(context,
                                        request_spec['instance_properties']))
                return instances

        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(rpc, 'call', rpc_call_wrapper)
        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)
Example #32
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-availability-zone',
                          'osapi_v3')
        self.no_availability_zone_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',
                    availability_zone.ATTRIBUTE_NAME: None,
                    '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'),
                })

            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)
Example #33
0
    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(nova.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(nova.db, 'instance_get_by_uuid',
                       fake_instance_get_by_uuid)

        def fake_instance_get_all(context, *args, **kwargs):
            return FAKE_INSTANCES

        self.stubs.Set(nova.db, 'instance_get_all', fake_instance_get_all)
        self.stubs.Set(nova.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(nova.db, 'instance_get',
                           fake_instance_get_for_create)
            self.stubs.Set(nova.db, 'instance_update',
                           fake_instance_get_for_create)

            def fake_instance_get_all_for_create(context, *args, **kwargs):
                return [inst]

            self.stubs.Set(nova.db, 'instance_get_all',
                           fake_instance_get_all_for_create)
            self.stubs.Set(nova.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(nova.db, 'instance_add_security_group',
                           fake_instance_add_security_group)

            return inst

        self.stubs.Set(nova.db, 'instance_create', fake_instance_create)

        app = v2.APIRouter()
        app = extensions.ExtensionMiddleware(app)
        app = wsgi.LazySerializationMiddleware(app)
        self.app = app
    def setUp(self):
        super(DiskConfigTestCase, self).setUp()
        self.flags(verbose=True,
                   osapi_compute_extension=[
                       'nova.api.openstack.compute.contrib.select_extensions'
                   ],
                   osapi_compute_ext_list=['Disk_config'])
        self._setup_fake_image_service()

        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(db, 'instance_get', fake_instance_get)

        def fake_instance_get_by_uuid(context,
                                      uuid,
                                      columns_to_join=None,
                                      use_subordinate=False):
            for instance in FAKE_INSTANCES:
                if uuid == instance['uuid']:
                    return instance

        self.stubs.Set(db, 'instance_get_by_uuid', fake_instance_get_by_uuid)

        def fake_instance_get_all(context, *args, **kwargs):
            return FAKE_INSTANCES

        self.stubs.Set(db, 'instance_get_all', fake_instance_get_all)
        self.stubs.Set(db, 'instance_get_all_by_filters',
                       fake_instance_get_all)

        def fake_instance_create(context, inst_, session=None):
            inst = fake_instance.fake_db_instance(
                **{
                    'id': 1,
                    'uuid': AUTO_INSTANCE_UUID,
                    'created_at': datetime.datetime(2010, 10, 10, 12, 0, 0),
                    'updated_at': datetime.datetime(2010, 10, 10, 12, 0, 0),
                    'progress': 0,
                    'name': 'instance-1',  # this is a property
                    'task_state': '',
                    'vm_state': '',
                    'auto_disk_config': inst_['auto_disk_config'],
                    'security_groups': inst_['security_groups'],
                })

            def fake_instance_get_for_create(context, id_, *args, **kwargs):
                return (inst, inst)

            self.stubs.Set(db, 'instance_update_and_get_original',
                           fake_instance_get_for_create)

            def fake_instance_get_all_for_create(context, *args, **kwargs):
                return [inst]

            self.stubs.Set(db, 'instance_get_all',
                           fake_instance_get_all_for_create)
            self.stubs.Set(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(db, 'instance_add_security_group',
                           fake_instance_add_security_group)

            return inst

        self.stubs.Set(db, 'instance_create', fake_instance_create)

        self.app = compute.APIRouter(init_only=('servers', 'images'))
Example #35
0
 def setUp(self):
     super(ExtendedStatusTest, self).setUp()
     fakes.stub_out_nw_api(self.stubs)
     self.stubs.Set(compute.api.API, 'get', fake_compute_get)
     self.stubs.Set(compute.api.API, 'get_all', fake_compute_get_all)
     self.stubs.Set(db, 'instance_get_by_uuid', fake_compute_get)