From dada6d433e4ca75fe0a53625a4e361f403f1ec5a Mon Sep 17 00:00:00 2001 From: Tzu-Mainn Chen Date: Tue, 26 Aug 2014 17:42:34 -0400 Subject: [PATCH] Adding plan parameter view on service configuration tab Change-Id: I4d1059b17351bfa1fb3739b78373c369406d724f --- tuskar_ui/infrastructure/parameters/forms.py | 69 +++++++++++++++++++ tuskar_ui/infrastructure/parameters/tables.py | 2 +- .../templates/parameters/_service_config.html | 32 +++++++++ .../templates/parameters/index.html | 8 ++- .../templates/parameters/service_config.html | 11 +++ tuskar_ui/infrastructure/parameters/tests.py | 35 +++++++++- tuskar_ui/infrastructure/parameters/urls.py | 3 + tuskar_ui/infrastructure/parameters/views.py | 24 ++++++- 8 files changed, 180 insertions(+), 4 deletions(-) create mode 100644 tuskar_ui/infrastructure/parameters/forms.py create mode 100644 tuskar_ui/infrastructure/parameters/templates/parameters/_service_config.html create mode 100644 tuskar_ui/infrastructure/parameters/templates/parameters/service_config.html diff --git a/tuskar_ui/infrastructure/parameters/forms.py b/tuskar_ui/infrastructure/parameters/forms.py new file mode 100644 index 000000000..4f9ded600 --- /dev/null +++ b/tuskar_ui/infrastructure/parameters/forms.py @@ -0,0 +1,69 @@ +# -*- coding: utf8 -*- +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import logging + +import django.forms +from django.utils.translation import ugettext_lazy as _ +import horizon.exceptions +import horizon.forms +import horizon.messages + +from tuskar_ui import api + + +LOG = logging.getLogger(__name__) + + +VIRT_TYPE_CHOICES = [ + ('kvm', _("Virtualized (kvm)")), + ('qemu', _("Baremetal (qemu)")), +] + + +class EditServiceConfig(horizon.forms.SelfHandlingForm): + virt_type = django.forms.ChoiceField( + label=_("Deployment Type"), + choices=VIRT_TYPE_CHOICES, + required=True, + ) + snmp_password = django.forms.CharField( + label=_("SNMP Password"), + required=False, + widget=django.forms.PasswordInput(render_value=True)) + + def handle(self, request, data): + plan = api.tuskar.Plan.get_the_plan(self.request) + compute_prefix = plan.get_role_by_name('compute').parameter_prefix + control_prefix = plan.get_role_by_name('controller').parameter_prefix + virt_type = data.get('virt_type') + snmp_password = data.get('snmp_password') + parameters = { + compute_prefix + 'NovaComputeLibvirtType': virt_type, + compute_prefix + 'SnmpdReadonlyUserPassword': snmp_password, + control_prefix + 'SnmpdReadonlyUserPassword': snmp_password, + } + try: + plan.patch(request, plan.uuid, parameters) + except Exception as e: + horizon.exceptions.handle( + request, + _("Unable to update the service configuration.")) + LOG.exception(e) + return False + else: + horizon.messages.success( + request, + _("Service configuration updated.")) + return True diff --git a/tuskar_ui/infrastructure/parameters/tables.py b/tuskar_ui/infrastructure/parameters/tables.py index bb31ca62e..49a5d4625 100644 --- a/tuskar_ui/infrastructure/parameters/tables.py +++ b/tuskar_ui/infrastructure/parameters/tables.py @@ -21,7 +21,7 @@ class ParametersTable(tables.DataTable): label = tables.Column('label', verbose_name=_("Parameter Name")) value = tables.Column('value', - verbose_name=_("Default Value")) + verbose_name=_("Value")) description = tables.Column('description', verbose_name=("Detailed Description")) diff --git a/tuskar_ui/infrastructure/parameters/templates/parameters/_service_config.html b/tuskar_ui/infrastructure/parameters/templates/parameters/_service_config.html new file mode 100644 index 000000000..cae02765a --- /dev/null +++ b/tuskar_ui/infrastructure/parameters/templates/parameters/_service_config.html @@ -0,0 +1,32 @@ +{% extends "horizon/common/_modal_form.html" %} +{% load i18n %} +{% load url from future %} + +{% block form_id %}configuration_form{% endblock %} +{% block form_action %}{% url 'horizon:infrastructure:parameters:service_configuration' %}{% endblock %} + +{% block modal_id %}provision_modal{% endblock %} +{% block modal-header %}{% trans "Service Configuration" %}{% endblock %} + +{% block modal-body %} +
+
+ {% include "horizon/common/_form_fields.html" %} +
+
+
+

{% trans "Description:" %}

+

+ {% trans "Configure values that cannot be defaulted" %} +

+

+ {% trans "These values cannot be defaulted. Please choose values for them and save them before you deploy your overcloud." %} +

