Exemplo n.º 1
0
    def test_is_rpm_newer(self):
        rpm_a = {
            "name": "rpm_test_name",
            "epoch": "0",
            "release": "el6.1",
            "version": "2",
            "arch": "noarch"
        }
        newer_a = {
            "name": "rpm_test_name",
            "epoch": "0",
            "release": "el6.1",
            "version": "3",
            "arch": "noarch"
        }
        newer_a_diff_arch = {
            "name": "rpm_test_name",
            "epoch": "0",
            "release": "el6.1",
            "version": "2",
            "arch": "i386"
        }
        rpm_b = {
            "name": "rpm_test_name_B",
            "epoch": "0",
            "release": "el6.1",
            "version": "5",
            "arch": "noarch"
        }

        self.assertTrue(util.is_rpm_newer(newer_a, rpm_a))
        self.assertFalse(util.is_rpm_newer(newer_a_diff_arch, rpm_a))
        self.assertFalse(util.is_rpm_newer(rpm_a, newer_a))
        self.assertFalse(util.is_rpm_newer(newer_a, rpm_b))
Exemplo n.º 2
0
    def test_is_rpm_newer(self):
        rpm_a = {"name": "rpm_test_name", "epoch":"0", "release":"el6.1", "version":"2", "arch":"noarch"}
        newer_a = {"name": "rpm_test_name", "epoch":"0", "release":"el6.1", "version":"3", "arch":"noarch"}
        newer_a_diff_arch = {"name": "rpm_test_name", "epoch":"0", "release":"el6.1", "version":"2", "arch":"i386"}
        rpm_b = {"name": "rpm_test_name_B", "epoch":"0", "release":"el6.1", "version":"5", "arch":"noarch"}

        self.assertTrue(util.is_rpm_newer(newer_a, rpm_a))
        self.assertFalse(util.is_rpm_newer(newer_a_diff_arch, rpm_a))
        self.assertFalse(util.is_rpm_newer(rpm_a, newer_a))
        self.assertFalse(util.is_rpm_newer(newer_a, rpm_b))
Exemplo n.º 3
0
Arquivo: yum.py Projeto: ulif/pulp_rpm
    def _rpms_applicable_to_consumer(consumer, errata_rpms):
        """
        :param consumer: profiled consumer
        :type consumer: pulp.server.plugins.model.Consumer

        :param errata_rpms: list of errata rpms
        :type errata_rpms: list of dicts

        :return: tuple, first entry list of dictionaries of applicable
        rpm entries, second entry dictionary with more info
        of which installed rpm will be upgraded by what rpm

        Note:
        This method does not take into consideration if the consumer
        is bound to the repo containing the RPM.
        :rtype: ([{}], {})
        """
        applicable_rpms = []
        older_rpms = {}
        if TYPE_ID_RPM not in consumer.profiles:
            msg = _(
                "Consumer [%(consumer_id)s] missing profile information for [%("
                "type_id_rpm)s], found profiles are: %(profiles)s")
            msg_dict = {
                'consumer_id': consumer.id,
                'type_id_rpm': TYPE_ID_RPM,
                'profiles': consumer.profiles.keys()
            }
            _logger.warn(msg, msg_dict)
            return applicable_rpms, older_rpms
        lookup = YumProfiler._form_lookup_table(consumer.profiles[TYPE_ID_RPM])
        for errata_rpm in errata_rpms:
            key = YumProfiler._form_lookup_key(errata_rpm)
            if key in lookup:
                installed_rpm = lookup[key]
                is_newer = util.is_rpm_newer(errata_rpm, installed_rpm)
                msg = _(
                    "Found a match of rpm <%(rpm)s> installed on consumer, is "
                    "%(errata_rpm)s newer than %(installed_rpm)s, %(is_newer)s"
                )
                msg_dict = {
                    'rpm': key,
                    'errata_rpm': errata_rpm,
                    'installed_rpm': installed_rpm,
                    'is_newer': is_newer
                }
                _logger.debug(msg, msg_dict)
                if is_newer:
                    applicable_rpms.append(errata_rpm)
                    older_rpms[key] = {
                        "installed": installed_rpm,
                        "available": errata_rpm
                    }
            else:
                msg = _(
                    "rpm %(key)s was not found in consumer profile of %(consumer_id)s"
                )
                _logger.debug(msg % {'key': key, 'consumer_id': consumer.id})
        return applicable_rpms, older_rpms
