예제 #1
0
    def test_no_auth_obj(self):
        mock_client_loader = self.mock_object(
            neutron_api.client_auth, 'AuthClientLoader')
        fake_context = 'fake_context'
        data = {
            'neutron': {
                'endpoint_type': 'foo_endpoint_type',
                'region_name': 'foo_region_name',
            }
        }

        self.client = None
        with test_utils.create_temp_config_with_opts(data):
            self.client = neutron_api.API()
            self.client.get_client(fake_context)

        mock_client_loader.assert_called_once_with(
            client_class=neutron_api.clientv20.Client,
            exception_module=neutron_api.neutron_client_exc,
            cfg_group=neutron_api.NEUTRON_GROUP
        )
        mock_client_loader.return_value.get_client.assert_called_once_with(
            self.client,
            fake_context,
            endpoint_type=data['neutron']['endpoint_type'],
            region_name=data['neutron']['region_name'],
        )
예제 #2
0
 def setUp(self):
     super(NeutronApiTest, self).setUp()
     self.context = context.get_admin_context()
     self.mock_object(base, 'Base', fakes.FakeModel)
     self.mock_object(
         clientv20, 'Client', mock.Mock(return_value=FakeNeutronClient()))
     self.neutron_api = neutron_api.API()
예제 #3
0
    def test_create_api_object(self):
        # instantiate Neutron API object
        neutron_api_instance = neutron_api.API()

        # Verify results
        self.assertTrue(hasattr(neutron_api_instance, 'client'))
        self.assertTrue(hasattr(neutron_api_instance, 'configuration'))
        self.assertEqual('DEFAULT', neutron_api_instance.config_group_name)
예제 #4
0
    def test_create_api_object(self):
        # instantiate Neutron API object
        neutron_api_instance = neutron_api.API()

        # Verify results
        self.assertTrue(clientv20.Client.called)
        self.assertTrue(hasattr(neutron_api_instance, 'client'))
        self.assertTrue(hasattr(neutron_api_instance, 'configuration'))
예제 #5
0
    def test_create_api_object_custom_config_group(self):
        # Set up test data
        fake_config_group_name = 'fake_config_group_name'

        # instantiate Neutron API object
        obj = neutron_api.API(fake_config_group_name)

        # Verify results
        self.assertTrue(clientv20.Client.called)
        self.assertTrue(hasattr(obj, 'client'))
        self.assertTrue(hasattr(obj, 'configuration'))
        self.assertEqual(fake_config_group_name, obj.configuration._group.name)
예제 #6
0
    def _update_port_host_id(port_id, host_id):
        from manila import exception
        from manila.network.neutron import api as neutron_api
        from neutronclient.common import exceptions as neutron_client_exc

        try:
            port_req_body = {'port': {'binding:host_id': host_id}}
            port = neutron_api.API().client.update_port(
                port_id, port_req_body).get('port', {})
            return port
        except neutron_client_exc.NeutronClientException as e:
            raise exception.NetworkException(code=e.status_code,
                                             message=e.message)
예제 #7
0
    def __init__(self, service_instance_manager):
        self.get_config_option = service_instance_manager.get_config_option
        self.vif_driver = importutils.import_class(
            self.get_config_option("interface_driver"))()

        if service_instance_manager.driver_config:
            network_config_group = (
                service_instance_manager.driver_config.network_config_group
                or service_instance_manager.driver_config.config_group)
        else:
            network_config_group = None

        self.neutron_api = neutron.API(config_group_name=network_config_group)
        self.service_network_id = self.get_service_network_id()
        self.connect_share_server_to_tenant_network = (
            self.get_config_option('connect_share_server_to_tenant_network'))
예제 #8
0
    def test_with_auth_obj(self):
        fake_context = 'fake_context'
        data = {
            'neutron': {
                'endpoint_type': 'foo_endpoint_type',
                'region_name': 'foo_region_name',
            }
        }

        self.client = None
        with test_utils.create_temp_config_with_opts(data):
            self.client = neutron_api.API()
            self.client.auth_obj = type(
                'FakeAuthObj', (object, ), {'get_client': mock.Mock()})
            self.client.get_client(fake_context)

        self.client.auth_obj.get_client.assert_called_once_with(
            self.client,
            fake_context,
            endpoint_type=data['neutron']['endpoint_type'],
            region_name=data['neutron']['region_name'],
        )
