Merge "Supporting logging in heat-translator with config file"
This commit is contained in:
commit
0ffc30381c
@ -11,6 +11,8 @@
|
||||
# under the License.
|
||||
|
||||
|
||||
import logging
|
||||
import logging.config
|
||||
import os
|
||||
import sys
|
||||
|
||||
@ -33,6 +35,9 @@ This should be only used for testing purpose. The proper use of
|
||||
Heat-Translator tool is via python-heatclient once it made available there.
|
||||
"""
|
||||
|
||||
logging.config.fileConfig('heat_translator_logging.conf')
|
||||
log = logging.getLogger("heat-translator")
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 3:
|
||||
|
43
heat_translator_logging.conf
Normal file
43
heat_translator_logging.conf
Normal file
@ -0,0 +1,43 @@
|
||||
|
||||
[loggers]
|
||||
keys=root,heat-translator
|
||||
|
||||
[handlers]
|
||||
keys=RotatingFileHandler,SysLogHandler,NullHandler
|
||||
|
||||
[formatters]
|
||||
keys=form01
|
||||
|
||||
[logger_root]
|
||||
level=DEBUG
|
||||
handlers=NullHandler
|
||||
|
||||
[logger_heat-translator]
|
||||
level=INFO
|
||||
#one can be removed based on requirements
|
||||
handlers=SysLogHandler, RotatingFileHandler
|
||||
qualname=heat-translator
|
||||
propagate=1
|
||||
|
||||
[handler_RotatingFileHandler]
|
||||
class=handlers.RotatingFileHandler
|
||||
level=INFO
|
||||
formatter=form01
|
||||
#rotation happens after 100MB
|
||||
args=('/tmp/heat-translator.log', 'a', 100000000, 5, 'utf8')
|
||||
|
||||
[handler_SysLogHandler]
|
||||
class=handlers.SysLogHandler
|
||||
formatter=form01
|
||||
level=INFO
|
||||
args=('/dev/log', handlers.SysLogHandler.LOG_SYSLOG)
|
||||
|
||||
[handler_NullHandler]
|
||||
class=NullHandler
|
||||
formatter=form01
|
||||
level=DEBUG
|
||||
args=()
|
||||
|
||||
[formatter_form01]
|
||||
format = %(asctime)s - %(name)s - %(levelname)s - %(filename)s : %(message)s
|
||||
datefmt =
|
@ -24,6 +24,7 @@ import yaml
|
||||
|
||||
YAML_ORDER_PARSER = toscaparser.utils.yamlparser.simple_ordered_parse
|
||||
log = logging.getLogger('tosca')
|
||||
log = logging.getLogger('heat-translator')
|
||||
|
||||
|
||||
class MemoryUnit(object):
|
||||
@ -75,6 +76,7 @@ class MemoryUnit(object):
|
||||
|
||||
msg = _('Provided unit "{0}" is not valid. The valid units are'
|
||||
' {1}').format(unit, MemoryUnit.UNIT_SIZE_DICT.keys())
|
||||
log.warning(msg)
|
||||
raise ValueError(msg)
|
||||
|
||||
|
||||
@ -96,10 +98,13 @@ class CompareUtils(object):
|
||||
both_equal = True
|
||||
for dict1_item, dict2_item in zip(dict1.items(), dict2.items()):
|
||||
if dict1_item != dict2_item:
|
||||
log.warning(CompareUtils.MISMATCH_VALUE2_LABEL,
|
||||
": %s \n is not equal to \n",
|
||||
CompareUtils.MISMATCH_VALUE1_LABEL,
|
||||
": %s", dict1_item, dict2_item)
|
||||
msg = (_("%(label1)s: %(item1)s \n is not equal to \n:"
|
||||
"%(label2)s: %(item2)s")
|
||||
% {'label1': CompareUtils.MISMATCH_VALUE2_LABEL,
|
||||
'item1': dict1_item,
|
||||
'label2': CompareUtils.MISMATCH_VALUE1_LABEL,
|
||||
'item2': dict2_item})
|
||||
log.warning(msg)
|
||||
both_equal = False
|
||||
break
|
||||
return both_equal
|
||||
|
@ -11,6 +11,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import logging
|
||||
from translator.hot.syntax.hot_template import HotTemplate
|
||||
from translator.hot.translate_inputs import TranslateInputs
|
||||
from translator.hot.translate_node_templates import TranslateNodeTemplates
|
||||
@ -20,6 +21,8 @@ from translator.hot.translate_outputs import TranslateOutputs
|
||||
class TOSCATranslator(object):
|
||||
'''Invokes translation methods.'''
|
||||
|
||||
log = logging.getLogger('heat-translator')
|
||||
|
||||
def __init__(self, tosca, parsed_params):
|
||||
super(TOSCATranslator, self).__init__()
|
||||
self.tosca = tosca
|
||||
@ -54,6 +57,8 @@ class TOSCATranslator(object):
|
||||
try:
|
||||
self.parsed_params[node_prop.value['get_input']]
|
||||
except Exception:
|
||||
raise ValueError(_('Must specify all input values in \
|
||||
TOSCA template, missing %s') %
|
||||
node_prop.value['get_input'])
|
||||
msg = (_('Must specify all input values in \
|
||||
TOSCA template, missing %s') %
|
||||
node_prop.value['get_input'])
|
||||
self.log.warning(msg)
|
||||
raise ValueError(msg)
|
||||
|
@ -54,7 +54,7 @@ TOSCA_TO_HOT_INPUT_TYPES = {'string': 'string',
|
||||
'null': 'string',
|
||||
'PortDef': 'number'}
|
||||
|
||||
log = logging.getLogger('tosca')
|
||||
log = logging.getLogger('heat-translator')
|
||||
|
||||
|
||||
class TranslateInputs(object):
|
||||
@ -83,6 +83,8 @@ class TranslateInputs(object):
|
||||
elif input.default is not None:
|
||||
hot_default = input.default
|
||||
else:
|
||||
log.warning(_("Need to specify a value "
|
||||
"for input {0}").format(input.name))
|
||||
raise Exception(_("Need to specify a value "
|
||||
"for input {0}").format(input.name))
|
||||
if input.type == "scalar-unit.size":
|
||||
@ -93,6 +95,7 @@ class TranslateInputs(object):
|
||||
hot_default = (ScalarUnit_Size(hot_default).
|
||||
get_num_from_scalar_unit('GiB'))
|
||||
if hot_default == 0:
|
||||
log.warning(_('Unit value should be > 0.'))
|
||||
raise Exception(_(
|
||||
'Unit value should be > 0.'))
|
||||
elif int(hot_default) < hot_default:
|
||||
|
@ -11,6 +11,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import logging
|
||||
import six
|
||||
|
||||
from toscaparser.functions import GetAttribute
|
||||
@ -90,6 +91,7 @@ TOSCA_TO_HOT_REQUIRES = {'container': 'server', 'host': 'server',
|
||||
'dependency': 'depends_on', "connects": 'depends_on'}
|
||||
|
||||
TOSCA_TO_HOT_PROPERTIES = {'properties': 'input'}
|
||||
log = logging.getLogger('heat-translator')
|
||||
|
||||
|
||||
class TranslateNodeTemplates(object):
|
||||
@ -339,9 +341,11 @@ class TranslateNodeTemplates(object):
|
||||
if connect_config is not None:
|
||||
config_location = 'source'
|
||||
else:
|
||||
raise Exception(_("Template error: "
|
||||
"no configuration found for ConnectsTo "
|
||||
"in {1}").format(self.nodetemplate.name))
|
||||
msg = _("Template error: "
|
||||
"no configuration found for ConnectsTo "
|
||||
"in {1}").format(self.nodetemplate.name)
|
||||
log.warning(msg)
|
||||
raise Exception(msg)
|
||||
config_name = source_node.name + '_' + target_name + '_connect_config'
|
||||
implement = connect_config.get('implementation')
|
||||
if config_location == 'target':
|
||||
|
@ -13,6 +13,7 @@
|
||||
"""Translate action implementations"""
|
||||
|
||||
import logging
|
||||
import logging.config
|
||||
import os
|
||||
import sys
|
||||
|
||||
@ -22,11 +23,13 @@ from toscaparser.tosca_template import ToscaTemplate
|
||||
from translator.hot.tosca_translator import TOSCATranslator
|
||||
from translator.osc import utils
|
||||
|
||||
logging.config.fileConfig('heat_translator_logging.conf')
|
||||
|
||||
|
||||
class TranslateTemplate(command.Command):
|
||||
"""Translate a template"""
|
||||
|
||||
log = logging.getLogger(__name__ + '.TranslateTemplate')
|
||||
log = logging.getLogger('heat-translator' + '.TranslateTemplate')
|
||||
auth_required = False
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
|
Loading…
x
Reference in New Issue
Block a user