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
# under the License.
WF_MANAGEMENT_NAME = 'workflowManagement'
class WorkflowManagementForm(object):
name = 'workflowManagement'
field_specs = [
{'name': 'stay_at_the_catalog',
'initial': False,
'description': 'If checked, you will be returned to the '
'Application Catalog page. If not - to the '
'Environment page, where you can deploy'
' the application.',
'required': False,
'type': 'boolean',
'label': 'Continue application adding'}]
validators = []
def __init__(self):
self.name = WF_MANAGEMENT_NAME
self.field_specs = [
{'name': 'stay_at_the_catalog',
'initial': False,
'description': 'If checked, you will be returned to the '
'Application Catalog page. If not - to the '
'Environment page, where you can deploy'
' the application.',
'required': False,
'type': 'boolean',
'label': 'Continue application adding'}]
self.validators = []
@classmethod
def name_field(cls, name):
def name_field(self, fqn):
return {'name': 'application_name',
'type': 'string',
'description': 'Enter a desired name for the application. '
@ -36,5 +38,5 @@ class WorkflowManagementForm(object):
' are allowed',
'label': 'Application Name',
'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
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):
self.cleaned_data = cleaned_data
self.templates = templates or {}
@ -82,10 +82,10 @@ class Service(object):
self._add_form(name, field_specs, validators)
# Add ManageWorkflowForm
workflow_form = catalog_forms.WorkflowManagementForm
workflow_form = catalog_forms.WorkflowManagementForm()
if semantic_version.Version.coerce(self.spec_version) >= \
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)
self._add_form(workflow_form.name,
@ -105,15 +105,6 @@ class Service(object):
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
def extract_form_data(data):
for form_name, form_data in data.iteritems():
@ -126,7 +117,7 @@ class Service(object):
self.context[name] = template
if semantic_version.Version.coerce(self.spec_version) \
>= 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']
self.application['?']['name'] = name
attributes = helpers.evaluate(self.application, self.context)
@ -172,7 +163,7 @@ def import_app(request, app_id):
app.set_data(app_data)
else:
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

View File

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

View File

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