Exemplo n.º 1
0
    def test_update_modulemd_filters(self):
        mod1 = yaml.safe_load(yaml1)
        self.assertNotIn("filter", mod1["data"])

        result = update(yaml1, filters=["foo", "bar"])
        mod2 = yaml.safe_load(result)
        self.assertEqual(set(mod2["data"]["filter"]["rpms"]), {"foo", "bar"})

        result = update(result, filters=["baz"])
        mod3 = yaml.safe_load(result)
        self.assertEqual(set(mod3["data"]["filter"]["rpms"]), {"baz"})
Exemplo n.º 2
0
    def test_update_modulemd_creation(self):
        """
        This is an example modulemd transformation that copr-frontend would do
        when generating a new module via web UI (not exactly, but it would
        change these properties).
        """
        mod1 = yaml.safe_load(yaml1)
        self.assertEqual(mod1["data"]["version"], 123)
        self.assertEqual(mod1["data"]["context"], "f32")
        self.assertEqual(mod1["data"]["summary"], "Summary and stuff")
        self.assertEqual(mod1["data"]["description"],
                         "This module has been generated using dir2module tool")
        self.assertEqual(mod1["data"]["license"]["module"], ["MIT"])
        self.assertEqual(mod1["data"]["license"]["content"],
                         ["BSD", "GPLv2", "MIT"])

        result = update(yaml1, version=234, context="f33", summary="A new sum",
                        description="A new desc", module_licenses=["BSD"],
                        content_licenses=["MIT", "WTFPL"])

        mod1 = yaml.safe_load(result)
        self.assertEqual(mod1["data"]["version"], 234)
        self.assertEqual(mod1["data"]["context"], "f33")
        self.assertEqual(mod1["data"]["summary"], "A new sum")
        self.assertEqual(mod1["data"]["description"], "A new desc")
        self.assertEqual(set(mod1["data"]["license"]["module"]), {"BSD"})
        self.assertEqual(set(mod1["data"]["license"]["content"]),
                         {"MIT", "WTFPL"})
Exemplo n.º 3
0
    def test_update_without_dependencies(self):
        """
        The logic for updating dependencies is a bit complicated and can fail
        when dependencies are not present in the modulemd YAML at all.
        """
        validate(yaml3_no_deps)
        mod1 = yaml.safe_load(yaml3_no_deps)
        self.assertNotIn("dependencies", mod1["data"])

        result = update(yaml3_no_deps, summary="Updated summary")
        mod2 = yaml.safe_load(result)
        self.assertEqual(mod2["data"]["summary"], "Updated summary")
        self.assertNotIn("dependencies", ["data"])

        result = update(yaml3_no_deps, requires={"foo": ["bar"]})
        mod3 = yaml.safe_load(result)
        self.assertEqual(mod3["data"]["dependencies"][0]["requires"],
                         {"foo": ["bar"]})
Exemplo n.º 4
0
    def test_update_modulemd_with_multiple_pairs_of_deps(self):
        """
        While uncommon, it's not impossible for there to be more than one
        Dependencies object in the list.
        """
        validate(yaml6_multiple_pairs_of_deps)
        mod1 = yaml.safe_load(yaml6_multiple_pairs_of_deps)
        self.assertEqual(len(mod1["data"]["dependencies"]), 2)

        dependencies = [
            {"buildrequires": {"platform": ["-epel8"]},
             "requires": {"platform": ["-epel8"]}},
            {"buildrequires": {"libfoo": ["rolling"],
                               "platform": ["epel8"]},
             "requires": {"libfoo": ["rolling"],
                          "platform": ["epel8"]}},
        ]
        self.assertEqual(mod1["data"]["dependencies"], dependencies)

        requires = {"foo": ["bar"]}
        with self.assertRaises(AttributeError) as context:
            update(yaml6_multiple_pairs_of_deps, requires=requires)
        self.assertIn("Provided YAML contains multiple pairs of dependencies. "
                      "It is ambiguous which one to update.",
                      str(context.exception))

        buildrequires = {"baz": ["qux"]}
        with self.assertRaises(AttributeError) as context:
            update(yaml6_multiple_pairs_of_deps, buildrequires=buildrequires)
        self.assertIn("Provided YAML contains multiple pairs of dependencies. "
                      "It is ambiguous which one to update.",
                      str(context.exception))

        result = update(yaml6_multiple_pairs_of_deps,
                        requires=requires, buildrequires=buildrequires)
        mod2 = yaml.safe_load(result)
        self.assertEqual(len(mod2["data"]["dependencies"]), 1)
        self.assertEqual(mod2["data"]["dependencies"][0], {
            "requires": {"foo": ["bar"]},
            "buildrequires": {"baz": ["qux"]},
        })
Exemplo n.º 5
0
    def test_update_modulemd_profiles(self):
        mod1 = yaml.safe_load(yaml1)
        self.assertNotIn("profiles", mod1["data"])

        profiles = {
            "default": ["foo"],
            "ubercool": ["foo", "bar"]
        }
        result = update(yaml1, profiles=profiles)
        mod2 = yaml.safe_load(result)
        self.assertEqual(len(mod2["data"]["profiles"]), 2)
        self.assertEqual(set(mod2["data"]["profiles"]["default"]["rpms"]),
                         {"foo"})
        self.assertEqual(set(mod2["data"]["profiles"]["ubercool"]["rpms"]),
                         {"foo", "bar"})

        result = update(result, profiles={"minimal": ["baz"]})
        mod3 = yaml.safe_load(result)
        self.assertEqual(len(mod3["data"]["profiles"]), 1)
        self.assertEqual(set(mod3["data"]["profiles"]["minimal"]["rpms"]),
                         {"baz"})
