Add fields to cinder:volumes and new attachments table

The following information is added: encrypted, availability_zone,
replication_status, multiattach, snapshot_id, source_volid,
consistencygroup_id, migration_status, attachments.

We discussed on IRC how to deal with changes to the data schema. There
was some agreement that versioning the schema was the most complete
solution.

But at the moment and in the medium term, we do not have much need for
understanding the different versions in code (ie. a version parameter
gets passed to the driver when creating a datasource). So in this
patch, I propose to document the cinder driver schema version as 2.1
(and the original version 2.0 to coincide with the cinder client
version used.) Rules written for 2.0 is compatible with 2.1 driver.
But rules written for 2.1 schema may not be compatible with the 2.0
driver.

The schema version is helpful so that when a policy is documented
with the schema version it is based on, users can figure out whether
it is compatible with a particular install of congress drivers.

At the same time, we avoid some implementation and maintenance
complexity by maintaining only the latest minor version of each major
version.

Note: the backward compatibility of this change would be achieved with
positional argument padding under review here:
https://review.openstack.org/#/c/448828/

Closes-bug: 1674537

Change-Id: Ia0f2f17b4e25f70600175ababb35805fbcdd3142
This commit is contained in:
Eric Kao 2017-03-20 21:14:01 -07:00
parent c707d2bd32
commit 13a58362b5
3 changed files with 95 additions and 10 deletions

View File

