Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
Add fedora support to tripleo-repos
Browse files Browse the repository at this point in the history
Deprecate --centos-mirror in favour of more generic parameter --mirror
but respects it for backwards compatibility.

Enable fedora mirrors to be configured with --mirror parameter.

Assures that default distro specific mirrors are using the distro
parameter.

Story: https://tree.taiga.io/project/tripleo-ci-board/task/733
Change-Id: I0c8852a0524b6460b4219d0e91c0f43444905a1f
Co-Authored-By: Sorin Sbarnea <ssbarnea@redhat.com>
  • Loading branch information
rafaelfolco and ssbarnea committed Feb 21, 2019
1 parent 70e30aa commit 98a91a8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 10 deletions.
38 changes: 31 additions & 7 deletions tripleo_repos/main.py
Expand Up @@ -35,8 +35,11 @@
DEFAULT_OUTPUT_PATH = '/etc/yum.repos.d'
DEFAULT_RDO_MIRROR = 'https://trunk.rdoproject.org'
RDO_RE = re.compile('baseurl=%s' % DEFAULT_RDO_MIRROR)
DEFAULT_CENTOS_MIRROR = 'http://mirror.centos.org'
CENTOS_RE = re.compile('baseurl=%s' % DEFAULT_CENTOS_MIRROR)

DEFAULT_MIRROR_MAP = {
'fedora': 'https://mirrors.fedoraproject.org',
'centos': 'http://mirror.centos.org'
}
CEPH_REPO_TEMPLATE = '''
[tripleo-centos-ceph-%(ceph_release)s]
name=tripleo-centos-ceph-%(ceph_release)s
Expand Down Expand Up @@ -78,6 +81,8 @@ def _parse_args():
"centos7 will be used unless you use CLI param to change it." %
distro, file=sys.stderr)
distro = 'centos7'
distro_key = re.sub(r'[0-9]+', '', distro)

parser = argparse.ArgumentParser(
description='Download and install repos necessary for TripleO. Note '
'that some of these repos require yum-plugin-priorities, '
Expand Down Expand Up @@ -108,14 +113,30 @@ def _parse_args():
parser.add_argument('-o', '--output-path',
default=DEFAULT_OUTPUT_PATH,
help='Directory in which to save the selected repos.')
parser.add_argument(
'--mirror',
default=DEFAULT_MIRROR_MAP[distro_key],
help='Server from which to install base OS packages. '
'Default value is based on distro param.')
parser.add_argument('--centos-mirror',
default=DEFAULT_CENTOS_MIRROR,
help='Server from which to install base CentOS '
'packages.')
default=None,
help='[deprecated] Server from which to install base '
'CentOS packages. If mentioned it will be used '
'as --mirror for backwards compatibility.')
parser.add_argument('--rdo-mirror',
default=DEFAULT_RDO_MIRROR,
help='Server from which to install RDO packages.')
return parser.parse_args()

args = parser.parse_args()
if args.centos_mirror:
print("WARNING: --centos-mirror was deprecated in favour of --mirror",
file=sys.stderr)
args.mirror = args.centos_mirror

distro_key = re.sub(r'[0-9]+', '', args.distro)
args.old_mirror = DEFAULT_MIRROR_MAP[distro_key]

return args


def _get_repo(path, args):
Expand Down Expand Up @@ -229,7 +250,10 @@ def _inject_mirrors(content, args):
handles that by using a regex to swap out the baseurl server.
"""
new_content = RDO_RE.sub('baseurl=%s' % args.rdo_mirror, content)
new_content = CENTOS_RE.sub('baseurl=%s' % args.centos_mirror, new_content)

r = re.compile('baseurl=%s' % args.old_mirror)
new_content = r.sub('baseurl=%s' % args.mirror, new_content)

return new_content


Expand Down
15 changes: 12 additions & 3 deletions tripleo_repos/tests/test_main.py
Expand Up @@ -69,7 +69,9 @@ def test_get_repo(self, mock_get):
mock_response.text = '88MPH'
mock_get.return_value = mock_response
fake_addr = 'http://lone/pine/mall'
content = main._get_repo(fake_addr, mock.Mock())
args = mock.Mock()
args.distro = 'centos'
content = main._get_repo(fake_addr, args)
self.assertEqual('88MPH', content)
mock_get.assert_called_once_with(fake_addr)

Expand Down Expand Up @@ -287,6 +289,9 @@ def test_install_repos_deps_mirror(self, mock_write, mock_get):
args.branch = 'master'
args.output_path = 'test'
args.centos_mirror = 'http://foo'
args.old_mirror = 'http://mirror.centos.org'
args.mirror = 'http://foo'
args.distro = 'centos'
args.rdo_mirror = 'http://bar'
# Abbrevieated repos to verify the regex works
fake_repo = '''
Expand Down Expand Up @@ -397,7 +402,10 @@ def test_inject_mirrors(self):
enabled=1
'''
mock_args = mock.Mock(centos_mirror='http://foo',
rdo_mirror='http://bar')
mirror='http://foo',
rdo_mirror='http://bar',
distro='centos',
old_mirror='http://mirror.centos.org')
result = main._inject_mirrors(start_repo, mock_args)
self.assertEqual(expected, result)

Expand All @@ -408,7 +416,8 @@ def test_inject_mirrors_no_match(self):
baseurl=https://some.mirror.com/centos7/some-repo-hash
enabled=1
'''
mock_args = mock.Mock(rdo_mirror='http://some.mirror.com')
mock_args = mock.Mock(rdo_mirror='http://some.mirror.com',
distro='centos')
# If a user has a mirror whose repos already point at itself then
# the _inject_mirrors call should be a noop.
self.assertEqual(start_repo, main._inject_mirrors(start_repo,
Expand Down

0 comments on commit 98a91a8

Please sign in to comment.