diff --git a/savanna/plugins/vanilla/config_helper.py b/savanna/plugins/vanilla/config_helper.py index 030e138e..5dab8ad6 100644 --- a/savanna/plugins/vanilla/config_helper.py +++ b/savanna/plugins/vanilla/config_helper.py @@ -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: diff --git a/savanna/tests/unit/utils/test_types.py b/savanna/tests/unit/utils/test_types.py new file mode 100644 index 00000000..294f88b1 --- /dev/null +++ b/savanna/tests/unit/utils/test_types.py @@ -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('')) diff --git a/savanna/utils/types.py b/savanna/utils/types.py index b1464c83..182eb37a 100644 --- a/savanna/utils/types.py +++ b/savanna/utils/types.py @@ -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