Ejemplo n.º 1
0
    def test_install_selector(self):
        sltr = hawkey.Selector(self.sack).set(name="walrus")
        # without checking versioning, the update is accepted:
        self.assertIsNone(hawkey.Goal(self.sack).upgrade(select=sltr))

        goal = hawkey.Goal(self.sack)
        goal.install(name="semolina")
        goal.run()
        self.assertEqual(str(goal.list_installs()[0]), 'semolina-2-0.x86_64')
Ejemplo n.º 2
0
 def test_upgrade(self):
     # select the installed "fool":
     pkg = hawkey.Query(self.sack).filter(name="walrus")[0]
     # without checking versioning, the update is accepted:
     self.assertIsNone(hawkey.Goal(self.sack).
                       upgrade_to(pkg, check_installed=False))
     # with the check it is not:
     goal = hawkey.Goal(self.sack)
     self.assertRaises(hawkey.Exception, goal.upgrade_to, package=pkg,
                       check_installed=True)
     # default value for check_installed is False:
     self.assertIsNone(hawkey.Goal(self.sack).upgrade_to(pkg))
Ejemplo n.º 3
0
    def test_install_selector_err(self):
        sltr = hawkey.Selector(self.sack)
        self.assertRaises(hawkey.ValueException, sltr.set, undefined="eapoe")

        sltr = hawkey.Selector(self.sack).set(name="semolina", arch="i666")
        goal = hawkey.Goal(self.sack)
        self.assertRaises(hawkey.ArchException, goal.install, select=sltr)
Ejemplo n.º 4
0
def run_goal(sack, group, br):
    # pylint:disable=E1101
    goal = hawkey.Goal(sack)
    problems = []
    for name in group:
        sltr = hawkey.Selector(sack).set(name=name)
        if not sltr.matches():
            problems.append(
                "Package in base build group not found: {}".format(name))
        goal.install(select=sltr)
    for r in br:
        sltr = _get_best_selector(sack, r)
        # pylint: disable=E1103
        if not sltr.matches():
            problems.append("No package found for: {}".format(r))
        else:
            goal.install(select=sltr)
    if not problems:
        kwargs = {}
        if config['dependency']['ignore_weak_deps']:
            kwargs = {'ignore_weak_deps': True}
        resolved = goal.run(**kwargs)
        return resolved, goal.problems, goal.list_installs(
        ) if resolved else None
    return False, problems, None
Ejemplo n.º 5
0
 def test_empty_selector(self):
     sltr = hawkey.Selector(self.sack)
     goal = hawkey.Goal(self.sack)
     # does not raise ValueException
     goal.install(select=sltr)
     goal.run()
     self.assertEqual(goal.list_installs(), [])
Ejemplo n.º 6
0
    def test_req(self):
        goal = hawkey.Goal(self.sack)
        self.assertEqual(goal.req_length(), 0)
        self.assertFalse(goal.req_has_erase())
        sltr = hawkey.Selector(self.sack).set(name="jay")
        goal.erase(select=sltr)
        self.assertEqual(goal.req_length(), 1)
        self.assertTrue(goal.req_has_erase())

        goal = hawkey.Goal(self.sack)
        goal.upgrade(select=sltr)
        self.assertFalse(goal.req_has_erase())

        goal = hawkey.Goal(self.sack)
        pkg = hawkey.Query(self.sack).filter(name="dog")[0]
        goal.erase(pkg, clean_deps=True)
        self.assertTrue(goal.req_has_erase())
Ejemplo n.º 7
0
 def test_actions(self):
     sltr = hawkey.Selector(self.sack).set(name="walrus")
     goal = hawkey.Goal(self.sack)
     self.assertEqual(set(), goal.actions)
     goal.upgrade(select=sltr)
     self.assertEqual(set([hawkey.UPGRADE]), goal.actions)
     goal.install(name="semolina")
     self.assertEqual(set([hawkey.UPGRADE, hawkey.INSTALL]), goal.actions)
