add eisoo client factory

add abclient in requirements.txt.
add eisoo client factory to create EISOO
AnyBackup client.
add tests to eisoo client factory.

Change-Id: I60f88b0cbacc12e588bf1e57757cba727db86765
Depends-On: I6467a4b2f24c07c75789ab52f580d031d47c642f
This commit is contained in:
lichunyu 2016-11-08 12:40:30 +08:00
parent 8750479d78
commit 42affab4d0
4 changed files with 141 additions and 0 deletions

View File

@ -0,0 +1,24 @@
[provider]
name=EISOO Provider
description=This provider provides data protection for applications with EISOO AnyBackup
id=e4008868-be97-492c-be41-44e50ef2e16f
plugin=karbor-eisoo-oracle-protection-plugin
bank=karbor-swift-bank-plugin
[swift_client]
swift_auth_url=http://127.0.0.1:5000/v2.0/
swift_auth_version=2
swift_user=admin
swift_key=password
swift_tenant_name=admin
[swift_bank_plugin]
lease_expire_window=120
lease_renew_window=100
lease_validity_window=100
[eisoo_client]
eisoo_endpoint=https://172.17.238.11:9801
eisoo_app_id=MTQ3NzAyMDg0MC41OQ==
eisoo_app_secret=OEVBM0IyQkQ3OEZGMDIxNTFGRUVDRjMwOTIzM0IyQ0M=

View File

@ -0,0 +1,57 @@
# 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 os
from oslo_config import cfg
from oslo_log import log as logging
from karbor.i18n import _LI
from karbor import utils
from abclient import client
EISOO_JOB_TYPE = (ORACLE_JOB_TYPE) = (1)
EISOO_JOB_STATUS = (RUNNING, SUCCESS, FAILED) = (4, 32, 64)
SERVICE = "eisoo"
eisoo_client_opts = [
cfg.StrOpt(SERVICE + '_endpoint',
help='URL of the eisoo endpoint.'),
cfg.StrOpt(SERVICE + '_app_id',
default=None,
help='App id for eisoo authentication.'),
cfg.StrOpt(SERVICE + '_app_secret',
default=None,
help='App secret for eisoo authenticaiton.'),
]
CONF = cfg.CONF
LOG = logging.getLogger(__name__)
def create(context, conf):
config_dir = utils.find_config(CONF.provider_config_dir)
config_file = os.path.abspath(os.path.join(config_dir,
'eisoo.conf'))
config = cfg.ConfigOpts()
config(args=['--config-file=' + config_file])
config.register_opts(eisoo_client_opts,
group=SERVICE + '_client')
LOG.info(_LI('Creating eisoo client with url %s.'),
config.eisoo_client.eisoo_endpoint)
abclient = client.ABClient(config.eisoo_client.eisoo_endpoint,
config.eisoo_client.eisoo_app_id,
config.eisoo_client.eisoo_app_secret)
return abclient

View File

@ -0,0 +1,59 @@
# Copyright (c) 2016 Shanghai EISOO Information Technology Corp.
# 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 karbor.context import RequestContext
from karbor.services.protection.clients import eisoo
from karbor.tests import base
class FakeConfig(object):
def __init__(self):
self.eisoo_client = EisooClient()
def __call__(self, args):
pass
def register_opts(self, opts, **kwargs):
pass
class EisooClient(object):
def __init__(self):
self.eisoo_endpoint = 'eisoo_endpoint'
self.eisoo_app_id = 'eisoo_app_id'
self.eisoo_app_secret = 'eisoo_app_secret'
class ABClientTest(base.TestCase):
def setUp(self):
super(ABClientTest, self).setUp()
self._context = RequestContext(user_id='admin',
project_id='asdf',
auth_token='qwe',
service_catalog=None)
@mock.patch('oslo_config.cfg.ConfigOpts', FakeConfig)
@mock.patch('karbor.utils.find_config')
@mock.patch('os.path.abspath')
def test_create_client_by_config_file(self, mock_findconfig, mock_abspath):
mock_findconfig.return_value = '/etc/provider.d'
mock_abspath.return_value = ''
client = eisoo.create(self._context, None)
self.assertEqual(client._app_id, 'eisoo_app_id')
def tearDown(self):
super(ABClientTest, self).tearDown()

View File

@ -39,3 +39,4 @@ oslo.i18n>=2.1.0 # Apache-2.0
python-swiftclient>=2.2.0 # Apache-2.0
python-heatclient!=1.6.0,>=1.5.0 # Apache-2.0
python-karborclient>=0.1.1 # Apache-2.0
abclient>=0.2.3 # Apache-2.0