Exemplo n.º 6
0
    def test_update_modulemd_dependencies(self):
        mod1 = yaml.safe_load(yaml1)
        deps1 = mod1["data"]["dependencies"][0]
        self.assertEqual(deps1["requires"], {"platform": ["f32"]})
        self.assertEqual(deps1["buildrequires"], {"platform": ["f32"]})

        result = update(yaml1, requires={"foo": ["f33"]},
                        buildrequires={"bar": ["master"]})

        mod2 = yaml.safe_load(result)
        deps2 = mod2["data"]["dependencies"][0]
        self.assertEqual(deps2["requires"], {"foo": ["f33"]})
        self.assertEqual(deps2["buildrequires"], {"bar": ["master"]})
Exemplo n.º 7
0
    def test_update_modulemd_components(self):
        mod1 = yaml.safe_load(yaml1)
        self.assertNotIn("components", mod1["data"])

        components = [
            {"name": "foo", "rationale": "Just because", "buildorder": 10},
            {"name": "bar", "rationale": "It's a dep"},
        ]
        result = update(yaml1, components=components)
        mod2 = yaml.safe_load(result)
        self.assertEqual(len(mod2["data"]["components"]["rpms"]), 2)
        self.assertEqual(mod2["data"]["components"]["rpms"]["foo"], {
            "rationale": "Just because",
            "buildorder": 10,
        })
        self.assertEqual(mod2["data"]["components"]["rpms"]["bar"], {
            "rationale": "It's a dep",
        })

        components = [{
            "name": "baz",
            "rationale": "Testing component properties",
            "buildorder": 20,
            "ref": "master",
            "repository": "http://foo.bar/baz.git",
        }]
        result = update(result, components=components)
        mod2 = yaml.safe_load(result)
        self.assertEqual(len(mod2["data"]["components"]["rpms"]), 1)
        baz = mod2["data"]["components"]["rpms"]["baz"]
        self.assertEqual(baz, {
            "rationale": "Testing component properties",
            "buildorder": 20,
            "ref": "master",
            "repository": "http://foo.bar/baz.git",
        })
Exemplo n.º 8
0
    def test_update_modulemd_runtime_dependencies(self):
        """
        Dropping dependencies can be tricky so should rather make sure that if
        we want to update only runtime dependencies, the buildtime dependencies
        remain untouched.
        """
        mod1 = yaml.safe_load(yaml1)
        deps1 = mod1["data"]["dependencies"][0]
        self.assertEqual(deps1["requires"], {"platform": ["f32"]})
        self.assertEqual(deps1["buildrequires"], {"platform": ["f32"]})

        result = update(yaml1, requires={"foo": ["f33"]})

        mod2 = yaml.safe_load(result)
        deps2 = mod2["data"]["dependencies"][0]
        self.assertEqual(deps2["requires"], {"foo": ["f33"]})
        self.assertEqual(deps2["buildrequires"], {"platform": ["f32"]})
Exemplo n.º 9
0
    def test_update_after_build(self):
        """
        This is an example modulemd transformation that copr-backend would do
        after finishing a module build.
        """
        # First, let's check that we can parse the modulemd YAML definition and
        # that it looks as expected
        mod1 = yaml.safe_load(yaml1)
        self.assertNotIn("arch", mod1["data"])
        for rpm in mod1["data"]["artifacts"]["rpms"]:
            self.assertTrue(rpm.startswith("LTK-"))

        # When copr-backend finishes a module build, it needs to update the
        # architecture and built artifacts
        rpms = ["foo-0:1.2-1.fc32.x86_64", "bar-1:1.2-3.fc32.x86_64"]
        result = update(yaml1, arch="x86_64", rpms_nevras=rpms)

        # Now let's see
        mod2 = yaml.safe_load(result)
        self.assertEqual(mod2["data"]["arch"], "x86_64")
        self.assertEqual(set(mod2["data"]["artifacts"]["rpms"]), set(rpms))
Exemplo n.º 10
0
    def test_update_modulemd_nsvca(self):
        """
        It is not expected change module name or stream, not even `libmodulemd`
        classes allow it. In case you want to update a module name, you need to
        create a new one. I say f*ck it, let us change whatever we want.
        """
        mod1 = yaml.safe_load(yaml1)
        self.assertEqual(mod1["data"]["name"], "foo")
        self.assertEqual(mod1["data"]["stream"], "devel")
        self.assertEqual(mod1["data"]["version"], 123)
        self.assertEqual(mod1["data"]["context"], "f32")

        result = update(yaml1, name="bar", stream="stable",
                        version=234, context="f33")

        mod2 = yaml.safe_load(result)
        self.assertEqual(mod2["data"]["name"], "bar")
        self.assertEqual(mod2["data"]["stream"], "stable")
        self.assertEqual(mod2["data"]["version"], 234)
        self.assertEqual(mod2["data"]["context"], "f33")

        self.assertEqual(mod2["data"]["summary"], "Summary and stuff")
        self.assertEqual(mod1["data"]["license"]["module"], ["MIT"])