Create volume pre-select default vol-type

This change makes it so the create volume screen selects the default
volume type (instead of the "No Volume Type" as the default).

Change-Id: I0fd0993adb422701f00ecfdfc81c737b7d1db794
Closes-bug: #1493433
This commit is contained in:
eric 2015-09-08 10:26:21 -06:00
parent 8d008a73c4
commit 16e8229075
4 changed files with 40 additions and 15 deletions

View File

@ -485,6 +485,7 @@ def volume_type_update(request, volume_type_id, name=None, description=None):
description)
@memoized
def volume_type_default(request):
return cinderclient(request).volume_types.default()

View File

@ -268,6 +268,10 @@ class CreateForm(forms.SelfHandlingForm):
self.fields['type'].choices = [("no_type", _("No volume type"))] + \
[(type.name, type.name)
for type in volume_types]
if 'initial' in kwargs and 'type' in kwargs['initial']:
# if there is a default volume type to select, then remove
# the first ""No volume type" entry
self.fields['type'].choices.pop(0)
if "snapshot_id" in request.GET:
self.prepare_source_fields_if_snapshot_specified(request)

View File

@ -42,6 +42,7 @@ class VolumeViewTests(test.TestCase):
@test.create_stubs({cinder: ('volume_create',
'volume_snapshot_list',
'volume_type_list',
'volume_type_default',
'volume_list',
'availability_zone_list',
'extension_supported'),
@ -63,6 +64,8 @@ class VolumeViewTests(test.TestCase):
'snapshot_source': '',
'availability_zone': az}
cinder.volume_type_default(IsA(http.HttpRequest)).\
AndReturn(self.volume_types.first())
cinder.volume_type_list(IsA(http.HttpRequest)).\
AndReturn(self.volume_types.list())
quotas.tenant_limit_usages(IsA(http.HttpRequest)).\
@ -113,6 +116,7 @@ class VolumeViewTests(test.TestCase):
'volume_snapshot_list',
'volume_type_list',
'volume_list',
'volume_type_default',
'availability_zone_list',
'extension_supported'),
api.glance: ('image_list_detailed',),
@ -154,6 +158,8 @@ class VolumeViewTests(test.TestCase):
cinder.extension_supported(IsA(http.HttpRequest), 'AvailabilityZones')\
.AndReturn(True)
cinder.volume_type_default(IsA(http.HttpRequest)).\
AndReturn(self.volume_types.first())
cinder.volume_list(IsA(
http.HttpRequest),
search_opts=SEARCH_OPTS).AndReturn(self.cinder_volumes.list())
@ -181,6 +187,7 @@ class VolumeViewTests(test.TestCase):
@test.create_stubs({cinder: ('volume_create',
'volume_snapshot_list',
'volume_type_list',
'volume_type_default',
'volume_list',
'availability_zone_list',
'extension_supported'),
@ -201,6 +208,8 @@ class VolumeViewTests(test.TestCase):
'snapshot_source': self.cinder_volume_snapshots.first().id,
'image_source': self.images.first().id}
cinder.volume_type_default(IsA(http.HttpRequest)).\
AndReturn(self.volume_types.first())
cinder.volume_type_list(IsA(http.HttpRequest)).\
AndReturn(self.volume_types.list())
cinder.volume_snapshot_list(IsA(http.HttpRequest),
@ -248,6 +257,7 @@ class VolumeViewTests(test.TestCase):
@test.create_stubs({cinder: ('volume_create',
'volume_snapshot_get',
'volume_get',
'volume_type_default',
'volume_type_list'),
quotas: ('tenant_limit_usages',)})
def test_create_volume_from_snapshot(self):
@ -264,6 +274,8 @@ class VolumeViewTests(test.TestCase):
'type': '',
'snapshot_source': snapshot.id}
cinder.volume_type_default(IsA(http.HttpRequest)).\
AndReturn(self.volume_types.first())
cinder.volume_type_list(IsA(http.HttpRequest)).\
AndReturn(self.volume_types.list())
quotas.tenant_limit_usages(IsA(http.HttpRequest)).\
@ -296,6 +308,7 @@ class VolumeViewTests(test.TestCase):
@test.create_stubs({cinder: ('volume_create',
'volume_get',
'volume_type_default',
'volume_list',
'volume_type_list',
'availability_zone_list',
@ -319,6 +332,8 @@ class VolumeViewTests(test.TestCase):
'volume_source_type': 'volume_source',
'volume_source': volume.id}
cinder.volume_type_default(IsA(http.HttpRequest)).\
AndReturn(self.volume_types.first())
cinder.volume_list(IsA(http.HttpRequest), search_opts=SEARCH_OPTS).\
AndReturn(self.cinder_volumes.list())
cinder.volume_type_list(IsA(http.HttpRequest)).\
@ -368,6 +383,7 @@ class VolumeViewTests(test.TestCase):
'volume_snapshot_list',
'volume_snapshot_get',
'volume_get',
'volume_type_default',
'volume_list',
'volume_type_list',
'availability_zone_list',
@ -403,6 +419,8 @@ class VolumeViewTests(test.TestCase):
filters={'property-owner_id': self.tenant.id,
'status': 'active'}) \
.AndReturn([[], False, False])
cinder.volume_type_default(IsA(http.HttpRequest)).\
AndReturn(self.volume_types.first())
cinder.volume_list(IsA(
http.HttpRequest),
search_opts=SEARCH_OPTS).AndReturn(self.cinder_volumes.list())
@ -482,6 +500,7 @@ class VolumeViewTests(test.TestCase):
@test.create_stubs({cinder: ('volume_create',
'volume_type_list',
'volume_type_default',
'availability_zone_list',
'extension_supported'),
api.glance: ('image_get',),
@ -500,6 +519,8 @@ class VolumeViewTests(test.TestCase):
'type': '',
'image_source': image.id}
cinder.volume_type_default(IsA(http.HttpRequest)).\
AndReturn(self.volume_types.first())
cinder.volume_type_list(IsA(http.HttpRequest)).\
AndReturn(self.volume_types.list())
quotas.tenant_limit_usages(IsA(http.HttpRequest)).\
@ -536,6 +557,7 @@ class VolumeViewTests(test.TestCase):
@test.create_stubs({cinder: ('volume_create',
'volume_type_list',
'volume_type_default',
'volume_list',
'volume_snapshot_list',
'availability_zone_list',
@ -573,6 +595,8 @@ class VolumeViewTests(test.TestCase):
filters={'property-owner_id': self.tenant.id,
'status': 'active'}) \
.AndReturn([[], False, False])
cinder.volume_type_default(IsA(http.HttpRequest)).\
AndReturn(self.volume_types.first())
cinder.volume_list(IsA(
http.HttpRequest),
search_opts=SEARCH_OPTS).AndReturn(self.cinder_volumes.list())

View File

@ -97,6 +97,15 @@ class CreateView(forms.ModalFormView):
success_url = reverse_lazy('horizon:project:volumes:volumes_tab')
page_title = _("Create a Volume")
def get_initial(self):
initial = super(CreateView, self).get_initial()
try:
self.default_vol_type = cinder.volume_type_default(self.request)
initial['type'] = self.default_vol_type.name
except dashboard_exception.NOT_FOUND:
pass
return initial
def get_context_data(self, **kwargs):
context = super(CreateView, self).get_context_data(**kwargs)
try:
@ -115,21 +124,8 @@ class CreateView(forms.ModalFormView):
# check if we have default volume type so we can present the
# description of no volume type differently
default_type = None
try:
default_type = cinder.volume_type_default(self.request)
except dashboard_exception.NOT_FOUND:
pass
if default_type is not None:
d_name = getattr(default_type, "name", "")
message =\
_("If \"No volume type\" is selected, the default "
"volume type \"%(name)s\" will be set for the "
"created volume.")
params = {'name': d_name}
no_type_description = encoding.force_text(message % params)
else:
no_type_description = None
if self.default_vol_type is None:
message = \
_("If \"No volume type\" is selected, the volume will be "
"created without a volume type.")