def test_transaction_download(self):
     pkg = mock.MagicMock()
     repo = mock.MagicMock()
     repo.id = 'test'
     pkg.name = "kernel"
     pkg.repo = repo
     self.cli.base.transaction.install_set = [pkg]
     self.command.opts = mock.MagicMock()
     self.command.opts.distro_sync = "distro_sync"
     self.command.opts.repos_ed = []
     self.cli.demands.allow_erasing = "allow_erasing"
     self.command.base.conf.best = "best"
     self.command.base.conf.installroot = "/"
     self.command.base.conf.releasever = "35"
     self.command.base.conf.gpgcheck = True
     self.command.base.conf.destdir = "/grape/wine"
     self.command.base.conf.install_weak_deps = True
     self.command.base.conf.module_platform_id = ''
     self.command.transaction_download()
     with system_upgrade.State() as state:
         self.assertEqual(state.download_status, "complete")
         self.assertEqual(state.distro_sync, "distro_sync")
         self.assertEqual(state.allow_erasing, "allow_erasing")
         self.assertEqual(state.best, "best")
         self.assertEqual(state.destdir, "/grape/wine")
Example #2
0
 def test_transaction_download_offline_upgrade(self):
     pkg = mock.MagicMock()
     repo = mock.MagicMock()
     repo.id = 'test'
     pkg.name = "kernel"
     pkg.repo = repo
     self.cli.base.transaction.install_set = [pkg]
     self.command.opts = mock.MagicMock()
     self.command.opts.distro_sync = True
     self.command.opts.command = "offline-upgrade"
     self.command.opts.repos_ed = []
     self.cli.demands.allow_erasing = "allow_erasing"
     self.command.base.conf.best = True
     self.command.base.conf.releasever = "35"
     self.command.base.conf.gpgcheck = True
     self.command.opts.destdir = self.datadir
     self.command.base.conf.install_weak_deps = True
     self.command.base.conf.module_platform_id = ''
     self.command.pre_configure_download()
     self.command.transaction_download()
     with system_upgrade.State(self.command.state.statefile) as state:
         self.assertEqual(state.download_status, "complete")
         self.assertEqual(state.distro_sync, False)
         self.assertEqual(state.destdir, self.datadir)
         self.assertEqual(state.upgrade_command, "offline-upgrade")
Example #3
0
    def setUp(self):
        cli = mock.MagicMock()
        self.cmd = download.DownloadCommand(cli)
        self.cmd.cli.base = dnf.cli.cli.BaseCli()
        self.cmd.cli.base.add_remote_rpms = mock.MagicMock()
        self.cmd.cli.base.download_packages = mock.Mock()

        # point the Sack and Subject to out stubs
        # b/c these are used in the _get_query methods
        self.orig_sack = self.cmd.cli.base.sack
        self.cmd.cli.base._sack = SackStub()

        self.orig_subject = dnf.subject.Subject
        dnf.subject.Subject = SubjectStub

        self.cmd.opts = mock.Mock()
        self.cmd.opts.resolve = False
        self.cmd.opts.arch = []
        repo = RepoStub('foo')
        repo.enable()
        self.cmd.base.repos.add(repo)
        repo = RepoStub('foo-source')
        repo.disable()
        self.cmd.base.repos.add(repo)
        repo = RepoStub('bar')
        repo.enable()
        self.cmd.base.repos.add(repo)
        repo = RepoStub('foobar-source')
        repo.disable()
        self.cmd.base.repos.add(repo)
        repo = RepoStub('foo-debuginfo')
        repo.disable()
        self.cmd.base.repos.add(repo)
Example #4
0
 def test_history_convert_tids(self):
     """Test history _convert_tids()."""
     cmd = dnf.cli.commands.HistoryCommand(self.cli)
     cmd.cli.base.output = mock.MagicMock()
     cmd.cli.base.output.history.last().tid = 123
     cmd.cli.base.output.history.search = mock.MagicMock(return_value=[99])
     support.command_configure(cmd, ['list', '1..5', 'last', 'last-10', 'kernel'])
     self.assertEqual(cmd._convert_tids(), [1, 2, 3, 4, 5, 99, 113, 123])
Example #5
0
 def test_history_convert_tids(self):
     """Test history _convert_tids()."""
     cmd = dnf.cli.commands.history.HistoryCommand(self.cli)
     cmd.cli.base.output = mock.MagicMock()
     cmd.cli.base.output.history.last().tid = 123
     cmd.cli.base.output.history.search = mock.MagicMock(return_value=[99])
     tests.support.command_configure(
         cmd, ['list', '1..5', 'last', 'last-10', 'kernel'])
     self.assertEqual(cmd._args2transaction_ids(),
                      ([123, 113, 99, 5, 4, 3, 2, 1], {(1, 5)}))
