def test_sync_success_regen(self): rs = _init_reposync(self.reposync) CFG = Mock() CFG.MOUNT_POINT = '/tmp' CFG.PREPENDED_DIR = '' CFG.AUTO_GENERATE_BOOTSTRAP_REPO = 1 rs.urls = [{ "source_url": ["http://none.host/bogus-url"], "id": 42, "metadata_signed": "N", "repo_label": None, 'repo_type': 'yum' }] _mock_rhnsql(self.reposync, {}) rs = _mock_sync(self.reposync, rs) rs.regen = True with patch("uyuni.common.context_managers.CFG", CFG): rs.sync() self.assertEqual( self.reposync.taskomatic. add_to_repodata_queue_for_channel_package_subscription.call_args, ((["Label"], [], "server.app.yumreposync"), {})) self.assertEqual( self.reposync.taskomatic.add_to_erratacache_queue.call_args, (("Label", ), {}))
def test_pass_multiple_urls_params(self): from spacewalk.satellite_tools.reposync import RepoSync urls = ['http://some.url', 'http://some-other.url'] repo_sync = RepoSync(channel_label="channel-label", repo_type=RTYPE, url=urls) repo_sync = _mock_sync(spacewalk.satellite_tools.reposync, repo_sync) CFG = Mock() CFG.MOUNT_POINT = '/tmp' CFG.PREPENDED_DIR = '' CFG.AUTO_GENERATE_BOOTSTRAP_REPO = 1 with patch("uyuni.common.context_managers.CFG", CFG): repo_sync.sync()
def test_sync_raises_channel_timeout(self): rs = self._create_mocked_reposync() CFG = Mock() CFG.MOUNT_POINT = '/tmp' CFG.PREPENDED_DIR = '' CFG.AUTO_GENERATE_BOOTSTRAP_REPO = 1 exception = self.reposync.ChannelTimeoutException("anony-error") rs.load_plugin = Mock(return_value=Mock(side_effect=exception)) rs.sendErrorMail = Mock() with patch("uyuni.common.context_managers.CFG", CFG): etime, ret = rs.sync() self.assertEqual(-1, ret) self.assertEqual(rs.sendErrorMail.call_args, (("anony-error", ), {})) self.assertEqual(self.reposync.log.call_args[0][1], exception)
def test_channel_exceptions(): """Test raising all the different exceptions when syncing""" # the only way to write a test generator with nose is if we put it # outside the class, so we have to repeat all the Mocks repoSync = spacewalk.satellite_tools.reposync repoSync.os = Mock() repoSync.rhnSQL.initDB = Mock() repoSync.rhnSQL.commit = Mock() CFG = Mock() CFG.MOUNT_POINT = '/tmp' CFG.PREPENDED_DIR = '' CFG.AUTO_GENERATE_BOOTSTRAP_REPO = 1 _mock_rhnsql(repoSync, [ [{ 'id': 'id1', 'repo_label': 'label1', 'source_url': 'http://url.one', 'metadata_signed': 'Y', 'repo_type': 'yum' }], [{ 'id': 'id2', 'repo_label': 'label2', 'source_url': 'http://url.two', 'metadata_signed': 'N', 'repo_type': 'yum' }], ]) rs = _create_mocked_reposync(repoSync) rs.sendErrorMail = Mock() repoSync.RepoSync._format_sources = Mock() for exc_class, exc_name in [(repoSync.ChannelException, "ChannelException"), (yum_src.RepoMDError, "RepoMDError")]: rs.load_plugin = Mock(return_value=Mock( side_effect=exc_class("error msg"))) with patch("uyuni.common.context_managers.CFG", CFG): _, ret = rs.sync() assert ret == -1 assert rs.sendErrorMail.call_args == (("%s: %s" % (exc_name, "error msg"), ), {})
def test_sync_raises_unexpected_error(self): rs = self._create_mocked_reposync() CFG = Mock() CFG.MOUNT_POINT = '/tmp' CFG.PREPENDED_DIR = '' CFG.AUTO_GENERATE_BOOTSTRAP_REPO = 1 rs.load_plugin = Mock(return_value=Mock(side_effect=TypeError)) rs.sendErrorMail = Mock() with patch("uyuni.common.context_managers.CFG", CFG): etime, ret = rs.sync() self.assertEqual(-1, ret) error_string = self.reposync.log.call_args[0][1] assert (error_string.startswith('Traceback') and 'TypeError' in error_string), ( "The error string does not contain the keywords " "'Traceback' and 'TypeError':\n %s\n---end of assert" % error_string)
def test_sync_success_no_regen(self): rs = _init_reposync(self.reposync) CFG = Mock() CFG.MOUNT_POINT = '/tmp' CFG.PREPENDED_DIR = '' CFG.AUTO_GENERATE_BOOTSTRAP_REPO = 1 rs.urls = [{ "source_url": ["http://none.host/bogus-url"], "id": 42, "metadata_signed": "N", "repo_label": None, 'repo_type': 'yum' }] _mock_rhnsql(self.reposync, None) rs = _mock_sync(self.reposync, rs) with patch("uyuni.common.context_managers.CFG", CFG): rs.sync() self.assertEqual( rs.repo_plugin.call_args[0], (('http://none.host/bogus-url', 'bogus-url', True, True))) self.assertEqual( rs.import_packages.call_args, ((rs.mocked_plugin, 42, "http://none.host/bogus-url", 1), {})) self.assertEqual(rs.import_updates.call_args, ((rs.mocked_plugin, ), {})) self.assertEqual(rs.import_products.call_args, ((rs.mocked_plugin, ), {})) # for the rest just check if they were called or not self.assertTrue(rs.update_date.called) # these aren't supposed to be called unless self.regen is True self.assertFalse( self.reposync.taskomatic. add_to_repodata_queue_for_channel_package_subscription.called) self.assertFalse( self.reposync.taskomatic.add_to_erratacache_queue.called)