Beispiel #1
0
 def test_show_with_details_information_non_existing_instance(self):
     req = self._get_request('/v2/fake/servers/%s' % NON_EXISTING_UUID,
                             'GET')
     ext_info = extension_info.LoadedExtensionInfo()
     servers_controller = servers.ServersController(extension_info=ext_info)
     self.assertRaises(exc.HTTPNotFound, servers_controller.show, req,
                       NON_EXISTING_UUID)
Beispiel #2
0
    def test_create_instance_decide_format_legacy(self):
        ext_info = extension_info.LoadedExtensionInfo()
        CONF.set_override(
            'extensions_blacklist',
            ['os-block-device-mapping', 'os-block-device-mapping-v1'],
            'osapi_v21')
        controller = servers_v21.ServersController(extension_info=ext_info)
        bdm = [{
            'device_name': 'foo1',
            'volume_id': fakes.FAKE_UUID,
            'delete_on_termination': True
        }]

        expected_legacy_flag = True

        old_create = compute_api.API.create

        def create(*args, **kwargs):
            legacy_bdm = kwargs.get('legacy_bdm', True)
            self.assertEqual(legacy_bdm, expected_legacy_flag)
            return old_create(*args, **kwargs)

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

        self.stubs.Set(compute_api.API, 'create', create)
        self.stubs.Set(compute_api.API, '_validate_bdm', _validate_bdm)

        self._test_create({}, override_controller=controller)

        params = {'block_device_mapping': bdm}
        self._test_create(params, override_controller=controller)
Beispiel #3
0
 def __init__(self, init_only=None):
     LOG.warning(_LW(
         "Deprecated: The v3 API was deprecated. The v2.1 API replaces it "
         "as the Nova API, please refer Nova api-paste.ini sample file for "
         "how to configure v2.1 API."))
     self._loaded_extension_info = extension_info.LoadedExtensionInfo()
     super(APIRouterV3, self).__init__(init_only, v3mode=True)
Beispiel #4
0
    def setUp(self):
        """Shared implementation for tests below that create instance."""
        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 = {}

        # Network API needs to be stubbed out before creating the controllers.
        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
            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,
                          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('')
Beispiel #5
0
 def _set_up_controller(self):
     ext_info = extension_info.LoadedExtensionInfo()
     self.controller = servers_v21.ServersController(
         extension_info=ext_info)
     CONF.set_override('extensions_blacklist', 'os-availability-zone',
                       'osapi_v21')
     self.no_availability_zone_controller = servers_v21.ServersController(
         extension_info=ext_info)
 def setUp(self):
     super(ExtensionInfoV21Test, self).setUp()
     ext_info = extension_info.LoadedExtensionInfo()
     ext_info.extensions = simulated_extension_list
     self.controller = extension_info.ExtensionInfoController(ext_info)
     patcher = mock.patch.object(policy, 'authorize', return_value=True)
     patcher.start()
     self.addCleanup(patcher.stop)
Beispiel #7
0
 def _set_up_controller(self):
     ext_info = extension_info.LoadedExtensionInfo()
     self.controller = servers_v21.ServersController(
         extension_info=ext_info)
     CONF.set_override('extensions_blacklist', 'os-config-drive',
                       'osapi_v21')
     self.no_config_drive_controller = servers_v21.ServersController(
         extension_info=ext_info)
Beispiel #8
0
 def _setup_controller(self):
     ext_info = extension_info.LoadedExtensionInfo()
     self.controller = servers_v21.ServersController(
         extension_info=ext_info)
     CONF.set_override('extensions_blacklist', 'os-block-device-mapping',
                       'osapi_v21')
     self.no_bdm_v2_controller = servers_v21.ServersController(
         extension_info=ext_info)
     CONF.set_override('extensions_blacklist', '', 'osapi_v21')
 def setUp(self):
     super(ServerStartStopPolicyEnforcementV21, self).setUp()
     ext_info = extension_info.LoadedExtensionInfo()
     self.controller = server_v21.ServersController(
                       extension_info=ext_info)
     self.req = fakes.HTTPRequest.blank('')
     self.stub_out(
         'nova.db.instance_get_by_uuid',
         fakes.fake_instance_get(
             project_id=self.req.environ['nova.context'].project_id))
Beispiel #10
0
    def __init__(self):
        self._loaded_extension_info = extension_info.LoadedExtensionInfo()
        super(APIRouterV21, self).__init__()

        for path, methods in ROUTE_LIST:
            for method, controller_info in methods.items():
                # TODO(alex_xu): In the end, I want to create single controller
                # instance instead of create controller instance for each
                # route.
                controller = controller_info[0]()
                action = controller_info[1]
                self.map.create_route(path, method, controller, action)
Beispiel #11
0
 def test_create_instance_both_bdm_formats(self):
     ext_info = extension_info.LoadedExtensionInfo()
     CONF.set_override('extensions_blacklist', '', 'osapi_v21')
     both_controllers = servers_v21.ServersController(
             extension_info=ext_info)
     bdm = [{'device_name': 'foo'}]
     bdm_v2 = [{'source_type': 'volume',
                'uuid': 'fake_vol'}]
     params = {'block_device_mapping': bdm,
               'block_device_mapping_v2': bdm_v2}
     self.assertRaises(exc.HTTPBadRequest, self._test_create, params,
                       override_controller=both_controllers)
