Merge "Use ShareInstance model to access share properties" into stable/ocata

This commit is contained in:
Zuul 2018-09-21 12:29:18 +00:00 committed by Gerrit Code Review
commit 0dd3501f74
6 changed files with 35 additions and 17 deletions

View File

@ -65,12 +65,13 @@ class ViewBuilder(common.ViewBuilder):
export_locations = share.get('export_locations', []) export_locations = share.get('export_locations', [])
if share['share_type_id'] and share.get('share_type'):
share_type = share['share_type']['name']
else:
share_type = share['share_type_id']
share_instance = share.get('instance') or {} share_instance = share.get('instance') or {}
if share_instance.get('share_type'):
share_type = share_instance.get('share_type').get('name')
else:
share_type = share_instance.get('share_type_id')
share_dict = { share_dict = {
'id': share.get('id'), 'id': share.get('id'),
'size': share.get('size'), 'size': share.get('size'),
@ -109,11 +110,13 @@ class ViewBuilder(common.ViewBuilder):
@common.ViewBuilder.versioned_method("2.6") @common.ViewBuilder.versioned_method("2.6")
def modify_share_type_field(self, context, share_dict, share): def modify_share_type_field(self, context, share_dict, share):
share_type = share.get('share_type_id') share_instance = share.get('instance') or {}
share_type = share_instance.get('share_type_id')
share_type_name = None share_type_name = None
if share.get('share_type'): if share_instance.get('share_type'):
share_type_name = share.get('share_type').get('name') share_type_name = share_instance.get('share_type').get('name')
share_dict.update({ share_dict.update({
'share_type_name': share_type_name, 'share_type_name': share_type_name,

View File

@ -54,6 +54,7 @@ def stub_share(id, **kwargs):
'share_network_id': None, 'share_network_id': None,
'share_server_id': 'fake_share_server_id', 'share_server_id': 'fake_share_server_id',
'access_rules_status': 'active', 'access_rules_status': 'active',
'share_type_id': '1',
} }
if 'instance' in kwargs: if 'instance' in kwargs:
share_instance.update(kwargs.pop('instance')) share_instance.update(kwargs.pop('instance'))

View File

@ -615,9 +615,9 @@ class ShareAPITest(test.TestCase):
'display_name': 'n2', 'display_name': 'n2',
'status': constants.STATUS_AVAILABLE, 'status': constants.STATUS_AVAILABLE,
'snapshot_id': 'fake_snapshot_id', 'snapshot_id': 'fake_snapshot_id',
'share_type_id': 'fake_share_type_id',
'instance': {'host': 'fake_host', 'instance': {'host': 'fake_host',
'share_network_id': 'fake_share_network_id'}, 'share_network_id': 'fake_share_network_id',
'share_type_id': 'fake_share_type_id'},
}, },
{'id': 'id3', 'display_name': 'n3'}, {'id': 'id3', 'display_name': 'n3'},
] ]
@ -655,7 +655,8 @@ class ShareAPITest(test.TestCase):
self.assertEqual( self.assertEqual(
shares[1]['status'], result['shares'][0]['status']) shares[1]['status'], result['shares'][0]['status'])
self.assertEqual( self.assertEqual(
shares[1]['share_type_id'], result['shares'][0]['share_type']) shares[1]['instance']['share_type_id'],
result['shares'][0]['share_type'])
self.assertEqual( self.assertEqual(
shares[1]['snapshot_id'], result['shares'][0]['snapshot_id']) shares[1]['snapshot_id'], result['shares'][0]['snapshot_id'])
if use_admin_context: if use_admin_context:

View File

@ -1529,10 +1529,10 @@ class ShareAPITest(test.TestCase):
'display_name': 'n2', 'display_name': 'n2',
'status': constants.STATUS_AVAILABLE, 'status': constants.STATUS_AVAILABLE,
'snapshot_id': 'fake_snapshot_id', 'snapshot_id': 'fake_snapshot_id',
'share_type_id': 'fake_share_type_id',
'instance': { 'instance': {
'host': 'fake_host', 'host': 'fake_host',
'share_network_id': 'fake_share_network_id', 'share_network_id': 'fake_share_network_id',
'share_type_id': 'fake_share_type_id',
}, },
}, },
{'id': 'id3', 'display_name': 'n3'}, {'id': 'id3', 'display_name': 'n3'},
@ -1571,7 +1571,8 @@ class ShareAPITest(test.TestCase):
self.assertEqual( self.assertEqual(
shares[1]['status'], result['shares'][0]['status']) shares[1]['status'], result['shares'][0]['status'])
self.assertEqual( self.assertEqual(
shares[1]['share_type_id'], result['shares'][0]['share_type']) shares[1]['instance']['share_type_id'],
result['shares'][0]['share_type'])
self.assertEqual( self.assertEqual(
shares[1]['snapshot_id'], result['shares'][0]['snapshot_id']) shares[1]['snapshot_id'], result['shares'][0]['snapshot_id'])
if use_admin_context: if use_admin_context:
@ -2538,7 +2539,12 @@ class ShareManageTest(test.TestCase):
} }
self._setup_manage_mocks() self._setup_manage_mocks()
return_share = mock.Mock( return_share = mock.Mock(
return_value=stubs.stub_share('fake', instance={})) return_value=stubs.stub_share(
'fake',
instance={
'share_type_id': '1',
})
)
self.mock_object( self.mock_object(
share_api.API, 'manage', return_share) share_api.API, 'manage', return_share)
share = { share = {

View File

@ -39,7 +39,12 @@ class ViewBuilderTestCase(test.TestCase):
'export_location': 'fake_export_location', 'export_location': 'fake_export_location',
'export_locations': ['fake_export_location'], 'export_locations': ['fake_export_location'],
'access_rules_status': 'fake_rule_status', 'access_rules_status': 'fake_rule_status',
'instance': {}, 'instance': {
'share_type': {
'name': 'fake_share_type_name',
},
'share_type_id': 'fake_share_type_id',
},
'replication_type': 'fake_replication_type', 'replication_type': 'fake_replication_type',
'has_replicas': False, 'has_replicas': False,
'user_id': 'fake_userid', 'user_id': 'fake_userid',

View File

@ -31,7 +31,6 @@ def fake_share(**kwargs):
'share_proto': 'fake_proto', 'share_proto': 'fake_proto',
'share_network_id': 'fake share network id', 'share_network_id': 'fake share network id',
'share_server_id': 'fake share server id', 'share_server_id': 'fake share server id',
'share_type_id': 'fake share type id',
'export_location': 'fake_location:/fake_share', 'export_location': 'fake_location:/fake_share',
'project_id': 'fake_project_uuid', 'project_id': 'fake_project_uuid',
'availability_zone': 'fake_az', 'availability_zone': 'fake_az',
@ -39,7 +38,10 @@ def fake_share(**kwargs):
'replication_type': None, 'replication_type': None,
'is_busy': False, 'is_busy': False,
'share_group_id': None, 'share_group_id': None,
'instance': {'host': 'fakehost'}, 'instance': {
'host': 'fakehost',
'share_type_id': '1',
},
'mount_snapshot_support': False, 'mount_snapshot_support': False,
} }
share.update(kwargs) share.update(kwargs)