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:
DennyZhang 2013-10-05 08:51:07 -07:00
parent 16f654cc74
commit 68251c24b2
3 changed files with 39 additions and 1 deletions

View File

@ -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.plugins.vanilla import oozie_helper as o_h
from savanna.swift import swift_helper as swift from savanna.swift import swift_helper as swift
from savanna.topology import topology_helper as topology from savanna.topology import topology_helper as topology
from savanna.utils import types as types
from savanna.utils import xmlutils as x from savanna.utils import xmlutils as x
@ -120,7 +121,7 @@ def _initialise_configs():
if cfg.default_value in ["true", "false"]: if cfg.default_value in ["true", "false"]:
cfg.config_type = "bool" cfg.config_type = "bool"
cfg.default_value = (cfg.default_value == 'true') 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.config_type = "int"
cfg.default_value = int(cfg.default_value) cfg.default_value = int(cfg.default_value)
if config['name'] in CLUSTER_WIDE_CONFS: if config['name'] in CLUSTER_WIDE_CONFS:

View 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(''))

View File

@ -84,3 +84,11 @@ class FrozenDict(dict):
class FrozenClassError(Exception): class FrozenClassError(Exception):
def __init__(self, instance): def __init__(self, instance):
self.message = "Class %s is immutable!" % type(instance).__name__ self.message = "Class %s is immutable!" % type(instance).__name__
def is_int(s):
try:
int(s)
return True
except Exception:
return False