Browse Source

Merge "Return a friendly error at flavor creation"

Jenkins 6 years ago
parent
commit
8734ea4977

+ 21
- 0
openstack_dashboard/dashboards/admin/flavors/forms.py View File

@@ -40,6 +40,24 @@ class CreateFlavor(forms.SelfHandlingForm):
40 40
     disk_gb = forms.IntegerField(label=_("Root Disk GB"))
41 41
     eph_gb = forms.IntegerField(label=_("Ephemeral Disk GB"))
42 42
 
43
+    def clean_name(self):
44
+        name = self.cleaned_data.get('name')
45
+        try:
46
+            flavors = api.nova.flavor_list(self.request)
47
+        except:
48
+            flavors = []
49
+            msg = _('Unable to get flavor list')
50
+            exceptions.check_message(["Connection", "refused"], msg)
51
+            raise
52
+        if flavors is not None:
53
+            for flavor in flavors:
54
+                if flavor.name == name:
55
+                    raise forms.ValidationError(
56
+                      _('The name "%s" is already used by another flavor.')
57
+                      % name
58
+                    )
59
+        return name
60
+
43 61
     def handle(self, request, data):
44 62
         try:
45 63
             flavor = api.nova.flavor_create(request,
@@ -59,6 +77,9 @@ class CreateFlavor(forms.SelfHandlingForm):
59 77
 class EditFlavor(CreateFlavor):
60 78
     flavor_id = forms.IntegerField(widget=forms.widgets.HiddenInput)
61 79
 
80
+    def clean_name(self):
81
+        return self.cleaned_data['name']
82
+
62 83
     def handle(self, request, data):
63 84
         try:
64 85
             flavor_id = data['flavor_id']

+ 1
- 0
openstack_dashboard/dashboards/admin/flavors/tests.py View File

@@ -23,6 +23,7 @@ class FlavorsTests(test.BaseAdminViewTests):
23 23
                                flavor.disk,
24 24
                                IsA(uuid.uuid4()),
25 25
                                ephemeral=eph).AndReturn(flavor)
26
+        api.nova.flavor_list(IsA(http.HttpRequest))
26 27
         self.mox.ReplayAll()
27 28
 
28 29
         url = reverse('horizon:admin:flavors:create')

Loading…
Cancel
Save