Example #6
0
 def test_rpmdb_version(self):
     base = support.MockBase()
     sack = base.sack
     yumdb = mock.MagicMock()
     version = base.sack._rpmdb_version(yumdb)
     self.assertEqual(version._num, support.TOTAL_RPMDB_COUNT)
     self.assertEqual(version._chksum.hexdigest(), support.RPMDB_CHECKSUM)
 def test_pre_configure_download_default(self):
     self.command.opts = mock.MagicMock()
     self.command.opts.destdir = None
     self.command.base.conf.destdir = None
     self.command.pre_configure_download()
     self.assertEqual(self.command.base.conf.cachedir,
                      system_upgrade.DEFAULT_DATADIR)
Example #8
0
 def test_reboot_prepare_only(self, reboot, log_status, run_prepare):
     self.command.opts = mock.MagicMock()
     self.command.opts.tid = [None]
     self.command.run_reboot()
     run_prepare.assert_called_once_with()
     self.assertFalse(log_status.called)
     self.assertFalse(reboot.called)
Example #9
0
    def setUp(self):
        def stub_fn(pkg_spec):
            if '.src.rpm' in pkg_spec:
                return Query.filter(sourcerpm=pkg_spec)
            else:
                q = Query.latest()
                return [pkg for pkg in q if pkg_spec == pkg.name]

        cli = mock.MagicMock()
        self.cmd = download.DownloadCommand(cli)
        self.cmd.cli.base.repos = dnf.repodict.RepoDict()
        self.cmd._get_query = stub_fn
        self.cmd._get_query_source = stub_fn
        self.cmd.opts = mock.Mock()
        self.cmd.opts.resolve = False
        repo = RepoStub('foo')
        repo.enable()
        self.cmd.base.repos.add(repo)
        repo = RepoStub('foo-source')
        repo.disable()
        self.cmd.base.repos.add(repo)
        repo = RepoStub('bar')
        repo.enable()
        self.cmd.base.repos.add(repo)
        repo = RepoStub('foobar-source')
        repo.disable()
        self.cmd.base.repos.add(repo)
    def test_available_false(self):
        '''
        Test to check available when it returns False
        '''

        ret = {
            'name': '192.168.10.15:30015',
            'changes': {},
            'result': False,
            'comment': 'error'
        }

        mock_wait = mock.MagicMock(
            side_effect=exceptions.CommandExecutionError('error'))

        with patch.dict(hanamod.__salt__,
                        {'hana.wait_for_connection': mock_wait}):
            assert hanamod.available('192.168.10.15', 30015, 'SYSTEM', 'pass',
                                     60, 5) == ret
        mock_wait.assert_called_once_with(host='192.168.10.15',
                                          port=30015,
                                          user='******',
                                          password='******',
                                          timeout=60,
                                          interval=5)
Example #11
0
 def test_run_reboot(self, reboot, log_status, run_prepare):
     self.command.opts = mock.MagicMock()
     self.command.opts.tid = ["reboot"]
     self.command.run_reboot()
     run_prepare.assert_called_once_with()
     self.assertEqual(system_upgrade.REBOOT_REQUESTED_ID,
                      log_status.call_args[0][1])
     self.assertTrue(reboot.called)
Example #12
0
 def setUp(self):
     self.datadir = tempfile.mkdtemp(prefix="system_upgrade_test_datadir-")
     system_upgrade.SystemUpgradeCommand.DATADIR = self.datadir
     self.cli = mock.MagicMock()
     self.cli.base.conf.installroot = "/"
     self.command = system_upgrade.SystemUpgradeCommand(cli=self.cli)
     self.command.base.conf.cachedir = os.path.join(self.datadir, "cache")
     self.command.base.conf.destdir = None
Example #13
0
 def test_configure_download(self):
     self.command.opts = mock.MagicMock()
     self.command.opts.tid = "download"
     self.command.configure()
     self.assertTrue(self.cli.demands.root_user)
     self.assertTrue(self.cli.demands.resolving)
     self.assertTrue(self.cli.demands.sack_activation)
     self.assertTrue(self.cli.demands.available_repos)
 def setUp(self):
     self.statedir = tempfile.mkdtemp(prefix="command.test.statedir.")
     self.statefile = os.path.join(self.statedir, "state")
     self.old_statefile = system_upgrade.State.statefile
     system_upgrade.State.statefile = self.statefile
     self.cli = mock.MagicMock()
     self.command = system_upgrade.SystemUpgradeCommand(cli=self.cli)
     self.command.base.conf.cachedir = os.path.join(self.statedir, "cache")
     self.command.base.conf.destdir = None
