fix working with cinder API v2
add cinder_service_type to config
and fix code to be compatible with cinderclient v2
Change-Id: Ia7eec95e19c5472d741fc9759ef4f8929ac516f7
(cherry picked from commit e22e6a1bc0
)
This commit is contained in:
parent
85986cfc8c
commit
4d989aefcb
|
@ -12,6 +12,8 @@
|
|||
# stop_ec2api
|
||||
|
||||
|
||||
env | sort
|
||||
|
||||
# Save trace setting
|
||||
XTRACE=$(set +o | grep xtrace)
|
||||
set -o xtrace
|
||||
|
|
|
@ -42,13 +42,12 @@ def create_snapshot(context, volume_id, description=None):
|
|||
volume_id)
|
||||
raise exception.IncorrectState(reason=msg)
|
||||
with common.OnCrashCleaner() as cleaner:
|
||||
os_snapshot = cinder.volume_snapshots.create(
|
||||
os_volume.id, force=True,
|
||||
display_description=description)
|
||||
os_snapshot = cinder.volume_snapshots.create(os_volume.id, True)
|
||||
cleaner.addCleanup(os_snapshot.delete)
|
||||
snapshot = db_api.add_item(context, 'snap', {'os_id': os_snapshot.id})
|
||||
cleaner.addCleanup(db_api.delete_item, context, snapshot['id'])
|
||||
os_snapshot.update(display_name=snapshot['id'])
|
||||
os_snapshot.update(display_name=snapshot['id'],
|
||||
display_description=description)
|
||||
|
||||
return _format_snapshot(context, snapshot, os_snapshot,
|
||||
volume_id=volume_id)
|
||||
|
@ -142,6 +141,8 @@ def _format_snapshot(context, snapshot, os_snapshot, volumes={},
|
|||
progress = os_snapshot.progress
|
||||
if not progress:
|
||||
progress = '0%'
|
||||
description = (getattr(os_snapshot, 'description', None) or
|
||||
getattr(os_snapshot, 'display_description', None))
|
||||
return {'snapshotId': snapshot['id'],
|
||||
'volumeId': volume_id,
|
||||
'status': mapped_status,
|
||||
|
@ -149,4 +150,4 @@ def _format_snapshot(context, snapshot, os_snapshot, volumes={},
|
|||
'progress': progress,
|
||||
'ownerId': ownerId,
|
||||
'volumeSize': os_snapshot.size,
|
||||
'description': os_snapshot.display_description}
|
||||
'description': description}
|
||||
|
|
|
@ -41,6 +41,10 @@ ec2_opts = [
|
|||
'catalog. Should be v2.1 with microversion support. '
|
||||
'If it is obsolete v2, a lot of useful EC2 compliant '
|
||||
'instance properties will be unavailable.'),
|
||||
cfg.StrOpt('cinder_service_type',
|
||||
default='volume',
|
||||
help='Service type of Volume API, registered in Keystone '
|
||||
'catalog.'),
|
||||
# TODO(andrey-mp): keystone v3 allows to pass domain_name
|
||||
# or domain_id to auth. This code should support this feature.
|
||||
cfg.StrOpt('admin_user',
|
||||
|
@ -82,27 +86,23 @@ def nova(context):
|
|||
|
||||
|
||||
def neutron(context):
|
||||
if neutronclient is None:
|
||||
return None
|
||||
|
||||
return neutronclient.Client(session=context.session,
|
||||
service_type='network')
|
||||
|
||||
|
||||
def glance(context):
|
||||
if glanceclient is None:
|
||||
return None
|
||||
|
||||
return glanceclient.Client('1', service_type='image',
|
||||
session=context.session)
|
||||
|
||||
|
||||
def cinder(context):
|
||||
if cinderclient is None:
|
||||
return nova(context, 'volume')
|
||||
|
||||
return cinderclient.Client('1', session=context.session,
|
||||
service_type='volume')
|
||||
url = context.session.get_endpoint(service_type=CONF.cinder_service_type)
|
||||
# TODO(jamielennox): This should be using proper version discovery from
|
||||
# the cinder service rather than just inspecting the URL for certain string
|
||||
# values.
|
||||
version = cinderclient.get_volume_api_from_url(url)
|
||||
return cinderclient.Client(version, session=context.session,
|
||||
service_type=CONF.cinder_service_type)
|
||||
|
||||
|
||||
def keystone(context):
|
||||
|
|
|
@ -55,6 +55,8 @@ def create_context(is_os_admin=False):
|
|||
session = (mock.sentinel.admin_session
|
||||
if is_os_admin else
|
||||
mock.sentinel.session)
|
||||
session.get_endpoint = mock.Mock(name="get_endpoint")
|
||||
session.get_endpoint.return_value = 'v1'
|
||||
return ec2api.context.RequestContext(fakes.ID_OS_USER, fakes.ID_OS_PROJECT,
|
||||
is_os_admin=is_os_admin,
|
||||
session=session)
|
||||
|
|
|
@ -116,7 +116,7 @@ class SnapshotTestCase(base.ApiTestCase):
|
|||
tools.purge_dict(fakes.DB_SNAPSHOT_1, ('id',)))
|
||||
|
||||
self.cinder.volume_snapshots.create.assert_called_once_with(
|
||||
fakes.ID_OS_VOLUME_2, force=True, display_description=None)
|
||||
fakes.ID_OS_VOLUME_2, force=True)
|
||||
|
||||
def test_format_snapshot_maps_status(self):
|
||||
fake_snapshot = fakes.OSSnapshot(fakes.OS_SNAPSHOT_1)
|
||||
|
|
Loading…
Reference in New Issue