Exemplo n.º 4
0
 def _find_newest_pkg(self, list_rpms, blacklist_units=None):
     """
     compare and return the newest rpm unit from the list of rpm units
     @param list_rpms: list of rpm units
     @return: returns newest rpm unit by rpm.name, rpm.arch
     """
     newest = {}
     for pkg in list_rpms:
         pkg_unit_key = pkg.unit_key
         if blacklist_units and pkg_unit_key in blacklist_units:
             continue
         if (pkg_unit_key["name"], pkg_unit_key["arch"]) not in newest:
             newest[(pkg_unit_key["name"], pkg_unit_key["arch"])] = pkg
         else:
             pkg2 = newest[(pkg_unit_key["name"], pkg_unit_key["arch"])]
             if util.is_rpm_newer(pkg_unit_key, pkg2.unit_key):
                 newest[(pkg_unit_key["name"], pkg_unit_key["arch"])] = pkg
     return newest.values()
Exemplo n.º 5
0
    def _rpms_applicable_to_consumer(consumer, errata_rpms):
        """
        :param consumer: profiled consumer
        :type consumer: pulp.server.plugins.model.Consumer

        :param errata_rpms: list of errata rpms
        :type errata_rpms: list of dicts

        :return: tuple, first entry list of dictionaries of applicable
        rpm entries, second entry dictionary with more info
        of which installed rpm will be upgraded by what rpm

        Note:
        This method does not take into consideration if the consumer
        is bound to the repo containing the RPM.
        :rtype: ([{}], {})
        """
        applicable_rpms = []
        older_rpms = {}
        if TYPE_ID_RPM not in consumer.profiles:
            msg = _("Consumer [%(consumer_id)s] missing profile information for [%("
                    "type_id_rpm)s], found profiles are: %(profiles)s")
            msg_dict = {'consumer_id': consumer.id, 'type_id_rpm': TYPE_ID_RPM,
                        'profiles': consumer.profiles.keys()}
            _logger.warn(msg, msg_dict)
            return applicable_rpms, older_rpms
        lookup = YumProfiler._form_lookup_table(consumer.profiles[TYPE_ID_RPM])
        for errata_rpm in errata_rpms:
            key = YumProfiler._form_lookup_key(errata_rpm)
            if key in lookup:
                installed_rpm = lookup[key]
                is_newer = util.is_rpm_newer(errata_rpm, installed_rpm)
                msg = _("Found a match of rpm <%(rpm)s> installed on consumer, is "
                        "%(errata_rpm)s newer than %(installed_rpm)s, %(is_newer)s")
                msg_dict = {'rpm': key, 'errata_rpm': errata_rpm, 'installed_rpm': installed_rpm,
                            'is_newer': is_newer}
                _logger.debug(msg, msg_dict)
                if is_newer:
                    applicable_rpms.append(errata_rpm)
                    older_rpms[key] = {"installed": installed_rpm, "available": errata_rpm}
            else:
                msg = _("rpm %(key)s was not found in consumer profile of %(consumer_id)s")
                _logger.debug(msg % {'key': key, 'consumer_id': consumer.id})
        return applicable_rpms, older_rpms
