Merge "Use ShareInstance model to access share properties"
This commit is contained in:
commit
01370846fa
@ -65,12 +65,13 @@ class ViewBuilder(common.ViewBuilder):
|
||||
|
||||
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 {}
|
||||
|
||||
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 = {
|
||||
'id': share.get('id'),
|
||||
'size': share.get('size'),
|
||||
@ -109,11 +110,13 @@ class ViewBuilder(common.ViewBuilder):
|
||||
|
||||
@common.ViewBuilder.versioned_method("2.6")
|
||||
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
|
||||
if share.get('share_type'):
|
||||
share_type_name = share.get('share_type').get('name')
|
||||
if share_instance.get('share_type'):
|
||||
share_type_name = share_instance.get('share_type').get('name')
|
||||
|
||||
share_dict.update({
|
||||
'share_type_name': share_type_name,
|
||||
|
@ -54,6 +54,7 @@ def stub_share(id, **kwargs):
|
||||
'share_network_id': None,
|
||||
'share_server_id': 'fake_share_server_id',
|
||||
'access_rules_status': 'active',
|
||||
'share_type_id': '1',
|
||||
}
|
||||
if 'instance' in kwargs:
|
||||
share_instance.update(kwargs.pop('instance'))
|
||||
|
@ -615,9 +615,9 @@ class ShareAPITest(test.TestCase):
|
||||
'display_name': 'n2',
|
||||
'status': constants.STATUS_AVAILABLE,
|
||||
'snapshot_id': 'fake_snapshot_id',
|
||||
'share_type_id': 'fake_share_type_id',
|
||||
'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'},
|
||||
]
|
||||
@ -655,7 +655,8 @@ class ShareAPITest(test.TestCase):
|
||||
self.assertEqual(
|
||||
shares[1]['status'], result['shares'][0]['status'])
|
||||
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(
|
||||
shares[1]['snapshot_id'], result['shares'][0]['snapshot_id'])
|
||||
if use_admin_context:
|
||||
|
@ -1529,10 +1529,10 @@ class ShareAPITest(test.TestCase):
|
||||
'display_name': 'n2',
|
||||
'status': constants.STATUS_AVAILABLE,
|
||||
'snapshot_id': 'fake_snapshot_id',
|
||||
'share_type_id': 'fake_share_type_id',
|
||||
'instance': {
|
||||
'host': 'fake_host',
|
||||
'share_network_id': 'fake_share_network_id',
|
||||
'share_type_id': 'fake_share_type_id',
|
||||
},
|
||||
},
|
||||
{'id': 'id3', 'display_name': 'n3'},
|
||||
@ -1571,7 +1571,8 @@ class ShareAPITest(test.TestCase):
|
||||
self.assertEqual(
|
||||
shares[1]['status'], result['shares'][0]['status'])
|
||||
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(
|
||||
shares[1]['snapshot_id'], result['shares'][0]['snapshot_id'])
|
||||
if use_admin_context:
|
||||
@ -2546,7 +2547,12 @@ class ShareManageTest(test.TestCase):
|
||||
}
|
||||
self._setup_manage_mocks()
|
||||
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(
|
||||
share_api.API, 'manage', return_share)
|
||||
share = {
|
||||
|
@ -39,7 +39,12 @@ class ViewBuilderTestCase(test.TestCase):
|
||||
'export_location': 'fake_export_location',
|
||||
'export_locations': ['fake_export_location'],
|
||||
'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',
|
||||
'has_replicas': False,
|
||||
'user_id': 'fake_userid',
|
||||
|
@ -31,7 +31,6 @@ def fake_share(**kwargs):
|
||||
'share_proto': 'fake_proto',
|
||||
'share_network_id': 'fake share network id',
|
||||
'share_server_id': 'fake share server id',
|
||||
'share_type_id': 'fake share type id',
|
||||
'export_location': 'fake_location:/fake_share',
|
||||
'project_id': 'fake_project_uuid',
|
||||
'availability_zone': 'fake_az',
|
||||
@ -39,7 +38,10 @@ def fake_share(**kwargs):
|
||||
'replication_type': None,
|
||||
'is_busy': False,
|
||||
'share_group_id': None,
|
||||
'instance': {'host': 'fakehost'},
|
||||
'instance': {
|
||||
'host': 'fakehost',
|
||||
'share_type_id': '1',
|
||||
},
|
||||
'mount_snapshot_support': False,
|
||||
}
|
||||
share.update(kwargs)
|
||||
|
Loading…
Reference in New Issue
Block a user