Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Return a friendly error at flavor creation

When trying to create a flavor with an Id/Name that is already in use, the
operation fails and no error message is being displayed

Change-Id: I92db8b52bc4e63e5e5ce4d90169944e484baeddd
Fixes: bug #1079155
  • Loading branch information...
commit dcda6940263a43344bf98aa1776cce34d25ff927 1 parent 241c63b
@mrunge mrunge authored
View
21 openstack_dashboard/dashboards/admin/flavors/forms.py
@@ -40,6 +40,24 @@ class CreateFlavor(forms.SelfHandlingForm):
disk_gb = forms.IntegerField(label=_("Root Disk GB"))
eph_gb = forms.IntegerField(label=_("Ephemeral Disk GB"))
+ def clean_name(self):
+ name = self.cleaned_data.get('name')
+ try:
+ flavors = api.nova.flavor_list(self.request)
+ except:
+ flavors = []
+ msg = _('Unable to get flavor list')
+ exceptions.check_message(["Connection", "refused"], msg)
+ raise
+ if flavors is not None:
+ for flavor in flavors:
+ if flavor.name == name:
+ raise forms.ValidationError(
+ _('The name "%s" is already used by another flavor.')
+ % name
+ )
+ return name
+
def handle(self, request, data):
try:
flavor = api.nova.flavor_create(request,
@@ -59,6 +77,9 @@ def handle(self, request, data):
class EditFlavor(CreateFlavor):
flavor_id = forms.IntegerField(widget=forms.widgets.HiddenInput)
+ def clean_name(self):
+ return self.cleaned_data['name']
+
def handle(self, request, data):
try:
flavor_id = data['flavor_id']
View
1  openstack_dashboard/dashboards/admin/flavors/tests.py
@@ -23,6 +23,7 @@ def test_create_new_flavor_when_none_exist(self):
flavor.disk,
IsA(uuid.uuid4()),
ephemeral=eph).AndReturn(flavor)
+ api.nova.flavor_list(IsA(http.HttpRequest))
self.mox.ReplayAll()
url = reverse('horizon:admin:flavors:create')
Please sign in to comment.
Something went wrong with that request. Please try again.