コード例 #1
0
    def evaluate(self, image_obj, context):
        name = self.pkg_name.value()
        version = self.pkg_version.value()
        comparison = self.version_comparison.value(default_if_none='exact')

        found = False

        # Filter is possible since the lazy='dynamic' is set on the packages relationship in Image.
        for img_pkg in image_obj.packages.filter(
                ImagePackage.name == name).all():
            if version is None:
                found = True
                break
            elif comparison == 'exact':
                if img_pkg.fullversion != version:
                    self._fire(
                        msg="Required input package (" + str(img_pkg.name) +
                        ") is present (" + str(img_pkg.fullversion) +
                        "), but not at the version specified in policy (" +
                        str(name) + ")")

                found = True
                break
            elif comparison == 'minimum':
                if img_pkg.fullversion != version:
                    # Check if version is less than param value
                    if compare_package_versions(
                            img_pkg.distro_namespace_meta.flavor, img_pkg.name,
                            img_pkg.version, img_pkg.name, version) < 0:
                        self._fire(
                            msg="Required min-version input package (" +
                            str(img_pkg.name) + ") is present (" +
                            str(img_pkg.fullversion) +
                            "), but is lower version than what is specified in policy ("
                            + str(version) + ")")

                # >=, so ok
                found = True
                break

        if not found:
            if version and comparison != 'name_only':
                self._fire(
                    msg=
                    "Required input package ({},{}) is not present in container image"
                    .format(str(name), str(version)))
            else:
                self._fire(
                    msg=
                    "Required input package ({}) is not present in container image"
                    .format(str(name)))
コード例 #2
0
    def evaluate(self, image_obj, context):
        fullmatch = self.pkg_full_match.value(default_if_none={})
        namematch = self.pkg_name_match.value(default_if_none=[])
        vermatch = self.pkg_version_match.value(default_if_none={})

        names = set(fullmatch.keys()).union(set(namematch)).union(
            set(vermatch.keys()))
        if not names:
            return

        # Filter is possible since the lazy='dynamic' is set on the packages relationship in Image.
        for img_pkg in image_obj.packages.filter(
                ImagePackage.name.in_(names)).all():
            if img_pkg.name in fullmatch:
                if img_pkg.fullversion != fullmatch.get(img_pkg.name):
                    # Found but not right version
                    self._fire(
                        msg="PKGNOTPRESENT input package (" +
                        str(img_pkg.name) + ") is present (" +
                        str(img_pkg.fullversion) +
                        "), but not at the version specified in policy (" +
                        str(fullmatch[img_pkg.name]) + ")")
                    fullmatch.pop(
                        img_pkg.name
                    )  # Assume only one version of a given package name is installed
                else:
                    # Remove it from the list
                    fullmatch.pop(img_pkg.name)

            # Name match is sufficient
            if img_pkg.name in namematch:
                namematch.remove(img_pkg.name)

            if img_pkg.name in vermatch:
                if img_pkg.fullversion != vermatch[img_pkg.name]:
                    # Check if version is less than param value
                    if compare_package_versions(
                            img_pkg.distro_namespace_meta.flavor, img_pkg.name,
                            img_pkg.version, img_pkg.name,
                            vermatch[img_pkg.name]) < 0:
                        self._fire(
                            msg="PKGNOTPRESENT input package (" +
                            str(img_pkg.name) + ") is present (" +
                            str(img_pkg.fullversion) +
                            "), but is lower version than what is specified in policy ("
                            + str(vermatch[img_pkg.name]) + ")")

                vermatch.pop(img_pkg.name)

        # Any remaining
        for pkg, version in fullmatch.items():
            self._fire(msg="PKGNOTPRESENT input package (" + str(pkg) + "-" +
                       str(version) + ") is not present in container image")

        for pkg, version in vermatch.items():
            self._fire(msg="PKGNOTPRESENT input package (" + str(pkg) + "-" +
                       str(version) + ") is not present in container image")

        for pkg in namematch:
            self._fire(msg="PKGNOTPRESENT input package (" + str(pkg) +
                       ") is not present in container image")