From b5ac930aabfeff69f9a669f6dd774851db53df99 Mon Sep 17 00:00:00 2001 From: Igor Malinovskiy Date: Fri, 28 Aug 2015 16:17:57 +0300 Subject: [PATCH] Use Share Instance ID in 'name' property Use Share Instance ID in 'name' property instead of proxyfing 'name' property of a share. Change-Id: I0058987424f5cdfb931a9805d08fc69bff859f5b Closes-Bug: #1489526 --- manila/db/sqlalchemy/models.py | 8 ++++++-- manila/tests/db/sqlalchemy/test_api.py | 7 +++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/manila/db/sqlalchemy/models.py b/manila/db/sqlalchemy/models.py index 96ebb5b953..bd041fc86f 100644 --- a/manila/db/sqlalchemy/models.py +++ b/manila/db/sqlalchemy/models.py @@ -267,8 +267,8 @@ class Share(BASE, ManilaBase): class ShareInstance(BASE, ManilaBase): __tablename__ = 'share_instances' - _extra_keys = ['export_location', 'availability_zone'] - _proxified_properties = ('name', 'user_id', 'project_id', 'size', + _extra_keys = ['name', 'export_location', 'availability_zone'] + _proxified_properties = ('user_id', 'project_id', 'size', 'display_name', 'display_description', 'snapshot_id', 'share_proto', 'share_type_id', 'is_public') @@ -277,6 +277,10 @@ class ShareInstance(BASE, ManilaBase): for share_property in self._proxified_properties: setattr(self, share_property, share[share_property]) + @property + def name(self): + return CONF.share_name_template % self.id + @property def export_location(self): if len(self.export_locations) > 0: diff --git a/manila/tests/db/sqlalchemy/test_api.py b/manila/tests/db/sqlalchemy/test_api.py index 59736a692c..832b98513f 100644 --- a/manila/tests/db/sqlalchemy/test_api.py +++ b/manila/tests/db/sqlalchemy/test_api.py @@ -186,6 +186,13 @@ class ShareDatabaseAPITestCase(test.TestCase): self.assertRaises(exception.NotFound, db_api.share_get, self.ctxt, share['id']) + def test_share_instance_get(self): + share = db_utils.create_share() + + instance = db_api.share_instance_get(self.ctxt, share.instance['id']) + + self.assertEqual('share-%s' % instance['id'], instance['name']) + @ddt.data('host') def test_share_get_all_sort_by_share_instance_fields(self, sort_key): shares = [db_utils.create_share(**{sort_key: n, 'size': 1})