Allow to decide between Nova-network and Neutron

Adds a heat.conf option to set the OpenStack component responsible for
networking, and makes heat-engine auto-discover the networking service
on start up if such option is not set.
Also adds a convenience method to Resource class to let resources decide
what networking service to use.

Implements blueprint discover-networking-service

Change-Id: If7121089068cc2d2774bedb73e4e252b520eb5b3
This commit is contained in:
Pavlo Shchelokovskyy 2014-08-21 10:11:06 +00:00
parent 48f402e4c2
commit 04de60093b
5 changed files with 41 additions and 1 deletions

View File

@ -46,12 +46,31 @@ gettextutils.install('heat', lazy=True)
LOG = logging.getLogger('heat.engine')
def discover_networking_service():
from heat.common import heat_keystoneclient as hkc
# create empty context
ctxt = hkc.context.RequestContext()
# create admin client
admin_client = hkc.KeystoneClient(ctxt).admin_client
services = admin_client.services.list()
if 'network' in [s.type for s in services]:
cfg.CONF.set_override('networking_service', 'neutron')
else:
cfg.CONF.set_override('networking_service', 'nova')
if __name__ == '__main__':
cfg.CONF(project='heat', prog='heat-engine')
logging.setup('heat')
messaging.setup()
if not cfg.CONF.networking_service:
discover_networking_service()
from heat.engine import service as engine
srv = engine.EngineService(cfg.CONF.host, rpc_api.ENGINE_TOPIC)

View File

@ -73,6 +73,10 @@
# Deprecated. (string value)
#onready=<None>
# Select OpenStack component responsible for networking - nova
# or neutron. (string value)
#networking_service=<None>
#
# Options defined in heat.common.config

View File

@ -138,7 +138,11 @@ engine_opts = [
help=_('RPC timeout for the engine liveness check that is used'
' for stack locking.')),
cfg.StrOpt('onready',
help=_('Deprecated.'))]
help=_('Deprecated.')),
cfg.StrOpt('networking_service',
choices=['nova', 'neutron'],
help=_('Select OpenStack component '
'responsible for networking - nova or neutron.'))]
rpc_opts = [
cfg.StrOpt('host',

View File

@ -1086,3 +1086,7 @@ class Resource(object):
# force fetch all resource data from the database again
self._data = None
return True
@staticmethod
def is_using_neutron():
return cfg.CONF.networking_service == 'neutron'

View File

@ -995,6 +995,15 @@ class ResourceTest(HeatTestCase):
TestResource.resource_to_template(
'Test::Resource::resource'))
def test_is_using_neutron(self):
snippet = rsrc_defn.ResourceDefinition('aresource',
'GenericResourceType')
res = resource.Resource('aresource', snippet, self.stack)
cfg.CONF.set_override('networking_service', 'neutron')
self.assertTrue(res.is_using_neutron())
cfg.CONF.set_override('networking_service', 'nova')
self.assertFalse(res.is_using_neutron())
class ResourceAdoptTest(HeatTestCase):
def setUp(self):