def test_translate_output(self): tosca_tpl = os.path.join( os.path.dirname(os.path.abspath(__file__)), "../../tests/data/" "tosca_nodejs_mongodb_two_instances.yaml") tosca = ToscaTemplate(tosca_tpl) translate = TOSCATranslator(tosca, []) hot_translation = translate.output_to_yaml() expected_output = { 'nodejs_url': { 'description': 'URL for the nodejs ' 'server, http://<IP>:3000', 'value': { 'get_attr': ['app_server', 'networks', 'private', 0] } }, 'mongodb_url': { 'description': 'URL for the mongodb server.', 'value': { 'get_attr': ['mongo_server', 'networks', 'private', 0] } } } hot_translation_dict = \ toscaparser.utils.yamlparser.simple_parse(hot_translation) outputs = hot_translation_dict.get('outputs') for resource_name in outputs: translated_value = outputs.get(resource_name) expected_value = expected_output.get(resource_name) self.assertEqual(translated_value, expected_value)
def take_action(self, parsed_args): log.debug(_('Translating the template with input parameters' '(%s).'), parsed_args) output = None session = self.app.cloud.get_session() flavors.SESSION = session images.SESSION = session if parsed_args.parameter: parsed_params = parsed_args.parameter else: parsed_params = {} if parsed_args.template_type == "tosca": path = parsed_args.template_file a_file = os.path.isfile(path) a_url = UrlUtils.validate_url(path) if not a_file else False if a_file or a_url: validate = parsed_args.validate_only if validate and validate.lower() == "true": ToscaTemplate(path, parsed_params, a_file) msg = (_('The input "%(path)s" successfully passed ' 'validation.') % {'path': path}) print(msg) else: tosca = ToscaTemplate(path, parsed_params, a_file) translator = TOSCATranslator(tosca, parsed_params) output = translator.output_to_yaml() else: msg = _('Could not find template file.\n') log.error(msg) sys.stdout.write(msg) raise SystemExit if output: if parsed_args.output_file: with open(parsed_args.output_file, 'w+') as f: f.write(output) else: print(output)