Пример #1
0
    def _combine(self, env=os.environ, keep_string=None):
        """
        Perform a prioritized recursive merge of config files.

        Returns a new dict.  Prior to merging the config files are interpolated with
        environment variables.

        1. Loads Molecule defaults.
        2. Loads a base config (if provided) and merges ontop of defaults.
        3. Loads the scenario's ``molecule file`` and merges ontop of previous
           merge.

        :return: dict
        """
        defaults = self._get_defaults()
        base_config = self.args.get("base_config")
        if base_config and os.path.exists(base_config):
            with util.open_file(base_config) as stream:
                s = stream.read()
                self._preflight(s)
                interpolated_config = self._interpolate(s, env, keep_string)
                defaults = util.merge_dicts(
                    defaults, util.safe_load(interpolated_config))

        if self.molecule_file:
            with util.open_file(self.molecule_file) as stream:
                s = stream.read()
                self._preflight(s)
                interpolated_config = self._interpolate(s, env, keep_string)
                defaults = util.merge_dicts(
                    defaults, util.safe_load(interpolated_config))

        return defaults
Пример #2
0
    def _combine(self):
        """
        Perform a prioritized recursive merge of config files, and returns
        a new dict.  Prior to merging the config files are interpolated with
        environment variables.

        1. Loads Molecule defaults.
        2. Loads a base config (if provided) and merges ontop of defaults.
        3. Loads the scenario's `molecule file` and merges ontop of previous
           merge.

        :return: dict
        """
        defaults = self._get_defaults()
        base_config = self.args.get('base_config')
        if base_config:
            if os.path.exists(base_config):
                with util.open_file(base_config) as stream:
                    interpolated_config = self._interpolate(stream.read())
                    defaults = util.merge_dicts(
                        defaults, util.safe_load(interpolated_config))

        with util.open_file(self.molecule_file) as stream:
            interpolated_config = self._interpolate(stream.read())
            defaults = util.merge_dicts(defaults,
                                        util.safe_load(interpolated_config))

        return defaults
Пример #3
0
def test_safe_load_exits_when_cannot_parse():
    data = """
---
%foo:
""".strip()

    with pytest.raises(SystemExit) as e:
        util.safe_load(data)

    assert 1 == e.value.code
Пример #4
0
def _config(_molecule_file, request):
    with open(_molecule_file) as f:
        d = util.safe_load(f)
    if hasattr(request, "param"):
        if isinstance(request.getfixturevalue(request.param), str):
            d2 = util.safe_load(request.getfixturevalue(request.param))
        else:
            d2 = request.getfixturevalue(request.param)
        # print(100, d)
        # print(200, d2)
        d = util.merge_dicts(d, d2)
        # print(300, d)

    return d
Пример #5
0
    def _combine(self):
        """
        Perform a prioritized recursive merge of the `molecule_file` with
        defaults, interpolate the result with environment variables, and
        returns a new dict.

        :return: dict
        """
        i = interpolation.Interpolator(interpolation.TemplateWithDefaults,
                                       os.environ)

        base = self._get_defaults()
        with util.open_file(self.molecule_file) as stream:
            try:
                interpolated_config = i.interpolate(stream.read())
                base = self.merge_dicts(base,
                                        util.safe_load(interpolated_config))
            except interpolation.InvalidInterpolation as e:
                msg = ("parsing config file '{}'.\n\n"
                       '{}\n{}'.format(self.molecule_file, e.place, e.string))
                util.sysexit_with_message(msg)

        schema.validate(base)

        return base
Пример #6
0
def pre_validate(stream, env, keep_string):
    data = util.safe_load(stream)

    v = Validator(allow_unknown=True)
    v.validate(data, pre_validate_base_schema(env, keep_string))

    return v.errors
Пример #7
0
def pre_validate(stream, env: MutableMapping, keep_string: str):
    """Pre-validate stream."""
    data = util.safe_load(stream)

    v = Validator(allow_unknown=True)
    v.validate(data, pre_validate_base_schema(env, keep_string))

    return v.errors, data
Пример #8
0
def from_yaml(data):
    """
    Interpolate the provided data and return a dict.

    Currently, this is used to reinterpolate the `molecule.yml` inside an
    Ansible playbook.  If there were any interpolation errors, they would
    have been found and raised earlier.

    :return: dict
    """
    i = interpolation.Interpolator(interpolation.TemplateWithDefaults,
                                   os.environ)
    interpolated_data = i.interpolate(data)

    return util.safe_load(interpolated_data)
Пример #9
0
    def _combine(self):
        """
        Perform a prioritized recursive merge of the `molecule_file` with
        defaults, interpolate the result with environment variables, and
        returns a new dict.

        :return: dict
        """
        i = interpolation.Interpolator(interpolation.TemplateWithDefaults,
                                       os.environ)

        base = self._get_defaults()
        with open(self.molecule_file, 'r') as stream:
            interpolated_config = i.interpolate(stream.read())
            base = self.merge_dicts(base, util.safe_load(interpolated_config))

        return base
Пример #10
0
    def _combine(self):
        """
        Perform a prioritized recursive merge of the `molecule_file` with
        defaults, interpolate the result with environment variables, and
        returns a new dict.

        :return: dict
        """
        i = interpolation.Interpolator(interpolation.TemplateWithDefaults,
                                       os.environ)

        base = self._get_defaults()
        with util.open_file(self.molecule_file) as stream:
            interpolated_config = i.interpolate(stream.read())
            base = self.merge_dicts(base, util.safe_load(interpolated_config))

        schema.validate(base)

        return base
