From 87fef185686872a2375294aae20be7ff63c37637 Mon Sep 17 00:00:00 2001 From: Mike McLean Date: Aug 14 2024 16:00:56 +0000 Subject: [PATCH 1/2] unit tests --- diff --git a/tests/test_kojira/test_repo_manager.py b/tests/test_kojira/test_repo_manager.py index 1a6131d..6ba65dd 100644 --- a/tests/test_kojira/test_repo_manager.py +++ b/tests/test_kojira/test_repo_manager.py @@ -247,6 +247,69 @@ class RepoManagerTest(unittest.TestCase): get.return_value.text = repomd self.mgr.checkExternalRepos() + + self.session.repo.getExternalRepoData.assert_has_calls([ + mock.call(1), + mock.call(2), + ]) + self.session.repo.setExternalRepoData.assert_has_calls([ + mock.call(1, {'max_ts': 1711390493}), + mock.call(2, {'max_ts': 1711390493}), + ]) + + @mock.patch('requests.get') + def test_check_external_no_arches(self, get): + # a new system with no hosts could report no arches + self.session.getAllArches.return_value = [] + # fake ext repo data + repo1 = {'external_repo_id': 1, 'external_repo_name': 'myrepo', + 'url': 'https://localhost/NOSUCHPATH'} + repo2 = {'external_repo_id': 2, 'external_repo_name': 'myotherrepo', + 'url': 'https://localhost/FAKEPATH/$arch'} + self.session.getTagExternalRepos.return_value = [repo1, repo2] + data1 = {} + data2 = {} + self.session.repo.getExternalRepoData.side_effect = [data1, data2] + repomd_fn = os.path.dirname(__file__) + '/data/external-repomd.xml' + with open(repomd_fn, 'rt') as fo: + repomd = fo.read() + get.return_value.text = repomd + + self.mgr.checkExternalRepos() + + self.session.repo.getExternalRepoData.assert_has_calls([ + mock.call(1), + # no call for repo2 since it has $arch in the url + ]) + self.session.repo.setExternalRepoData.assert_has_calls([ + mock.call(1, {'max_ts': 1711390493}), + # no call for repo2 since it has $arch in the url + ]) + + @mock.patch('requests.get') + def test_check_external_cache(self, get): + # fake ext repo data + repo1 = {'external_repo_id': 1, 'external_repo_name': 'myrepo', + 'url': 'https://localhost/NOSUCHPATH'} + repo2 = {'external_repo_id': 2, 'external_repo_name': 'myotherrepo', + 'url': 'https://localhost/NOSUCHPATH'} # same url + self.session.getTagExternalRepos.return_value = [repo1, repo2] + data1 = {} + data2 = {} + self.session.repo.getExternalRepoData.side_effect = [data1, data2] + self.session.getAllArches.return_value = ['i386', 'x86_64', 'riscv'] + repomd_fn = os.path.dirname(__file__) + '/data/external-repomd.xml' + with open(repomd_fn, 'rt') as fo: + repomd = fo.read() + get.return_value.text = repomd + + self.mgr.checkExternalRepos() + + get.assert_called_once() + self.session.repo.getExternalRepoData.assert_has_calls([ + mock.call(1), + mock.call(2), + ]) self.session.repo.setExternalRepoData.assert_has_calls([ mock.call(1, {'max_ts': 1711390493}), mock.call(2, {'max_ts': 1711390493}), From 70531116fc896b161858aeb7b72a941630679635 Mon Sep 17 00:00:00 2001 From: Mike McLean Date: Aug 14 2024 16:01:05 +0000 Subject: [PATCH 2/2] adjust warning message --- diff --git a/util/kojira b/util/kojira index 5e98f39..a311deb 100755 --- a/util/kojira +++ b/util/kojira @@ -434,7 +434,8 @@ class RepoManager(object): # getting the list of all tag arches for all tags that might use the repo is # way more expensive if not arches: - self.logger.warning('No arches reported. Unable to check external repos with $arch') + self.logger.warning('No arches reported by hub. Are any hosts enabled? ' + 'Unable to check external repos containing $arch') ts_cache = {} for erepo_id in sorted(external_repos):