@ -13,6 +13,20 @@
# under the License.
#
"""Schema version history
version: 2.1
date: 2016-03-27
changes:
- Added columns to the volumes table: encrypted, availability_zone,
replication_status, multiattach, snapshot_id, source_volid,
consistencygroup_id, migration_status
- Added the attachments table for volume attachment information.
version: 2.0
Initial schema version.
"""
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
@ -27,6 +41,7 @@ from congress.datasources import datasource_utils as ds_utils
class CinderDriver(datasource_driver.PollingDataSourceDriver,
datasource_driver.ExecutionDriver):
VOLUMES = "volumes"
ATTACHMENTS = "attachments"
SNAPSHOTS = "snapshots"
SERVICES = "services"
@ -46,7 +61,25 @@ class CinderDriver(datasource_driver.PollingDataSourceDriver,
{'fieldname': 'name', 'translator': value_trans},
{'fieldname': 'bootable', 'translator': value_trans},
{'fieldname': 'created_at', 'translator': value_trans},
{'fieldname': 'volume_type', 'translator': value_trans})}
{'fieldname': 'volume_type', 'translator': value_trans},
{'fieldname': 'encrypted', 'translator': value_trans},
{'fieldname': 'availability_zone', 'translator': value_trans},
{'fieldname': 'replication_status', 'translator': value_trans},
{'fieldname': 'multiattach', 'translator': value_trans},
{'fieldname': 'snapshot_id', 'translator': value_trans},
{'fieldname': 'source_volid', 'translator': value_trans},
{'fieldname': 'consistencygroup_id', 'translator': value_trans},
{'fieldname': 'migration_status', 'translator': value_trans},
{'fieldname': 'attachments',
'translator': {'translation-type': 'LIST',
'table-name': ATTACHMENTS,
'val-col': 'attachment',
'val-col-desc': 'List of attachments',
'parent-key': 'id',
'parent-col-name': 'volume_id',
'parent-key-desc': 'UUID of volume',
'translator': value_trans}},
)}
snapshots_translator = {
'translation-type': 'HDICT',

View File

@ -41,33 +41,74 @@ class TestCinderDriver(base.TestCase):
'status': 'available',
'description': 'foo',
'name': 'bar',
'bootable': 'False',
'bootable': 'false',
'created_at': '2014-10-09T12:16:23.000000',
'volume_type': 'lvmdriver-1'}),
'volume_type': 'lvmdriver-1',
'encrypted': False,
'availability_zone': 'nova1',
'replication_status': 'r_status1',
'multiattach': True,
'snapshot_id': '3b890e8a-7881-4430-b087-9e9e642e5e0d',
'source_volid':
'b4c36f7a-ac1b-41a6-9e83-03a6c1149669',
'consistencygroup_id':
'7aa9787f-285d-4d22-8211-e20af07f1044',
'migration_status': 'm_status1',
'attachments':
['d9655db9-640b-40a5-ae2f-1166183518a6',
'fc1a3f20-9be3-431f-9cb2-670c191e4282'],
'extra_attribute': ['extra']}),
ResponseObj({'id': '7cd8f73d-3243-49c9-a25b-a77ceb6ad1fa',
'size': '1',
'user_id': '6e14edb203a84aa6a5a6a90872cbae79',
'status': 'creating',
'description': 'wonder',
'name': 'alice',
'bootable': 'True',
'bootable': 'true',
'created_at': '2014-10-12T06:54:55.000000',
'volume_type': 'None'})]
'volume_type': 'None',
'encrypted': True,
'availability_zone': 'nova2',
'replication_status': 'r_status2',
'multiattach': False,
'snapshot_id': '658b5663-9e83-406b-8b81-4a50cafaa2d6',
'source_volid':
'bf789ec1-b4a2-4ea0-94f4-4a6ebcc00ad8',
'consistencygroup_id':
'960ec54c-c2a4-4e4c-8192-8b1d9eb65fae',
'migration_status': 'm_status2',
'attachments': [],
'extra_attribute': ['extra']})]
volume_list = self.driver._translate_volumes(volumes_data)
self.assertIsNotNone(volume_list)
self.assertEqual(2, len(volume_list))
self.assertEqual(4, len(volume_list))
self.assertEqual({('8bf2eddb-0e1a-46f9-a49a-853f8016f476', '1',
'b75055d5f0834d99ae874f085cf95272', 'available',
'foo', 'bar', 'False', '2014-10-09T12:16:23.000000',
'lvmdriver-1'),
'foo', 'bar', 'false', '2014-10-09T12:16:23.000000',
'lvmdriver-1', 'False', 'nova1', 'r_status1',
'True', '3b890e8a-7881-4430-b087-9e9e642e5e0d',
'b4c36f7a-ac1b-41a6-9e83-03a6c1149669',
'7aa9787f-285d-4d22-8211-e20af07f1044',
'm_status1'),
('7cd8f73d-3243-49c9-a25b-a77ceb6ad1fa', '1',
'6e14edb203a84aa6a5a6a90872cbae79', 'creating',
'wonder', 'alice', 'True',
'2014-10-12T06:54:55.000000', 'None')},
'wonder', 'alice', 'true',
'2014-10-12T06:54:55.000000', 'None',
'True', 'nova2', 'r_status2', 'False',
'658b5663-9e83-406b-8b81-4a50cafaa2d6',
'bf789ec1-b4a2-4ea0-94f4-4a6ebcc00ad8',
'960ec54c-c2a4-4e4c-8192-8b1d9eb65fae',
'm_status2')},
self.driver.state['volumes'])
self.assertEqual({('8bf2eddb-0e1a-46f9-a49a-853f8016f476',
'd9655db9-640b-40a5-ae2f-1166183518a6'),
('8bf2eddb-0e1a-46f9-a49a-853f8016f476',
'fc1a3f20-9be3-431f-9cb2-670c191e4282')},
self.driver.state['attachments'])
def test_list_snaphosts(self):
snapshots_data = [
ResponseObj({'status': 'available',

View File

@ -0,0 +1,11 @@
---
prelude: >
features:
- The following Cinder volume attributes are now
available through Congress driver for cinder.
encrypted, availability_zone, replication_status,
multiattach, snapshot_id, source_volid, consistencygroup_id,
migration_status, attachments.
- The Cinder schema version is set to 2.1, backward
compatible with policy rules written under the
previous Cinder driver data schema.