Skip to content

Commit

Permalink
[WIP] working on the iterator
Browse files Browse the repository at this point in the history
Signed-off-by: Jose Luis Rivero <jrivero@osrfoundation.org>
  • Loading branch information
j-rivero committed Mar 26, 2024
1 parent a7ace26 commit 518af3a
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 39 deletions.
10 changes: 10 additions & 0 deletions plugins/config/_test_repository.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,21 @@ projects:
- name: osrf
type: stable
- name: ignition-transport7
distributions:
ubuntu:
- no-existing-distro
repositories:
- name: osrf
type: stable
- name: osrf
type: prerelease
- name: ignition-transport7
distributions:
ubuntu:
- jammy
repositories:
- name: osrf
type: stable
- name: ignition-.*
repositories:
- name: osrf
Expand Down
18 changes: 16 additions & 2 deletions plugins/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,26 @@ def load_config_file(config_file_path='config/repository.yaml'):
exit(-1)


def get_project_config(project, config):
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'])

print(config['projects'])
if pattern.search(project):
try:
if linux_distro in config['projects'][project]['distributions'][distro.id()]:
print("FOO")
# print(project_config['distributions'][distro.id()])
except KeyError as kerror:
print(kerror)
if str(kerror) == 'distributions':
pass # supported use case, no distributions defined
else:
warn(str(kerror))

return p
return None

Expand Down Expand Up @@ -213,9 +226,10 @@ def validate_input(args):


def process_project_install(project, config, linux_distro, dry_run=False):
project_config = get_project_config(project, config)
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,
Expand Down
102 changes: 65 additions & 37 deletions plugins/repository_TEST.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,64 +26,92 @@ def setUp(self):
self.config = repository.load_config_file('config/_test_repository.yaml')


class TestBasicOperations(TestBase):
# class TestBasicOperations(TestBase):

def test_config_file_path(self):
self.assertTrue(self.config)
# def test_config_file_path(self):
# self.assertTrue(self.config)


class TestRepoKey(TestBase):
# class TestRepoKey(TestBase):

def test_basic_ok(self):
self.assertEqual(
repository.get_repo_key('osrf', self.config),
'ABC1234567890')
# def test_basic_ok(self):
# self.assertEqual(
# repository.get_repo_key('osrf', self.config),
# 'ABC1234567890')


class TestRepo_URL(TestBase):
# class TestRepo_URL(TestBase):

def test_basic_ok(self):
self.assertEqual(
repository.get_repo_url('osrf', 'prerelease', self.config),
'http://prerelease-' + repository.get_linux_distro())
# def test_basic_ok(self):
# self.assertEqual(
# repository.get_repo_url('osrf', 'prerelease', self.config),
# 'http://prerelease-' + repository.get_linux_distro())

def test_no_repo(self):
with self.assertRaises(SystemExit):
repository.get_repo_url('invalid_repo', 'invalid_type', self.config)
# def test_no_repo(self):
# with self.assertRaises(SystemExit):
# repository.get_repo_url('invalid_repo', 'invalid_type', self.config)

def test_no_type(self):
with self.assertRaises(SystemExit):
repository.get_repo_url('osrf', 'invalid_tye', self.config)
# def test_no_type(self):
# with self.assertRaises(SystemExit):
# repository.get_repo_url('osrf', 'invalid_tye', self.config)


class TestProjectNameResolution(TestBase):

def test_direct_match(self):
project_config = repository.get_project_config('ignition-math6',
self.config)
# def test_direct_match(self):
# 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):
# self.assertIsNone(
# repository.get_first_valid_project_config('fooooo',
# self.config,
# 'jammy'))

# def test_regexp(self):
# 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')

def test_non_exist(self):
self.assertIsNone(repository.get_project_config('fooooo', self.config))

def test_regexp(self):
project_config = repository.get_project_config('ignition-plugin',
self.config)
for p in repository.get_repositories_config(project_config):
self.assertEqual(p['name'], 'osrf')
self.assertEqual(p['type'], 'regexp')
# class TestProjectInstall(TestBase):

# def test_no_distributions(self):
# repository.process_project_install('ignition-math6',
# self.config,
# 'jammy',
# dry_run=True)

class TestProjectInstall(TestBase):
# def test_distributions(self):
# repository.process_project_install('ignition-transport7',
# self.config,
# 'jammy',
# dry_run=True)

def test_non_exist(self):
with self.assertRaises(SystemExit):
repository.process_project_install('fooooo',
self.config,
'jammy',
dry_run=True)
# def test_non_exist(self):
# with self.assertRaises(SystemExit):
# repository.process_project_install('fooooo',
# self.config,
# 'jammy',
# dry_run=True)


if __name__ == '__main__':
Expand Down

0 comments on commit 518af3a

Please sign in to comment.