Move neutron_ooi_endpoint to nova.conf

We move the neutron_ooi_endpoint configuration to nova.conf
instead of api-paste.ini.

Change-Id: Ie302158326f461cc9a3171bdce8012b96c38db43
Closes-bug: #1600133
This commit is contained in:
jorgesece 2016-07-08 10:35:51 +01:00
parent 8b93f4065d
commit 599fa241ac
8 changed files with 76 additions and 31 deletions

View File

@ -15,6 +15,9 @@ Moreover, the following options are available:
* ``ooi_listen_port``: Port ooi will bind to. Defaults to ``8787``.
* ``ooi_workers``: Number of workers to spawn, by default it is set to the
number of CPUs in the node.
* ``neutron_ooi_endpoint``: Neutron endpoint, configures the network
management by using neutron. If this is not set, the system will use
nova-network.
Paste Configuration
*******************
@ -37,7 +40,6 @@ First it is needed to add the OCCI filter like this::
[filter:occi]
paste.filter_factory = ooi.wsgi:OCCIMiddleware.factory
openstack_version = /v2
neutron_ooi_endpoint = http://127.0.0.1:9696/v2.0
``openstack_version`` can be configured to any of the supported OpenStack API
versions, as indicated in Table :ref:`api-versions`. If it is not configured,
@ -54,14 +56,6 @@ by default it will take the ``/v2.1`` value.
v2.1 ``/v2.1`` ``[composite:openstack_compute_api_v21]``
===================== ===================== =============================================
OpenStack has two components to support network management. On one side, nova-network
provides a simple network management which creates, lists, shows information for, and deletes networks.
Admin permissions are required to create and delete networks. On the other side, the neutron component
allows to manage and configure advanced network features. OOI implements the OCCI interface to simple
network management by using either nova-network or neutron.
``neutron_ooi_endpoint`` configures the neutron endpoint. It is an optional parameter that configures
the network management by using neutron. If this is not set, the system will use nova-network.
The next step is to create a ``composite`` section for the OCCI interface. It
is needed to duplicate the :ref:`corresponding OpenStack API ``composite``<api-versions>` section,
renaming it to ``occi_api_v11``. Once duplicated, the ``occi`` middleware needs
@ -85,10 +79,21 @@ The last step regarding the API configuration is to add it to create the
Finally, you need to enable it in the OpenStack nova configuration, so that it
is loaded properly. Add ``ooi`` to the ``enabled_apis`` option in the
configuration file and adapt the port if needed, via the ``ooi_listen_port``
(by default it listens in the ``8787`` port)::
(by default it listens in the ``8787`` port). On the other hand, network management
by using neutron can be configure via the ``neutron_ooi_endpoint`` option
(if it is not set, the system will use nova-network)::
enabled_apis=ec2,osapi_compute,metadata,ooi
ooi_listen_port=8787
neutron_ooi_endpoint=http://127.0.0.1:9696/v2.0
OpenStack has two components to support network management. On one side, nova-network
provides a simple network management which creates, lists, shows information for, and deletes networks.
Admin permissions are required to create and delete networks. On the other side, the neutron component
allows to manage and configure advanced network features. OOI implements the OCCI interface to simple
network management by using either nova-network or neutron.
``neutron_ooi_endpoint`` configures the neutron endpoint. It is an optional parameter that configures
the network management by using neutron. If this is not set, the system will use nova-network.
If everything is OK, after rebooting the ``nova-api`` service you should be able
to access your OCCI endpoint at::

View File

@ -9,7 +9,6 @@ use = call:nova.api.openstack.urlmap:urlmap_factory
[filter:occi]
paste.filter_factory = ooi.wsgi:OCCIMiddleware.factory
openstack_version = /v2.0
neutron_ooi_endpoint = http://127.0.0.1:9696/v2.0
[composite:occi_api_11]
use = call:nova.api.auth:pipeline_factory

View File

@ -9,7 +9,6 @@ use = call:nova.api.openstack.urlmap:urlmap_factory
[filter:occi]
paste.filter_factory = ooi.wsgi:OCCIMiddleware.factory
openstack_version = /v2.1
neutron_ooi_endpoint = http://127.0.0.1:9696/v2.0
[composite:occi_api_11]
use = call:nova.api.auth:pipeline_factory_v21

View File

@ -9,7 +9,6 @@ use = call:nova.api.openstack.urlmap:urlmap_factory
[filter:occi]
paste.filter_factory = ooi.wsgi:OCCIMiddleware.factory
openstack_version = /v2.1
neutron_ooi_endpoint = http://127.0.0.1:9696/v2.0
[composite:occi_api_11]
use = call:nova.api.auth:pipeline_factory_v21

View File

@ -13,3 +13,7 @@
# Number of workers for OCCI (ooi) API service. The default will be equal to
# the number of CPUs available. (integer value)
#ooi_workers = <None>
# Neutron endpoint which configures the network management by using neutron.
# If this is not set, the system will use nova-network.
neutron_ooi_endpoint = <None>

View File

