Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GUI-2784: Fix ELB Wizard form field choices for Angular 1.5 compatibility #2087

Merged
merged 11 commits into from Oct 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
56 changes: 56 additions & 0 deletions eucaconsole/forms/angularcompat.py
@@ -0,0 +1,56 @@
# -*- coding: utf-8 -*-
# Copyright 2013-2016 Hewlett Packard Enterprise Development LP
#
# Redistribution and use of this software in source and binary forms,
# with or without modification, are permitted provided that the following
# conditions are met:
#
# Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

"""
Angular 1.4/1.5 Compatible WTForm Classes

"""

from wtforms import SelectField, SelectMultipleField


def clean_value(v):
"""Return value with Angular 1.4/1.5 prefix (e.g. 'string:') removed if str/unicode"""
if isinstance(v, str) or isinstance(v, unicode):
return v.replace('string:', '').strip()
return v


class AngularCompatibleSelectField(SelectField):
def process_formdata(self, valuelist):
if valuelist:
try:
self.data = self.coerce(clean_value(valuelist[0]))
except ValueError:
raise ValueError(self.gettext('Invalid Choice: could not coerce'))


class AngularCompatibleSelectMultipleField(SelectMultipleField):
def process_formdata(self, valuelist):
try:
self.data = list(self.coerce(clean_value(x)) for x in valuelist)
except ValueError:
raise ValueError(self.gettext('Invalid choice(s): one or more data inputs could not be coerced'))
9 changes: 5 additions & 4 deletions eucaconsole/forms/elbs.py
Expand Up @@ -35,6 +35,7 @@

from ..i18n import _
from . import BaseSecureForm, ChoicesManager, TextEscapedField, NAME_WITHOUT_SPACES_NOTICE, BLANK_CHOICE
from .angularcompat import AngularCompatibleSelectField, AngularCompatibleSelectMultipleField
from ..constants.elbs import SSL_CIPHERS
from ..views import BaseView

