Hiding neutron Client class
* This needed to introduce client() method to keep consistency with other OS client services already placed in Savanna * Renamed old Client class to NeutronClientRemoteWrapper * This is needed to fix bug #1277501 Change-Id: I346613d04143ad4a4ce58b9d6de3d464d3cd36ff
This commit is contained in:
parent
4ccf81f3db
commit
63bd15acdf
@ -19,21 +19,21 @@ import unittest2
|
||||
from savanna.utils.openstack import neutron as neutron_client
|
||||
|
||||
|
||||
class NeutronTest(unittest2.TestCase):
|
||||
class NeutronClientRemoteWrapperTest(unittest2.TestCase):
|
||||
@mock.patch("neutronclient.neutron.client.Client")
|
||||
def test_get_router(self, patched):
|
||||
patched.side_effect = _test_get_neutron_client
|
||||
neutron = neutron_client.Client('33b47310-b7a8-4559-bf95-45ba669a448e',
|
||||
None, None, None)
|
||||
neutron = neutron_client.NeutronClientRemoteWrapper(
|
||||
'33b47310-b7a8-4559-bf95-45ba669a448e', None, None, None)
|
||||
self.assertEqual('6c4d4e32-3667-4cd4-84ea-4cc1e98d18be',
|
||||
neutron.get_router())
|
||||
|
||||
|
||||
def _test_get_neutron_client(api_version, *args, **kwargs):
|
||||
return TestNeutron()
|
||||
return FakeNeutronClient()
|
||||
|
||||
|
||||
class TestNeutron():
|
||||
class FakeNeutronClient():
|
||||
def list_routers(self):
|
||||
return {"routers": [{"status": "ACTIVE", "external_gateway_info": {
|
||||
"network_id": "61f95d3f-495e-4409-8c29-0b806283c81e"},
|
||||
|
@ -21,13 +21,27 @@ from neutronclient.neutron import client as neutron_cli
|
||||
import requests
|
||||
from requests import adapters
|
||||
|
||||
from savanna import context
|
||||
from savanna.openstack.common import log as logging
|
||||
from savanna.utils.openstack import base
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Client():
|
||||
def client():
|
||||
ctx = context.ctx()
|
||||
args = {
|
||||
'username': ctx.username,
|
||||
'tenant_name': ctx.tenant_name,
|
||||
'tenant_id': ctx.tenant_id,
|
||||
'token': ctx.token,
|
||||
'endpoint_url': base.url_for(ctx.service_catalog, 'network')
|
||||
}
|
||||
return neutron_cli.Client('2.0', **args)
|
||||
|
||||
|
||||
class NeutronClientRemoteWrapper():
|
||||
neutron = None
|
||||
adapters = {}
|
||||
routers = {}
|
||||
@ -40,7 +54,8 @@ class Client():
|
||||
self.network = network
|
||||
|
||||
def get_router(self):
|
||||
matching_router = Client.routers.get(self.network, None)
|
||||
matching_router = NeutronClientRemoteWrapper.routers.get(self.network,
|
||||
None)
|
||||
if matching_router:
|
||||
LOG.debug('Returning cached qrouter')
|
||||
return matching_router['id']
|
||||
@ -53,7 +68,8 @@ class Client():
|
||||
if port['network_id'] == self.network), None)
|
||||
if port:
|
||||
matching_router = router
|
||||
Client.routers[self.network] = matching_router
|
||||
NeutronClientRemoteWrapper.routers[
|
||||
self.network] = matching_router
|
||||
break
|
||||
|
||||
if not matching_router:
|
||||
|
@ -68,8 +68,10 @@ _global_remote_semaphore = None
|
||||
|
||||
|
||||
def _get_proxy(neutron_info):
|
||||
client = neutron.Client(neutron_info['network'], neutron_info['uri'],
|
||||
neutron_info['token'], neutron_info['tenant'])
|
||||
client = neutron.NeutronClientRemoteWrapper(neutron_info['network'],
|
||||
neutron_info['uri'],
|
||||
neutron_info['token'],
|
||||
neutron_info['tenant'])
|
||||
qrouter = client.get_router()
|
||||
proxy = paramiko.ProxyCommand('ip netns exec qrouter-{0} nc {1} 22'
|
||||
.format(qrouter, neutron_info['host']))
|
||||
@ -147,10 +149,9 @@ def _get_http_client(host, port, neutron_info, *args, **kwargs):
|
||||
_http_session))
|
||||
if not _http_session:
|
||||
if neutron_info:
|
||||
neutron_client = neutron.Client(neutron_info['network'],
|
||||
neutron_info['uri'],
|
||||
neutron_info['token'],
|
||||
neutron_info['tenant'])
|
||||
neutron_client = neutron.NeutronClientRemoteWrapper(
|
||||
neutron_info['network'], neutron_info['uri'],
|
||||
neutron_info['token'], neutron_info['tenant'])
|
||||
# can return a new session here because it actually uses
|
||||
# the same adapter (and same connection pools) for a given
|
||||
# host and port tuple
|
||||
|
Loading…
Reference in New Issue
Block a user