Merge "Encapsulate smaug client in Operation Engine"

This commit is contained in:
Jenkins 2016-10-17 03:35:39 +00:00 committed by Gerrit Code Review
commit 2ef7a563d1
5 changed files with 117 additions and 5 deletions

View File

@ -24,12 +24,12 @@ function create_karbor_accounts {
if is_service_enabled karbor-api; then
create_service_user "karbor" "admin"
create_service_user "$KARBOR_SERVICE_NAME" "admin"
if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
get_or_create_service "karbor" "data-protect" "Application Data Protection Service"
get_or_create_endpoint "data-protect" "$REGION_NAME" \
get_or_create_service "$KARBOR_SERVICE_NAME" "$KARBOR_SERVICE_TYPE" "Application Data Protection Service"
get_or_create_endpoint "$KARBOR_SERVICE_TYPE" "$REGION_NAME" \
"$KARBOR_API_PROTOCOL://$KARBOR_API_HOST:$KARBOR_API_PORT/v1/\$(tenant_id)s" \
"$KARBOR_API_PROTOCOL://$KARBOR_API_HOST:$KARBOR_API_PORT/v1/\$(tenant_id)s" \
"$KARBOR_API_PROTOCOL://$KARBOR_API_HOST:$KARBOR_API_PORT/v1/\$(tenant_id)s"
@ -73,6 +73,11 @@ function configure_karbor_api {
# Configure for clients_keystone
iniset $KARBOR_API_CONF clients_keystone auth_uri $KEYSTONE_AUTH_URI
# Config karbor client
iniset $KARBOR_API_CONF karbor_client service_name $KARBOR_SERVICE_NAME
iniset $KARBOR_API_CONF karbor_client service_type $KARBOR_SERVICE_TYPE
iniset $KARBOR_API_CONF karbor_client version 1
else
iniset $KARBOR_API_CONF DEFAULT auth_strategy noauth
fi

View File

@ -18,3 +18,6 @@ KARBOR_API_PROTOCOL=${KARBOR_API_PROTOCOL:-$SERVICE_PROTOCOL}
KARBOR_AUTH_CACHE_DIR=${KARBOR_AUTH_CACHE_DIR:-/var/cache/karbor}
export PYTHONPATH=$PYTHONPATH:$KARBOR_DIR
KARBOR_SERVICE_NAME=karbor
KARBOR_SERVICE_TYPE=data-protect

View File

@ -76,6 +76,32 @@ global_opts = [
CONF.register_opts(global_opts)
service_client_opts = [
cfg.StrOpt('service_name',
help='The name of service registered in Keystone'),
cfg.StrOpt('service_type',
help='The type of service registered in Keystone'),
cfg.StrOpt('version',
help='The version of service client'),
cfg.StrOpt('region_id',
default='RegionOne',
help='The region id which the service belongs to.'),
cfg.StrOpt('ca_cert_file',
default=None,
help='Location of the CA certificate file '
'to use for client requests in SSL connections.'),
cfg.BoolOpt('auth_insecure',
default=False,
help='Bypass verification of server certificate when '
'making SSL connection to service.')
]
keystone_client_opts = [
cfg.StrOpt('auth_uri',
default='',

View File

@ -10,10 +10,46 @@
# License for the specific language governing permissions and limitations
# under the License.
from oslo_config import cfg
from oslo_log import log as logging
from karbor.common import config
from karbor.common import karbor_keystone_plugin
from karborclient import client as karbor_client
LOG = logging.getLogger(__name__)
CONFIG_GROUP = 'karbor_client'
CONF = cfg.CONF
CONF.register_opts(config.service_client_opts,
group=CONFIG_GROUP)
def get_karbor_endpoint():
pass
try:
sc_cfg = CONF[CONFIG_GROUP]
kc_plugin = karbor_keystone_plugin.KarborKeystonePlugin()
return kc_plugin.get_service_endpoint(
sc_cfg.service_name, sc_cfg.service_type, sc_cfg.region_id)
except Exception:
raise
def create(context, **kwargs):
pass
endpoint = kwargs.get('endpoint')
if not endpoint:
endpoint = get_karbor_endpoint()
endpoint = endpoint.replace("$(tenant_id)s", context.project_id)
LOG.debug("Creating karbor client with url %s.", endpoint)
sc_cfg = CONF[CONFIG_GROUP]
args = {
'version': sc_cfg.version,
'endpoint': endpoint,
'token': context.auth_token,
'cacert': sc_cfg.ca_cert_file,
'insecure': sc_cfg.auth_insecure,
}
return karbor_client.Client(**args)

View File

@ -0,0 +1,42 @@
# 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.
import mock
from oslo_config import cfg
from karbor.common import karbor_keystone_plugin
from karbor import context
from karbor.services.operationengine import karbor_client
from karbor.tests import base
class KarborClientTest(base.TestCase):
@mock.patch.object(karbor_keystone_plugin.KarborKeystonePlugin, '_do_init')
@mock.patch.object(karbor_keystone_plugin.KarborKeystonePlugin,
'get_service_endpoint')
def test_create_client(self, get_service_endpoint, do_init):
ctx = context.get_admin_context()
ctx.project_id = '123'
cfg.CONF.set_default('version', '1', 'karbor_client')
karbor_url = "http://127.0.0.1:9090"
sc = karbor_client.create(ctx, endpoint=karbor_url)
self.assertEqual(karbor_url, sc.http_client.endpoint)
karbor_url = "http://127.0.0.1:9090/$(tenant_id)s"
get_service_endpoint.return_value = karbor_url
endpoint = karbor_url.replace("$(tenant_id)s", ctx.project_id)
sc = karbor_client.create(ctx)
self.assertEqual(endpoint, sc.http_client.endpoint)