Add fedora support to tripleo-repos

For Stein we are working on tripleo support as part of the python3 code.
In order to assist in the development, tripleo-repos should allow for
fedora to be passed into the command.

Change-Id: I23df8f6fe68ba47c92bdb3c031de44b47b1a16e2
Related-Blueprint: python3-support
This commit is contained in:
Alex Schultz 2018-11-05 16:55:09 -07:00
parent 8615360381
commit 1389b7a9db
2 changed files with 88 additions and 20 deletions

View File

@ -117,6 +117,21 @@ def _write_repo(content, target):
print('Installed repo %s to %s' % (m.group(1), filename))
def _validate_distro_repos(args):
"""Validate requested repos are valid for the distro"""
if args.distro in ['fedora']:
valid_repos = ['current', 'ceph', 'deps']
elif args.distro in ['centos7']:
valid_repos = ['ceph', 'current', 'current-tripleo',
'current-tripleo-dev', 'deps']
invalid_repos = [x for x in args.repos if x not in valid_repos]
if len(invalid_repos) > 0:
raise InvalidArguments('{} repo(s) are not valid for {}. Valid repos '
'are: {}'.format(invalid_repos, args.distro,
valid_repos))
return True
def _validate_current_tripleo(repos):
"""Validate current usage
@ -151,8 +166,10 @@ def _validate_branch_repos(branch, repos):
def _validate_args(args):
_validate_current_tripleo(args.repos)
_validate_branch_repos(args.branch, args.repos)
if args.distro != 'centos7':
raise InvalidArguments('centos7 is the only supported distro')
if args.distro not in ['centos7', 'fedora']:
raise InvalidArguments('centos7 or fedora is the only supported '
'distros at this time')
_validate_distro_repos(args)
def _remove_existing(args):
@ -167,6 +184,8 @@ def _remove_existing(args):
def _get_base_path(args):
if args.branch != 'master':
if args.distro not in ['centos7']:
raise InvalidArguments('Branches only suppported with centos7')
distro_branch = '%s-%s' % (args.distro, args.branch)
else:
distro_branch = args.distro
@ -257,9 +276,10 @@ def _install_repos(args, base_path):
raise InvalidArguments('Invalid repo "%s" specified' % repo)
def _run_yum_clean():
def _run_pkg_clean(distro):
pkg_mgr = 'yum' if distro == 'centos7' else 'dnf'
try:
subprocess.check_call(['yum', 'clean', 'metadata'])
subprocess.check_call([pkg_mgr, 'clean', 'metadata'])
except subprocess.CalledProcessError:
print('ERROR: Failed to clean yum metadata.')
raise
@ -269,10 +289,11 @@ def main():
args = _parse_args()
_validate_args(args)
base_path = _get_base_path(args)
_install_priorities()
if args.distro in ['centos7']:
_install_priorities()
_remove_existing(args)
_install_repos(args, base_path)
_run_yum_clean()
_run_pkg_clean(args.distro)
if __name__ == '__main__':

View File

@ -22,26 +22,45 @@ from tripleo_repos import main
class TestTripleORepos(testtools.TestCase):
@mock.patch('tripleo_repos.main._run_yum_clean')
@mock.patch('tripleo_repos.main._parse_args')
@mock.patch('sys.argv', ['tripleo-repos', 'current'])
@mock.patch('tripleo_repos.main._run_pkg_clean')
@mock.patch('tripleo_repos.main._validate_args')
@mock.patch('tripleo_repos.main._get_base_path')
@mock.patch('tripleo_repos.main._install_priorities')
@mock.patch('tripleo_repos.main._remove_existing')
@mock.patch('tripleo_repos.main._install_repos')
def test_main(self, mock_install, mock_remove, mock_ip, mock_gbp,
mock_validate, mock_parse, mock_clean):
mock_args = mock.Mock()
mock_parse.return_value = mock_args
mock_validate, mock_clean):
args = main._parse_args()
mock_path = mock.Mock()
mock_gbp.return_value = mock_path
main.main()
mock_validate.assert_called_once_with(mock_args)
mock_gbp.assert_called_once_with(mock_args)
mock_validate.assert_called_once_with(args)
mock_gbp.assert_called_once_with(args)
mock_ip.assert_called_once_with()
mock_remove.assert_called_once_with(mock_args)
mock_install.assert_called_once_with(mock_args, mock_path)
mock_clean.assert_called_once_with()
mock_remove.assert_called_once_with(args)
mock_install.assert_called_once_with(args, mock_path)
mock_clean.assert_called_once_with('centos7')
@mock.patch('sys.argv', ['tripleo-repos', 'current', '-d', 'fedora'])
@mock.patch('tripleo_repos.main._run_pkg_clean')
@mock.patch('tripleo_repos.main._validate_args')
@mock.patch('tripleo_repos.main._get_base_path')
@mock.patch('tripleo_repos.main._install_priorities')
@mock.patch('tripleo_repos.main._remove_existing')
@mock.patch('tripleo_repos.main._install_repos')
def test_main_fedora(self, mock_install, mock_remove, mock_ip, mock_gbp,
mock_validate, mock_clean):
args = main._parse_args()
mock_path = mock.Mock()
mock_gbp.return_value = mock_path
main.main()
mock_validate.assert_called_once_with(args)
mock_gbp.assert_called_once_with(args)
assert not mock_ip.called, '_install_priorities should no tbe called'
mock_remove.assert_called_once_with(args)
mock_install.assert_called_once_with(args, mock_path)
mock_clean.assert_called_once_with('fedora')
@mock.patch('requests.get')
def test_get_repo(self, mock_get):
@ -101,6 +120,20 @@ class TestTripleORepos(testtools.TestCase):
path = main._get_base_path(args)
self.assertEqual('http://trunk.rdoproject.org/centos7-liberty/', path)
def test_get_base_path_fedora(self):
args = mock.Mock()
args.branch = 'master'
args.distro = 'fedora'
args.rdo_mirror = 'http://trunk.rdoproject.org'
path = main._get_base_path(args)
self.assertEqual('http://trunk.rdoproject.org/fedora/', path)
def test_get_base_path_fedora_branch(self):
args = mock.Mock()
args.branch = 'rocky'
args.distro = 'fedora'
self.assertRaises(main.InvalidArguments, main._get_base_path, args)
@mock.patch('subprocess.check_call')
def test_install_priorities(self, mock_check_call):
main._install_priorities()
@ -382,15 +415,20 @@ enabled=1
mock_args))
@mock.patch('subprocess.check_call')
def test_run_yum_clean(self, mock_check_call):
main._run_yum_clean()
def test_run_pkg_clean(self, mock_check_call):
main._run_pkg_clean('centos7')
mock_check_call.assert_called_once_with(['yum', 'clean', 'metadata'])
@mock.patch('subprocess.check_call')
def test_run_yum_clean_fails(self, mock_check_call):
def test_run_pkg_clean_fedora(self, mock_check_call):
main._run_pkg_clean('fedora')
mock_check_call.assert_called_once_with(['dnf', 'clean', 'metadata'])
@mock.patch('subprocess.check_call')
def test_run_pkg_clean_fails(self, mock_check_call):
mock_check_call.side_effect = subprocess.CalledProcessError(88, '88')
self.assertRaises(subprocess.CalledProcessError,
main._run_yum_clean)
main._run_pkg_clean, ['centos7'])
class TestValidate(testtools.TestCase):
@ -444,3 +482,12 @@ class TestValidate(testtools.TestCase):
self.args.distro = 'Jigawatts 1.21'
self.assertRaises(main.InvalidArguments, main._validate_args,
self.args)
def test_validate_distro_repos(self):
self.assertTrue(main._validate_distro_repos(self.args))
def test_validate_distro_repos_fedora_tripleo_dev(self):
self.args.distro = 'fedora'
self.args.repos = ['current-tripleo-dev']
self.assertRaises(main.InvalidArguments, main._validate_distro_repos,
self.args)