config_helper.py doesn't handle negative int correctly
The check-in is supposed to fix bug 1235702. But handling float parameters takes much more tests, thus we leave this part for later. Partially Close-bug: #1235702 Change-Id: I08ca62c577ddda5083e08391b0693455d6ca68dc
This commit is contained in:
parent
16f654cc74
commit
68251c24b2
@ -21,6 +21,7 @@ from savanna.plugins.vanilla import mysql_helper as m_h
|
||||
from savanna.plugins.vanilla import oozie_helper as o_h
|
||||
from savanna.swift import swift_helper as swift
|
||||
from savanna.topology import topology_helper as topology
|
||||
from savanna.utils import types as types
|
||||
from savanna.utils import xmlutils as x
|
||||
|
||||
|
||||
@ -120,7 +121,7 @@ def _initialise_configs():
|
||||
if cfg.default_value in ["true", "false"]:
|
||||
cfg.config_type = "bool"
|
||||
cfg.default_value = (cfg.default_value == 'true')
|
||||
if str(cfg.default_value).isdigit():
|
||||
elif types.is_int(cfg.default_value):
|
||||
cfg.config_type = "int"
|
||||
cfg.default_value = int(cfg.default_value)
|
||||
if config['name'] in CLUSTER_WIDE_CONFS:
|
||||
|
29
savanna/tests/unit/utils/test_types.py
Normal file
29
savanna/tests/unit/utils/test_types.py
Normal file
@ -0,0 +1,29 @@
|
||||
# Copyright (c) 2013 Mirantis Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
# implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import unittest2
|
||||
|
||||
from savanna.utils import types as types
|
||||
|
||||
|
||||
class TypesTestCase(unittest2.TestCase):
|
||||
|
||||
def test_is_int(self):
|
||||
self.assertTrue(types.is_int('1'))
|
||||
self.assertTrue(types.is_int('0'))
|
||||
self.assertTrue(types.is_int('-1'))
|
||||
self.assertFalse(types.is_int('1.1'))
|
||||
self.assertFalse(types.is_int('ab'))
|
||||
self.assertFalse(types.is_int(''))
|
@ -84,3 +84,11 @@ class FrozenDict(dict):
|
||||
class FrozenClassError(Exception):
|
||||
def __init__(self, instance):
|
||||
self.message = "Class %s is immutable!" % type(instance).__name__
|
||||
|
||||
|
||||
def is_int(s):
|
||||
try:
|
||||
int(s)
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
|
Loading…
Reference in New Issue
Block a user