Merge "Remove obsolete names checks"
This commit is contained in:
commit
fb273e513f
@ -12,8 +12,6 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import re
|
|
||||||
|
|
||||||
from oslo_db import exception as db_exc
|
from oslo_db import exception as db_exc
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
from sqlalchemy import desc
|
from sqlalchemy import desc
|
||||||
@ -39,8 +37,6 @@ LOG = logging.getLogger(__name__)
|
|||||||
|
|
||||||
API_NAME = 'Environments'
|
API_NAME = 'Environments'
|
||||||
|
|
||||||
VALID_NAME_REGEX = re.compile('^[a-zA-Z]+[\w.-]*$')
|
|
||||||
|
|
||||||
|
|
||||||
class Controller(object):
|
class Controller(object):
|
||||||
@request_statistics.stats_count(API_NAME, 'Index')
|
@request_statistics.stats_count(API_NAME, 'Index')
|
||||||
@ -67,7 +63,7 @@ class Controller(object):
|
|||||||
LOG.debug('Environments:Create <Body {body}>'.format(body=body))
|
LOG.debug('Environments:Create <Body {body}>'.format(body=body))
|
||||||
policy.check('create_environment', request.context)
|
policy.check('create_environment', request.context)
|
||||||
|
|
||||||
if not body.get('name'):
|
if not('name' in body and body['name'].strip()):
|
||||||
msg = _('Please, specify a name of the environment to create')
|
msg = _('Please, specify a name of the environment to create')
|
||||||
LOG.exception(msg)
|
LOG.exception(msg)
|
||||||
raise exc.HTTPBadRequest(explanation=msg)
|
raise exc.HTTPBadRequest(explanation=msg)
|
||||||
@ -77,20 +73,14 @@ class Controller(object):
|
|||||||
msg = _('Environment name should be 255 characters maximum')
|
msg = _('Environment name should be 255 characters maximum')
|
||||||
LOG.exception(msg)
|
LOG.exception(msg)
|
||||||
raise exc.HTTPBadRequest(explanation=msg)
|
raise exc.HTTPBadRequest(explanation=msg)
|
||||||
if VALID_NAME_REGEX.match(name):
|
try:
|
||||||
try:
|
environment = envs.EnvironmentServices.create(
|
||||||
environment = envs.EnvironmentServices.create(
|
body.copy(),
|
||||||
body.copy(),
|
request.context)
|
||||||
request.context)
|
except db_exc.DBDuplicateEntry:
|
||||||
except db_exc.DBDuplicateEntry:
|
msg = _('Environment with specified name already exists')
|
||||||
msg = _('Environment with specified name already exists')
|
|
||||||
LOG.exception(msg)
|
|
||||||
raise exc.HTTPConflict(explanation=msg)
|
|
||||||
else:
|
|
||||||
msg = _('Environment name must contain only alphanumeric or "_-." '
|
|
||||||
'characters, must start with alpha')
|
|
||||||
LOG.exception(msg)
|
LOG.exception(msg)
|
||||||
raise exc.HTTPClientError(explanation=msg)
|
raise exc.HTTPConflict(explanation=msg)
|
||||||
|
|
||||||
return environment.to_dict()
|
return environment.to_dict()
|
||||||
|
|
||||||
@ -138,7 +128,7 @@ class Controller(object):
|
|||||||
|
|
||||||
session = db_session.get_session()
|
session = db_session.get_session()
|
||||||
environment = session.query(models.Environment).get(environment_id)
|
environment = session.query(models.Environment).get(environment_id)
|
||||||
if VALID_NAME_REGEX.match(str(body['name'])):
|
if str(body['name']).strip():
|
||||||
try:
|
try:
|
||||||
environment.update(body)
|
environment.update(body)
|
||||||
environment.save(session)
|
environment.save(session)
|
||||||
@ -147,8 +137,8 @@ class Controller(object):
|
|||||||
LOG.error(msg)
|
LOG.error(msg)
|
||||||
raise exc.HTTPConflict(explanation=msg)
|
raise exc.HTTPConflict(explanation=msg)
|
||||||
else:
|
else:
|
||||||
msg = _('Environment name must contain only alphanumeric '
|
msg = _('Environment name must contain at least one '
|
||||||
'or "_-." characters, must start with alpha')
|
'non-white space symbol')
|
||||||
LOG.error(msg)
|
LOG.error(msg)
|
||||||
raise exc.HTTPClientError(explanation=msg)
|
raise exc.HTTPClientError(explanation=msg)
|
||||||
|
|
||||||
|
@ -16,7 +16,6 @@ from oslo_db import exception as db_exc
|
|||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
from webob import exc
|
from webob import exc
|
||||||
|
|
||||||
from murano.api.v1 import environments as envs_api
|
|
||||||
from murano.api.v1 import request_statistics
|
from murano.api.v1 import request_statistics
|
||||||
from murano.common.i18n import _
|
from murano.common.i18n import _
|
||||||
from murano.common import policy
|
from murano.common import policy
|
||||||
@ -63,9 +62,9 @@ class Controller(object):
|
|||||||
try:
|
try:
|
||||||
LOG.debug('ENV TEMP NAME: {templ_name}>'.format(
|
LOG.debug('ENV TEMP NAME: {templ_name}>'.format(
|
||||||
templ_name=body['name']))
|
templ_name=body['name']))
|
||||||
if not envs_api.VALID_NAME_REGEX.match(str(body['name'])):
|
if not str(body['name']).strip():
|
||||||
msg = _('Environment Template must contain only alphanumeric '
|
msg = _('Environment Template must contain at least one '
|
||||||
'or "_-." characters, must start with alpha')
|
'non-white space symbol')
|
||||||
LOG.error(msg)
|
LOG.error(msg)
|
||||||
raise exc.HTTPBadRequest(msg)
|
raise exc.HTTPBadRequest(msg)
|
||||||
except Exception:
|
except Exception:
|
||||||
@ -125,9 +124,9 @@ class Controller(object):
|
|||||||
try:
|
try:
|
||||||
LOG.debug('ENV TEMP NAME: {temp_name}>'.format(
|
LOG.debug('ENV TEMP NAME: {temp_name}>'.format(
|
||||||
temp_name=body['name']))
|
temp_name=body['name']))
|
||||||
if not envs_api.VALID_NAME_REGEX.match(str(body['name'])):
|
if not str(body['name']).strip():
|
||||||
msg = _('Env Template must contain only alphanumeric '
|
msg = _('Environment Template must contain at least one '
|
||||||
'or "_-." characters, must start with alpha')
|
'non-white space symbol')
|
||||||
LOG.exception(msg)
|
LOG.exception(msg)
|
||||||
raise exc.HTTPBadRequest(msg)
|
raise exc.HTTPBadRequest(msg)
|
||||||
except Exception:
|
except Exception:
|
||||||
@ -182,10 +181,9 @@ class Controller(object):
|
|||||||
template = env_temps.EnvTemplateServices.\
|
template = env_temps.EnvTemplateServices.\
|
||||||
get_env_template(env_template_id)
|
get_env_template(env_template_id)
|
||||||
|
|
||||||
if ('name' not in body or
|
if ('name' not in body or not str(body['name']).strip()):
|
||||||
not envs_api.VALID_NAME_REGEX.match(str(body['name']))):
|
msg = _('Environment Template must contain at least one '
|
||||||
msg = _('Environment must contain only alphanumeric '
|
'non-white space symbol')
|
||||||
'or "_-." characters, must start with alpha')
|
|
||||||
LOG.error(msg)
|
LOG.error(msg)
|
||||||
raise exc.HTTPBadRequest(explanation=msg)
|
raise exc.HTTPBadRequest(explanation=msg)
|
||||||
LOG.debug('ENVIRONMENT NAME: {env_name}>'.format(
|
LOG.debug('ENVIRONMENT NAME: {env_name}>'.format(
|
||||||
|
@ -147,7 +147,7 @@ class TestEnvTemplate(base.TestCase):
|
|||||||
"""Check the deletion of an wrong environment template request."""
|
"""Check the deletion of an wrong environment template request."""
|
||||||
self.assertRaises(exceptions.BadRequest,
|
self.assertRaises(exceptions.BadRequest,
|
||||||
self.client.create_env_template,
|
self.client.create_env_template,
|
||||||
'-+3')
|
' ')
|
||||||
|
|
||||||
@tag('all', 'coverage')
|
@tag('all', 'coverage')
|
||||||
@attr(type='negative')
|
@attr(type='negative')
|
||||||
|
@ -54,6 +54,32 @@ class TestEnvironments(base.TestCase):
|
|||||||
|
|
||||||
self.environments.pop(self.environments.index(env))
|
self.environments.pop(self.environments.index(env))
|
||||||
|
|
||||||
|
@tag('all', 'coverage')
|
||||||
|
@attr(type='smoke')
|
||||||
|
def test_create_and_delete_environment_with_unicode_name(self):
|
||||||
|
environments_list_start = self.client.get_environments_list()[1]
|
||||||
|
|
||||||
|
unicode_name = u'$yaql \u2665 unicode'
|
||||||
|
resp, env = self.client.create_environment(unicode_name)
|
||||||
|
self.environments.append(env)
|
||||||
|
|
||||||
|
self.assertEqual(resp.status, 200)
|
||||||
|
self.assertEqual(unicode_name, env['name'])
|
||||||
|
|
||||||
|
environments_list = self.client.get_environments_list()[1]
|
||||||
|
|
||||||
|
self.assertEqual(len(environments_list_start['environments']) + 1,
|
||||||
|
len(environments_list['environments']))
|
||||||
|
|
||||||
|
self.client.delete_environment(env['id'])
|
||||||
|
|
||||||
|
environments_list = self.client.get_environments_list()[1]
|
||||||
|
|
||||||
|
self.assertEqual(len(environments_list_start['environments']),
|
||||||
|
len(environments_list['environments']))
|
||||||
|
|
||||||
|
self.environments.pop(self.environments.index(env))
|
||||||
|
|
||||||
@tag('all', 'coverage')
|
@tag('all', 'coverage')
|
||||||
@attr(type='smoke')
|
@attr(type='smoke')
|
||||||
def test_get_environment(self):
|
def test_get_environment(self):
|
||||||
|
@ -95,7 +95,7 @@ class TestEnvTemplateApi(tb.ControllerTest, tb.MuranoApiTestCase):
|
|||||||
)
|
)
|
||||||
self.expect_policy_check('create_env_template')
|
self.expect_policy_check('create_env_template')
|
||||||
|
|
||||||
body = {'name': 'my+#temp'}
|
body = {'name': ' '}
|
||||||
req = self._post('/templates', json.dumps(body))
|
req = self._post('/templates', json.dumps(body))
|
||||||
result = req.get_response(self.api)
|
result = req.get_response(self.api)
|
||||||
self.assertEqual(400, result.status_code)
|
self.assertEqual(400, result.status_code)
|
||||||
|
@ -140,13 +140,14 @@ class TestEnvironmentApi(tb.ControllerTest, tb.MuranoApiTestCase):
|
|||||||
)
|
)
|
||||||
self.expect_policy_check('create_environment')
|
self.expect_policy_check('create_environment')
|
||||||
|
|
||||||
body = {'name': 'my+#env'}
|
body = {'name': ' '}
|
||||||
req = self._post('/environments', json.dumps(body))
|
req = self._post('/environments', json.dumps(body))
|
||||||
result = req.get_response(self.api)
|
result = req.get_response(self.api)
|
||||||
self.assertEqual(400, result.status_code)
|
self.assertEqual(400, result.status_code)
|
||||||
|
|
||||||
def test_unicode_environment_name_create(self):
|
def test_unicode_environment_name_create(self):
|
||||||
"""Check that an unicode env name results in an HTTPClientError."""
|
"""Check that an unicode env name doesn't raise an HTTPClientError."""
|
||||||
|
self._configure_opts()
|
||||||
self._set_policy_rules(
|
self._set_policy_rules(
|
||||||
{'list_environments': '@',
|
{'list_environments': '@',
|
||||||
'create_environment': '@',
|
'create_environment': '@',
|
||||||
@ -154,10 +155,10 @@ class TestEnvironmentApi(tb.ControllerTest, tb.MuranoApiTestCase):
|
|||||||
)
|
)
|
||||||
self.expect_policy_check('create_environment')
|
self.expect_policy_check('create_environment')
|
||||||
|
|
||||||
body = {'name': u'yaql ♥ unicode'.encode('utf-8')}
|
body = {'name': u'$yaql \u2665 unicode'}
|
||||||
req = self._post('/environments', json.dumps(body))
|
req = self._post('/environments', json.dumps(body))
|
||||||
result = req.get_response(self.api)
|
result = req.get_response(self.api)
|
||||||
self.assertEqual(400, result.status_code)
|
self.assertEqual(200, result.status_code)
|
||||||
|
|
||||||
def test_no_environment_name_create(self):
|
def test_no_environment_name_create(self):
|
||||||
"""Check that no env name provided results in an HTTPBadResquest."""
|
"""Check that no env name provided results in an HTTPBadResquest."""
|
||||||
|
Loading…
Reference in New Issue
Block a user