Browse Source

Limit stream validation for CentOS 8 only

When preparing repos it doesn't make sense to validate 'stream'
for any distro except centos 8. Centos 9 is stream only and all
before 8 don't have a stream.

Change-Id: If6911737bf423806d1ec84ee4a5d147e74521719
changes/34/821834/2
Sagi Shnaidman 5 months ago
parent
commit
5ee86bdd9a
  1. 12
      plugins/module_utils/tripleo_repos/main.py
  2. 29
      tests/unit/tripleo_repos/test_main.py

12
plugins/module_utils/tripleo_repos/main.py

@ -303,11 +303,15 @@ def _validate_tripleo_ci_testing(repos):
return True
def _validate_distro_stream(args, distro_name):
def _validate_distro_stream(args, distro_name, distro_major_version_id):
"""Validate stream related args vs host
Fails if stream is to be used but the host isn't a stream OS or vice versa
"""
if 'centos' not in distro_name.lower():
return True
if distro_name.lower() == 'centos' and distro_major_version_id != '8':
return True
is_stream = args.stream and not args.no_stream
if is_stream and 'stream' not in distro_name.lower():
raise InvalidArguments('--stream provided, but OS is not the Stream '
@ -319,11 +323,11 @@ def _validate_distro_stream(args, distro_name):
return True
def _validate_args(args, distro_name):
def _validate_args(args, distro_name, distro_major_version_id):
_validate_current_tripleo(args.repos)
_validate_distro_repos(args)
_validate_tripleo_ci_testing(args.repos)
_validate_distro_stream(args, distro_name)
_validate_distro_stream(args, distro_name, distro_major_version_id)
def _remove_existing(args):
@ -541,7 +545,7 @@ def _run_pkg_clean(distro):
def main():
distro_id, distro_major_version_id, distro_name = _get_distro()
args = _parse_args(distro_id, distro_major_version_id)
_validate_args(args, distro_name)
_validate_args(args, distro_name, distro_major_version_id)
base_path = _get_base_path(args)
if args.distro in ['centos7']:
_install_priorities()

29
tests/unit/tripleo_repos/test_main.py

@ -39,7 +39,7 @@ class TestTripleORepos(testtools.TestCase):
mock_path = mock.Mock()
mock_gbp.return_value = mock_path
main.main()
mock_validate.assert_called_once_with(args, 'CentOS 8')
mock_validate.assert_called_once_with(args, 'CentOS 8', '8')
mock_gbp.assert_called_once_with(args)
mock_ip.assert_called_once_with()
mock_remove.assert_called_once_with(args)
@ -61,7 +61,7 @@ class TestTripleORepos(testtools.TestCase):
mock_path = mock.Mock()
mock_gbp.return_value = mock_path
main.main()
mock_validate.assert_called_once_with(args, 'CentOS 8')
mock_validate.assert_called_once_with(args, 'CentOS 8', '8')
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)
@ -637,64 +637,65 @@ class TestValidate(testtools.TestCase):
self.args.repos = ['current']
self.args.branch = 'master'
self.args.distro = 'centos7'
self.distro_major_version_id = "7"
self.args.stream = False
self.args.no_stream = False
def test_good(self):
main._validate_args(self.args, '')
main._validate_args(self.args, '', '')
def test_current_and_tripleo_dev(self):
self.args.repos = ['current', 'current-tripleo-dev']
self.assertRaises(main.InvalidArguments, main._validate_args,
self.args, '')
self.args, '', '')
def test_tripleo_ci_testing_and_current_tripleo(self):
self.args.repos = ['current-tripleo', 'tripleo-ci-testing']
self.assertRaises(main.InvalidArguments, main._validate_args,
self.args, '')
self.args, '', '')
def test_tripleo_ci_testing_and_ceph_opstools_allowed(self):
self.args.repos = ['ceph', 'opstools', 'tripleo-ci-testing']
main._validate_args(self.args, '')
main._validate_args(self.args, '', '')
def test_tripleo_ci_testing_and_deps_allowed(self):
self.args.repos = ['deps', 'tripleo-ci-testing']
main._validate_args(self.args, '')
main._validate_args(self.args, '', '')
def test_ceph_and_tripleo_dev(self):
self.args.repos = ['current-tripleo-dev', 'ceph']
self.args.output_path = main.DEFAULT_OUTPUT_PATH
main._validate_args(self.args, '')
main._validate_args(self.args, '', '')
def test_deps_and_tripleo_dev(self):
self.args.repos = ['deps', 'current-tripleo-dev']
self.assertRaises(main.InvalidArguments, main._validate_args,
self.args, '')
self.args, '', '')
def test_current_and_tripleo(self):
self.args.repos = ['current', 'current-tripleo']
self.assertRaises(main.InvalidArguments, main._validate_args,
self.args, '')
self.args, '', '')
def test_deps_and_tripleo_allowed(self):
self.args.repos = ['deps', 'current-tripleo']
main._validate_args(self.args, '')
main._validate_args(self.args, '', '')
def test_invalid_distro(self):
self.args.distro = 'Jigawatts 1.21'
self.assertRaises(main.InvalidArguments, main._validate_args,
self.args, '')
self.args, '', '')
def test_invalid_stream(self):
self.args.stream = True
self.assertRaises(main.InvalidArguments, main._validate_args,
self.args, 'CentOS 8')
self.args, 'CentOS 8', '8')
def test_invalid_no_stream(self):
self.args.stream = False
self.args.no_stream = True
self.assertRaises(main.InvalidArguments, main._validate_args,
self.args, 'CentOS 8 Stream')
self.args, 'CentOS 8 Stream', '8')
def test_validate_distro_repos(self):
self.assertTrue(main._validate_distro_repos(self.args))

Loading…
Cancel
Save