Add service name conf option for neutron and nova

This will be especially used in testing environments where there are multiple
nova and neutron services in the same region.

Change-Id: I4ff2ce0143d66f857629e3220952552a3d0fc632
Closes-Bug: 1539440
changes/28/273928/1
Brandon Logan 7 years ago
parent 6d7bb98a50
commit 4c96356030
  1. 8
      etc/octavia.conf
  2. 20
      octavia/common/clients.py
  3. 13
      octavia/common/config.py
  4. 2
      octavia/network/drivers/neutron/allowed_address_pairs.py
  5. 2
      octavia/network/drivers/neutron/base.py
  6. 4
      octavia/tests/unit/common/test_clients.py

@ -203,3 +203,11 @@
# Amphora MASTER gratuitous ARP refresh settings
# vrrp_garp_refresh_interval = 5
# vrrp_garp_refresh_count = 2
[nova]
# The name of the nova service in the keystone catalog
# service_name =
[neutron]
# The name of the neutron service in the keystone catalog
# service_name =

@ -27,18 +27,22 @@ class NovaAuth(object):
nova_client = None
@classmethod
def get_nova_client(cls, region):
def get_nova_client(cls, region, service_name=None):
"""Create nova client object.
:param region: The region of the service
:param service_name: The name of the nova service in the catalog
:return: a Nova Client object.
:raises Exception: if the client cannot be created
"""
if not cls.nova_client:
kwargs = {'region_name': region,
'session': keystone.get_session()}
if service_name:
kwargs['service_name'] = service_name
try:
cls.nova_client = nova_client.Client(
NOVA_VERSION, session=keystone.get_session(),
region_name=region
NOVA_VERSION, **kwargs
)
except Exception:
with excutils.save_and_reraise_exception():
@ -50,18 +54,22 @@ class NeutronAuth(object):
neutron_client = None
@classmethod
def get_neutron_client(cls, region):
def get_neutron_client(cls, region, service_name=None):
"""Create neutron client object.
:param region: The region of the service
:param service_name: The name of the neutron service in the catalog
:return: a Neutron Client object.
:raises Exception: if the client cannot be created
"""
if not cls.neutron_client:
kwargs = {'region_name': region,
'session': keystone.get_session()}
if service_name:
kwargs['service_name'] = service_name
try:
cls.neutron_client = neutron_client.Client(
NEUTRON_VERSION, session=keystone.get_session(),
region_name=region
NEUTRON_VERSION, **kwargs
)
except Exception:
with excutils.save_and_reraise_exception():

@ -342,6 +342,17 @@ keepalived_vrrp_opts = [
]
nova_opts = [
cfg.StrOpt('service_name',
help=_('The name of the nova service in the keystone catalog'))
]
neutron_opts = [
cfg.StrOpt('service_name',
help=_('The name of the neutron service in the '
'keystone catalog'))
]
# Register the configuration options
cfg.CONF.register_opts(core_opts)
cfg.CONF.register_opts(amphora_agent_opts, group='amphora_agent')
@ -360,6 +371,8 @@ cfg.CONF.register_cli_opts(healthmanager_opts, group='health_manager')
cfg.CONF.import_group('keystone_authtoken', 'keystonemiddleware.auth_token')
cfg.CONF.register_opts(keystone_authtoken_v3_opts,
group='keystone_authtoken_v3')
cfg.CONF.register_opts(nova_opts, group='nova')
cfg.CONF.register_opts(neutron_opts, group='neutron')
# Ensure that the control exchange is set correctly

@ -40,7 +40,7 @@ class AllowedAddressPairsDriver(neutron_base.BaseNeutronDriver):
super(AllowedAddressPairsDriver, self).__init__()
self._check_aap_loaded()
self.nova_client = clients.NovaAuth.get_nova_client(
cfg.CONF.os_region_name
cfg.CONF.os_region_name, service_name=cfg.CONF.nova.service_name
)
def _check_aap_loaded(self):

@ -33,7 +33,7 @@ class BaseNeutronDriver(base.AbstractNetworkDriver):
def __init__(self):
self.sec_grp_enabled = True
self.neutron_client = clients.NeutronAuth.get_neutron_client(
cfg.CONF.os_region_name
cfg.CONF.os_region_name, service_name=cfg.CONF.neutron.service_name
)
extensions = self.neutron_client.list_extensions()
self._extensions = extensions.get('extensions')

@ -55,7 +55,7 @@ class TestNovaAuth(base.TestCase):
# Getting the session again should return the same object
bc2 = clients.NovaAuth.get_nova_client(
region="test-region")
region="test-region", service_name='novaEndpoint1')
self.assertIs(bc1, bc2)
@ -92,5 +92,5 @@ class TestNeutronAuth(base.TestCase):
# Getting the session again should return the same object
bc2 = clients.NeutronAuth.get_neutron_client(
region="test-region")
region="test-region", service_name="neutronEndpoint1")
self.assertIs(bc1, bc2)

Loading…
Cancel
Save