Ejemplo n.º 1
0
    def handle_build_module(self):
        result = ActionResult.SUCCESS
        try:
            data = json.loads(self.data["data"])
            ownername = data["ownername"]
            projectname = data["projectname"]
            chroots = data["chroots"]
            modulemd_data = base64.b64decode(data["modulemd_b64"]).decode("utf-8")
            project_path = os.path.join(self.opts.destdir, ownername, projectname)
            self.log.info(modulemd_data)

            for chroot in chroots:
                arch = get_chroot_arch(chroot)
                mmd = Modulemd.ModuleStream()
                mmd.import_from_string(modulemd_data)
                mmd.set_arch(arch)
                artifacts = Modulemd.SimpleSet()

                srcdir = os.path.join(project_path, chroot)
                module_tag = "{}+{}-{}-{}".format(chroot, mmd.get_name(), (mmd.get_stream() or ''),
                                                  (str(mmd.get_version()) or '1'))
                module_relpath = os.path.join(module_tag, "latest", arch)
                destdir = os.path.join(project_path, "modules", module_relpath)

                if os.path.exists(destdir):
                    self.log.warning("Module %s already exists. Omitting.", destdir)
                else:
                    # We want to copy just the particular module builds
                    # into the module destdir, not the whole chroot
                    os.makedirs(destdir)
                    prefixes = ["{:08d}-".format(x) for x in data["builds"]]
                    dirs = [d for d in os.listdir(srcdir) if d.startswith(tuple(prefixes))]
                    for folder in dirs:
                        shutil.copytree(os.path.join(srcdir, folder), os.path.join(destdir, folder))
                        self.log.info("Copy directory: %s as %s",
                                      os.path.join(srcdir, folder), os.path.join(destdir, folder))

                        for f in os.listdir(os.path.join(destdir, folder)):
                            if not f.endswith(".rpm") or f.endswith(".src.rpm"):
                                continue
                            artifact = format_filename(zero_epoch=True, *splitFilename(f))
                            artifacts.add(artifact)

                    mmd.set_rpm_artifacts(artifacts)
                    self.log.info("Module artifacts: %s", mmd.get_rpm_artifacts())
                    Modulemd.dump([mmd], os.path.join(destdir, "modules.yaml"))
                    if not call_copr_repo(destdir):
                        result = ActionResult.FAILURE

        except Exception:
            self.log.exception("handle_build_module failed")
            result = ActionResult.FAILURE

        return result
Ejemplo n.º 2
0
    def test_constructors(self):
        for version in modulestream_versions:

            # Test that the new() function works
            stream = Modulemd.ModuleStream.new(version, "foo", "latest")
            assert stream
            assert isinstance(stream, Modulemd.ModuleStream)

            assert stream.props.mdversion == version
            assert stream.get_mdversion() == version
            assert stream.props.module_name == "foo"
            assert stream.get_module_name() == "foo"
            assert stream.props.stream_name == "latest"
            assert stream.get_stream_name() == "latest"

            # Test that the new() function works without a stream name
            stream = Modulemd.ModuleStream.new(version, "foo")
            assert stream
            assert isinstance(stream, Modulemd.ModuleStream)

            assert stream.props.mdversion == version
            assert stream.get_mdversion() == version
            assert stream.props.module_name == "foo"
            assert stream.get_module_name() == "foo"
            assert stream.props.stream_name is None
            assert stream.get_stream_name() is None

            # Test that the new() function works with no module name
            stream = Modulemd.ModuleStream.new(version, None, "latest")
            assert stream
            assert isinstance(stream, Modulemd.ModuleStream)

            assert stream.props.mdversion == version
            assert stream.get_mdversion() == version
            assert stream.props.module_name is None
            assert stream.get_module_name() is None
            assert stream.props.stream_name == "latest"
            assert stream.get_stream_name() == "latest"

            # Test that the new() function works with no module or stream
            stream = Modulemd.ModuleStream.new(version)
            assert stream
            assert isinstance(stream, Modulemd.ModuleStream)

            assert stream.props.mdversion == version
            assert stream.get_mdversion() == version
            assert stream.props.module_name is None
            assert stream.get_module_name() is None
            assert stream.props.stream_name is None
            assert stream.get_stream_name() is None

        # Test that we cannot instantiate directly
        with self.assertRaisesRegexp(
            TypeError, "cannot create instance of abstract"
        ):
            Modulemd.ModuleStream()

        # Test with a zero mdversion
        with self.assertRaisesRegexp(TypeError, "constructor returned NULL"):
            with self.expect_signal():
                defs = Modulemd.ModuleStream.new(0)

        # Test with an unknown mdversion
        with self.assertRaisesRegexp(TypeError, "constructor returned NULL"):
            with self.expect_signal():
                defs = Modulemd.ModuleStream.new(
                    Modulemd.ModuleStreamVersionEnum.LATEST + 1
                )
Ejemplo n.º 3
0
 def yaml2modulemd(cls, yaml):
     mmd = Modulemd.ModuleStream()
     mmd.import_from_string(yaml)
     return mmd
Ejemplo n.º 4
0
 def __init__(self, name="", stream="", version=0, summary="", config=None):
     self.config = config
     licenses = Modulemd.SimpleSet()
     licenses.add("unknown")
     self.mmd = Modulemd.ModuleStream(mdversion=1, name=name, stream=stream, version=version, summary=summary,
                                      description="", content_licenses=licenses, module_licenses=licenses)