Example #15
0
 def check_reboot(self, status='complete', lexists=False, command='system-upgrade',
                  state_command='system-upgrade'):
     with patch('system_upgrade.os.path.lexists') as lexists_func:
         self.command.state.state_version = 2
         self.command.state.download_status = status
         self.command.opts = mock.MagicMock()
         self.command.opts.command = command
         self.command.state.upgrade_command = state_command
         lexists_func.return_value = lexists
         self.command.check_reboot()
Example #16
0
    def setUp(self):
        cli = mock.MagicMock()
        self.cmd = repodiff.RepoDiffCommand(cli)
        self.cmd.cli.base = dnf.cli.cli.BaseCli()
        self.cmd.cli.base._sack = dnf.sack.Sack()
        self.cmd.opts = mock.Mock()
        self.cmd.opts.compare_arch = False

        self.repodiff = self.cmd._repodiff(QueryStub(PACKAGES_OLD),
                                           QueryStub(PACKAGES_NEW))
Example #17
0
 def setUp(self):
     self.datadir = tempfile.mkdtemp(prefix="system_upgrade_test_datadir-")
     self.installroot = tempfile.TemporaryDirectory(prefix="system_upgrade_test_installroot-")
     system_upgrade.SystemUpgradeCommand.DATADIR = self.datadir
     self.cli = mock.MagicMock()
     # the installroot is not strictly necessary for the test, but
     # releasever detection is accessing host system files without it, and
     # this fails on permissions in COPR srpm builds (e.g. from rpm-gitoverlay)
     self.cli.base.conf.installroot = self.installroot.name
     self.command = system_upgrade.SystemUpgradeCommand(cli=self.cli)
     self.command.base.conf.cachedir = os.path.join(self.datadir, "cache")
     self.command.base.conf.destdir = None
    def test_setup_cwd(self):

        mock_remove = mock.MagicMock()
        mock_mkdir = mock.MagicMock()
        mock_touch = mock.MagicMock()
        mock_chown = mock.MagicMock()
        mock_set_mode = mock.MagicMock()
        mock_append = mock.MagicMock()

        with patch.dict(
                netweavermod.__salt__, {
                    'file.remove': mock_remove,
                    'file.mkdir': mock_mkdir,
                    'file.touch': mock_touch,
                    'file.chown': mock_chown,
                    'file.set_mode': mock_set_mode,
                    'file.append': mock_append
                }):
            netweavermod.setup_cwd('/software', '/tmp',
                                   ['/path/dvd1', '/path/dvd2'])

            mock_remove.assert_called_once_with('/tmp')
            mock_mkdir.assert_called_once_with('/tmp',
                                               user='******',
                                               group='sapinst',
                                               mode=775)
            mock_touch.assert_called_once_with('/tmp/start_dir.cd')
            mock_chown.assert_called_once_with('/tmp/start_dir.cd', 'root',
                                               'sapinst')
            mock_set_mode.assert_called_once_with('/tmp/start_dir.cd', 775)
            mock_append.assert_has_calls([
                mock.call('/tmp/start_dir.cd', args='/software'),
                mock.call('/tmp/start_dir.cd',
                          args=['/path/dvd1', '/path/dvd2'])
            ])
