def test_os_env_no_value(self):
     open_mock = mock.mock_open(
         read_data='env_value: !os_env MYVAR\n')
     self.patch('devops.helpers.templates.open', open_mock, create=True)
     self.os_mock.environ = {}
     with self.assertRaises(error.DevopsError):
         templates.yaml_template_load('/path/to/my.yaml')
    def test_include_exception(self):
        mock_open1 = mock.mock_open(read_data='myinclude: !include file2.yaml')
        mock_open1.return_value.name = '/path/to/my.yaml'
        mock_open2 = mock.mock_open(read_data='10')
        mock_open2.return_value.name = '/path/to/file2.yaml'
        open_mock = self.patch('devops.helpers.templates.open',
                               new_callable=mock.mock_open,
                               create=True)
        open_mock.side_effect = (mock_open1.return_value,
                                 mock_open2.return_value)

        with self.assertRaises(error.DevopsError):
            templates.yaml_template_load('/path/to/my.yaml')
    def test_include_exception(self):
        mock_open1 = mock.mock_open(read_data='myinclude: !include file2.yaml')
        mock_open1.return_value.name = '/path/to/my.yaml'
        mock_open2 = mock.mock_open(read_data='10')
        mock_open2.return_value.name = '/path/to/file2.yaml'
        open_mock = self.patch(
            'devops.helpers.templates.open',
            new_callable=mock.mock_open, create=True)
        open_mock.side_effect = (
            mock_open1.return_value, mock_open2.return_value)

        with self.assertRaises(error.DevopsError):
            templates.yaml_template_load('/path/to/my.yaml')
 def test_os_env(self):
     open_mock = mock.mock_open(
         read_data='env_value: !os_env MYVAR\n')
     self.patch('devops.helpers.templates.open', open_mock, create=True)
     self.os_mock.environ = {'MYVAR': '30'}
     m = templates.yaml_template_load('/path/to/my.yaml')
     assert m['env_value'] == 30
 def env(self):
     if self.__env is None:
         # hack before we find proper solution for loading devops templates
         external_config = os.environ.get("DEVOPS_SETTINGS_TEMPLATE", None)
         if external_config:
             config = yaml_template_load(external_config)
         else:
             config = self._devops_config
         self.__env = EnvironmentModel(config)
     return self.__env
    def __init__(self):
        super(UpgradeCustom, self).__init__()
        data = yaml_template_load(
            settings.UPGRADE_TEST_TEMPLATE)['upgrade_data']
        self.upgrade_data = data

        logger.debug("Got following data from upgrade template:")
        for step in data:
            logger.debug("\n".join(
                ["{}:{}".format(key, value) for key, value in step.items()]))