Ejemplo n.º 8
0
 def test_erase_selector(self):
     """ Tests automatic Selector from keyword arguments, with special
         keywords that don't become a part of the Selector.
     """
     goal = hawkey.Goal(self.sack)
     goal.erase(clean_deps=True, name="flying")
     goal.run()
     self.assertEqual(len(goal.list_erasures()), 2)
Ejemplo n.º 9
0
    def test_clone(self):
        pkg = base.by_name(self.sack, "penny-lib")
        goal = hawkey.Goal(self.sack)
        goal.erase(pkg)
        self.assertFalse(goal.run())

        goal2 = deepcopy(goal)
        self.assertTrue(goal2.run(allow_uninstall=True))
        self.assertEqual(len(goal2.list_erasures()), 2)
Ejemplo n.º 10
0
    def test_actions(self):
        sltr = hawkey.Selector(self.sack).set(name="walrus")
        goal = hawkey.Goal(self.sack)

        self.assertEqual(
            0, goal.actions &
            (hawkey.ERASE | hawkey.DISTUPGRADE | hawkey.DISTUPGRADE_ALL
             | hawkey.DOWNGRADE | hawkey.INSTALL | hawkey.UPGRADE
             | hawkey.UPGRADE_ALL))
        goal.upgrade(select=sltr)
        self.assertEqual(hawkey.UPGRADE, goal.actions)
Ejemplo n.º 11
0
 def test_reinstall(self):
     inst = base.by_name_repo(self.sack, "fool", hawkey.SYSTEM_REPO_NAME)
     avail = base.by_name_repo(self.sack, "fool", "main")
     goal = hawkey.Goal(self.sack)
     goal.install(avail)
     self.assertTrue(goal.run())
     self.assertLength(goal.list_erasures(), 0)
     self.assertLength(goal.list_installs(), 0)
     self.assertLength(goal.list_reinstalls(), 1)
     reinstall = goal.list_reinstalls()[0]
     obsoleted = goal.obsoleted_by_package(reinstall)
     self.assertItemsEqual(list(map(str, obsoleted)), ("fool-1-3.noarch", ))
Ejemplo n.º 12
0
 def _get_packages_with_deps(self, pkg_specs):
     """ get packages matching pkg_specs and the deps """
     pkgs = self._get_packages(pkg_specs)
     goal = hawkey.Goal(self.base.sack)
     for pkg in pkgs:
         goal.install(pkg)
     rc = goal.run()
     if rc:
         pkgs = goal.list_installs()
         return pkgs
     else:
         logger.debug(_("Error in resolve"))
         return []
Ejemplo n.º 13
0
    def test_clone(self):
        pkg = base.by_name(self.sack, "penny-lib")
        goal = hawkey.Goal(self.sack)
        goal.erase(pkg)
        self.assertFalse(goal.run())

        goal2 = deepcopy(goal)
        self.assertTrue(goal2.run(allow_uninstall=True))
        self.assertEqual(len(goal2.list_erasures()), 2)

        goal3 = deepcopy(goal)
        goal3.add_protected(hawkey.Query(self.sack).filter(name="flying"))
        self.assertFalse(goal3.run(allow_uninstall=True))
Ejemplo n.º 14
0
    def run(self, extcmds):
        base = self.base
        sack = base.sack
        goal = hawkey.Goal(sack)

        base.push_userinstalled(goal)

        solved = goal.run()
        if base.conf.debug_solver:
            goal.write_debugdata('./debugdata-autoerase')
        assert solved

        for pkg in goal.list_unneeded():
            base.package_remove(pkg)
Ejemplo n.º 15
0
    def test_run_callback(self):
        "Test goal.run() can use callback parameter just as well as run_all()"
        sack = base.TestSack(repo_dir=self.repo_dir)
        sack.load_system_repo()
        sack.load_test_repo("main", "main.repo")

        pkg = base.by_name(sack, "penny-lib")
        goal = hawkey.Goal(sack)
        goal.erase(pkg)
        collector = Collector()
        self.assertTrue(
            goal.run(allow_uninstall=True, callback=collector.new_solution_cb))
        self.assertEqual(collector.cnt, 1)
        self.assertEqual(len(collector.erasures), 2)