Example #19
0
class MakeCacheCommandTest(tests.support.DnfBaseTestCase):

    REPOS = ['main']
    CLI = "mock"

    def setUp(self):
        super(MakeCacheCommandTest, self).setUp()
        for r in self.base.repos.values():
            r.basecachedir = self.base.conf.cachedir

    @staticmethod
    @mock.patch('dnf.Base.fill_sack', new=mock.MagicMock())
    def _do_makecache(cmd):
        return tests.support.command_run(cmd, ['timer'])

    def assert_last_info(self, logger, msg):
        self.assertEqual(logger.info.mock_calls[-1], mock.call(msg))

    @mock.patch('dnf.base.logger', new_callable=tests.support.mock_logger)
    @mock.patch('dnf.cli.commands._', dnf.pycomp.NullTranslations().ugettext)
    @mock.patch('dnf.util.on_ac_power', return_value=True)
    def test_makecache_timer(self, _on_ac_power, logger):
        cmd = makecache.MakeCacheCommand(self.cli)

        self.base.conf.metadata_timer_sync = 0
        self.assertFalse(self._do_makecache(cmd))
        self.assert_last_info(logger, u'Metadata timer caching disabled.')

        self.base.conf.metadata_timer_sync = 5  # resync after 5 seconds
        self.base._repo_persistor.since_last_makecache = mock.Mock(
            return_value=3)
        self.assertFalse(self._do_makecache(cmd))
        self.assert_last_info(logger, u'Metadata cache refreshed recently.')

    @mock.patch('dnf.base.logger', new_callable=tests.support.mock_logger)
    @mock.patch('dnf.cli.commands._', dnf.pycomp.NullTranslations().ugettext)
    @mock.patch('dnf.util.on_ac_power', return_value=False)
    def test_makecache_timer_battery(self, _on_ac_power, logger):
        cmd = makecache.MakeCacheCommand(self.cli)
        self.base.conf.metadata_timer_sync = 5

        self.assertFalse(self._do_makecache(cmd))
        msg = u'Metadata timer caching disabled when running on a battery.'
        self.assert_last_info(logger, msg)

    @mock.patch('dnf.cli.commands._', dnf.pycomp.NullTranslations().ugettext)
    @mock.patch('dnf.util.on_ac_power', return_value=None)
    def test_makecache_timer_battery2(self, _on_ac_power):
        cmd = makecache.MakeCacheCommand(self.cli)
        self.base.conf.metadata_timer_sync = 5
        self.assertTrue(self._do_makecache(cmd))
Example #20
0
 def test_configure_upgrade(self):
     # write state like download would have
     with self.command.state as state:
         state.download_status = "complete"
         state.distro_sync = True
         state.allow_erasing = True
         state.best = True
     # okay, now configure upgrade
     self.command.opts = mock.MagicMock()
     self.command.opts.tid = "upgrade"
     self.command.configure()
     # did we reset the depsolving flags?
     self.assertTrue(self.command.opts.distro_sync)
     self.assertTrue(self.cli.demands.allow_erasing)
     self.assertTrue(self.command.base.conf.best)
     # are we on autopilot?
     self.assertTrue(self.command.base.conf.assumeyes)
     self.assertTrue(self.cli.demands.cacheonly)
Example #21
0
    def setUp(self):
        base = support.MockBase("main")
        base.output = mock.MagicMock()

        repo = base.repos['main']
        repo.baseurl = ['http:///dnf-test']
        repo.basecachedir = base.conf.cachedir

        walk = [
            (
                repo.basecachedir,
                [os.path.basename(repo.cachedir)],
                [repo.id + '.solv'],
            ),
            (repo.cachedir, ['repodata', 'packages'], ['metalink.xml']),
            (repo.cachedir + '/repodata', [], ['foo.xml', 'bar.xml.bz2']),
            (repo.cachedir + '/packages', [], ['foo.rpm']),
        ]
        os.walk = self.walk = mock.Mock(return_value=walk)
        self.base = base
        self.cmd = clean.CleanCommand(base.mock_cli())
    def test_available_true(self):
        '''
        Test to check available when it returns True
        '''

        ret = {
            'name': '192.168.10.15:30015',
            'changes': {},
            'result': True,
            'comment': 'HANA is available'
        }

        mock_wait = mock.MagicMock()

        with patch.dict(hanamod.__salt__,
                        {'hana.wait_for_connection': mock_wait}):
            assert hanamod.available('192.168.10.15', 30015, 'SYSTEM', 'pass',
                                     60, 5) == ret
        mock_wait.assert_called_once_with(host='192.168.10.15',
                                          port=30015,
                                          user='******',
                                          password='******',
                                          timeout=60,
                                          interval=5)