Exemplo n.º 6
0
    def _rpms_applicable_to_consumer(consumer, errata_rpms):
        """
        :param consumer: profiled consumer
        :type consumer: pulp.server.plugins.model.Consumer

        :param errata_rpms: list of errata rpms
        :type errata_rpms: list of dicts

        :return: tuple, first entry list of dictionaries of applicable
        rpm entries, second entry dictionary with more info
        of which installed rpm will be upgraded by what rpm

        Note:
        This method does not take into consideration if the consumer
        is bound to the repo containing the RPM.
        :rtype: ([{}], {})
        """
        applicable_rpms = []
        older_rpms = {}
        if TYPE_ID_RPM not in consumer.profiles:
            _logger.warn(
                "Consumer [%s] is missing profile information for [%s], found profiles are: %s"
                % (consumer.id, TYPE_ID_RPM, consumer.profiles.keys()))
            return applicable_rpms, older_rpms
        lookup = YumProfiler._form_lookup_table(consumer.profiles[TYPE_ID_RPM])
        for errata_rpm in errata_rpms:
            key = YumProfiler._form_lookup_key(errata_rpm)
            if key in lookup:
                installed_rpm = lookup[key]
                is_newer = util.is_rpm_newer(errata_rpm, installed_rpm)
                _logger.debug(
                    "Found a match of rpm <%s> installed on consumer, is %s newer than %s, %s"
                    % (key, errata_rpm, installed_rpm, is_newer))
                if is_newer:
                    applicable_rpms.append(errata_rpm)
                    older_rpms[key] = {
                        "installed": installed_rpm,
                        "available": errata_rpm
                    }
            else:
                _logger.debug(
                    "rpm %s was not found in consumer profile of %s" %
                    (key, consumer.id))
        return applicable_rpms, older_rpms
Exemplo n.º 7
0
    def rpms_applicable_to_consumer(self, consumer, errata_rpms):
        """
        :param consumer:
        :type consumer: pulp.server.plugins.model.Consumer

        :param errata_rpms: 
        :type errata_rpms: list of dicts

        :return:    tuple, first entry list of dictionaries of applicable 
                    rpm entries, second entry dictionary with more info 
                    of which installed rpm will be upgraded by what rpm

                    Note:
                    This method does not take into consideration if the consumer
                    is bound to the repo containing the RPM.
        :rtype: ([{}], {})
        """
        applicable_rpms = []
        older_rpms = {}
        if not consumer.profiles.has_key(TYPE_ID_RPM):
            _LOG.warn(
                "Consumer [%s] is missing profile information for [%s], found profiles are: %s"
                % (consumer.id, TYPE_ID_RPM, consumer.profiles.keys())
            )
            return applicable_rpms, older_rpms
        lookup = self.form_lookup_table(consumer.profiles[TYPE_ID_RPM])
        for errata_rpm in errata_rpms:
            key = self.form_lookup_key(errata_rpm)
            if lookup.has_key(key):
                installed_rpm = lookup[key]
                is_newer = util.is_rpm_newer(errata_rpm, installed_rpm)
                _LOG.info(
                    "Found a match of rpm <%s> installed on consumer, is %s newer than %s, %s"
                    % (key, errata_rpm, installed_rpm, is_newer)
                )
                if is_newer:
                    applicable_rpms.append(errata_rpm)
                    older_rpms[key] = {"installed": installed_rpm, "available": errata_rpm}
            else:
                _LOG.info("rpm %s was not found in consumer profile of %s" % (key, consumer.id))
        return applicable_rpms, older_rpms
Exemplo n.º 8
0
    def _form_lookup_table(rpms):
        """
        Build a dictionary mapping RPM names and arches (generated with the _form_lookup_key()
        method) to the full unit key for each RPM. In case of multiple rpms with same name and
        arch, unit key of the newest rpm is stored as the value.

        :param rpms: A list of RPM unit keys
        :type  rpms: list
        :return:     A dictionary mapping the lookup keys to the RPM unit keys
        :rtype:      dict
        """
        lookup = {}
        for rpm in rpms:
            key = YumProfiler._form_lookup_key(rpm)
            # In case of duplicate key, replace the value only if the rpm is newer
            # than the old value.
            if key in lookup:
                existing_unit = lookup[key]
                if not util.is_rpm_newer(rpm, existing_unit):
                    continue
            lookup[key] = rpm
        return lookup
