Merge "Replaces neutronclient's initialisation with keystoneauth"
This commit is contained in:
commit
7efd098dc6
|
@ -14,6 +14,7 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from keystoneauth1 import loading as ks_loading
|
||||
from oslo_config import cfg
|
||||
|
||||
from hyperv.common.i18n import _
|
||||
|
@ -154,6 +155,8 @@ def register_opts():
|
|||
|
||||
CONF.register_group(NEUTRON_GROUP)
|
||||
CONF.register_opts(NEUTRON_OPTS, group=NEUTRON_GROUP_NAME)
|
||||
ks_loading.register_session_conf_options(CONF, NEUTRON_GROUP)
|
||||
ks_loading.register_auth_conf_options(CONF, NEUTRON_GROUP)
|
||||
|
||||
CONF.register_group(HNV_GROUP)
|
||||
CONF.register_opts(HNV_OPTS, group=HNV_GROUP_NAME)
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from keystoneauth1 import loading as ks_loading
|
||||
from neutronclient.v2_0 import client as clientv20
|
||||
from oslo_log import log as logging
|
||||
|
||||
|
@ -30,19 +31,14 @@ class NeutronAPIClient(object):
|
|||
self._init_client()
|
||||
|
||||
def _init_client(self):
|
||||
params = {
|
||||
'endpoint_url': CONF.neutron.url,
|
||||
'timeout': CONF.neutron.url_timeout,
|
||||
'insecure': True,
|
||||
'ca_cert': None,
|
||||
'username': CONF.neutron.admin_username,
|
||||
'tenant_name': CONF.neutron.admin_tenant_name,
|
||||
'password': CONF.neutron.admin_password,
|
||||
'auth_url': CONF.neutron.admin_auth_url,
|
||||
'auth_strategy': CONF.neutron.auth_strategy
|
||||
}
|
||||
session = ks_loading.load_session_from_conf_options(
|
||||
CONF, config.NEUTRON_GROUP)
|
||||
auth_plugin = ks_loading.load_auth_from_conf_options(
|
||||
CONF, config.NEUTRON_GROUP)
|
||||
|
||||
self._client = clientv20.Client(**params)
|
||||
self._client = clientv20.Client(
|
||||
session=session,
|
||||
auth=auth_plugin)
|
||||
|
||||
def get_network_subnets(self, network_id):
|
||||
try:
|
||||
|
|
|
@ -25,8 +25,9 @@ from hyperv.tests import base
|
|||
|
||||
class TestConfig(base.HyperVBaseTestCase):
|
||||
|
||||
@mock.patch.object(config, 'ks_loading')
|
||||
@mock.patch.object(config, 'CONF')
|
||||
def test_register_opts(self, mock_CONF):
|
||||
def test_register_opts(self, mock_CONF, mock_ks_loading):
|
||||
config.register_opts()
|
||||
|
||||
all_groups = [config.HYPERV_AGENT_GROUP, config.NVGRE_GROUP,
|
||||
|
@ -41,3 +42,8 @@ class TestConfig(base.HyperVBaseTestCase):
|
|||
(config.HNV_OPTS, config.HNV_GROUP_NAME)]
|
||||
mock_CONF.register_opts.assert_has_calls([
|
||||
mock.call(opts, group=group) for opts, group in all_opts])
|
||||
|
||||
mock_ks_loading.register_session_conf_options.assert_called_once_with(
|
||||
mock_CONF, config.NEUTRON_GROUP)
|
||||
mock_ks_loading.register_auth_conf_options.assert_called_once_with(
|
||||
mock_CONF, config.NEUTRON_GROUP)
|
||||
|
|
|
@ -39,20 +39,20 @@ class TestNeutronClient(base.BaseTestCase):
|
|||
self._neutron._client = mock.MagicMock()
|
||||
|
||||
@mock.patch.object(neutron_client.clientv20, "Client")
|
||||
def test_init_client(self, mock_client):
|
||||
@mock.patch.object(neutron_client, "ks_loading")
|
||||
def test_init_client(self, mock_ks_loading, mock_client):
|
||||
self._neutron._init_client()
|
||||
|
||||
self.assertEqual(mock_client.return_value, self._neutron._client)
|
||||
mock_ks_loading.load_session_from_conf_options.assert_called_once_with(
|
||||
CONF, config.NEUTRON_GROUP)
|
||||
mock_ks_loading.load_auth_from_conf_options.assert_called_once_with(
|
||||
CONF, config.NEUTRON_GROUP)
|
||||
session = mock_ks_loading.load_session_from_conf_options.return_value
|
||||
plugin = mock_ks_loading.load_auth_from_conf_options.return_value
|
||||
mock_client.assert_called_once_with(
|
||||
endpoint_url=CONF.neutron.url,
|
||||
timeout=CONF.neutron.url_timeout,
|
||||
insecure=True,
|
||||
ca_cert=None,
|
||||
username=CONF.neutron.admin_username,
|
||||
tenant_name=CONF.neutron.admin_tenant_name,
|
||||
password=CONF.neutron.admin_password,
|
||||
auth_url=CONF.neutron.admin_auth_url,
|
||||
auth_strategy=CONF.neutron.auth_strategy)
|
||||
session=session,
|
||||
auth=plugin)
|
||||
|
||||
def test_get_network_subnets(self):
|
||||
self._neutron._client.show_network.return_value = {
|
||||
|
|
Loading…
Reference in New Issue