Example #23
0
class MakeCacheCommandTest(support.TestCase):
    def setUp(self):
        self.base = support.MockBase()
        self.cli = self.base.mock_cli()

    @staticmethod
    @mock.patch('dnf.Base.fill_sack', new=mock.MagicMock())
    def _do_makecache(cmd):
        return cmd.run(['timer'])

    def assert_last_info(self, logger, msg):
        self.assertEqual(logger.info.mock_calls[-1], mock.call(msg))

    @mock.patch('dnf.cli.commands.makecache.logger',
                new_callable=support.mock_logger)
    @mock.patch('dnf.cli.commands._', dnf.pycomp.NullTranslations().ugettext)
    @mock.patch('dnf.util.on_ac_power', return_value=True)
    def test_makecache_timer(self, _on_ac_power, logger):
        cmd = makecache.MakeCacheCommand(self.cli)

        self.base.conf.metadata_timer_sync = 0
        self.assertFalse(self._do_makecache(cmd))
        self.assert_last_info(logger, u'Metadata timer caching disabled.')

        self.base.conf.metadata_timer_sync = 5  # resync after 5 seconds
        self.base._persistor.since_last_makecache = mock.Mock(return_value=3)
        self.assertFalse(self._do_makecache(cmd))
        self.assert_last_info(logger, u'Metadata cache refreshed recently.')

        self.base._persistor.since_last_makecache = mock.Mock(return_value=10)
        self.base._sack = 'nonempty'
        r = support.MockRepo("glimpse", None)
        self.base.repos.add(r)

        # regular case 1: metadata is already expired:
        r.metadata_expire_in = mock.Mock(return_value=(False, 0))
        r.sync_strategy = dnf.repo.SYNC_TRY_CACHE
        self.assertTrue(self._do_makecache(cmd))
        self.assert_last_info(logger, u'Metadata cache created.')
        self.assertTrue(r._expired)
        r._expired = False

        # regular case 2: metadata is cached and will expire later than
        # metadata_timer_sync:
        r.metadata_expire_in = mock.Mock(return_value=(True, 100))
        r.sync_strategy = dnf.repo.SYNC_TRY_CACHE
        self.assertTrue(self._do_makecache(cmd))
        self.assert_last_info(logger, u'Metadata cache created.')
        self.assertFalse(r._expired)

        # regular case 3: metadata is cached but will eqpire before
        # metadata_timer_sync:
        r.metadata_expire_in = mock.Mock(return_value=(True, 4))
        r.sync_strategy = dnf.repo.SYNC_TRY_CACHE
        self.assertTrue(self._do_makecache(cmd))
        self.assert_last_info(logger, u'Metadata cache created.')
        self.assertTrue(r._expired)

    @mock.patch('dnf.cli.commands.makecache.logger',
                new_callable=support.mock_logger)
    @mock.patch('dnf.cli.commands._', dnf.pycomp.NullTranslations().ugettext)
    @mock.patch('dnf.util.on_ac_power', return_value=False)
    def test_makecache_timer_battery(self, _on_ac_power, logger):
        cmd = makecache.MakeCacheCommand(self.cli)
        self.base.conf.metadata_timer_sync = 5

        self.assertFalse(self._do_makecache(cmd))
        msg = u'Metadata timer caching disabled when running on a battery.'
        self.assert_last_info(logger, msg)

    @mock.patch('dnf.cli.commands._', dnf.pycomp.NullTranslations().ugettext)
    @mock.patch('dnf.util.on_ac_power', return_value=None)
    def test_makecache_timer_battery2(self, _on_ac_power):
        cmd = makecache.MakeCacheCommand(self.cli)
        self.base.conf.metadata_timer_sync = 5
        self.assertTrue(self._do_makecache(cmd))
Example #24
0
 def test_run_log_list(self):
     self.command.opts = mock.MagicMock()
     self.command.opts.number = None
     with patch('system_upgrade.list_logs') as list_logs:
         self.command.run_log()
     list_logs.assert_called_once_with()
Example #25
0
 def test_run_log_prev(self):
     with patch('system_upgrade.show_log') as show_log:
         self.command.opts = mock.MagicMock()
         self.command.opts.number = -2
         self.command.run_log()
     show_log.assert_called_once_with(-2)
Example #26
0
 def test_configure_log(self):
     self.command.opts = mock.MagicMock()
     self.command.opts.tid = "log"
     self.command.configure()
 def test_pre_configure_download_default(self):
     self.command.opts = mock.MagicMock()
     self.command.pre_configure_download()
     self.assertEqual(self.command.base.conf.cachedir, DEFAULT_DATADIR)
 def test_pre_configure_download_destdir(self):
     self.command.opts = mock.MagicMock()
     self.command.opts.destdir = "/grape/wine"
     self.command.pre_configure_download()
     self.assertEqual(self.command.base.conf.destdir, "/grape/wine")
Example #29
0
    def setUp(self):
        self.base = support.MockBase("search")
        self.cli = dnf.cli.cli.Cli(self.base)

        self.base.output = mock.MagicMock()
        self.base.output.fmtSection = lambda str: str
Example #30
0
 def test_pre_configure_download_destdir(self):
     self.command.opts = mock.MagicMock()
     self.command.opts.destdir = self.datadir
     self.command.pre_configure_download()
     self.assertEqual(self.command.base.conf.destdir, self.datadir)