diff --git a/pungi/phases/ostree.py b/pungi/phases/ostree.py index 3d738de8..170d8011 100644 --- a/pungi/phases/ostree.py +++ b/pungi/phases/ostree.py @@ -94,10 +94,16 @@ class OSTreeThread(WorkerThread): def tweak_file(path, source_repo): - """Replace mirrorlist line in repo file with baseurl pointing to source_repo.""" + """ + Ensure a given .repo file points to `source_repo`. + + This function replaces all lines starting with `mirrorlist`, `metalink` or + `baseurl` with `baseurl` set to requested repository. + """ with open(path, 'r') as f: contents = f.read() replacement = 'baseurl={}'.format(source_repo) - contents = re.sub(r'^mirrorlist=.*$', replacement, contents, flags=re.MULTILINE) + contents = re.sub(r'^(mirrorlist|metalink|baseurl)=.*$', + replacement, contents, flags=re.MULTILINE) with open(path, 'w') as f: f.write(contents) diff --git a/tests/test_ostree_phase.py b/tests/test_ostree_phase.py index 8181863c..c8c29506 100755 --- a/tests/test_ostree_phase.py +++ b/tests/test_ostree_phase.py @@ -78,6 +78,10 @@ class OSTreeThreadTest(helpers.PungiTestCase): helpers.touch(os.path.join(target, 'fedora-atomic-docker-host.json')) helpers.touch(os.path.join(target, 'fedora-rawhide.repo'), 'mirrorlist=mirror-mirror-on-the-wall') + helpers.touch(os.path.join(target, 'fedora-24.repo'), + 'metalink=who-is-the-fairest-of-them-all') + helpers.touch(os.path.join(target, 'fedora-23.repo'), + 'baseurl=why-not-zoidberg?') @mock.patch('pungi.wrappers.scm.get_dir_from_scm') @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper') @@ -131,6 +135,12 @@ class OSTreeThreadTest(helpers.PungiTestCase): with open(self.topdir + '/work/ostree/config_repo/fedora-rawhide.repo') as f: self.assertIn('baseurl=http://example.com/Everything/x86_64/os'.format(self.topdir), f.read()) + with open(self.topdir + '/work/ostree/config_repo/fedora-24.repo') as f: + self.assertIn('baseurl=http://example.com/Everything/x86_64/os'.format(self.topdir), + f.read()) + with open(self.topdir + '/work/ostree/config_repo/fedora-23.repo') as f: + self.assertIn('baseurl=http://example.com/Everything/x86_64/os'.format(self.topdir), + f.read()) @mock.patch('pungi.wrappers.scm.get_dir_from_scm') @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper')