def test_hot_translate_template_by_url_with_local_abspath_import(self): tosca_file = 'https://raw.githubusercontent.com/openstack/' \ 'heat-translator/master/translator/tests/data/' \ 'tosca_single_instance_wordpress_with_local_abspath' \ '_import.yaml' hot_file = '../tests/data/hot_output/' \ 'hot_single_instance_wordpress.yaml' params = { 'db_name': 'wordpress', 'db_user': '******', 'db_pwd': 'wp_pass', 'db_root_pwd': 'passw0rd', 'db_port': 3366, 'cpus': 8 } self.assertRaises(ValidationError, TranslationUtils.compare_tosca_translation_with_hot, tosca_file, hot_file, params) expected_msg = _('Absolute file name "/tmp/wordpress.yaml" cannot be ' 'used in a URL-based input template "https://raw.' 'githubusercontent.com/openstack/heat-translator/' 'master/translator/tests/data/tosca_single_instance_' 'wordpress_with_local_abspath_import.yaml".') ExceptionCollector.assertExceptionMessage(ImportError, expected_msg)
def _check_error(self, tosca_file, hot_file, params, assert_error, expected_msg, c_error): arglist = ["--template-file", tosca_file, "--template-type", "tosca"] parsed_args = self.check_parser(self.cmd, arglist, []) parsed_args.parameter = params self.assertRaises(assert_error, self.cmd.take_action, parsed_args) ExceptionCollector.assertExceptionMessage(c_error, expected_msg)
def _test_failed_translation(self, tosca_file, hot_file, params, msg, msg_path, error_raise, error_collect): if msg_path: path = os.path.normpath(os.path.join( os.path.dirname(os.path.realpath(__file__)), tosca_file)) msg = msg % path self.assertRaises( error_raise, TranslationUtils.compare_tosca_translation_with_hot, tosca_file, hot_file, params) ExceptionCollector.assertExceptionMessage(error_collect, msg)
def test_translate_csar_wordpress_invalid_import_path(self): tosca_file = '../tests/data/csar_wordpress_invalid_import_path.zip' hot_file = '' params = {} self.assertRaises(ValidationError, TranslationUtils.compare_tosca_translation_with_hot, tosca_file, hot_file, params) expected_msg = _('Import ' '"Invalid_import_path/wordpress.yaml" is not valid.') ExceptionCollector.assertExceptionMessage(ImportError, expected_msg)
def _test_failed_translation(self, tosca_file, hot_file, params, msg, msg_path, error_raise, error_collect): if msg_path: path = os.path.normpath(os.path.join( os.path.dirname(os.path.realpath(__file__)), tosca_file)) msg = msg % path self.assertRaises( error_raise, TranslationUtils.compare_tosca_translation_with_hot, tosca_file, hot_file, params) ExceptionCollector.assertExceptionMessage(error_collect, msg)
def test_translate_csar_wordpress_invalid_import_path(self): tosca_file = '../tests/data/csar_wordpress_invalid_import_path.zip' hot_file = '' params = {} self.assertRaises( ValidationError, TranslationUtils.compare_tosca_translation_with_hot, tosca_file, hot_file, params) expected_msg = _('Import ' '"Invalid_import_path/wordpress.yaml" is not valid.') ExceptionCollector.assertExceptionMessage(ImportError, expected_msg)
def test_translate_csar_wordpress_invalid_script_url(self): tosca_file = '../tests/data/csar_wordpress_invalid_script_url.zip' hot_file = '' params = {} self.assertRaises(ValidationError, TranslationUtils.compare_tosca_translation_with_hot, tosca_file, hot_file, params) expected_msg = _('The resource at ' '"https://raw.githubusercontent.com/openstack/' 'heat-translator/master/translator/tests/data/' 'custom_types/wordpress1.yaml" cannot be accessed.') ExceptionCollector.assertExceptionMessage(URLException, expected_msg)
def test_translate_csar_not_zip(self): tosca_file = '../tests/data/csar_not_zip.zip' hot_file = '' params = {} self.assertRaises(ValidationError, TranslationUtils.compare_tosca_translation_with_hot, tosca_file, hot_file, params) path = os.path.normpath( os.path.join(os.path.dirname(os.path.realpath(__file__)), tosca_file)) expected_msg = _('"%s" is not a valid zip file.') % path ExceptionCollector.assertExceptionMessage(ValidationError, expected_msg)
def test_translate_csar_wordpress_invalid_script_url(self): tosca_file = '../tests/data/csar_wordpress_invalid_script_url.zip' hot_file = '' params = {} self.assertRaises( ValidationError, TranslationUtils.compare_tosca_translation_with_hot, tosca_file, hot_file, params) expected_msg = _('The resource at ' '"https://raw.githubusercontent.com/openstack/' 'heat-translator/master/translator/tests/data/' 'custom_types/wordpress1.yaml" cannot be accessed.') ExceptionCollector.assertExceptionMessage(URLException, expected_msg)
def test_translate_csar_not_zip(self): tosca_file = '../tests/data/csar_not_zip.zip' hot_file = '' params = {} self.assertRaises( ValidationError, TranslationUtils.compare_tosca_translation_with_hot, tosca_file, hot_file, params) path = os.path.normpath(os.path.join( os.path.dirname(os.path.realpath(__file__)), tosca_file)) expected_msg = _('"%s" is not a valid zip file.') % path ExceptionCollector.assertExceptionMessage(ValidationError, expected_msg)
def test_translate_csar_metadata_not_yaml(self): tosca_file = '../tests/data/csar_metadata_not_yaml.zip' hot_file = '' params = {} self.assertRaises(ValidationError, TranslationUtils.compare_tosca_translation_with_hot, tosca_file, hot_file, params) path = os.path.normpath( os.path.join(os.path.dirname(os.path.realpath(__file__)), tosca_file)) expected_msg = _('The file "TOSCA-Metadata/TOSCA.meta" in the CSAR ' '"%s" does not contain valid YAML content.') % path ExceptionCollector.assertExceptionMessage(ValidationError, expected_msg)
def test_translate_csar_metadata_not_yaml(self): tosca_file = '../tests/data/csar_metadata_not_yaml.zip' hot_file = '' params = {} self.assertRaises( ValidationError, TranslationUtils.compare_tosca_translation_with_hot, tosca_file, hot_file, params) path = os.path.normpath(os.path.join( os.path.dirname(os.path.realpath(__file__)), tosca_file)) expected_msg = _('The file "TOSCA-Metadata/TOSCA.meta" in the CSAR ' '"%s" does not contain valid YAML content.') % path ExceptionCollector.assertExceptionMessage(ValidationError, expected_msg)
def test_translate_csar_wrong_metadata_file(self): tosca_file = '../tests/data/csar_wrong_metadata_file.zip' hot_file = '' params = {} self.assertRaises(ValidationError, TranslationUtils.compare_tosca_translation_with_hot, tosca_file, hot_file, params) path = os.path.normpath( os.path.join(os.path.dirname(os.path.realpath(__file__)), tosca_file)) expected_msg = _('"%s" is not a valid CSAR as it does not contain the ' 'required file "TOSCA.meta" in the folder ' '"TOSCA-Metadata".') % path ExceptionCollector.assertExceptionMessage(ValidationError, expected_msg)
def test_translate_csar_wrong_metadata_file(self): tosca_file = '../tests/data/csar_wrong_metadata_file.zip' hot_file = '' params = {} self.assertRaises( ValidationError, TranslationUtils.compare_tosca_translation_with_hot, tosca_file, hot_file, params) path = os.path.normpath(os.path.join( os.path.dirname(os.path.realpath(__file__)), tosca_file)) expected_msg = _('"%s" is not a valid CSAR as it does not contain the ' 'required file "TOSCA.meta" in the folder ' '"TOSCA-Metadata".') % path ExceptionCollector.assertExceptionMessage(ValidationError, expected_msg)
def test_hot_translate_template_by_url_with_local_abspath_import(self): tosca_file = 'https://raw.githubusercontent.com/openstack/' \ 'heat-translator/master/translator/tests/data/' \ 'tosca_single_instance_wordpress_with_local_abspath' \ '_import.yaml' hot_file = '../tests/data/hot_output/' \ 'hot_single_instance_wordpress.yaml' params = {'db_name': 'wordpress', 'db_user': '******', 'db_pwd': 'wp_pass', 'db_root_pwd': 'passw0rd', 'db_port': 3366, 'cpus': 8} self.assertRaises( ValidationError, TranslationUtils.compare_tosca_translation_with_hot, tosca_file, hot_file, params) expected_msg = _('Absolute file name "/tmp/wordpress.yaml" cannot be ' 'used in a URL-based input template "https://raw.' 'githubusercontent.com/openstack/heat-translator/' 'master/translator/tests/data/tosca_single_instance_' 'wordpress_with_local_abspath_import.yaml".') ExceptionCollector.assertExceptionMessage(ImportError, expected_msg)
def _check_error(self, tosca_file, hot_file, params, assert_error, expected_msg, c_error): arglist = ["--template-file", tosca_file, "--template-type", "tosca"] parsed_args = self.check_parser(self.cmd, arglist, []) parsed_args.parameter = params self.assertRaises(assert_error, self.cmd.take_action, parsed_args) ExceptionCollector.assertExceptionMessage(c_error, expected_msg)