Add manila client for karbor

Change-Id: I7aa8acb186fc428a3263dd90d39f177965d2835f
blueprint: manila-share-proection-plugin
This commit is contained in:
chenying 2017-03-24 22:56:03 +08:00
parent af256d7063
commit 3158f5e24c
4 changed files with 146 additions and 1 deletions

View File

@ -78,7 +78,8 @@ class RequestContext(context.RequestContext):
if s.get('type') in
('identity', 'compute', 'object-store',
'image', 'volume', 'volumev2', 'network',
'volumev3', 'orchestration')]
'volumev3', 'orchestration',
'share', 'sharev2')]
else:
# if list is empty or none
self.service_catalog = []

View File

@ -0,0 +1,74 @@
# 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 manilaclient import client as mc
from oslo_config import cfg
from oslo_log import log as logging
from karbor.common import config
from karbor.services.protection.clients import utils
LOG = logging.getLogger(__name__)
SERVICE = "manila"
manila_client_opts = [
cfg.StrOpt(SERVICE + '_endpoint',
help='URL of the manila endpoint.'),
cfg.StrOpt(SERVICE + '_catalog_info',
default='sharev2:manilav2:publicURL',
help='Info to match when looking for manila in the service '
'catalog. Format is: separated values of the form: '
'<service_type>:<service_name>:<endpoint_type> - '
'Only used if manila_endpoint is unset'),
cfg.StrOpt(SERVICE + '_ca_cert_file',
default=None,
help='Location of the CA certificate file '
'to use for client requests in SSL connections.'),
cfg.BoolOpt(SERVICE + '_auth_insecure',
default=False,
help='Bypass verification of server certificate when '
'making SSL connection to manila.'),
]
CONFIG_GROUP = '%s_client' % SERVICE
CONF = cfg.CONF
CONF.register_opts(config.service_client_opts, group=CONFIG_GROUP)
CONF.register_opts(manila_client_opts, group=CONFIG_GROUP)
CONF.set_default('service_name', 'manilav2', CONFIG_GROUP)
CONF.set_default('service_type', 'sharev2', CONFIG_GROUP)
MANILACLIENT_VERSION = '2'
def create(context, conf, **kwargs):
conf.register_opts(manila_client_opts, group=CONFIG_GROUP)
client_config = conf[CONFIG_GROUP]
url = utils.get_url(SERVICE, context, client_config,
append_project_fmt='%(url)s/%(project)s', **kwargs)
LOG.debug('Creating manila client with url %s.', url)
if kwargs.get('session'):
return mc.Client(MANILACLIENT_VERSION, session=kwargs.get('session'),
endpoint_override=url)
args = {
'input_auth_token': context.auth_token,
'project_id': context.project_id,
'service_catalog_url': url,
'cacert': client_config.manila_ca_cert_file,
'insecure': client_config.manila_auth_insecure,
}
client = mc.Client(MANILACLIENT_VERSION, **args)
client.client.auth_token = context.auth_token
client.client.management_url = url
return client

View File

@ -0,0 +1,69 @@
# 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 keystoneauth1 import session as keystone_session
from oslo_config import cfg
from karbor.context import RequestContext
from karbor.services.protection.clients import manila
from karbor.tests import base
class ManilaClientTest(base.TestCase):
def setUp(self):
super(ManilaClientTest, self).setUp()
self._public_url = 'http://127.0.0.1:8776/v2/abcd'
service_catalog = [
{'type': 'sharev2',
'name': 'manilav2',
'endpoints': [{'publicURL': self._public_url}],
},
]
self._context = RequestContext(user_id='demo',
project_id='abcd',
auth_token='efgh',
service_catalog=service_catalog)
@mock.patch('karbor.services.protection.clients.utils.get_url')
@mock.patch('manilaclient.client.Client')
def test_create_client(self, create, get_url):
get_url.return_value = self._public_url
client_version = manila.MANILACLIENT_VERSION
session = keystone_session.Session(auth=None)
manila.create(self._context, cfg.CONF, session=session)
create.assert_called_with(client_version,
endpoint_override=self._public_url,
session=session)
@mock.patch('karbor.services.protection.clients.utils.get_url')
@mock.patch('manilaclient.client.Client')
def test_create_client_without_session(self, create, get_url):
get_url.return_value = self._public_url
client_config = cfg.CONF[manila.CONFIG_GROUP]
client_version = manila.MANILACLIENT_VERSION
args = {
'input_auth_token': self._context.auth_token,
'project_id': self._context.project_id,
'service_catalog_url': self._public_url,
'cacert': client_config.manila_ca_cert_file,
'insecure': client_config.manila_auth_insecure,
}
manila.create(self._context, cfg.CONF)
create.assert_called_with(client_version, **args)

View File

@ -10,6 +10,7 @@ greenlet>=0.3.2 # MIT
icalendar>=3.10 # BSD
keystoneauth1>=2.18.0 # Apache-2.0
keystonemiddleware>=4.12.0 # Apache-2.0
python-manilaclient>=1.12.0 # Apache-2.0
oslo.config>=3.22.0 # Apache-2.0
oslo.concurrency>=3.8.0 # Apache-2.0
oslo.context>=2.12.0 # Apache-2.0