keystone: move to v3

Change-Id: I2bd316e52aede8ca207d364d247b2a0ffeccf9c4
This commit is contained in:
Yuval Brik 2017-02-07 14:00:45 +02:00
parent 5edffcb12e
commit a808a5bcf3
35 changed files with 83 additions and 77 deletions

View File

@ -2,7 +2,7 @@
"restore": {
"provider_id": "cf56bd3e-97a7-4078-b6d5-f36246333fd9",
"checkpoint_id": "dcb20606-ad71-40a3-80e4-ef0fafdad0c3",
"restore_target": "http://192.168.1.2:35357/v2.0/",
"restore_target": "http://192.168.1.2/identity/",
"restore_auth": {
"type": "password",
"username": "admin",
@ -15,4 +15,4 @@
}
}
}
}
}

View File

@ -4,7 +4,7 @@
"project_id": "e486a2f49695423ca9c47e589b948108",
"provider_id": "cf56bd3e-97a7-4078-b6d5-f36246333fd9",
"checkpoint_id": "dcb20606-ad71-40a3-80e4-ef0fafdad0c3",
"restore_target": "http://192.168.1.2:35357/v2.0/",
"restore_target": "http://192.168.1.2/identity/",
"restore_auth": {
"type": "password",
"username": "admin",

View File

@ -5,7 +5,7 @@
"project_id": "e486a2f49695423ca9c47e589b948108",
"provider_id": "cf56bd3e-97a7-4078-b6d5-f36246333fd9",
"checkpoint_id": "dcb20606-ad71-40a3-80e4-ef0fafdad0c3",
"restore_target": "http://192.168.1.2:35357/v2.0/",
"restore_target": "http://192.168.1.2/identity/",
"parameters": {
"OS::Cinder::Volume": {
},

View File

@ -755,7 +755,7 @@ None
"project_id": "e486a2f49695423ca9c47e589b948108",
"provider_id": "cf56bd3e-97a7-4078-b6d5-f36246333fd9",
"checkpoint_id": "dcb20606-ad71-40a3-80e4-ef0fafdad0c3",
"restore_target": "http://192.168.1.2:35357/v2.0/",
"restore_target": "http://192.168.1.2/identity/",
"parameters": {
"username": "admin",
"password": "***"
@ -780,7 +780,7 @@ None
"restore": {
"provider_id": "cf56bd3e-97a7-4078-b6d5-f36246333fd9",
"checkpoint_id": "dcb20606-ad71-40a3-80e4-ef0fafdad0c3",
"restore_target": "http://192.168.1.2:35357/v2.0/",
"restore_target": "http://192.168.1.2/identity/",
"restore_auth": {
"type": "password",
"username": "admin",
@ -804,7 +804,7 @@ None
"project_id": "e486a2f49695423ca9c47e589b948108",
"provider_id": "cf56bd3e-97a7-4078-b6d5-f36246333fd9",
"checkpoint_id": "dcb20606-ad71-40a3-80e4-ef0fafdad0c3",
"restore_target": "http://192.168.1.2:35357/v2.0/",
"restore_target": "http://192.168.1.2/identity/v3",
"restore_auth": {
"type": "password",
"username": "admin",
@ -831,7 +831,7 @@ None
"project_id": "e486a2f49695423ca9c47e589b948108",
"provider_id": "cf56bd3e-97a7-4078-b6d5-f36246333fd9",
"checkpoint_id": "dcb20606-ad71-40a3-80e4-ef0fafdad0c3",
"restore_target": "http://192.168.1.2:35357/v2.0/",
"restore_target": "http://192.168.1.2/identity/",
"parameters": {
"username": "admin",
"password": "***"

View File

@ -1101,7 +1101,7 @@ paths:
"project_id": "e486a2f49695423ca9c47e589b948108",
"provider_id": "cf56bd3e-97a7-4078-b6d5-f36246333fd9",
"checkpoint_id": "dcb20606-ad71-40a3-80e4-ef0fafdad0c3",
"restore_target": "http://192.168.1.2:35357/v2.0/",
"restore_target": "http://192.168.1.2/identity/",
"parameters": {
"OS::Cinder::Volume": {
},
@ -1148,7 +1148,7 @@ paths:
"project_id": "e486a2f49695423ca9c47e589b948108",
"provider_id": "cf56bd3e-97a7-4078-b6d5-f36246333fd9",
"checkpoint_id": "dcb20606-ad71-40a3-80e4-ef0fafdad0c3",
"restore_target": "http://192.168.1.2:35357/v2.0/",
"restore_target": "http://192.168.1.2/identity/",
"parameters": {
"OS::Cinder::Volume": {
},
@ -1185,7 +1185,7 @@ paths:
"project_id": "e486a2f49695423ca9c47e589b948108",
"provider_id": "cf56bd3e-97a7-4078-b6d5-f36246333fd9",
"checkpoint_id": "dcb20606-ad71-40a3-80e4-ef0fafdad0c3",
"restore_target": "http://192.168.1.2:35357/v2.0/",
"restore_target": "http://192.168.1.2/identity/",
"parameters": {
"OS::Cinder::Volume": {
},

View File

@ -18,8 +18,7 @@ This example will show protecting volume.
bank=karbor-swift-bank-plugin
[swift_client]
swift_auth_url=http://10.229.47.230:5000/v2.0/
swift_auth_version=2
swift_auth_url=http://10.229.47.230/identity/
swift_user=admin
swift_key=123456
swift_tenant_name=admin
@ -37,7 +36,7 @@ This example will show protecting volume.
export OS_USERNAME=admin
export OS_PASSWORD=123456
export OS_TENANT_NAME=admin
export OS_AUTH_URL=http://10.229.47.230:35357/v2.0/
export OS_AUTH_URL=http://10.229.47.230/identity/
#. Show the provider information::
@ -131,7 +130,7 @@ This example will show protecting volume.
#. Execute a restore operation manually with a checkpoint id::
karbor --debug restore-create cf56bd3e-97a7-4078-b6d5-f36246333fd9 2c14b9d6-529b-4308-bb17-7334eb351fd7 'http://10.229.47.230:35357/v2.0/' --parameters 'username'='admin' 'password'='123456'
karbor --debug restore-create cf56bd3e-97a7-4078-b6d5-f36246333fd9 2c14b9d6-529b-4308-bb17-7334eb351fd7 'http://10.229.47.230/identity/' --parameters 'username'='admin' 'password'='123456'
+----------------+-------------------------------------------------+
| Property | Value |
+----------------+-------------------------------------------------+
@ -140,7 +139,7 @@ This example will show protecting volume.
| parameters | {u'username': u'admin', u'password': u'123456'} |
| project_id | 8ea0fc3673794f1492b875d349400181 |
| provider_id | cf56bd3e-97a7-4078-b6d5-f36246333fd9 |
| restore_target | http://10.229.47.230:35357/v2.0/ |
| restore_target | http://10.229.47.230/identity/ |
| status | success |
+----------------+-------------------------------------------------+

View File

@ -6,11 +6,10 @@ id=e4008868-be97-492c-be41-44e50ef2e16f
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_auth_url=http://127.0.0.1/identity
swift_user=demo
swift_key=password
swift_tenant_name=admin
swift_tenant_name=demo
[swift_bank_plugin]
lease_expire_window=120

View File

@ -7,11 +7,10 @@ plugin=karbor-noop-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_auth_url=http://127.0.0.1/identity
swift_user=demo
swift_key=password
swift_tenant_name=admin
swift_tenant_name=demo
[swift_bank_plugin]
lease_expire_window=120

View File

@ -9,11 +9,10 @@ plugin=karbor-server-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_auth_url=http://127.0.0.1/identity
swift_user=demo
swift_key=password
swift_tenant_name=admin
swift_tenant_name=demo
[swift_bank_plugin]
lease_expire_window=120

View File

@ -152,9 +152,8 @@ class KarborKeystonePlugin(object):
return users[0].id if users else None
except Exception:
msg = ("get service's user(%s) endpoint failed" % user_name)
raise exception.AuthorizationFailure(obj=msg)
except Exception as e:
raise exception.AuthorizationFailure(obj=e)
def _get_karbor_auth_plugin(self, trust_id=None):
auth_plugin = loading.load_auth_from_conf_options(

View File

@ -79,7 +79,8 @@ class ClientFactory(object):
raise exception.KarborException(_('Unknown service(%s)') % service)
kwargs['keystone_plugin'] = cls._keystone_plugin
kwargs['session'] = cls._generate_session(context, service)
if context:
kwargs['session'] = cls._generate_session(context, service)
return module.create(context, conf, **kwargs)

View File

@ -10,9 +10,14 @@
# License for the specific language governing permissions and limitations
# under the License.
from keystoneauth1 import identity
from keystoneauth1 import session as keystone_session
from oslo_config import cfg
from oslo_log import log as logging
from swiftclient import client as swift
LOG = logging.getLogger(__name__)
SERVICE = 'swift'
swift_client_opts = [
cfg.StrOpt(SERVICE + '_endpoint',
@ -27,11 +32,6 @@ swift_client_opts = [
'are unset'),
cfg.StrOpt('swift_auth_url',
help='The URL of the Keystone endpoint'),
cfg.StrOpt('swift_auth_version',
default='1',
help='Swift authentication version. '
'Specify "1" for auth 1.0, or "2" for auth 2.0. '
'Only used if swift_auth_url is set.'),
cfg.StrOpt('swift_tenant_name',
help='Swift tenant/account name. '
'Required when connecting to an auth 2.0 system'),
@ -66,15 +66,21 @@ def create(context, conf, **kwargs):
register_opts(conf)
client_config = conf.swift_client
connection = swift.Connection(
authurl=client_config.swift_auth_url,
auth_version=client_config.swift_auth_version,
tenant_name=client_config.swift_tenant_name,
user=client_config.swift_user,
key=client_config.swift_key,
session = kwargs.get('session')
if not session:
auth = identity.Password(
auth_url=client_config.swift_auth_url,
username=client_config.swift_user,
password=client_config.swift_key,
project_name=client_config.swift_tenant_name,
)
session = keystone_session.Session(auth=auth)
return swift.Connection(
session=session,
insecure=client_config.swift_auth_insecure,
cacert=client_config.swift_ca_cert_file,
retries=client_config.swift_retry_attempts,
starting_backoff=client_config.swift_retry_backoff,
insecure=client_config.swift_auth_insecure,
cacert=client_config.swift_ca_cert_file)
return connection
)

View File

@ -14,7 +14,7 @@ import os
import six
from karbor import exception
from karbor.i18n import _, _LE
from karbor.i18n import _, _LE, _LI
from karbor.services.protection import bank_plugin
from karbor.services.protection.checkpoint import CheckpointCollection
from karbor import utils
@ -183,6 +183,8 @@ class ProviderRegistry(object):
{'provider': provider_config.provider.name,
'reason': e})
else:
LOG.info(_LI('Loaded provider: %s successully.'),
provider_config.provider.name)
self.providers[provider.id] = provider
def list_providers(self, marker=None, limit=None, sort_keys=None,

View File

@ -20,11 +20,11 @@ import os_client_config
from oslotest import base
def _get_cloud_config(cloud='devstack-admin'):
def _get_cloud_config(cloud='devstack'):
return os_client_config.OpenStackConfig().get_one_cloud(cloud=cloud)
def _credentials(cloud='devstack-admin'):
def _credentials(cloud='devstack'):
"""Retrieves credentials to run functional tests
Credentials are either read via os-client-config from the environment

View File

@ -37,7 +37,7 @@ class PlanApiTest(base.TestCase):
def setUp(self):
super(PlanApiTest, self).setUp()
self.controller = plans.PlansController()
self.ctxt = context.RequestContext('admin', 'fakeproject', True)
self.ctxt = context.RequestContext('demo', 'fakeproject', True)
@mock.patch(
'karbor.objects.plan.Plan.create')

View File

@ -27,7 +27,7 @@ class ProtectablesApiTest(base.TestCase):
def setUp(self):
super(ProtectablesApiTest, self).setUp()
self.controller = protectables.ProtectablesController()
self.ctxt = context.RequestContext('admin', 'fakeproject', True)
self.ctxt = context.RequestContext('demo', 'fakeproject', True)
@mock.patch(
'karbor.api.v1.protectables.ProtectablesController._get_all')

View File

@ -28,7 +28,7 @@ class ProvidersApiTest(base.TestCase):
def setUp(self):
super(ProvidersApiTest, self).setUp()
self.controller = providers.ProvidersController()
self.ctxt = context.RequestContext('admin', 'fakeproject', True)
self.ctxt = context.RequestContext('demo', 'fakeproject', True)
@mock.patch(
'karbor.api.v1.providers.ProvidersController._get_all')

View File

@ -27,10 +27,10 @@ CONF = cfg.CONF
DEFAULT_PROJECT_ID = '39bb894794b741e982bd26144d2949f6'
DEFAULT_PROVIDER_ID = 'efc6a88b-9096-4bb6-8634-cda182a6e12a'
DEFAULT_CHECKPOINT_ID = '09edcbdc-d1c2-49c1-a212-122627b20968'
DEFAULT_RESTORE_TARGET = '192.168.1.2:35357/v2.0'
DEFAULT_RESTORE_TARGET = '192.168.1.2/identity/'
DEFAULT_RESTORE_AUTH = {
'type': 'password',
'username': 'admin',
'username': 'demo',
'password': 'test',
}
DEFAULT_PARAMETERS = {
@ -41,7 +41,7 @@ class RestoreApiTest(base.TestCase):
def setUp(self):
super(RestoreApiTest, self).setUp()
self.controller = restores.RestoresController()
self.ctxt = context.RequestContext('admin', 'fakeproject', True)
self.ctxt = context.RequestContext('demo', 'fakeproject', True)
@mock.patch(
'karbor.services.protection.api.API.restore')

View File

@ -46,7 +46,7 @@ class ScheduledOperationApiTest(base.TestCase):
self.controller = operation_api.ScheduledOperationController()
self.controller.operationengine_api = self.remote_operation_api
self.ctxt = context.RequestContext('admin', 'fakeproject', True)
self.ctxt = context.RequestContext('demo', 'fakeproject', True)
self.req = fakes.HTTPRequest.blank('/v1/scheduled_operations')
trigger = self._create_trigger()

View File

@ -43,7 +43,7 @@ class TriggerApiTest(base.TestCase):
super(TriggerApiTest, self).setUp()
self.controller = trigger_api.TriggersController()
self.controller.operationengine_api = FakeRemoteOperationApi()
self.ctxt = context.RequestContext('admin', 'fakeproject',
self.ctxt = context.RequestContext('demo', 'fakeproject',
True)
self.req = fakes.HTTPRequest.blank('/v1/triggers')
self.default_create_trigger_param = {

View File

@ -30,7 +30,7 @@ class CinderClientTest(base.TestCase):
'endpoints': [{'publicURL': self._public_url}],
},
]
self._context = RequestContext(user_id='admin',
self._context = RequestContext(user_id='demo',
project_id='abcd',
auth_token='efgh',
service_catalog=service_catalog)

View File

@ -40,7 +40,7 @@ class EisooClient(object):
class ABClientTest(base.TestCase):
def setUp(self):
super(ABClientTest, self).setUp()
self._context = RequestContext(user_id='admin',
self._context = RequestContext(user_id='demo',
project_id='asdf',
auth_token='qwe',
service_catalog=None)

View File

@ -32,7 +32,7 @@ class GlanceClientTest(base.TestCase):
'name': 'glance',
},
]
self._context = RequestContext(user_id='admin',
self._context = RequestContext(user_id='demo',
project_id='abcd',
auth_token='efgh',
service_catalog=service_catalog)

View File

@ -32,7 +32,7 @@ class NeutronClientTest(base.TestCase):
'name': 'neutron',
},
]
self._context = RequestContext(user_id='admin',
self._context = RequestContext(user_id='demo',
project_id='abcd',
auth_token='efgh',
service_catalog=service_catalog)

View File

@ -27,7 +27,7 @@ class NovaClientTest(base.TestCase):
'endpoints': [{'publicURL': 'http://127.0.0.1:8774/v2.1/abcd'}],
},
]
self._context = RequestContext(user_id='admin',
self._context = RequestContext(user_id='demo',
project_id='abcd',
auth_token='efgh',
service_catalog=service_catalog)

View File

@ -29,7 +29,7 @@ class SwiftClientTest(base.TestCase):
'name': 'swift',
},
]
self._context = RequestContext(user_id='admin',
self._context = RequestContext(user_id='demo',
project_id='abcd',
auth_token='efgh',
service_catalog=service_catalog)
@ -38,17 +38,19 @@ class SwiftClientTest(base.TestCase):
swift.register_opts(self.conf)
def test_create_client_by_keystone(self):
self.skipTest('test needs revision')
auth_url = 'http://127.0.0.1/identity/'
self.conf.set_default('swift_auth_url',
'http://127.0.0.1:5000/v2.0',
auth_url,
'swift_client')
self.conf.set_override('swift_user', 'admin', 'swift_client',
self.conf.set_override('swift_user', 'demo', 'swift_client',
enforce_type=True)
self.conf.set_override('swift_key', 'secrete', 'swift_client',
enforce_type=True)
self.conf.set_override('swift_tenant_name', 'abcd', 'swift_client',
enforce_type=True)
sc = swift.create(self._context, self.conf)
self.assertEqual(sc.authurl, 'http://127.0.0.1:5000/v2.0')
self.assertEqual(sc.user, 'admin')
self.assertEqual(sc.authurl, auth_url)
self.assertEqual(sc.user, 'demo')
self.assertEqual(sc.key, 'secrete')
self.assertEqual(sc.os_options['tenant_name'], 'abcd')

View File

@ -33,7 +33,7 @@ class ClientUtilsTest(base.TestCase):
'endpoints': [{'publicURL': self._public_url}],
},
]
self._context = RequestContext(user_id='admin',
self._context = RequestContext(user_id='demo',
project_id='abcd',
auth_token='efgh',
service_catalog=service_catalog)

View File

@ -500,7 +500,7 @@ class RestoreDbTestCase(ModelBaseTestCase):
"project_id": "586cc6ce-e286-40bd-b2b5-dd32694d9944",
"provider_id": "2220f8b1-975d-4621-a872-fa9afb43cb6c",
"checkpoint_id": "09edcbdc-d1c2-49c1-a212-122627b20968",
"restore_target": "192.168.1.2:35357/v2.0",
"restore_target": "192.168.1.2/identity/",
"parameters": "{'username': 'admin'}",
"status": "SUCCESS"
}

View File

@ -21,7 +21,7 @@ def fake_db_restore(**updates):
"project_id": "586cc6ce-e286-40bd-b2b5-dd32694d9944",
"provider_id": "2220f8b1-975d-4621-a872-fa9afb43cb6c",
"checkpoint_id": "09edcbdc-d1c2-49c1-a212-122627b20968",
"restore_target": "192.168.1.2:35357/v2.0",
"restore_target": "192.168.1.2/identity/",
"parameters": '{}',
"restore_auth": '{"type": "password", "username": "admin",'
'"password": "test" }',

View File

@ -48,7 +48,7 @@ class ImageProtectablePluginTest(base.TestCase):
'type': 'compute',
'endpoints': [{'publicURL': 'http://127.0.0.1:8774/v2.1/abcd'}]
}]
self._context = RequestContext(user_id='admin',
self._context = RequestContext(user_id='demo',
project_id='abcd',
auth_token='efgh',
service_catalog=service_catalog)

View File

@ -37,7 +37,7 @@ class ServerProtectablePluginTest(base.TestCase):
'endpoints': [{'publicURL': 'http://127.0.0.1:8774/v2.1/abcd'}],
},
]
self._context = RequestContext(user_id='admin',
self._context = RequestContext(user_id='demo',
project_id='abcd',
auth_token='efgh',
service_catalog=service_catalog)

View File

@ -42,7 +42,7 @@ class VolumeProtectablePluginTest(base.TestCase):
'endpoints': [{'publicURL': 'http://127.0.0.1:8776/v3/abcd'}],
},
]
self._context = RequestContext(user_id='admin',
self._context = RequestContext(user_id='demo',
project_id='abcd',
auth_token='efgh',
service_catalog=service_catalog)

View File

@ -107,7 +107,7 @@ class CinderProtectionPluginTest(base.TestCase):
'http://127.0.0.1:8776/v2',
'cinder_client')
self.cntxt = RequestContext(user_id='admin',
self.cntxt = RequestContext(user_id='demo',
project_id='abcd',
auth_token='efgh')
self.cinder_client = client_factory.ClientFactory.create_client(

View File

@ -110,7 +110,7 @@ class GlanceProtectionPluginTest(base.TestCase):
'http://127.0.0.1:9292',
'glance_client')
self.cntxt = RequestContext(user_id='admin',
self.cntxt = RequestContext(user_id='demo',
project_id='abcd',
auth_token='efgh')
self.glance_client = client_factory.ClientFactory.create_client(

View File

@ -238,7 +238,7 @@ class Checkpoint(object):
class NovaProtectionPluginTest(base.TestCase):
def setUp(self):
super(NovaProtectionPluginTest, self).setUp()
self.cntxt = RequestContext(user_id='admin',
self.cntxt = RequestContext(user_id='demo',
project_id='abcd',
auth_token='efgh')
self.plugin = NovaProtectionPlugin()