Skip to content

Commit

Permalink
Implement the distribution requirement to repo installation
Browse files Browse the repository at this point in the history
Signed-off-by: Jose Luis Rivero <[email protected]>
  • Loading branch information
j-rivero committed Apr 1, 2024
1 parent 8f7e2d1 commit 5d8b330
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 20 deletions.
12 changes: 10 additions & 2 deletions plugins/config/_test_repository.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,19 @@ projects:
- name: osrf
type: stable
- name: ignition-transport7
distributions:
ubuntu:
- no-existing-distro
repositories:
- name: osrf
type: stable
type: broken
- name: ignition-transport7
distributions:
ubuntu:
- jammy
repositories:
- name: osrf
type: prerelease
type: stable
- name: ignition-.*
repositories:
- name: osrf
Expand Down
53 changes: 41 additions & 12 deletions plugins/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,30 @@ def load_config_file(config_file_path='config/repository.yaml'):
exit(-1)


def load_project(project, config):
ret = []
def get_first_valid_project_config(project, config, linux_distro):
"""Returns the project configuration from yaml that correspond
to the first match while searching starting from top to bottom
"""
for p in config['projects']:
pattern = re.compile(p['name'])

if pattern.search(project):
ret = p['repositories']
break
# project name found, check that requirements are met
try:
# 1. If distribution requirement exists check it
if linux_distro in p['distributions'][distro.id()]:
return p
except KeyError as kerror:
# 2. No disitribution requirement set
if 'distributions' in str(kerror):
return p
assert f"Unexpected keyerror: #{str(kerror)}"

if not ret:
error('Unknown project: ' + project)
return None

return ret

def get_repositories_config(project_config):
return project_config['repositories']


def get_linux_distro():
Expand Down Expand Up @@ -159,8 +171,8 @@ def run_apt_update():
_check_call(['apt-get', 'update'])


def install_repos(project_list, config, linux_distro, gpg_check):
for p in project_list:
def install_repos(repos_list, config, linux_distro, gpg_check):
for p in repos_list:
install_repo(p['name'], p['type'], config, linux_distro, gpg_check)


Expand Down Expand Up @@ -207,7 +219,7 @@ def normalize_args(args):
if force_linux_distro:
linux_distro = force_linux_distro
else:
linux_distro = None
linux_distro = distro.codename()
if '--keyserver' in args:
warn('--keyserver option is deprecated. It is safe to remove it')
return action, repo_name, repo_type, project, linux_distro, gpg_check
Expand All @@ -220,14 +232,31 @@ def validate_input(args):
error('Unknown action: ' + args.action)


def process_project_install(project, config, linux_distro, gpg_check,
dry_run=False):
project_config = get_first_valid_project_config(project, config, linux_distro)
if not project_config:
error('Unknown project: ' + project)

if not dry_run: # useful for tests
install_repos(get_repositories_config(project_config),
config,
linux_distro,
gpg_check)


def process_input(args, config):
action, repo_name, repo_type, project, linux_distro, gpg_check = args

if (action == 'enable'):
if project:
project_list = load_project(project, config)
install_repos(project_list, config, linux_distro, gpg_check)
# project dependant installation
process_project_install(project,
config,
linux_distro,
gpg_check)
else:
# generic repository installation
install_repo(repo_name,
repo_type,
config,
Expand Down
51 changes: 45 additions & 6 deletions plugins/repository_TEST.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,60 @@ def test_no_type(self):
class TestProjectNameResolution(TestBase):

def test_direct_match(self):
projects = repository.load_project('ignition-math6', self.config)
for p in projects:
project_config = \
repository.get_first_valid_project_config('ignition-math6',
self.config,
'jammy')
for p in repository.get_repositories_config(project_config):
self.assertEqual(p['name'], 'osrf')
self.assertEqual(p['type'], 'stable')

def test_non_exist(self):
with self.assertRaises(SystemExit):
repository.load_project('fooooo', self.config)
self.assertIsNone(
repository.get_first_valid_project_config('fooooo',
self.config,
'jammy'))

def test_regexp(self):
projects = repository.load_project('ignition-plugin', self.config)
for p in projects:
project_config = \
repository.get_first_valid_project_config('ignition-plugin',
self.config,
'jammy')
for p in repository.get_repositories_config(project_config):
self.assertEqual(p['name'], 'osrf')
self.assertEqual(p['type'], 'regexp')

def test_precedence(self):
project_config = \
repository.get_first_valid_project_config('ignition-transport7',
self.config,
'jammy')
for p in repository.get_repositories_config(project_config):
self.assertEqual(p['name'], 'osrf')
self.assertEqual(p['type'], 'stable')


class TestProjectInstall(TestBase):

def test_no_distributions(self):
repository.process_project_install('ignition-math6',

Check failure on line 98 in plugins/repository_TEST.py

View workflow job for this annotation

GitHub Actions / build

Argument missing for parameter "gpg_check" (reportCallIssue)
self.config,
'jammy',
dry_run=True)

def test_distributions(self):
repository.process_project_install('ignition-transport7',

Check failure on line 104 in plugins/repository_TEST.py

View workflow job for this annotation

GitHub Actions / build

Argument missing for parameter "gpg_check" (reportCallIssue)
self.config,
'jammy',
dry_run=True)

def test_non_exist(self):
with self.assertRaises(SystemExit):
repository.process_project_install('fooooo',

Check failure on line 111 in plugins/repository_TEST.py

View workflow job for this annotation

GitHub Actions / build

Argument missing for parameter "gpg_check" (reportCallIssue)
self.config,
'jammy',
dry_run=True)


if __name__ == '__main__':
unittest.main()

0 comments on commit 5d8b330

Please sign in to comment.