Skip pulling cinder information if cinder api is unavailable

Now if user wants create node group template
and cinder is unavailable, dashboard send
error message: "Unable to retrive volumes type
list".
We can skip pulling cinder information if it's
unavailable and show only one option to "storage
location" field: "Ephemeral Drive".

Change-Id: I53907be435f2c4290adb07d0ec0a2c121c9b890a
Closes-bug: 1524432
This commit is contained in:
Michael Lelyakin 2016-09-04 14:56:39 +00:00 committed by Mikhail Lelyakin
parent 177ce51f46
commit 5a7e0c150d
2 changed files with 37 additions and 12 deletions

View File

@ -12,6 +12,7 @@
from django.core.urlresolvers import reverse
from django import http
import mock
from mox3.mox import IgnoreArg # noqa
from mox3.mox import IsA # noqa
import six
@ -37,7 +38,9 @@ CREATE_URL = reverse(
class DataProcessingNodeGroupTests(test.TestCase):
def _setup_copy_test(self):
@mock.patch('openstack_dashboard.api.base.is_service_enabled')
def _setup_copy_test(self, service_checker):
service_checker.return_value = True
ngt = self.nodegroup_templates.first()
configs = self.plugins_configs.first()
dash_api.cinder.extension_supported(IsA(http.HttpRequest),
@ -141,7 +144,9 @@ class DataProcessingNodeGroupTests(test.TestCase):
dash_api.cinder: ('extension_supported',
'availability_zone_list',
'volume_type_list')})
def test_create(self):
@mock.patch('openstack_dashboard.api.base.is_service_enabled')
def test_create(self, service_checker):
service_checker.return_value = True
flavor = self.flavors.first()
ngt = self.nodegroup_templates.first()
configs = self.plugins_configs.first()
@ -234,7 +239,9 @@ class DataProcessingNodeGroupTests(test.TestCase):
dash_api.cinder: ('extension_supported',
'availability_zone_list',
'volume_type_list')})
def test_update(self):
@mock.patch('openstack_dashboard.api.base.is_service_enabled')
def test_update(self, service_checker):
service_checker.return_value = True
flavor = self.flavors.first()
ngt = self.nodegroup_templates.first()
configs = self.plugins_configs.first()

View File

@ -12,6 +12,7 @@
# limitations under the License.
import itertools
import logging
import uuid
from django.utils import encoding
@ -39,9 +40,24 @@ from sahara_dashboard.content.data_processing.utils \
from sahara_dashboard.content.data_processing.utils \
import workflow_helpers
LOG = logging.getLogger(__name__)
BASE_IMAGE_URL = "horizon:project:data_processing.clusters:register"
def is_cinder_enabled(request):
return saharaclient.base.is_service_enabled(request, 'volume')
def storage_choices(request):
choices = [("ephemeral_drive", _("Ephemeral Drive")), ]
if is_cinder_enabled(request):
choices.append(("cinder_volume", _("Cinder Volume")))
else:
LOG.warning(_("Cinder service is unavailable now"))
return choices
class GeneralConfigAction(workflows.Action):
nodegroup_name = forms.CharField(label=_("Template Name"))
@ -61,8 +77,7 @@ class GeneralConfigAction(workflows.Action):
storage = forms.ChoiceField(
label=_("Storage location"),
help_text=_("Choose a storage location"),
choices=[("ephemeral_drive", "Ephemeral Drive"),
("cinder_volume", "Cinder Volume")],
choices=[],
widget=forms.Select(attrs={
"class": "storage_field switchable",
'data-slug': 'storage_loc'
@ -180,6 +195,9 @@ class GeneralConfigAction(workflows.Action):
widget=forms.HiddenInput(),
initial=hadoop_version
)
self.fields["storage"].choices = storage_choices(request)
node_parameters = hlps.get_general_node_group_configs(plugin,
hadoop_version)
for param in node_parameters:
@ -195,11 +213,10 @@ class GeneralConfigAction(workflows.Action):
widget=forms.HiddenInput(),
initial=req.get("guide_template_type"))
try:
if is_cinder_enabled(request):
volume_types = cinder.volume_type_list(request)
except Exception:
exceptions.handle(request,
_("Unable to get volume type list."))
else:
volume_types = []
self.fields['volume_type'].choices = [(None, _("No volume type"))] + \
[(type.name, type.name)
@ -221,9 +238,10 @@ class GeneralConfigAction(workflows.Action):
def populate_volumes_availability_zone_choices(self, request, context):
az_list = [(None, _('No availability zone specified'))]
az_list.extend([(az.zoneName, az.zoneName)
for az in cinder_utils.availability_zone_list(request)
if az.zoneState['available']])
if is_cinder_enabled(request):
az_list.extend([(az.zoneName, az.zoneName)
for az in cinder_utils.availability_zone_list(
request) if az.zoneState['available']])
return az_list
def populate_image_choices(self, request, context):