Ejemplo n.º 16
0
 def prepare_goal(self, srpm):
     goal = hawkey.Goal(self.sack)
     problems = []
     for name in self.group:
         sltr = hawkey.Selector(self.sack).set(name=name)
         goal.install(select=sltr)
     for reldep in srpm.requires:
         subj = dnf.subject.Subject(str(reldep))
         sltr = subj.get_best_selector(self.sack)
         # pylint: disable=E1103
         if sltr is None or not sltr.matches():
             problems.append("No package found for: {}".format(reldep))
         else:
             goal.install(select=sltr)
     return goal, problems
Ejemplo n.º 17
0
 def _get_packages_with_deps(self, pkg_specs, source=False):
     """Get packages matching pkg_specs and the deps."""
     pkgs = self._get_packages(pkg_specs)
     goal = hawkey.Goal(self.base.sack)
     for pkg in pkgs:
         goal.install(pkg)
     rc = goal.run()
     if rc:
         new_pkgs = goal.list_installs() + goal.list_upgrades()
         for pkg in pkgs:
             if pkg not in new_pkgs:
                 new_pkgs += [pkg]
         return new_pkgs
     else:
         logger.debug(_('Error in resolve'))
         return []
 def _get_packages_with_deps(self, pkg_specs, source=False):
     """Get packages matching pkg_specs and the deps."""
     pkgs = self._get_packages(pkg_specs)
     pkg_set = set(pkgs)
     for pkg in pkgs:
         goal = hawkey.Goal(self.base.sack)
         goal.install(pkg)
         rc = goal.run()
         if rc:
             pkg_set.update(goal.list_installs())
             pkg_set.update(goal.list_upgrades())
         else:
             msg = [_('Error in resolve of packages:')]
             logger.error("\n    ".join(msg + [str(pkg) for pkg in pkgs]))
             logger.error(
                 dnf.util._format_resolve_problems(goal.problem_rules()))
             raise dnf.exceptions.Error()
     return pkg_set
Ejemplo n.º 19
0
    def try_to_install(self, *packages):
        """
        Try to solve the goal of installing the given package,
        starting from an empty package set.
        """
        g = hawkey.Goal(self._sack)
        for package in packages:
            g.install(package)
        results = dict(installs=[], upgrades=[], erasures=[], problems=[])
        install_succeeded = g.run()
        if install_succeeded:
            results['installs'] = g.list_installs()
            results['upgrades'] = g.list_upgrades()
            results['erasures'] = g.list_erasures()
        else:
            results['problems'] = g.problems

        return install_succeeded, results
Ejemplo n.º 20
0
 def _get_packages_with_deps(self, pkg_specs, source=False):
     """Get packages matching pkg_specs and the deps."""
     pkgs = self._get_packages(pkg_specs)
     goal = hawkey.Goal(self.base.sack)
     for pkg in pkgs:
         goal.install(pkg)
     rc = goal.run()
     if rc:
         new_pkgs = goal.list_installs() + goal.list_upgrades()
         for pkg in pkgs:
             if pkg not in new_pkgs:
                 new_pkgs += [pkg]
         return new_pkgs
     else:
         msg = [_('Error in resolve of packages:')]
         logger.warning("\n    ".join(msg + [str(pkg) for pkg in pkgs]))
         logger.warning(
             dnf.util._format_resolve_problems(goal.problem_rules()))
         return []
Ejemplo n.º 21
0
def run_goal(sack, br, group):
    """
    Perform resolution (simulated installation) of given dependencies and build group.
    The only difference in treatment of dependencies vs. packages from the build group is
    that missing packages in build group are silently skipped, whereas missing packages
    in dependencies are reported as problems and fail the resolution.

    :param sack: hawkey.Sack to use for the resolution.
    :param br: List of dependencies (strings from BuildRequires)
    :param group: list of packages in the build group (strings)
    :return: If the resolution succeeded:
             (True, [], installs), where installs is list of string names of packages
             that would be installed.
             If the resolution failed (something was not installable):
             (False, problems, None), where problems is a list of human-readable strings
             describing the problems that prevent installation.
    """
    # pylint:disable=E1101
    goal = hawkey.Goal(sack)
    problems = []
    for name in group:
        sltr = _get_builddep_selector(sack, name)
        if sltr.matches():
            # missing packages are silently skipped as in dnf
            goal.install(select=sltr)
    for r in br:
        sltr = _get_builddep_selector(sack, r)
        # pylint: disable=E1103
        if not sltr.matches():
            problems.append("No package found for: {}".format(r))
        else:
            goal.install(select=sltr)
    kwargs = {}
    if get_config('dependency.ignore_weak_deps'):
        kwargs = {'ignore_weak_deps': True}
    goal.run(**kwargs)
    for first, *rest in goal.problem_rules():
        problems.append(
            f"Problem: {first}" +
            ''.join(f'\n - {problem}' for problem in rest)
        )
    resolved = not problems
    return resolved, problems, goal.list_installs() if resolved else None
