Remove environment name restrictions

Since we don't use environments and environment templates names during
deployment process we don't need to check what is the name of the
environment. Now we should only keep it human-readable and check that
it exists.

Change-Id: I2d665b41deebf0c008d8b2b71802a1ab2c6673e8
Closes-Bug: #1405788
This commit is contained in:
zhurong 2015-12-19 00:23:28 +08:00
parent 74bfa719c8
commit 4b7846ae4a
6 changed files with 58 additions and 16 deletions

View File

@ -13,7 +13,6 @@
# under the License.
import ast
from django.core import validators
from django import forms
from django.utils.translation import ugettext_lazy as _
from horizon import exceptions
@ -26,18 +25,15 @@ from muranodashboard.common import net
from muranodashboard.environments import api
LOG = logging.getLogger(__name__)
NAME_VALIDATORS = [validators.RegexValidator('^[a-zA-Z]+[\w.-]*$')]
ENV_NAME_HELP_TEXT = _("Environment names must contain only "
"alphanumeric or '_-.' characters "
"and must start with alpha")
ENV_NAME_HELP_TEXT = _("Environment name must contain at least one "
"non-white space symbol.")
class CreateEnvironmentForm(horizon_forms.SelfHandlingForm):
name = forms.CharField(label="Environment Name",
validators=NAME_VALIDATORS,
error_messages={'invalid': ENV_NAME_HELP_TEXT},
help_text=ENV_NAME_HELP_TEXT,
max_length=255)
max_length=255,
required=True)
net_config = forms.ChoiceField(
label=_("Environment Default Network"),
@ -57,6 +53,13 @@ class CreateEnvironmentForm(horizon_forms.SelfHandlingForm):
self.fields['net_config'].choices = net_choices
self.fields['net_config'].help_text = help_text
def clean_name(self):
cleaned_data = super(CreateEnvironmentForm, self).clean()
env_name = cleaned_data.get('name')
if not env_name.strip():
self._errors['name'] = self.error_class([ENV_NAME_HELP_TEXT])
return env_name
def handle(self, request, data):
try:
net_config = ast.literal_eval(data.pop('net_config'))
@ -65,7 +68,7 @@ class CreateEnvironmentForm(horizon_forms.SelfHandlingForm):
env = api.environment_create(request, data)
request.session['env_id'] = env.id
messages.success(request,
'Created environment "{0}"'.format(data['name']))
u'Created environment "{0}"'.format(data['name']))
return True
except exc.HTTPConflict:
msg = _('Environment with specified name already exists')

View File

@ -33,7 +33,6 @@ from muranodashboard.api import packages as pkg_api
from muranodashboard.catalog import views as catalog_views
from muranodashboard.environments import api
from muranodashboard.environments import consts
from muranodashboard.environments import forms as env_forms
from muranodashboard.packages import consts as pkg_consts
@ -304,10 +303,7 @@ class EnvironmentsTable(tables.DataTable):
name = tables.Column('name',
link='horizon:murano:environments:services',
verbose_name=_('Name'),
form_field=forms.CharField(
validators=env_forms.NAME_VALIDATORS,
error_messages={'invalid':
env_forms.ENV_NAME_HELP_TEXT},),
form_field=forms.CharField(),
update_action=UpdateName,
truncate=40)

View File

@ -177,7 +177,7 @@ class UITestCase(BaseDeps):
self.driver.find_element(method, value)
except (exc.NoSuchElementException, exc.ElementNotVisibleException):
present = False
self.assertFalse(present, "Element {0} is preset on the page"
self.assertFalse(present, u"Element {0} is preset on the page"
" while it should't".format(value))
self.driver.implicitly_wait(30)

View File

@ -8,7 +8,7 @@ HotPackageDir = os.path.join(os.path.dirname(os.path.realpath(__file__)),
CategorySelector = "//a[contains(text(), '{0}')][contains(@class, 'dropdown-toggle')]" # noqa
App = "//div[contains(@class, 'app-list')]//h4[contains(text(), '{0}')]"
MockAppDescr = "//div[h4[contains(text(), 'MockApp')]]/p"
AppPackages = "//tr[@data-display='{0}']"
AppPackages = u"//tr[@data-display='{0}']"
TagInDetails = "//div[contains(@class, 'app-meta')]//ul//li[strong[contains(text(), 'Tags')]]" # noqa
TestImage = "//tr[td[contains(text(), '{0}')]]"
DeleteImageMeta = TestImage + "//td//button[contains(text(), 'Delete Metadata')]" # noqa

View File

@ -99,6 +99,45 @@ class TestSuiteEnvironment(base.ApplicationTestCase):
by.By.XPATH,
"//div[@id='environment_switcher']/a[contains(text(), 'TestEnv')]")
def test_create_and_delete_environment_with_unicode_name(self):
"""Test check ability to create and delete environment with unicode name
Scenario:
1. Create environment with unicode name
2. Navigate to this environment
3. Go back to environment list and delete created environment
"""
unicode_name = u'$yaql \u2665 unicode'
self.go_to_submenu('Environments')
self.create_environment(unicode_name)
self.go_to_submenu('Environments')
self.delete_environment(unicode_name)
self.check_element_not_on_page(by.By.LINK_TEXT, unicode_name)
def test_check_env_name_validation(self):
"""Test checks validation of field that usually define environment name
Scenario:
1. Navigate to Application Catalog > Environmentss
2. Press 'Create environment'
3. Check a set of names, if current name isn't valid
appropriate error message should appears
"""
self.go_to_submenu('Environments')
self.driver.find_element_by_css_selector(c.CreateEnvironment).click()
self.driver.find_element_by_id(c.ConfirmCreateEnvironment).click()
error_message = 'This field is required.'
self.driver.find_element_by_xpath(
c.ErrorMessage.format(error_message))
self.fill_field(by.By.ID, 'id_name', ' ')
self.driver.find_element_by_id(c.ConfirmCreateEnvironment).click()
error_message = ('Environment name must contain at least one '
'non-white space symbol.')
self.driver.find_element_by_xpath(
c.ErrorMessage.format(error_message))
class TestSuiteImage(base.ImageTestCase):
def test_rename_image(self):

View File

@ -0,0 +1,4 @@
---
fixes:
- It is now possible to use any symbols in
environments name.