Permalink
Browse files

added distro-sync explicit packages support (RhBug:963710)

  • Loading branch information...
1 parent a217a72 commit d9a48422ee956a920e13b13c2ebff68ebbbb2ec7 Jan Silhan committed with Ales Kozumplik Mar 3, 2014
Showing with 51 additions and 10 deletions.
  1. +9 −4 dnf/base.py
  2. +5 −2 dnf/cli/cli.py
  3. +0 −3 dnf/cli/commands.py
  4. +1 −1 package/dnf.spec.in
  5. +36 −0 tests/test_distsync.py
View
@@ -1585,11 +1585,16 @@ def upgrade_to(self, pkg_spec, reponame=None):
return 0
- def distro_sync(self, pkg=None):
- if pkg is None:
+ def distro_sync(self, pkg_spec=None):
+ if pkg_spec is None:
self._goal.distupgrade_all()
- return 1
- return 0
+ else:
+ sltr = dnf.subject.Subject(pkg_spec).get_best_selector(self.sack)
+ if not sltr:
+ self.logger.info(_('No package %s installed.'), pkg_spec)
+ return 0
+ self._goal.distupgrade(select=sltr)
+ return 1
def remove(self, pkg_spec, reponame=None):
"""Mark the specified package for removal. #:api """
View
@@ -369,8 +369,11 @@ def distro_sync_userlist(self, userlist):
2 = we've got work yet to do, onto the next stage
"""
oldcount = self._goal.req_length()
- assert(len(userlist) == 0)
- self.distro_sync()
+ if len(userlist) == 0:
+ self.distro_sync()
+ else:
+ for pkg_spec in userlist:
+ self.distro_sync(pkg_spec)
cnt = self._goal.req_length() - oldcount
if cnt <= 0 and not self._goal.req_has_distupgrade_all():
View
@@ -480,9 +480,6 @@ def doCheck(self, basecmd, extcmds):
"""
checkGPGKey(self.base, self.cli)
checkEnabledRepo(self.base, extcmds)
- if extcmds:
- self.cli.logger.critical(_('distro-sync accepts no package specs.'))
- raise dnf.cli.CliError
def run(self, extcmds):
return self.base.distro_sync_userlist(extcmds)
View
@@ -1,5 +1,5 @@
%global gitrev cfa9c14
-%global hawkey_version 0.4.11
+%global hawkey_version 0.4.12
%global librepo_version 1.4.0
%global libcomps_version 0.1.4
View
@@ -18,6 +18,11 @@
from __future__ import absolute_import
from tests import support
import rpm
+import hawkey
+try:
+ from unittest import mock
+except ImportError:
+ from tests import mock
class DistroSyncAll(support.ResultTestCase):
def setUp(self):
@@ -31,3 +36,34 @@ def test_distro_sync_all(self):
q = self.sack.query().available().filter(name=["pepper", "librita"])
packages.extend(q)
self.assertResult(self.yumbase, packages)
+
+
+class DistroSync(support.ResultTestCase):
+ def setUp(self):
+ self._yumbase = support.BaseCliStub()
+ self._yumbase._sack = support.mock_sack('main', 'updates')
+ self._yumbase._goal = hawkey.Goal(self._yumbase.sack)
+ self._yumbase.logger = mock.create_autospec(self._yumbase.logger)
+
+ def test_distro_sync(self):
+ installed = self._get_installed(self._yumbase)
+ original_pkg = list(filter(lambda p: p.name == "hole", installed))
+ self._yumbase.distro_sync_userlist(('bla', 'hole'))
+ obsolete_pkg = list(filter(lambda p: p.name == "tour", installed))
+
+ # check from log package name that is not installed
+ self.assertEqual(self._yumbase.logger.mock_calls[1][1][1], 'bla')
+
+ installed2 = self._get_installed(self._yumbase)
+ updated_pkg = list(filter(lambda p: p.name == "hole", installed2))
+ self.assertLength(updated_pkg, 1)
+ self.assertLength(original_pkg, 1)
+ self.assertLength(updated_pkg, 1)
+
+ # holy pkg upgraded from version 1 to 2 and obsoletes tour
+ self.assertEqual(original_pkg[0].version, "1")
+ self.assertEqual(updated_pkg[0].version, "2")
+ installed.remove(original_pkg[0])
+ installed.remove(obsolete_pkg[0])
+ installed2.remove(updated_pkg[0])
+ self.assertEqual(installed, installed2)

0 comments on commit d9a4842

Please sign in to comment.