Exemple #7
0
    def __init__(self):
        super(UpgradeCustom, self).__init__()
        data = yaml_template_load(
            settings.UPGRADE_TEST_TEMPLATE)['upgrade_data']
        self.upgrade_data = data

        logger.debug("Got following data from upgrade template:")
        for step in data:
            logger.debug("\n".join(
                ["{}:{}".format(key, value) for key, value in step.items()]))
    def load_template(self, filename):
        """Method for reading file with devops config

        :param filename: string
        """
        if filename is not None:
            LOG.debug("Preparing to load config from template '{0}'".format(
                filename))
            self.config = templates.yaml_template_load(filename)
        else:
            LOG.error("Template filename is not set, loading config " +
                      "from template aborted.")
 def test_mapping_order(self):
     open_mock = mock.mock_open(read_data='mapping:\n'
                                '    one: 1\n'
                                '    two: 2\n'
                                '    three: 3\n')
     self.patch('devops.helpers.templates.open', open_mock, create=True)
     m = templates.yaml_template_load('/path/to/my.yaml')
     assert isinstance(m['mapping'], collections.OrderedDict)
     assert m['mapping'] == collections.OrderedDict([
         ('one', 1),
         ('two', 2),
         ('three', 3),
     ])
 def test_mapping_order(self):
     open_mock = mock.mock_open(
         read_data='mapping:\n'
                   '    one: 1\n'
                   '    two: 2\n'
                   '    three: 3\n')
     self.patch('devops.helpers.templates.open', open_mock, create=True)
     m = templates.yaml_template_load('/path/to/my.yaml')
     assert isinstance(m['mapping'], collections.OrderedDict)
     assert m['mapping'] == collections.OrderedDict([
         ('one', 1),
         ('two', 2),
         ('three', 3),
     ])
    def test_include(self):
        self.isfiles.append('/path/to/file2.yaml')
        mock_open1 = mock.mock_open(read_data='myinclude: !include file2.yaml')
        mock_open1.return_value.name = '/path/to/my.yaml'
        mock_open2 = mock.mock_open(read_data='10')
        mock_open2.return_value.name = '/path/to/file2.yaml'
        open_mock = self.patch('devops.helpers.templates.open',
                               new_callable=mock.mock_open,
                               create=True)
        open_mock.side_effect = (mock_open1.return_value,
                                 mock_open2.return_value)

        m = templates.yaml_template_load('/path/to/my.yaml')
        assert m == {'myinclude': 10}
    def test_include(self):
        self.isfiles.append('/path/to/file2.yaml')
        mock_open1 = mock.mock_open(read_data='myinclude: !include file2.yaml')
        mock_open1.return_value.name = '/path/to/my.yaml'
        mock_open2 = mock.mock_open(read_data='10')
        mock_open2.return_value.name = '/path/to/file2.yaml'
        open_mock = self.patch(
            'devops.helpers.templates.open',
            new_callable=mock.mock_open, create=True)
        open_mock.side_effect = (
            mock_open1.return_value, mock_open2.return_value)

        m = templates.yaml_template_load('/path/to/my.yaml')
        assert m == {'myinclude': 10}
    def load_template(self, filename):
        """Method for reading file with devops config

        :param filename: string
        """
        if filename is not None:
            LOG.debug(
                "Preparing to load config from template '{0}'".format(
                    filename
                )
            )
            self.config = templates.yaml_template_load(filename)
        else:
            LOG.error("Template filename is not set, loading config " +
                      "from template aborted.")
def create_config():
    env = os.environ

    conf_path = env['CONF_PATH']
    conf = yaml_template_load(conf_path)

    slaves_count = int(env['SLAVES_COUNT'])

    group = conf['template']['devops_settings']['groups'][0]
    defined = filter(lambda x: x['role'] == 'k8s-node', group['nodes'])
    node_params = filter(lambda x: x['name'].endswith('slave-0'),
                         group['nodes'])[0]['params']

    for i in range(len(defined), slaves_count):
        group['nodes'].append({
            'name': 'slave-{}'.format(i),
            'role': 'k8s-node',
            'params': deepcopy(node_params)
        })

    return conf
Exemple #15
0
def create_config():
    env = os.environ

    conf_path = env['CONF_PATH']
    conf = yaml_template_load(conf_path)

    slaves_count = int(env['SLAVES_COUNT'])

    group = conf['template']['devops_settings']['groups'][0]
    defined = filter(lambda x: x['role'] == 'k8s-node',
                     group['nodes'])
    node_params = filter(lambda x: x['name'].endswith('slave-0'),
                         group['nodes'])[0]['params']

    for i in range(len(defined), slaves_count):
        group['nodes'].append(
            {'name': 'slave-{}'.format(i),
             'role': 'k8s-node',
             'params': deepcopy(node_params)})

    return conf
 def test_not_file(self):
     with self.assertRaises(error.DevopsError):
         templates.yaml_template_load('/path/to/dir')
 def test_os_env(self):
     open_mock = mock.mock_open(read_data='env_value: !os_env MYVAR\n')
     self.patch('devops.helpers.templates.open', open_mock, create=True)
     self.os_mock.environ = {'MYVAR': '30'}
     m = templates.yaml_template_load('/path/to/my.yaml')
     assert m['env_value'] == 30
 def test_os_env_no_value(self):
     open_mock = mock.mock_open(read_data='env_value: !os_env MYVAR\n')
     self.patch('devops.helpers.templates.open', open_mock, create=True)
     self.os_mock.environ = {}
     with self.assertRaises(error.DevopsError):
         templates.yaml_template_load('/path/to/my.yaml')
 def test_not_file(self):
     with self.assertRaises(error.DevopsError):
         templates.yaml_template_load('/path/to/dir')