Fix share creation from snapshot
For the moment if we create share from snapshot from first attempt we get share created from scratch, not from snapshot. This bug appered after merge of [1] to manila and usage of 2.6+ microversion in Manila UI. The reason why [1] had influence is in changed share view that became incompatible with 'choices' in UI that depend on share type names. So, start using correct field 'share_type_name', that will set default value for share type omitting the need to set it manually all the time, it also will trigger correct snapshot ID selection for request. Also, fix logic for second+ attempt, where we were using different set of data after failed attempt to submit request. [1] I082bdac82c981adf733c709472ce1b9e26d5650b Change-Id: I4b5a04ed16d8e579ad816e84ad907ddd97e13ac1 Closes-Bug: #1685657
This commit is contained in:
parent
eeb254081c
commit
c458dff54c
|
@ -112,17 +112,23 @@ class CreateForm(forms.SelfHandlingForm):
|
|||
|
||||
self.fields['share_proto'].choices = [(sp, sp) for sp in
|
||||
self.enabled_share_protocols]
|
||||
if "snapshot_id" in request.GET:
|
||||
if ("snapshot_id" in request.GET or
|
||||
kwargs.get("data", {}).get("snapshot")):
|
||||
try:
|
||||
snapshot = self.get_snapshot(request,
|
||||
request.GET["snapshot_id"])
|
||||
snapshot = self.get_snapshot(
|
||||
request,
|
||||
request.GET.get("snapshot_id",
|
||||
kwargs.get("data", {}).get("snapshot")))
|
||||
self.fields['name'].initial = snapshot.name
|
||||
self.fields['size'].initial = snapshot.size
|
||||
self.fields['snapshot'].choices = ((snapshot.id, snapshot),)
|
||||
try:
|
||||
# Set the share type from the original share
|
||||
orig_share = manila.share_get(request, snapshot.share_id)
|
||||
self.fields['share_type'].initial = orig_share.share_type
|
||||
# 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)
|
||||
except Exception:
|
||||
pass
|
||||
self.fields['size'].help_text = _(
|
||||
|
@ -182,11 +188,6 @@ class CreateForm(forms.SelfHandlingForm):
|
|||
|
||||
def handle(self, request, data):
|
||||
try:
|
||||
# usages = quotas.tenant_limit_usages(self.request)
|
||||
# availableGB = usages['maxTotalShareGigabytes'] - \
|
||||
# usages['gigabytesUsed']
|
||||
# availableVol = usages['maxTotalShares'] - usages['sharesUsed']
|
||||
|
||||
snapshot_id = None
|
||||
source_type = data.get('share_source_type', None)
|
||||
share_network = data.get('share_network', None)
|
||||
|
@ -201,21 +202,7 @@ class CreateForm(forms.SelfHandlingForm):
|
|||
'snapshot size (%sGiB)') % snapshot.size
|
||||
raise ValidationError(error_message)
|
||||
else:
|
||||
if type(data['size']) is str:
|
||||
data['size'] = int(data['size'])
|
||||
#
|
||||
# if availableGB < data['size']:
|
||||
# error_message = _('A share of %(req)iGB cannot be created as '
|
||||
# 'you only have %(avail)iGB of your quota '
|
||||
# 'available.')
|
||||
# params = {'req': data['size'],
|
||||
# 'avail': availableGB}
|
||||
# raise ValidationError(error_message % params)
|
||||
# elif availableVol <= 0:
|
||||
# error_message = _('You are already using all of your '
|
||||
# 'available'
|
||||
# ' shares.')
|
||||
# raise ValidationError(error_message)
|
||||
data['size'] = int(data['size'])
|
||||
|
||||
metadata = {}
|
||||
try:
|
||||
|
|
|
@ -142,7 +142,7 @@ class ShareViewTests(test.TestCase):
|
|||
res = self.client.post(url, formData)
|
||||
|
||||
mock_az_list.assert_called_once_with(mock.ANY)
|
||||
api_manila.share_snapshot_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)
|
||||
api_manila.share_network_list.assert_called_once_with(mock.ANY)
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
fixes:
|
||||
- Fixed form of share creation from snapshot. Before it was losing
|
||||
source snapshot ID in request and was creating share from scratch instead
|
||||
of expected snapshot-sourced variant.
|
Loading…
Reference in New Issue