Set parent share az when creating a share from snapshot

This patch-set modifies how we manage user input when creating a share
from snapshot. Since we use the same form for the basic create share workflow
and for the create share from snapshot workflow, we need to add a check
to distinguish both cases: when creating a share from snapshot, the
parent share availability zone is picked by default. Otherwise, if it's a
regular share create, the user can pick up the availability zone they need.

Closes-Bug: #1915706

Change-Id: I8d93c2214cb187a763df861555ddd7b444c9ca89
This commit is contained in:
Dina Saparbaeva 2021-03-05 18:35:47 +00:00 committed by Dina Saparbaeva
parent 44437c364d
commit 4d333690c4
2 changed files with 5 additions and 8 deletions

View File

@ -127,12 +127,12 @@ class CreateForm(forms.SelfHandlingForm):
self.fields['size'].initial = snapshot.size
self.fields['snapshot'].choices = ((snapshot.id, snapshot),)
try:
# Set the share type from the original share
# Set the share type and az from the original share
orig_share = manila.share_get(request, snapshot.share_id)
# NOTE(vponomaryov): we should use share type name, not ID,
# because we use names in our choices above.
self.fields['share_type'].initial = (
orig_share.share_type_name)
self.fields['availability_zone'].initial = (
orig_share.availability_zone)
except Exception:
pass
self.fields['size'].help_text = _(
@ -230,7 +230,7 @@ class CreateForm(forms.SelfHandlingForm):
share_type=data['share_type'],
is_public=is_public,
metadata=metadata,
availability_zone=data['availability_zone'],
availability_zone=data.get('availability_zone') or None,
share_group_id=data.get('sg') or None,
)
message = _('Creating share "%s"') % data['name']

View File

@ -148,9 +148,7 @@ class ShareViewTests(test.APITestCase):
'share_source_type': 'snapshot',
'snapshot': snapshot.id,
'share-network-choices-fake': share_net.id,
'availability_zone': 'fake_az',
}
mock_az_list.return_value = [self.FakeAZ('fake_az'), ]
self.mock_object(
api_manila, "share_create", mock.Mock(return_value=share))
self.mock_object(
@ -167,7 +165,6 @@ class ShareViewTests(test.APITestCase):
res = self.client.post(url, formData)
mock_az_list.assert_called_once_with(mock.ANY)
api_manila.share_snapshot_list.assert_not_called()
api_manila.share_snapshot_get.assert_called_once_with(
mock.ANY, snapshot.id)
@ -179,7 +176,7 @@ class ShareViewTests(test.APITestCase):
snapshot_id=snapshot.id, is_public=False,
share_group_id=None, share_network=share_net.id, metadata={},
share_type=formData['share_type'],
availability_zone=formData['availability_zone'])
availability_zone=None)
self.assertRedirectsNoFollow(res, INDEX_URL)
def test_delete_share(self):