Fix initial value for the 'name' field

'name' field is inserted automatically if ui definition has 2.2
version of higher.
If ui definitions were nested, name for parent app was used.
This happend since list of filed were not cleaned up from the previous time.

Also, some improvement was made: initial value is not get from the application section,
but is passed from the fqn, which is get from api.

Change-Id: I01c51d48185400f34a7dbd15fca349ad7ddbef05
Closes-Bug: #1493075
This commit is contained in:
Ekaterina Chernova
2015-09-08 15:37:12 +03:00
parent 4cf9fc2a77
commit 6e000185af
4 changed files with 25 additions and 30 deletions

View File

@@ -12,23 +12,25 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
WF_MANAGEMENT_NAME = 'workflowManagement'
class WorkflowManagementForm(object): class WorkflowManagementForm(object):
name = 'workflowManagement' def __init__(self):
field_specs = [ self.name = WF_MANAGEMENT_NAME
{'name': 'stay_at_the_catalog', self.field_specs = [
'initial': False, {'name': 'stay_at_the_catalog',
'description': 'If checked, you will be returned to the ' 'initial': False,
'Application Catalog page. If not - to the ' 'description': 'If checked, you will be returned to the '
'Environment page, where you can deploy' 'Application Catalog page. If not - to the '
' the application.', 'Environment page, where you can deploy'
'required': False, ' the application.',
'type': 'boolean', 'required': False,
'label': 'Continue application adding'}] 'type': 'boolean',
validators = [] 'label': 'Continue application adding'}]
self.validators = []
@classmethod def name_field(self, fqn):
def name_field(cls, name):
return {'name': 'application_name', return {'name': 'application_name',
'type': 'string', 'type': 'string',
'description': 'Enter a desired name for the application. ' 'description': 'Enter a desired name for the application. '
@@ -36,5 +38,5 @@ class WorkflowManagementForm(object):
' are allowed', ' are allowed',
'label': 'Application Name', 'label': 'Application Name',
'regexpValidator': '^[-\w]+$', 'regexpValidator': '^[-\w]+$',
'initial': name 'initial': fqn.split('.')[-1]
} }

View File

@@ -58,7 +58,7 @@ class Service(object):
because Service instance is re-created on each request from UI definition because Service instance is re-created on each request from UI definition
stored at local file-system cache . stored at local file-system cache .
""" """
def __init__(self, cleaned_data, version, forms=None, templates=None, def __init__(self, cleaned_data, version, fqn, forms=None, templates=None,
application=None, **kwargs): application=None, **kwargs):
self.cleaned_data = cleaned_data self.cleaned_data = cleaned_data
self.templates = templates or {} self.templates = templates or {}
@@ -82,10 +82,10 @@ class Service(object):
self._add_form(name, field_specs, validators) self._add_form(name, field_specs, validators)
# Add ManageWorkflowForm # Add ManageWorkflowForm
workflow_form = catalog_forms.WorkflowManagementForm workflow_form = catalog_forms.WorkflowManagementForm()
if semantic_version.Version.coerce(self.spec_version) >= \ if semantic_version.Version.coerce(self.spec_version) >= \
semantic_version.Version.coerce('2.2'): semantic_version.Version.coerce('2.2'):
app_name_field = workflow_form.name_field(self._get_app_name()) app_name_field = workflow_form.name_field(fqn)
workflow_form.field_specs.insert(0, app_name_field) workflow_form.field_specs.insert(0, app_name_field)
self._add_form(workflow_form.name, self._add_form(workflow_form.name,
@@ -105,15 +105,6 @@ class Service(object):
self.forms.append(Form) self.forms.append(Form)
def _get_app_name(self):
try:
return self.application['?']['type'].split('.')[-1]
except KeyError:
LOG.info(_("Service key '?' or 'type' parameter is"
" missing in application object model"))
self.application.setdefault('?', {})
return ''
@staticmethod @staticmethod
def extract_form_data(data): def extract_form_data(data):
for form_name, form_data in data.iteritems(): for form_name, form_data in data.iteritems():
@@ -126,7 +117,7 @@ class Service(object):
self.context[name] = template self.context[name] = template
if semantic_version.Version.coerce(self.spec_version) \ if semantic_version.Version.coerce(self.spec_version) \
>= semantic_version.Version.coerce('2.2'): >= semantic_version.Version.coerce('2.2'):
management_form = catalog_forms.WorkflowManagementForm.name management_form = catalog_forms.WF_MANAGEMENT_NAME
name = self.context['$'][management_form]['application_name'] name = self.context['$'][management_form]['application_name']
self.application['?']['name'] = name self.application['?']['name'] = name
attributes = helpers.evaluate(self.application, self.context) attributes = helpers.evaluate(self.application, self.context)
@@ -172,7 +163,7 @@ def import_app(request, app_id):
app.set_data(app_data) app.set_data(app_data)
else: else:
LOG.debug('Creating new forms for app {0}'.format(fqn)) LOG.debug('Creating new forms for app {0}'.format(fqn))
app = _apps[app_id] = Service(app_data, app_version, **service) app = _apps[app_id] = Service(app_data, app_version, fqn, **service)
return app return app

View File

@@ -68,7 +68,7 @@ def _generate_hostname(pattern, number):
def _name(context): def _name(context):
name = context.get_data[ name = context.get_data[
catalog_forms.WorkflowManagementForm.name]['application_name'] catalog_forms.WF_MANAGEMENT_NAME]['application_name']
return name return name

View File

@@ -39,6 +39,7 @@ class TestService(testtools.TestCase):
service = services.Service(cleaned_data={}, service = services.Service(cleaned_data={},
version=2, version=2,
fqn='io.murano.Test',
application=self.application, application=self.application,
forms=ui) forms=ui)
form = next(e for e in service.forms form = next(e for e in service.forms
@@ -59,6 +60,7 @@ class TestService(testtools.TestCase):
service = services.Service(cleaned_data={}, service = services.Service(cleaned_data={},
version=2, version=2,
fqn='io.murano.Test',
application=self.application, application=self.application,
forms=ui) forms=ui)
form = next(e for e in service.forms form = next(e for e in service.forms