summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrey Pavlov <andrey-mp@yandex.ru>2015-12-07 16:10:18 +0300
committerAndrey Pavlov <andrey-mp@yandex.ru>2015-12-17 15:29:20 +0300
commit4d989aefcb779e6ec7fcb59296552820d8db9e3e (patch)
tree6884a6b81b56a3b16f2e10bf95802083ad648e39
parent85986cfc8cedd0f70e9728f284e359f46259820e (diff)
fix working with cinder API v21.0.2
add cinder_service_type to config and fix code to be compatible with cinderclient v2 Change-Id: Ia7eec95e19c5472d741fc9759ef4f8929ac516f7 (cherry picked from commit e22e6a1bc0b504d3af43efc6ef0358b36f1a8368)
Notes
Notes (review): Code-Review+2: Alexandre Levine <alexandrelevine@gmail.com> Workflow+1: Alexandre Levine <alexandrelevine@gmail.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Thu, 17 Dec 2015 18:37:16 +0000 Reviewed-on: https://review.openstack.org/258538 Project: openstack/ec2-api Branch: refs/heads/stable/liberty
-rwxr-xr-xdevstack/plugin.sh2
-rw-r--r--ec2api/api/snapshot.py11
-rw-r--r--ec2api/clients.py22
-rw-r--r--ec2api/tests/unit/base.py2
-rw-r--r--ec2api/tests/unit/test_snapshot.py2
-rw-r--r--setup.cfg2
6 files changed, 23 insertions, 18 deletions
diff --git a/devstack/plugin.sh b/devstack/plugin.sh
index b07df9c..5ec7b5e 100755
--- a/devstack/plugin.sh
+++ b/devstack/plugin.sh
@@ -12,6 +12,8 @@
12# stop_ec2api 12# stop_ec2api
13 13
14 14
15env | sort
16
15# Save trace setting 17# Save trace setting
16XTRACE=$(set +o | grep xtrace) 18XTRACE=$(set +o | grep xtrace)
17set -o xtrace 19set -o xtrace
diff --git a/ec2api/api/snapshot.py b/ec2api/api/snapshot.py
index a656aba..2fdbeba 100644
--- a/ec2api/api/snapshot.py
+++ b/ec2api/api/snapshot.py
@@ -42,13 +42,12 @@ def create_snapshot(context, volume_id, description=None):
42 volume_id) 42 volume_id)
43 raise exception.IncorrectState(reason=msg) 43 raise exception.IncorrectState(reason=msg)
44 with common.OnCrashCleaner() as cleaner: 44 with common.OnCrashCleaner() as cleaner:
45 os_snapshot = cinder.volume_snapshots.create( 45 os_snapshot = cinder.volume_snapshots.create(os_volume.id, True)
46 os_volume.id, force=True,
47 display_description=description)
48 cleaner.addCleanup(os_snapshot.delete) 46 cleaner.addCleanup(os_snapshot.delete)
49 snapshot = db_api.add_item(context, 'snap', {'os_id': os_snapshot.id}) 47 snapshot = db_api.add_item(context, 'snap', {'os_id': os_snapshot.id})
50 cleaner.addCleanup(db_api.delete_item, context, snapshot['id']) 48 cleaner.addCleanup(db_api.delete_item, context, snapshot['id'])
51 os_snapshot.update(display_name=snapshot['id']) 49 os_snapshot.update(display_name=snapshot['id'],
50 display_description=description)
52 51
53 return _format_snapshot(context, snapshot, os_snapshot, 52 return _format_snapshot(context, snapshot, os_snapshot,
54 volume_id=volume_id) 53 volume_id=volume_id)
@@ -142,6 +141,8 @@ def _format_snapshot(context, snapshot, os_snapshot, volumes={},
142 progress = os_snapshot.progress 141 progress = os_snapshot.progress
143 if not progress: 142 if not progress:
144 progress = '0%' 143 progress = '0%'
144 description = (getattr(os_snapshot, 'description', None) or
145 getattr(os_snapshot, 'display_description', None))
145 return {'snapshotId': snapshot['id'], 146 return {'snapshotId': snapshot['id'],
146 'volumeId': volume_id, 147 'volumeId': volume_id,
147 'status': mapped_status, 148 'status': mapped_status,
@@ -149,4 +150,4 @@ def _format_snapshot(context, snapshot, os_snapshot, volumes={},
149 'progress': progress, 150 'progress': progress,
150 'ownerId': ownerId, 151 'ownerId': ownerId,
151 'volumeSize': os_snapshot.size, 152 'volumeSize': os_snapshot.size,
152 'description': os_snapshot.display_description} 153 'description': description}
diff --git a/ec2api/clients.py b/ec2api/clients.py
index 9831da1..15cd7ca 100644
--- a/ec2api/clients.py
+++ b/ec2api/clients.py
@@ -41,6 +41,10 @@ ec2_opts = [
41 'catalog. Should be v2.1 with microversion support. ' 41 'catalog. Should be v2.1 with microversion support. '
42 'If it is obsolete v2, a lot of useful EC2 compliant ' 42 'If it is obsolete v2, a lot of useful EC2 compliant '
43 'instance properties will be unavailable.'), 43 'instance properties will be unavailable.'),
44 cfg.StrOpt('cinder_service_type',
45 default='volume',
46 help='Service type of Volume API, registered in Keystone '
47 'catalog.'),
44 # TODO(andrey-mp): keystone v3 allows to pass domain_name 48 # TODO(andrey-mp): keystone v3 allows to pass domain_name
45 # or domain_id to auth. This code should support this feature. 49 # or domain_id to auth. This code should support this feature.
46 cfg.StrOpt('admin_user', 50 cfg.StrOpt('admin_user',
@@ -82,27 +86,23 @@ def nova(context):
82 86
83 87
84def neutron(context): 88def neutron(context):
85 if neutronclient is None:
86 return None
87
88 return neutronclient.Client(session=context.session, 89 return neutronclient.Client(session=context.session,
89 service_type='network') 90 service_type='network')
90 91
91 92
92def glance(context): 93def glance(context):
93 if glanceclient is None:
94 return None
95
96 return glanceclient.Client('1', service_type='image', 94 return glanceclient.Client('1', service_type='image',
97 session=context.session) 95 session=context.session)
98 96
99 97
100def cinder(context): 98def cinder(context):
101 if cinderclient is None: 99 url = context.session.get_endpoint(service_type=CONF.cinder_service_type)
102 return nova(context, 'volume') 100 # TODO(jamielennox): This should be using proper version discovery from
103 101 # the cinder service rather than just inspecting the URL for certain string
104 return cinderclient.Client('1', session=context.session, 102 # values.
105 service_type='volume') 103 version = cinderclient.get_volume_api_from_url(url)
104 return cinderclient.Client(version, session=context.session,
105 service_type=CONF.cinder_service_type)
106 106
107 107
108def keystone(context): 108def keystone(context):
diff --git a/ec2api/tests/unit/base.py b/ec2api/tests/unit/base.py
index 7762731..521ed05 100644
--- a/ec2api/tests/unit/base.py
+++ b/ec2api/tests/unit/base.py
@@ -55,6 +55,8 @@ def create_context(is_os_admin=False):
55 session = (mock.sentinel.admin_session 55 session = (mock.sentinel.admin_session
56 if is_os_admin else 56 if is_os_admin else
57 mock.sentinel.session) 57 mock.sentinel.session)
58 session.get_endpoint = mock.Mock(name="get_endpoint")
59 session.get_endpoint.return_value = 'v1'
58 return ec2api.context.RequestContext(fakes.ID_OS_USER, fakes.ID_OS_PROJECT, 60 return ec2api.context.RequestContext(fakes.ID_OS_USER, fakes.ID_OS_PROJECT,
59 is_os_admin=is_os_admin, 61 is_os_admin=is_os_admin,
60 session=session) 62 session=session)
diff --git a/ec2api/tests/unit/test_snapshot.py b/ec2api/tests/unit/test_snapshot.py
index 26ae6ac..1f6b590 100644
--- a/ec2api/tests/unit/test_snapshot.py
+++ b/ec2api/tests/unit/test_snapshot.py
@@ -116,7 +116,7 @@ class SnapshotTestCase(base.ApiTestCase):
116 tools.purge_dict(fakes.DB_SNAPSHOT_1, ('id',))) 116 tools.purge_dict(fakes.DB_SNAPSHOT_1, ('id',)))
117 117
118 self.cinder.volume_snapshots.create.assert_called_once_with( 118 self.cinder.volume_snapshots.create.assert_called_once_with(
119 fakes.ID_OS_VOLUME_2, force=True, display_description=None) 119 fakes.ID_OS_VOLUME_2, force=True)
120 120
121 def test_format_snapshot_maps_status(self): 121 def test_format_snapshot_maps_status(self):
122 fake_snapshot = fakes.OSSnapshot(fakes.OS_SNAPSHOT_1) 122 fake_snapshot = fakes.OSSnapshot(fakes.OS_SNAPSHOT_1)
diff --git a/setup.cfg b/setup.cfg
index 4c63cff..d8bb8db 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,6 +1,6 @@
1[metadata] 1[metadata]
2name = ec2-api 2name = ec2-api
3version = 1.0.1 3version = 1.0.2
4summary = OpenStack Ec2api Service 4summary = OpenStack Ec2api Service
5description-file = 5description-file =
6 README.rst 6 README.rst