Exemplo n.º 9
0
    def _form_lookup_table(rpms):
        """
        Build a dictionary mapping RPM names and arches (generated with the _form_lookup_key()
        method) to the full unit key for each RPM. In case of multiple rpms with same name and
        arch, unit key of the newest rpm is stored as the value.

        :param rpms: A list of RPM unit keys
        :type  rpms: list
        :return:     A dictionary mapping the lookup keys to the RPM unit keys
        :rtype:      dict
        """
        lookup = {}
        for rpm in rpms:
            key = YumProfiler._form_lookup_key(rpm)
            # In case of duplicate key, replace the value only if the rpm is newer
            # than the old value.
            if key in lookup:
                existing_unit = lookup[key]
                if not util.is_rpm_newer(rpm, existing_unit):
                    continue
            lookup[key] = rpm
        return lookup
Exemplo n.º 10
0
    def _is_rpm_applicable(rpm_unit_key, profile_lookup_table):
        """
        Checks whether given rpm upgrades an rpm on the consumer.

        :param rpm_unit_key:         An rpm's unit_key
        :type  rpm_unit_key:         dict
        :param profile_lookup_table: lookup table of consumer profile keyed by "name arch"
        :type  profile_lookup_table: dict
        :return:                     true if applicable, false otherwise
        :rtype:                      boolean
        """
        if not rpm_unit_key or not profile_lookup_table:
            return False

        key = YumProfiler._form_lookup_key(rpm_unit_key)

        if key in profile_lookup_table:
            installed_rpm = profile_lookup_table[key]
            # If an rpm is found, check if it is older than the available rpm
            if util.is_rpm_newer(rpm_unit_key, installed_rpm):
                return True

        return False
Exemplo n.º 11
0
    def _is_rpm_applicable(rpm_unit_key, profile_lookup_table):
        """
        Checks whether given rpm upgrades an rpm on the consumer.

        :param rpm_unit_key:         An rpm's unit_key
        :type  rpm_unit_key:         dict
        :param profile_lookup_table: lookup table of consumer profile keyed by "name arch"
        :type  profile_lookup_table: dict
        :return:                     true if applicable, false otherwise
        :rtype:                      boolean
        """
        if not rpm_unit_key or not profile_lookup_table:
            return False

        key = YumProfiler._form_lookup_key(rpm_unit_key)

        if key in profile_lookup_table:
            installed_rpm = profile_lookup_table[key]
            # If an rpm is found, check if it is older than the available rpm
            if util.is_rpm_newer(rpm_unit_key, installed_rpm):
                return True

        return False
Exemplo n.º 12
0
    def rpm_applicable_to_consumer(self, consumer, rpm):
        """
        Checks whether given rpm upgrades an rpm on the consumer.

        :param consumer: a profiled consumer
        :type consumer: pulp.server.plugins.model.Consumer

        :param rpm: a package rpm
        :type rpm: dict

        :return:  a tuple consisting of applicable flag and upgrade details
        :rtype: (applicable_flag, {'name arch':{'available':{}, 'installed':{}}})
        """
        applicable = False
        older_rpm = {}

        if not consumer.profiles.has_key(TYPE_ID_RPM):
            _LOG.warn("Consumer [%s] is missing profile information for [%s], found profiles are: %s" % \
                    (consumer.id, TYPE_ID_RPM, consumer.profiles.keys()))
            return applicable, older_rpm

        # Form a lookup table from consumer profile
        lookup = self.form_lookup_table(consumer.profiles[TYPE_ID_RPM])
        key = self.form_lookup_key(rpm)
        
        if lookup.has_key(key):
            installed_rpm = lookup[key]
            # If an rpm is found, check if it is older than the available rpm
            is_newer = util.is_rpm_newer(rpm, installed_rpm)
            _LOG.debug("Found a match of rpm <%s> installed on consumer, is %s newer than %s, %s" % (key, rpm, installed_rpm, is_newer))
            if is_newer:
                applicable = True
                older_rpm[key] = {"installed":installed_rpm, "available":rpm}
        else:
            _LOG.debug("rpm %s was not found in consumer profile of %s" % (key, consumer.id))

        return applicable, older_rpm