Пример #1
0
def init_global_conf():
    '''Initialize the configuration provider.

    Allows the configuration to be shared throughout the translator code.
    The file used is translator.conf, and is within the conf/ directory. It
    is a standard ini format, and is prcessed using the ConfigParser module.

    '''
    conf_path = os.path.dirname(os.path.abspath(__file__))
    conf_file = os.path.join(conf_path, CONF_FILENAME)
    ConfigProvider._load_config(conf_file)
def _generate_type_map():
    '''Generate TOSCA translation types map.

    Load user defined classes from location path specified in conf file.
    Base classes are located within the tosca directory.

    '''

    # Base types directory
    BASE_PATH = 'translator/hot/tosca'

    # Custom types directory defined in conf file
    custom_path = translatorConfig.get_value('DEFAULT',
                                             'custom_types_location')

    # First need to load the parent module, for example 'contrib.hot',
    # for all of the dynamically loaded classes.
    _load_custom_mod(custom_path)
    classes = []
    _load_classes((BASE_PATH, custom_path), classes)
    try:
        types_map = {clazz.toscatype: clazz for clazz in classes}
    except AttributeError as e:
        raise ToscaClassAttributeError(message=e.message)

    return types_map
def _generate_type_map():
    '''Generate TOSCA translation types map.

    Load user defined classes from location path specified in conf file.
    Base classes are located within the tosca directory.

    '''

    # Base types directory
    BASE_PATH = 'translator/hot/tosca'

    # Custom types directory defined in conf file
    custom_path = translatorConfig.get_value('DEFAULT',
                                             'custom_types_location')

    # First need to load the parent module, for example 'contrib.hot',
    # for all of the dynamically loaded classes.
    classes = []
    _load_classes((BASE_PATH, custom_path), classes)
    try:
        types_map = {clazz.toscatype: clazz for clazz in classes}
    except AttributeError as e:
        raise ToscaClassAttributeError(message=e.message)

    return types_map
Пример #4
0
Test the heat-translator translation from command line as:
#heat-translator
  --template-file=<path to the YAML template>
  --template-type=<type of template e.g. tosca>
  --parameters="purpose=test"
Takes three user arguments,
1. Path to the file that needs to be translated (required)
2. type of translation (e.g. tosca) (optional)
3. Input parameters (optional)

In order to use heat-translator to only validate template,
without actual translation, pass --validate-only=true along with
other required arguments.

"""
conf_file = ConfigProvider.get_translator_logging_file()
try:
    logging.config.fileConfig(conf_file)
except Exception:
    pass
log = logging.getLogger("heat-translator")


class TranslatorShell(object):

    SUPPORTED_TYPES = ['tosca']
    TOSCA_CSAR_META_DIR = "TOSCA-Metadata"

    def get_parser(self, argv):
        parser = argparse.ArgumentParser(prog="heat-translator")
Пример #5
0
Test the heat-translator translation from command line as:
#heat-translator
  --template-file=<path to the YAML template>
  --template-type=<type of template e.g. tosca>
  --parameters="purpose=test"
Takes three user arguments,
1. type of translation (e.g. tosca) (required)
2. Path to the file that needs to be translated (required)
3. Input parameters (optional)

In order to use heat-translator to only validate template,
without actual translation, pass --validate-only=true along with
other required arguments.

"""
conf_file = ConfigProvider.get_translator_logging_file()
logging.config.fileConfig(conf_file)
log = logging.getLogger("heat-translator")


class TranslatorShell(object):

    SUPPORTED_TYPES = ['tosca']

    def _validate(self, args):
        if len(args) < 2:
            msg = _("The program requires minimum two arguments. "
                    "Please refer to the usage documentation.")
            log.error(msg)
            raise ValueError(msg)
        if "--template-file=" not in args[0]:
Пример #6
0
 def test_get_all_values(self, mock_translator_config):
     mock_translator_config.return_value = ['hot']
     values = translatorConfig.get_all_values()
     self.assertTrue(translatorConfig._translator_config.items.called)
     self.assertEqual(values[0], 'hot')
Пример #7
0
 def test_get_value(self, mock_translator_config):
     mock_translator_config.return_value = 'hot'
     value = translatorConfig.get_value('DEFAULT', 'language')
     self.assertTrue(translatorConfig._translator_config.get.called)
     self.assertEqual(value, 'hot')
Пример #8
0
 def test_load_config(self, mock_config_parser):
     translatorConfig._translator_config.read = mock.MagicMock()
     translatorConfig._load_config('fake_file.conf')
     self.assertTrue(translatorConfig._translator_config.read.called)
Пример #9
0
 def reload(*args):
     func(*args)
     path = os.path.dirname(os.path.abspath(__file__)) + '/../conf/'
     conf_file = os.path.join(path, 'translator.conf')
     translatorConfig._load_config(conf_file)
Пример #10
0
 def test_get_all_values(self):
     ret_value = mock.MagicMock(return_value=['hot'])
     translatorConfig._translator_config.items = ret_value
     values = translatorConfig.get_all_values()
     self.assertTrue(translatorConfig._translator_config.items.called)
     self.assertEqual(values[0], 'hot')
Пример #11
0
 def test_get_value(self):
     ret_value = mock.MagicMock(return_value='hot')
     translatorConfig._translator_config.get = ret_value
     value = translatorConfig.get_value('DEFAULT', 'language')
     self.assertTrue(translatorConfig._translator_config.get.called)
     self.assertEqual(value, 'hot')
Пример #12
0
 def test_load_config(self, mock_config_parser):
     translatorConfig._translator_config.read = mock.MagicMock()
     translatorConfig._load_config('fake_file.conf')
     self.assertTrue(translatorConfig._translator_config.read.called)
Пример #13
0
 def reload(*args):
     func(*args)
     path = os.path.dirname(os.path.abspath(__file__)) + '/../conf/'
     conf_file = os.path.join(path, 'translator.conf')
     translatorConfig._load_config(conf_file)
Пример #14
0
 def test_get_all_values(self):
     ret_value = mock.MagicMock(return_value=['hot'])
     translatorConfig._translator_config.items = ret_value
     values = translatorConfig.get_all_values()
     self.assertTrue(translatorConfig._translator_config.items.called)
     self.assertEqual(values[0], 'hot')
Пример #15
0
 def test_get_value(self):
     ret_value = mock.MagicMock(return_value='hot')
     translatorConfig._translator_config.get = ret_value
     value = translatorConfig.get_value('DEFAULT', 'language')
     self.assertTrue(translatorConfig._translator_config.get.called)
     self.assertEqual(value, 'hot')