Merge "Return a friendly error at flavor creation"

This commit is contained in:
Jenkins 2012-11-21 20:07:43 +00:00 committed by Gerrit Code Review
commit 8734ea4977
2 changed files with 22 additions and 0 deletions

View File

@ -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 @@ class CreateFlavor(forms.SelfHandlingForm):
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 File

@ -23,6 +23,7 @@ class FlavorsTests(test.BaseAdminViewTests):
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')