예제 #9
0
    def test_no_auth_obj(self):
        mock_client_loader = self.mock_object(neutron_api.client_auth,
                                              'AuthClientLoader')
        fake_context = 'fake_context'
        data = {
            'DEFAULT': {
                'neutron_admin_username': '******',
                'neutron_admin_password': '******',
                'neutron_admin_tenant_name': 'foo_tenant_name',
                'neutron_admin_auth_url': 'foo_auth_url',
            },
            'neutron': {
                'endpoint_type': 'foo_endpoint_type',
                'region_name': 'foo_region_name',
            }
        }

        self.client = None
        with test_utils.create_temp_config_with_opts(data):
            self.client = neutron_api.API()
            self.client.get_client(fake_context)

        mock_client_loader.assert_called_once_with(
            client_class=neutron_api.clientv20.Client,
            exception_module=neutron_api.neutron_client_exc,
            cfg_group=neutron_api.NEUTRON_GROUP,
            deprecated_opts_for_v2={
                'username': data['DEFAULT']['neutron_admin_username'],
                'password': data['DEFAULT']['neutron_admin_password'],
                'tenant_name': data['DEFAULT']['neutron_admin_tenant_name'],
                'auth_url': data['DEFAULT']['neutron_admin_auth_url'],
            },
        )
        mock_client_loader.return_value.get_client.assert_called_once_with(
            self.client,
            fake_context,
            endpoint_type=data['neutron']['endpoint_type'],
            region_name=data['neutron']['region_name'],
        )
예제 #10
0
 def __init__(self, db, _helpers, *args, **kwargs):
     """Do initialization."""
     super(ServiceInstanceManager, self).__init__()
     self.driver_config = None
     if "driver_config" in kwargs:
         self.driver_config = kwargs["driver_config"]
     if not self.get_config_option("service_instance_user"):
         raise exception.ServiceInstanceException(
             _('Service instance user '
               'is not specified'))
     self.admin_context = context.get_admin_context()
     self._execute = utils.execute
     self.compute_api = compute.API()
     self.neutron_api = neutron.API()
     self._helpers = _helpers
     self.db = db
     attempts = 5
     while attempts:
         try:
             self.service_tenant_id = self.neutron_api.admin_tenant_id
             break
         except exception.NetworkException:
             LOG.debug('Connection to neutron failed.')
             attempts -= 1
             time.sleep(3)
     else:
         raise exception.ServiceInstanceException(
             _('Can not receive '
               'service tenant id.'))
     self.share_networks_servers = {}
     self.service_network_id = self._get_service_network()
     self.vif_driver = importutils.import_class(
         self.get_config_option("interface_driver"))()
     self._setup_connectivity_with_service_instances()
     self.max_time_to_build_instance = self.get_config_option(
         "max_time_to_build_instance")
     self.path_to_private_key = self.get_config_option(
         "path_to_private_key")
     self.path_to_public_key = self.get_config_option("path_to_public_key")
예제 #11
0
 def neutron_api(self):
     if not self._neutron_api:
         self._neutron_api = neutron.API(
             config_group_name=self._network_config_group)
     return self._neutron_api
예제 #12
0
 def neutron_api(self):
     if not self._neutron_api:
         self._neutron_api = neutron_api.API(*self._neutron_api_args,
                                             **self._neutron_api_kwargs)
     return self._neutron_api
예제 #13
0
 def __init__(self, *args, **kwargs):
     db_driver = kwargs.pop('db_driver', None)
     super(NeutronNetworkPlugin, self).__init__(db_driver=db_driver)
     self.neutron_api = neutron_api.API(*args, **kwargs)
 def __init__(self):
     super(NeutronNetworkPlugin, self).__init__()
     self.neutron_api = neutron_api.API()
예제 #15
0
 def test_create_api_object(self):
     with mock.patch.object(base.Base, '__init__', mock.Mock()):
         neutron_api_obj = neutron_api.API()
         base.Base.__init__.assert_called_once()
         neutron.get_client.assert_called_once_with('context')
예제 #16
0
 def _create_neutron_api(self):
     self.neutron_api = neutron_api.API()