+
+{% endblock %} + +{% block modal-footer %} + + {% trans "Cancel" %} +{% endblock %} +{% load form_helpers %} diff --git a/tuskar_ui/infrastructure/parameters/templates/parameters/index.html b/tuskar_ui/infrastructure/parameters/templates/parameters/index.html index fd3f10fdd..325bc8db7 100644 --- a/tuskar_ui/infrastructure/parameters/templates/parameters/index.html +++ b/tuskar_ui/infrastructure/parameters/templates/parameters/index.html @@ -9,10 +9,16 @@ {% block main %}
-{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/tuskar_ui/infrastructure/parameters/templates/parameters/service_config.html b/tuskar_ui/infrastructure/parameters/templates/parameters/service_config.html new file mode 100644 index 000000000..00ca422ca --- /dev/null +++ b/tuskar_ui/infrastructure/parameters/templates/parameters/service_config.html @@ -0,0 +1,11 @@ +{% extends "base.html" %} +{% load i18n %} +{% block title %}{% trans "Service Configuration" %}{% endblock %} + +{% block page_header %} + {% include "horizon/common/_page_header.html" with title=_("Service Configuration") %} +{% endblock %} + +{% block main %} + {% include "infrastructure/parameters/_service_config.html" %} +{% endblock %} diff --git a/tuskar_ui/infrastructure/parameters/tests.py b/tuskar_ui/infrastructure/parameters/tests.py index a09dbb8f6..e914d1471 100644 --- a/tuskar_ui/infrastructure/parameters/tests.py +++ b/tuskar_ui/infrastructure/parameters/tests.py @@ -25,6 +25,8 @@ from tuskar_ui.test.test_data import tuskar_data INDEX_URL = urlresolvers.reverse( 'horizon:infrastructure:parameters:index') +SERVICE_CONFIG_URL = urlresolvers.reverse( + 'horizon:infrastructure:parameters:service_configuration') TEST_DATA = utils.TestDataContainer() tuskar_data.data(TEST_DATA) @@ -52,10 +54,41 @@ class ParametersTest(test.BaseAdminViewTests): def test_param_object(self): param_dict = {'parameter_group': 'Neutron', - 'default': '1.2.3.4', + 'value': '1.2.3.4', 'name': 'Ip Address', 'description': 'This is an IP Address'} p = views.ServiceParameter(param_dict, 5) self.assertEqual(p.id, 5) self.assertEqual(p.value, '1.2.3.4') + + def test_service_config_get(self): + plan = api.tuskar.Plan(self.tuskarclient_plans.first()) + role = api.tuskar.Role(self.tuskarclient_roles.first()) + with contextlib.nested( + patch('tuskar_ui.api.tuskar.Plan.get_the_plan', + return_value=plan), + patch('tuskar_ui.api.tuskar.Plan.get_role_by_name', + return_value=role), + ): + res = self.client.get(SERVICE_CONFIG_URL) + self.assertTemplateUsed( + res, 'infrastructure/parameters/service_config.html') + + def test_service_config_post(self): + plan = api.tuskar.Plan(self.tuskarclient_plans.first()) + role = api.tuskar.Role(self.tuskarclient_roles.first()) + data = { + 'virt_type': 'qemu', + 'snmp_password': 'password', + } + with contextlib.nested( + patch('tuskar_ui.api.tuskar.Plan.get_the_plan', + return_value=plan), + patch('tuskar_ui.api.tuskar.Plan.patch', + return_value=plan), + patch('tuskar_ui.api.tuskar.Plan.get_role_by_name', + return_value=role), + ): + res = self.client.post(SERVICE_CONFIG_URL, data) + self.assertRedirectsNoFollow(res, INDEX_URL) diff --git a/tuskar_ui/infrastructure/parameters/urls.py b/tuskar_ui/infrastructure/parameters/urls.py index 0f9052a52..0beae9b7a 100644 --- a/tuskar_ui/infrastructure/parameters/urls.py +++ b/tuskar_ui/infrastructure/parameters/urls.py @@ -20,4 +20,7 @@ from tuskar_ui.infrastructure.parameters import views urlpatterns = urls.patterns( '', urls.url(r'^$', views.IndexView.as_view(), name='index'), + urls.url(r'^service-config$', + views.ServiceConfigView.as_view(), + name='service_configuration'), ) diff --git a/tuskar_ui/infrastructure/parameters/views.py b/tuskar_ui/infrastructure/parameters/views.py index a746bb474..97ec029c4 100644 --- a/tuskar_ui/infrastructure/parameters/views.py +++ b/tuskar_ui/infrastructure/parameters/views.py @@ -12,9 +12,12 @@ # License for the specific language governing permissions and limitations # under the License. +from django.core.urlresolvers import reverse_lazy +import horizon.forms from horizon import tables as horizon_tables from tuskar_ui import api +from tuskar_ui.infrastructure.parameters import forms from tuskar_ui.infrastructure.parameters import tables @@ -22,11 +25,30 @@ class ServiceParameter: def __init__(self, params_dict, id): self.id = id self.label = params_dict.get('name') - self.value = params_dict.get('default') + self.value = params_dict.get('value') self.category = params_dict.get('parameter_group') self.description = params_dict.get('description') +class ServiceConfigView(horizon.forms.ModalFormView): + template_name = "infrastructure/parameters/service_config.html" + form_class = forms.EditServiceConfig + success_url = reverse_lazy('horizon:infrastructure:parameters:index') + + def get_initial(self): + plan = api.tuskar.Plan.get_the_plan(self.request) + compute_prefix = plan.get_role_by_name('compute').parameter_prefix + + virt_type = plan.parameter_value( + compute_prefix + 'NovaComputeLibvirtType') + #TODO(tzumainn): what if compute and control values are different... + snmp_password = plan.parameter_value( + compute_prefix + 'SnmpdReadonlyUserPassword') + + return {'virt_type': virt_type, + 'snmp_password': snmp_password} + + class IndexView(horizon_tables.DataTableView): table_class = tables.ParametersTable template_name = "infrastructure/parameters/index.html"