Ejemplo n.º 22
0
def run_goal(sack, br, group):
    # pylint:disable=E1101
    goal = hawkey.Goal(sack)
    problems = []
    for name in group:
        sltr = _get_best_selector(sack, name)
        # missing packages are silently skipped as in dnf
        goal.install(select=sltr)
    for r in br:
        sltr = _get_best_selector(sack, r)
        # pylint: disable=E1103
        if not sltr.matches():
            problems.append("No package found for: {}".format(r))
        else:
            goal.install(select=sltr)
    if not problems:
        kwargs = {}
        if get_config('dependency.ignore_weak_deps'):
            kwargs = {'ignore_weak_deps': True}
        resolved = goal.run(**kwargs)
        return resolved, goal.problems, goal.list_installs(
        ) if resolved else None
    return False, problems, None
Ejemplo n.º 23
0
 def _packages_can_be_installed_together(self, left, right):
     """
     Returns True if the given packages can be installed together and False
     if it runs into a conflict or indirect Requires relationship method.
     """
     # XXX there must be a better way of testing for explicit Conflicts but
     # the best I could find was to try solving the installation of both and
     # checking the problem output...
     g = hawkey.Goal(self._sack)
     g.install(left)
     g.install(right)
     g.run()
     if g.problems and 'conflicts' in g.problems[0]:
         logger.debug('Found explicit Conflicts between %s and %s', left,
                      right)
         return False
     if g.problems and \
        six.text_type(right) in g.problems[0] and \
        'none of the providers can be installed' in g.problems[0]:
         logger.debug(
             "Packages can't be installed together and won't conflict %s and %s",
             left, right)
         return False
     return True
Ejemplo n.º 24
0
 def setUp(self):
     self.sack = base.TestSack(repo_dir=self.repo_dir)
     self.sack.load_test_repo(hawkey.SYSTEM_REPO_NAME,
                              "@System-broken.repo", True)
     self.goal = hawkey.Goal(self.sack)
Ejemplo n.º 25
0
 def test_list_err(self):
     goal = hawkey.Goal(self.sack)
     self.assertRaises(hawkey.ValueException, goal.list_installs)
Ejemplo n.º 26
0
 def test_actions(self):
     sltr = hawkey.Selector(self.sack).set(name="walrus")
     goal = hawkey.Goal(self.sack)
     self.assertEqual(set(), goal.actions)
     goal.upgrade(select=sltr)
     self.assertEqual(set([hawkey.UPGRADE]), goal.actions)
Ejemplo n.º 27
0
 def setUp(self):
     self.sack = base.TestSack(repo_dir=self.repo_dir)
     self.sack.load_system_repo()
     self.sack.load_test_repo("greedy", "greedy.repo")
     self.goal = hawkey.Goal(self.sack)
Ejemplo n.º 28
0
 def test_install_selector(self):
     sltr = hawkey.Selector(self.sack).set(name="walrus")
     # without checking versioning, the update is accepted:
     self.assertIsNone(hawkey.Goal(self.sack).upgrade(select=sltr))
Ejemplo n.º 29
0
 def test_install_selector_weak(self):
     sltr = hawkey.Selector(self.sack).set(name='hello')
     goal = hawkey.Goal(self.sack)
     goal.install(select=sltr, optional=True)
     self.assertTrue(goal.run())