diff --git a/translator/hot/tosca_translator.py b/translator/hot/tosca_translator.py index efed755b..14ef8a19 100644 --- a/translator/hot/tosca_translator.py +++ b/translator/hot/tosca_translator.py @@ -24,11 +24,12 @@ log = logging.getLogger('heat-translator') class TOSCATranslator(object): '''Invokes translation methods.''' - def __init__(self, tosca, parsed_params): + def __init__(self, tosca, parsed_params, deploy=None): super(TOSCATranslator, self).__init__() self.tosca = tosca self.hot_template = HotTemplate() self.parsed_params = parsed_params + self.deploy = deploy self.node_translator = None log.info(_('Initialized parmaters for translation.')) @@ -43,7 +44,8 @@ class TOSCATranslator(object): return self.hot_template.output_to_yaml() def _translate_inputs(self): - translator = TranslateInputs(self.tosca.inputs, self.parsed_params) + translator = TranslateInputs(self.tosca.inputs, self.parsed_params, + self.deploy) return translator.translate() def _translate_outputs(self): diff --git a/translator/hot/translate_inputs.py b/translator/hot/translate_inputs.py index ca96ca68..e62eb555 100644 --- a/translator/hot/translate_inputs.py +++ b/translator/hot/translate_inputs.py @@ -61,18 +61,19 @@ class TranslateInputs(object): '''Translate TOSCA Inputs to Heat Parameters.''' - def __init__(self, inputs, parsed_params): + def __init__(self, inputs, parsed_params, deploy=None): self.inputs = inputs self.parsed_params = parsed_params + self.deploy = deploy def translate(self): return self._translate_inputs() def _translate_inputs(self): hot_inputs = [] - hot_default = None log.info(_('Translating TOSCA input type to HOT input type.')) for input in self.inputs: + hot_default = None hot_input_type = TOSCA_TO_HOT_INPUT_TYPES[input.type] if input.name in self.parsed_params: @@ -82,10 +83,11 @@ class TranslateInputs(object): hot_default = DataEntity.validate_datatype(input.type, input.default) else: - msg = _("Need to specify a value " - "for input {0}.").format(input.name) - log.error(msg) - raise Exception(msg) + if self.deploy: + msg = _("Need to specify a value " + "for input {0}.").format(input.name) + log.error(msg) + raise Exception(msg) if input.type == "scalar-unit.size": # Assumption here is to use this scalar-unit.size for size of # cinder volume in heat templates and will be in GB. @@ -110,7 +112,8 @@ class TranslateInputs(object): hot_constraints = [] if input.constraints: for constraint in input.constraints: - constraint.validate(hot_default) + if hot_default: + constraint.validate(hot_default) hc, hvalue = self._translate_constraints( constraint.constraint_key, constraint.constraint_value) hot_constraints.append({hc: hvalue}) diff --git a/translator/shell.py b/translator/shell.py index 93eb512f..8f8e632b 100644 --- a/translator/shell.py +++ b/translator/shell.py @@ -64,6 +64,9 @@ class TranslatorShell(object): raise ValueError(msg) def main(self, args): + # TODO(spzala): set self.deploy based on passed args once support for + # --deploy argument is enabled. + self.deploy = False self._validate(args) path = args[0].split('--template-file=')[1] # e.g. --template_file=translator/tests/data/tosca_helloworld.yaml @@ -151,7 +154,7 @@ class TranslatorShell(object): if sourcetype == "tosca": log.debug(_('Loading the tosca template.')) tosca = ToscaTemplate(path, parsed_params, a_file) - translator = TOSCATranslator(tosca, parsed_params) + translator = TOSCATranslator(tosca, parsed_params, self.deploy) log.debug(_('Translating the tosca template.')) output = translator.translate() return output