Пример #11
0
def from_yaml(data):
    """
    Interpolate the provided data and return a dict.

    Currently, this is used to reinterpolate the `molecule.yml` inside an
    Ansible playbook.  If there were any interpolation errors, they would
    have been found and raised earlier.

    :return: dict
    """
    molecule_env_file = os.environ['MOLECULE_ENV_FILE']

    env = os.environ.copy()
    env = config.set_env_from_file(env, molecule_env_file)

    i = interpolation.Interpolator(interpolation.TemplateWithDefaults, env)
    interpolated_data = i.interpolate(data)

    return util.safe_load(interpolated_data)
Пример #12
0
<<<<<<< HEAD:Rake/molecule/__GEMS_.py/__GEMS_.py/apt-py.git/commandinit.yaml/init.yml/config.py
        i = interpolation.Interpolator(interpolation.TemplateWithDefaults,
                                       os.environ)
=======
=======
<<<<<<< HEAD:molecule/config.py
>>>>>>> e91355cf081d9dcd78efe38cdcc6f0353a1aa3ac
        defaults = self._get_defaults()
        base_config = self.args.get('base_config')
        if base_config and os.path.exists(base_config):
            with util.open_file(base_config) as stream:
                s = stream.read()
                self._preflight(s)
                interpolated_config = self._interpolate(s, env, keep_string)
                defaults = util.merge_dicts(
                    defaults, util.safe_load(interpolated_config))
<<<<<<< HEAD
>>>>>>> 0fa82e7a3daa84ebd03d8af67403c6551113d3e4:molecule/config.py

        base = self._get_defaults()
        with util.open_file(self.molecule_file) as stream:
<<<<<<< HEAD:Rake/molecule/__GEMS_.py/__GEMS_.py/apt-py.git/commandinit.yaml/init.yml/config.py
            try:
                interpolated_config = i.interpolate(stream.read())
                base = self.merge_dicts(base,
=======
=======
=======
        i = interpolation.Interpolator(interpolation.TemplateWithDefaults,
                                       os.environ)
>>>>>>> b1eb06d375fd544a849fcf5c39f51dc334b87338:Rake/molecule/__GEMS_.py/__GEMS_.py/apt-py.git/commandinit.yaml/init.yml/config.py
Пример #13
0
def _config(_molecule_file, request):
    d = util.safe_load(open(_molecule_file))
    if hasattr(request, 'param'):
        d = util.merge_dicts(d, request.getfixturevalue(request.param))

    return d
Пример #14
0
def test_safe_load():
    assert {"foo": "bar"} == util.safe_load("foo: bar")
Пример #15
0
def test_safe_load_returns_empty_dict_on_empty_string():
    assert {} == util.safe_load("")
Пример #16
0
    def _get_v1_config(self):
        d = util.safe_load(open(self._molecule_file))
        schema_v1.validate(d)

        return d
Пример #17
0
def test_safe_load():
    assert {'foo': 'bar'} == util.safe_load('foo: bar')
Пример #18
0
def pre_validate(stream, env, keep_string):
    data = util.safe_load(stream)

    v = Validator(allow_unknown=True)
Пример #19
0
        if molecule_env_var:
            if re.match(pattern, value):
                msg = ('cannot reference $MOLECULE special variables '
                       'in this section')
                self._error(field, msg)


<<<<<<< HEAD
<<<<<<< HEAD:Rake/Gemfile/molecule/model/schema_v2.py
def pre_validate(stream, env, keep_string):
=======
<<<<<<< HEAD:molecule/model/schema_v2.py
def pre_validate(stream):
>>>>>>> e91355cf081d9dcd78efe38cdcc6f0353a1aa3ac
    data = util.safe_load(stream)

    v = Validator(allow_unknown=True)
    v.validate(data, pre_validate_base_schema)
=======
def pre_validate(stream, env, keep_string):
    data = util.safe_load(stream)

    v = Validator(allow_unknown=True)
<<<<<<< HEAD
    v.validate(data, pre_validate_base_schema)
>>>>>>> 0fa82e7a3daa84ebd03d8af67403c6551113d3e4:molecule/model/schema_v2.py
=======
    v.validate(data, pre_validate_base_schema(env, keep_string))
>>>>>>> b1eb06d375fd544a849fcf5c39f51dc334b87338:Rake/Gemfile/molecule/model/schema_v2.py
>>>>>>> e91355cf081d9dcd78efe38cdcc6f0353a1aa3ac
Пример #20
0
def test_safe_load():
    assert {'foo': 'bar'} == util.safe_load('foo: bar')
Пример #21
0
def from_yaml(data):
    i = interpolation.Interpolator(interpolation.TemplateWithDefaults,
                                   os.environ)
    interpolated_data = i.interpolate(data)

    return util.safe_load(interpolated_data)
Пример #22
0
def from_yaml(data):
    i = interpolation.Interpolator(interpolation.TemplateWithDefaults,
                                   os.environ)
    interpolated_data = i.interpolate(data)

    return util.safe_load(interpolated_data)
Пример #23
0
def test_safe_load_returns_empty_dict_on_empty_string():
    assert {} == util.safe_load('')
Пример #24
0
def config(molecule_v1_file):
    return util.safe_load(open(molecule_v1_file))
Пример #25
0
    def _get_v1_config(self):
        d = util.safe_load(open(self._molecule_file))
        errors = schema_v1.validate(d)
        self._check_errors(errors)

        return d
Пример #26
0
def config(molecule_v1_file):
    return util.safe_load(open(molecule_v1_file))