ksa auth conf and client for Cyborg access

Framework for communication with the Cyborg API.

- Standard keystoneauth1 config options for setting up authentication in
the [cyborg] section of nova*.conf.
- A new nova.accelerator.cyborg module containing a get_client method to
return a client containing a keystoneauth1 adapter pointing
to the Cyborg service with user- and service- based authentication.
- Requirements updates to pull in the os-service-types release
containing the 'accelerator' service type.

Change-Id: Iee0766269d61948ad701911e8b0e5e24d3d6eb04
Blueprint: nova-cyborg-interaction
This commit is contained in:
Sundar Nadathur 2019-01-16 00:31:01 -08:00
parent 53775aa819
commit c071741d56
7 changed files with 121 additions and 1 deletions

View File

View File

@ -0,0 +1,32 @@
# Copyright 2019 Intel
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from oslo_log import log as logging
from nova import service_auth
from nova import utils
LOG = logging.getLogger(__name__)
def get_client(context):
return _CyborgClient(context)
class _CyborgClient(object):
def __init__(self, context):
auth = service_auth.get_auth_plugin(context)
self._client = utils.get_ksa_adapter('accelerator', ksa_auth=auth)

View File

@ -29,6 +29,7 @@ from nova.conf import conductor
from nova.conf import configdrive
from nova.conf import console
from nova.conf import consoleauth
from nova.conf import cyborg
from nova.conf import database
from nova.conf import devices
from nova.conf import ephemeral_storage
@ -80,6 +81,7 @@ conductor.register_opts(CONF)
configdrive.register_opts(CONF)
console.register_opts(CONF)
consoleauth.register_opts(CONF)
cyborg.register_opts(CONF)
database.register_opts(CONF)
devices.register_opts(CONF)
ephemeral_storage.register_opts(CONF)

43
nova/conf/cyborg.py Normal file
View File

@ -0,0 +1,43 @@
# Copyright 2019 OpenStack Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# 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 nova.conf import utils as confutils
DEFAULT_SERVICE_TYPE = 'accelerator'
CYBORG_GROUP = 'cyborg'
cyborg_group = cfg.OptGroup(
CYBORG_GROUP,
title='Cyborg Options',
help="""
Configuration options for Cyborg (accelerator as a service).
""")
def register_opts(conf):
conf.register_group(cyborg_group)
confutils.register_ksa_opts(conf, cyborg_group, DEFAULT_SERVICE_TYPE,
include_auth=False)
def list_opts():
return {
cyborg_group: (
ks_loading.get_session_conf_options() +
confutils.get_ksa_adapter_opts(DEFAULT_SERVICE_TYPE))
}

View File

@ -118,7 +118,8 @@ class RequestContext(context.RequestContext):
# Only include required parts of service_catalog
self.service_catalog = [s for s in service_catalog
if s.get('type') in ('image', 'block-storage', 'volumev3',
'key-manager', 'placement', 'network')]
'key-manager', 'placement', 'network',
'accelerator')]
else:
# if list is empty or none
self.service_catalog = []

View File

View File

@ -0,0 +1,42 @@
# Copyright 2019 OpenStack Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from nova.accelerator import cyborg
from nova import context
from nova import test
class CyborgTestCase(test.NoDBTestCase):
def setUp(self):
super(CyborgTestCase, self).setUp()
self.context = context.get_admin_context()
self.client = cyborg.get_client(self.context)
def test_get_client(self):
# Set up some ksa conf options
region = 'MyRegion'
endpoint = 'http://example.com:1234'
self.flags(group='cyborg',
region_name=region,
endpoint_override=endpoint)
ctxt = context.get_admin_context()
client = cyborg.get_client(ctxt)
# Dig into the ksa adapter a bit to ensure the conf options got through
# We don't bother with a thorough test of get_ksa_adapter - that's done
# elsewhere - this is just sanity-checking that we spelled things right
# in the conf setup.
self.assertEqual('accelerator', client._client.service_type)
self.assertEqual(region, client._client.region_name)
self.assertEqual(endpoint, client._client.endpoint_override)