Exemple #1
0
    def _create_templates(self):
        """
        Creates the templates used by molecule.

        :return: None
        """
        # ansible.cfg
        kwargs = {
            'molecule_dir': self.config.config['molecule']['molecule_dir']
        }
        if not os.path.isfile(self.config.config['ansible']['config_file']):
            util.write_template(
                self.config.config['molecule']['ansible_config_template'],
                self.config.config['ansible']['config_file'],
                kwargs=kwargs)
            self._state.change_state('customconf', False)
        else:
            self._state.change_state('customconf', True)

        # rakefile
        kwargs = {
            'state_file': self.config.config['molecule']['state_file'],
            'serverspec_dir': self.config.config['molecule']['serverspec_dir']
        }
        util.write_template(
            self.config.config['molecule']['rakefile_template'],
            self.config.config['molecule']['rakefile_file'],
            kwargs=kwargs)
Exemple #2
0
    def _write_vagrant_file(self):
        kwargs = {'config': self.molecule.config.config,
                  'current_platform': self.platform,
                  'current_provider': self.provider}

        template = self.molecule.config.config['molecule'][
            'vagrantfile_template']
        dest = self.molecule.config.config['molecule']['vagrantfile_file']
        util.write_template(template, dest, kwargs=kwargs)
Exemple #3
0
def test_write_template(temp_dir):
    source_file = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                               '..', 'resources', 'test_write_template.j2')
    dest_file = os.path.join(temp_dir, 'test_util_write_template.tmp')
    util.write_template(source_file, dest_file, {'test': 'chicken'})
    with open(dest_file, 'r') as f:
        data = f.read()

    assert data == 'this is a chicken\n'
Exemple #4
0
def test_write_template(temp_dir):
    source_file = os.path.join(
        os.path.dirname(os.path.abspath(__file__)), os.path.pardir,
        'resources', 'test_write_template.j2')
    dest_file = os.path.join(temp_dir, 'test_util_write_template.tmp')
    util.write_template(source_file, dest_file, {'test': 'chicken'})
    with open(dest_file, 'r') as f:
        data = f.read()

    assert data == 'this is a chicken\n'
Exemple #5
0
def test_write_template():
    d = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'support')
    src = os.path.join(d, 'test_write_template.j2')
    tmp_file = '/tmp/test_util_write_template.tmp'
    util.write_template(src, tmp_file, {'test': 'chicken'})
    with open(tmp_file, 'r') as f:
        data = f.read()
    os.remove(tmp_file)

    assert data == 'this is a chicken\n'
Exemple #6
0
def test_write_template(temp_dir):
    source_file = os.path.join(
        os.path.dirname(os.path.abspath(__file__)), os.path.pardir, "resources", "test_write_template.j2"
    )
    dest_file = os.path.join(temp_dir, "test_util_write_template.tmp")
    util.write_template(source_file, dest_file, {"test": "chicken"})
    with open(dest_file, "r") as f:
        data = f.read()

    assert data == "this is a chicken\n"
Exemple #7
0
def test_write_template_template_does_not_exist(temp_dir):
    dest_file = os.path.join(temp_dir, 'test_util_write_template.tmp')
    with pytest.raises(SystemExit):
        util.write_template('/non/existent', dest_file, {'foo': 'bar'})
Exemple #8
0
def test_write_template_template_does_not_exist(temp_dir):
    dest_file = os.path.join(temp_dir, 'test_util_write_template.tmp')
    with pytest.raises(SystemExit):
        util.write_template('/non/existent', dest_file, {'foo': 'bar'})
Exemple #9
0
def test_write_template_template_does_not_exist(temp_dir):
    dest_file = os.path.join(temp_dir, "test_util_write_template.tmp")
    with pytest.raises(SystemExit):
        util.write_template("/non/existent", dest_file, {"foo": "bar"})