[ostree] Set each repo to point to current compose

Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2016-04-15 08:17:40 +02:00
parent e6079e4c85
commit 46ab1cb6f6
2 changed files with 18 additions and 2 deletions

View File

@ -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)

View File

@ -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')