Beispiel #12
0
    def __init__(self):
        self._loaded_extension_info = extension_info.LoadedExtensionInfo()
        super(APIRouterV21, self).__init__()

        for path, methods in ROUTE_LIST:
            # NOTE(alex_xu): The variable 'methods' is a dict in normal, since
            # the dict includes all the methods supported in the path. But
            # if the variable 'method' is a string, it means a redirection.
            # For example, the request to the '' will be redirect to the '/' in
            # the Nova API. To indicate that, using the target path instead of
            # a dict. The route entry just writes as "('', '/)".
            if isinstance(methods, str):
                self.map.redirect(path, methods)
                continue

            for method, controller_info in methods.items():
                # TODO(alex_xu): In the end, I want to create single controller
                # instance instead of create controller instance for each
                # route.
                controller = controller_info[0]()
                action = controller_info[1]
                self.map.create_route(path, method, controller, action)
 def _set_up_controller(self):
     ext_info = extension_info.LoadedExtensionInfo()
     CONF.set_override('extensions_blacklist', 'os-scheduler-hints',
                       'osapi_v21')
     self.no_scheduler_hints_controller = servers_v21.ServersController(
         extension_info=ext_info)
Beispiel #14
0
 def setUp(self):
     super(ExtensionInfoV21Test, self).setUp()
     ext_info = extension_info.LoadedExtensionInfo()
     ext_info.extensions = simulated_extension_list
     self.controller = extension_info.ExtensionInfoController(ext_info)
     self.stubs.Set(policy, 'enforce', fake_policy_enforce)
Beispiel #15
0
 def _get_controller(self):
     ext_info = extension_info.LoadedExtensionInfo()
     return self.servers.ServersController(extension_info=ext_info)
Beispiel #16
0
 def setUp(self):
     super(ExtensionInfoPolicyEnforcementV21, self).setUp()
     ext_info = extension_info.LoadedExtensionInfo()
     ext_info.extensions = fake_extensions
     self.controller = extension_info.ExtensionInfoController(ext_info)
     self.req = fakes.HTTPRequest.blank('')
 def _setup(self):
     ext_info = extension_info.LoadedExtensionInfo()
     self.controller = quota_classes_v21.QuotaClassSetsController(
         extension_info=ext_info)
    def setUp(self):
        """Shared implementation for tests below that create instance."""
        super(MultiCreateExtensionTestV21, 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 = extension_info.LoadedExtensionInfo()
        self.controller = servers_v21.ServersController(
            extension_info=ext_info)
        CONF.set_override('extensions_blacklist', 'os-multiple-create',
                          'osapi_v21')
        self.no_mult_create_controller = servers_v21.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': inst['uuid'],
                'instance_type': 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": "",
                "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,
                          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')

        fakes.stub_out_rate_limiting(self.stubs)
        fakes.stub_out_key_pair_funcs(self.stubs)
        fake.stub_out_image_service(self)
        fakes.stub_out_nw_api(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.db.instance_create', instance_create)
        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.stubs.Set(manager.VlanManager, 'allocate_fixed_ip',
                       fake_method)
        self.req = fakes.HTTPRequest.blank('')
Beispiel #19
0
 def test_check_bad_extension(self):
     loaded_ext_info = extension_info.LoadedExtensionInfo()
     self.assertFalse(loaded_ext_info._check_extension(fake_bad_extension))
Beispiel #20
0
 def __init__(self):
     self._loaded_extension_info = extension_info.LoadedExtensionInfo()
     super(APIRouterV21, self).__init__()
Beispiel #21
0
 def __init__(self, init_only=None):
     self._loaded_extension_info = extension_info.LoadedExtensionInfo()
     super(APIRouterV3, self).__init__(init_only, v3mode=True)
 def _setup_controller(self):
     ext_info = extension_info.LoadedExtensionInfo()
     self.controller = server_v21.ServersController(extension_info=ext_info)
Beispiel #23
0
 def setUp(self):
     super(ExtensionInfoTest, self).setUp()
     ext_info = extension_info.LoadedExtensionInfo()
     ext_info.extensions = fake_extensions
     self.controller = extension_info.ExtensionInfoController(ext_info)
    def setUp(self):
        """Shared implementation for tests below that create instance."""
        super(ServersControllerCreateTest, 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 = {}

        # Network API needs to be stubbed out before creating the controllers.
        fakes.stub_out_nw_api(self)

        ext_info = extension_info.LoadedExtensionInfo()
        self.controller = servers.ServersController(extension_info=ext_info)
        CONF.set_override('extensions_blacklist', 'os-user-data', 'osapi_v21')
        self.no_user_data_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': 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),
                    user_data.ATTRIBUTE_NAME: None,
                    "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')

        fakes.stub_out_key_pair_funcs(self)
        fake.stub_out_image_service(self)

        self.stubs.Set(uuid, 'uuid4', fake_gen_uuid)
        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.db.instance_create', instance_create)
        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.stubs.Set(manager.VlanManager, 'allocate_fixed_ip', fake_method)
 def setUp(self):
     super(QuotaClassesPolicyEnforcementV21, self).setUp()
     ext_info = extension_info.LoadedExtensionInfo()
     self.controller = quota_classes_v21.QuotaClassSetsController(
         extension_info=ext_info)
     self.req = fakes.HTTPRequest.blank('')