def test_validation_err_ux2(path, message): """ Test that validation errors are useful """ p = PbVarsParser(path) with pytest.raises(ABValidationError) as ex: p.get_build_and_metadata() s = str(ex.value) assert message in s
def test_set_all_params(): """ test that we can set all the parameters """ p = PbVarsParser(full_conf_pb_path) b, m = p.get_build_and_metadata() b.playbook_path = "/somewhere.yaml" b.validate() m.validate() assert isinstance(b, Build) assert isinstance(m, ImageMetadata) assert b.base_image == "mona_lisa" assert b.layering assert not b.cache_tasks assert b.ansible_extra_args == "--some --args" assert b.build_volumes == ["/c:/d"] assert b.target_image == "funky-mona-lisa" assert m.env_vars == {"z": "value"} assert m.volumes == ["/a"] assert m.working_dir == "/workshop" assert m.labels == {"x": "y"} assert m.annotations == {"bohemian": "rhapsody"} assert m.cmd == "command -x -y z" assert m.user == "leonardo"
def test_multiplay(caplog): set_logging() p = PbVarsParser(multiplay_path) b, m = p.get_build_and_metadata() assert b.target_image != "nope" assert "Variables are loaded only from the first play." == caplog.records[0].msg assert "no bender data found in the playbook" == caplog.records[1].msg
def _build(self): pb_vars_p = PbVarsParser(self.args.playbook_path) build, metadata = pb_vars_p.get_build_and_metadata() build.metadata = metadata if self.args.workdir: metadata.working_dir = self.args.workdir if self.args.labels: for label in self.args.labels: err_msg = "Label variable {} doesn't seem to be " + \ "specified in format 'KEY=VALUE'.".format(label) k, v = split_once_or_fail_with(label, "=", err_msg) metadata.labels[k] = v if self.args.annotations: for ann in self.args.annotations: err_msg = "Annotation {} doesn't seem to be " + \ "specified in format 'KEY=VALUE'.".format(ann) k, v = split_once_or_fail_with(ann, "=", err_msg) metadata.annotations[k] = v if self.args.env_vars: for e_v in self.args.env_vars: err_msg = "Environment variable {} doesn't seem to be " + \ "specified in format 'KEY=VALUE'.".format(e_v) k, v = split_once_or_fail_with(e_v, "=", err_msg) metadata.env_vars[k] = v if self.args.cmd: metadata.cmd = self.args.cmd if self.args.entrypoint: metadata.entrypoint = self.args.entrypoint if self.args.user: metadata.user = self.args.user if self.args.ports: metadata.ports = self.args.ports if self.args.runtime_volumes: metadata.volumes = self.args.runtime_volumes build.playbook_path = self.args.playbook_path if self.args.build_volumes: build.build_volumes = self.args.build_volumes if self.args.base_image: build.base_image = self.args.base_image if self.args.target_image: build.target_image = self.args.target_image if self.args.builder: build.builder_name = self.args.builder if self.args.no_cache is not None: build.cache_tasks = not self.args.no_cache if self.args.squash: build.squash = self.args.squash if self.args.extra_buildah_from_args: build.buildah_from_extra_args = self.args.extra_buildah_from_args if self.args.extra_ansible_args: build.ansible_extra_args = self.args.extra_ansible_args if self.args.python_interpreter: build.python_interpreter = self.args.python_interpreter if self.args.build_entrypoint: build.build_entrypoint = self.args.build_entrypoint self.app.build(build)
def test_validation_err_ux(): """ Test that validation errors are useful """ p = PbVarsParser(basic_playbook_path) b, m = p.get_build_and_metadata() with pytest.raises(jsonschema.exceptions.ValidationError) as ex: b.validate() s = str(ex.value) assert "is not of type" in s assert "Failed validating 'type' in schema" in s
def test_b_m_empty(): """ test that build and metadata are 'empty' when there are no vars """ p = PbVarsParser(basic_playbook_path) b, m = p.get_build_and_metadata() b.playbook_path = "/somewhere.yaml" b.base_image = "fedora:29" b.playbook_path = "/asd.yaml" b.target_image = "lolz" b.validate() m.validate() assert isinstance(b, Build) assert isinstance(m, ImageMetadata) assert b.cache_tasks is True assert b.layering is True