@ -16,10 +16,18 @@
import webob.exc
import warnings
from ooi.log import log as logging
LOG = logging.getLogger(__name__)
warnings.simplefilter("default", DeprecationWarning)
def raise_deprecation_message(message):
warnings.warn(message, DeprecationWarning, stacklevel=2)
class ConvertedException(webob.exc.WSGIHTTPException):
def __init__(self, code=0, title="", explanation=""):

View File

@ -18,7 +18,9 @@
import mock
import uuid
import warnings
from oslo_config import cfg
import webob
from ooi.api import helpers
@ -36,10 +38,16 @@ class TestFunctionalNeutron(test_middleware.TestMiddleware):
self.schema = 'http://schemas.ogf.org/occi/infrastructure#network'
self.accept = self.content_type = None
self.application_url = fakes.application_url
self.neutron_endpoint = "foo"
self.app = wsgi.OCCIMiddleware(
None,
neutron_ooi_endpoint=self.neutron_endpoint)
neutron_ooi_endpoint = "foo"
def mock_endpoint(self, bar):
if bar == "neutron_ooi_endpoint":
return neutron_ooi_endpoint
with mock.patch.object(cfg.ConfigOpts, "__getattr__",
side_effect=mock_endpoint,
autospec=True):
self.app = wsgi.OCCIMiddleware(None)
def assertExpectedResult(self, expected, result):
expected = ["%s: %s" % e for e in expected]
@ -47,6 +55,21 @@ class TestFunctionalNeutron(test_middleware.TestMiddleware):
results = str(result.text).splitlines()
self.assertItemsEqual(expected, results)
def test_deprecated_configuration(self):
with warnings.catch_warnings(record=True) as w:
neutron_endopoint = "/foo"
warnings.simplefilter("always", DeprecationWarning)
wsgi.OCCIMiddleware(None,
neutron_ooi_endpoint=neutron_endopoint)
expected_message = (
"Configuration of neutron_ooi_endpoint"
" in api-paste.ini file is deprecated,"
" include it in nova.conf")
self.assertEqual(1, len(w))
self.assertIs(DeprecationWarning,
w[-1].category)
self.assertEqual(expected_message, w[-1].message.message)
@mock.patch.object(helpers.BaseHelper, "_get_req")
def test_list_networks_empty(self, m):
tenant = fakes.tenants["bar"]
@ -208,9 +231,7 @@ class TestFunctionalNova(test_middleware.TestMiddleware):
self.schema = 'http://schemas.ogf.org/occi/infrastructure#network'
self.accept = self.content_type = None
self.application_url = fakes.application_url
self.app = wsgi.OCCIMiddleware(
None,
None)
self.app = wsgi.OCCIMiddleware(None)
def assertExpectedResult(self, expected, result):
expected = ["%s: %s" % e for e in expected]

View File

@ -41,15 +41,15 @@ occi_opts = [
config.cfg.StrOpt('ooi_listen',
default="0.0.0.0",
help='The IP address on which the OCCI (ooi) API '
'will listen.'),
'will listen.'),
config.cfg.IntOpt('ooi_listen_port',
default=8787,
help='The port on which the OCCI (ooi) API '
'will listen.'),
'will listen.'),
config.cfg.IntOpt('ooi_workers',
help='Number of workers for OCCI (ooi) API service. '
'The default will be equal to the number of CPUs '
'available.'),
'The default will be equal to the number of CPUs '
'available.'),
# NEUTRON
config.cfg.StrOpt('neutron_ooi_endpoint',
default=None,
@ -114,9 +114,19 @@ class OCCIMiddleware(object):
neutron_ooi_endpoint=None):
self.application = application
self.openstack_version = openstack_version
self.neutron_ooi_endpoint = neutron_ooi_endpoint
self.resources = {}
if CONF.neutron_ooi_endpoint:
self.neutron_ooi_endpoint = CONF.neutron_ooi_endpoint
elif neutron_ooi_endpoint:
exception.raise_deprecation_message(
"Configuration of neutron_ooi_endpoint"
" in api-paste.ini file is deprecated,"
" include it in nova.conf")
self.neutron_ooi_endpoint = neutron_ooi_endpoint
else:
self.neutron_ooi_endpoint = None
self.resources = {}
self.mapper = routes.Mapper()
self._setup_routes()
@ -251,7 +261,7 @@ class OCCIMiddleware(object):
match = re.search(r"\bOCCI/\d\.\d\b", req.user_agent)
if match and self.occi_string != match.group():
return Fault(webob.exc.HTTPNotImplemented(
explanation="%s not supported" % match.group()))
explanation="%s not supported" % match.group()))
match = self.mapper.match(req.path_info, req.environ)
if not match:
@ -456,12 +466,12 @@ class ResourceExceptionHandler(object):
if isinstance(ex_value, exception.OCCIException):
raise Fault(exception.ConvertedException(
code=ex_value.code,
explanation=ex_value.format_message()))
code=ex_value.code,
explanation=ex_value.format_message()))
elif isinstance(ex_value, exception.NotImplemented):
raise Fault(exception.ConvertedException(
code=ex_value.code,
explanation=ex_value.format_message()))
code=ex_value.code,
explanation=ex_value.format_message()))
elif isinstance(ex_value, TypeError):
exc_info = (ex_type, ex_value, ex_traceback)
LOG.error('Exception handling resource: %s', ex_value,