Expand Down Expand Up @@ -80,7 +81,7 @@ class ELBAccessLogsFormMixin(object):
logging_enabled = wtforms.BooleanField(label=_(u'Enable logging'))
bucket_name_error_msg = _(u'Bucket name is required')
bucket_name_help_text = _(u'Choose from your existing buckets, or create a new bucket.')
bucket_name = wtforms.SelectField(
bucket_name = AngularCompatibleSelectField(
label=_(u'Bucket name'),
validators=[BucketInfoRequired(message=bucket_name_error_msg)],
)
Expand Down Expand Up @@ -350,14 +351,14 @@ class CreateELBForm(ELBHealthChecksForm, ELBAccessLogsFormMixin):
label=_(u'VPC network'),
validators=[validators.InputRequired(message=vpc_network_error_msg)],
)
vpc_subnet = wtforms.SelectMultipleField(
vpc_subnet = AngularCompatibleSelectMultipleField(
label=_(u'VPC subnets'),
)
securitygroup = wtforms.SelectMultipleField(
securitygroup = AngularCompatibleSelectMultipleField(
label=_(u'Security groups')
)
securitygroup_help_text = _(u'If you do not select a security group, the default group will be used.')
zone = wtforms.SelectMultipleField(
zone = AngularCompatibleSelectMultipleField(
label=_(u'Availability zones')
)
cross_zone_enabled_help_text = _(u'Distribute traffic evenly across all instances in all availability zones')
Expand Down
6 changes: 3 additions & 3 deletions eucaconsole/static/js/pages/elb_wizard.js
Expand Up @@ -149,9 +149,9 @@ angular.module('ELBWizard', [
$scope.pingPort = 80;
$scope.pingPath = '/';
$scope.responseTimeout = 5;
$scope.timeBetweenPings = 30;
$scope.failuresUntilUnhealthy = 2;
$scope.passesUntilHealthy = 2;
$scope.timeBetweenPings = '30';
$scope.failuresUntilUnhealthy = '2';
$scope.passesUntilHealthy = '2';
$scope.showsCertificateTabDiv = false;
$scope.certificateTab = 'SSL';
$scope.certificateRadioButton = 'existing';
Expand Down
9 changes: 6 additions & 3 deletions eucaconsole/views/elbs.py
Expand Up @@ -56,6 +56,7 @@
ELB_PREDEFINED_SECURITY_POLICY_NAME_PREFIX, ELB_CUSTOM_SECURITY_POLICY_NAME_PREFIX,
AWS_ELB_ACCOUNT_IDS)
from ..forms import ChoicesManager
from ..forms.angularcompat import clean_value
from ..forms.buckets import CreateBucketForm
from ..forms.elbs import (
ELBForm, ELBDeleteForm, CreateELBForm, ELBHealthChecksForm, ELBsFiltersForm,
Expand Down Expand Up @@ -321,6 +322,8 @@ def configure_access_logs(self, elb_name=None, elb=None):
req_params = self.request.params
params_logging_enabled = req_params.get('logging_enabled') == 'y'
params_bucket_name = req_params.get('bucket_name')
if params_bucket_name and params_bucket_name.startswith('string:'):
params_bucket_name = clean_value(params_bucket_name)
params_bucket_prefix = req_params.get('bucket_prefix', '')
params_collection_interval = int(req_params.get('collection_interval', 60))
if elb is not None:
Expand Down Expand Up @@ -1248,11 +1251,11 @@ def elb_create(self):
if self.create_form.validate():
name = self.request.params.get('name')
listeners_args = self.get_listeners_args()
vpc_subnet = self.request.params.getall('vpc_subnet') or None
vpc_subnet = self.create_form.vpc_subnet.data or None
if vpc_subnet == 'None':
vpc_subnet = None
securitygroup = self.request.params.getall('securitygroup') or None
zone = self.request.params.getall('zone') or None
securitygroup = self.create_form.securitygroup.data or None
zone = self.create_form.zone.data or None
cross_zone_enabled = self.request.params.get('cross_zone_enabled') or False
instances = self.request.params.getall('instances') or None
backend_certificates = self.request.params.get('backend_certificates') or None
Expand Down
2 changes: 1 addition & 1 deletion tests/__init__.py
Expand Up @@ -139,7 +139,7 @@ class BaseFormTestCase(unittest.TestCase):
default_term.configure(
memory_cache,
expiration_time=300,
arguments= {
arguments={
'url': [memory_cache_url],
'binary': True,
'min_compress_len': 1024,
Expand Down
2 changes: 1 addition & 1 deletion tests/elbs/test_elbs.py
@@ -1,4 +1,4 @@
# Copyright 2013-2015 Hewlett Packard Enterprise Development LP
# Copyright 2013-2016 Hewlett Packard Enterprise Development LP
#
# Redistribution and use of this software in source and binary forms,
# with or without modification, are permitted provided that the following
Expand Down
Empty file added tests/utils/__init__.py
Empty file.
49 changes: 49 additions & 0 deletions tests/utils/test_angularcompat.py
@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-
# Copyright 2013-2016 Hewlett Packard Enterprise Development LP
#
# Redistribution and use of this software in source and binary forms,
# with or without modification, are permitted provided that the following
# conditions are met:
#
# Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""
Angular compatibility utility tests

"""

from eucaconsole.forms.angularcompat import clean_value


from tests import BaseTestCase


class FieldValueCleanupTestCase(BaseTestCase):

def test_clean_value_with_angular_string_prefix(self):
val = 'string:foo'
self.assertEqual(clean_value(val), 'foo')

def test_clean_value_without_angular_string_prefix(self):
val = 'some value'
self.assertEqual(clean_value(val), 'some value')

def test_clean_value_with_integer(self):
val = 20
self.assertEqual(clean_value(val), 20)