def test_repo_local(samplesdir, localconfig): keyrings = localconfig.trusted_gpg_keyrings repo_location = os.path.join(samplesdir, 'samplerepo', 'dummy') suite = ArchiveSuite('testing') component = ArchiveComponent('main') arch = ArchiveArchitecture('amd64') arch_all = ArchiveArchitecture('all') repo = Repository(repo_location, 'Dummy', trusted_keyrings=[]) # we have no keyrings set, so this should fail with pytest.raises(GpgException): src_pkgs = repo.source_packages(suite, component) # try again! repo = Repository(repo_location, 'Dummy', trusted_keyrings=keyrings) src_pkgs = repo.source_packages(suite, component) bin_pkgs = repo.binary_packages(suite, component, arch) assert len(bin_pkgs) == 4 bin_pkgs.extend(repo.binary_packages(suite, component, arch_all)) # check packages assert len(src_pkgs) == 8 assert len(bin_pkgs) == 7 validate_src_packages(src_pkgs) validate_bin_packages(bin_pkgs)
def _get_repo_binary_package_map(self, repo, suite_name: str, component_name: str, arch_name: str = None, with_installer: bool = True): ''' Get an associative array of the newest binary packages present in a repository. ''' suite = ArchiveSuite(suite_name) component = ArchiveComponent(component_name) arch = ArchiveArchitecture(arch_name) arch_all = ArchiveArchitecture('all') bpkgs = repo.binary_packages(suite, component, arch) bpkgs.extend(repo.binary_packages(suite, component, arch_all)) # always append arch:all packages if with_installer: # add d-i packages to the mix bpkgs.extend(repo.installer_packages(suite, component, arch)) bpkgs.extend(repo.installer_packages(suite, component, arch_all)) # always append arch:all packages return make_newest_packages_dict(bpkgs)
def database(localconfig, podman_ip, podman_services): ''' Retrieve a pristine, empty Laniakea database connection. This will wipe the global database, so tests using this can never run in parallel. ''' import json from laniakea.db import Database, session_scope, ArchiveRepository, ArchiveSuite, \ ArchiveComponent, ArchiveArchitecture from laniakea.db.core import config_set_project_name, config_set_distro_tag # get IP of our database container db_port = podman_services.port_for('postgres', 5432) # update database URL to use scratch database in our container pgdb_url = 'postgresql://*****:*****@{}:{}/laniakea_unittest'.format( podman_ip, db_port) LocalConfig.instance._database_url = pgdb_url assert localconfig.database_url == pgdb_url # update the on-disk configuration, we may pass that on to independent modules with open(localconfig.fname, 'r') as f: config_json = json.load(f) config_json['Database']['host'] = podman_ip config_json['Database']['port'] = db_port with open(localconfig.fname, 'w') as f: json.dump(config_json, f) # create database factory singleton, if it didn't exist yet db = Database(localconfig) # wait for the database to become available podman_services.wait_until_responsive( timeout=60.0, pause=0.5, check=lambda: pgsql_test_available(session_scope)) # clear database tables so test function has a pristine database to work with with session_scope() as session: session.execute('DROP owned BY lkdbuser_test;') db.downgrade('base') db.create_tables() # add core configuration data to the database config_set_project_name('Test Project') config_set_distro_tag('test') with session_scope() as session: # master repository, currently the only one we support repo = ArchiveRepository('master') session.add(repo) # components acpt_main = ArchiveComponent('main') acpt_contrib = ArchiveComponent('contrib') acpt_nonfree = ArchiveComponent('non-free') acpt_contrib.parent_component = acpt_main acpt_nonfree.parent_component = acpt_main all_components = [acpt_main, acpt_contrib, acpt_nonfree] session.add_all(all_components) # architectures arch_all = ArchiveArchitecture('all') arch_amd64 = ArchiveArchitecture('amd64') arch_arm64 = ArchiveArchitecture('arm64') all_architectures = [arch_all, arch_amd64, arch_arm64] session.add_all(all_architectures) # add 'unstable' suite suite_us = ArchiveSuite('unstable') suite_us.repos = [repo] suite_us.components = all_components suite_us.architectures = all_architectures suite_us.accept_uploads = True session.add(suite_us) # add 'testing' suite suite_te = ArchiveSuite('testing') suite_te.repos = [repo] suite_te.components = all_components suite_te.architectures = all_architectures suite_te.devel_target = True session.add(suite_te) # add 'experimental' suite suite_ex = ArchiveSuite('experimental') suite_ex.repos = [repo] suite_ex.components = all_components suite_ex.architectures = [arch_all, arch_amd64] suite_ex.accept_uploads = True suite_ex.parent = suite_us session.add(suite_ex) return db
def _add_new_suite(session): ''' Interactively register a new suite. ''' from laniakea.db import ArchiveRepository, ArchiveSuite, ArchiveComponent, ArchiveArchitecture repo = session.query(ArchiveRepository) \ .filter(ArchiveRepository.name == 'master').one() suite_name = input_str('Adding a new suite. Please set a name') suite = session.query(ArchiveSuite) \ .filter(ArchiveSuite.name == suite_name).one_or_none() if suite: print_note('Removing existing suite with the same name ("{}")'.format( suite_name)) session.delete(suite) session.commit() suite = ArchiveSuite(suite_name) suite.repos = [repo] component_names = input_list('List of components for suite "{}"'.format( suite.name)) add_main_dep = 'main' in component_names if add_main_dep: component_names.remove('main') component_names.insert(0, 'main') suite.components = [] main_component = None for cname in component_names: component = session.query(ArchiveComponent) \ .filter(ArchiveComponent.name == cname).one_or_none() if not component: component = ArchiveComponent(cname) if add_main_dep and main_component and cname != 'main': component.parent_component = main_component session.add(component) if cname == 'main': main_component = component suite.components.append(component) arch_names = input_list('List of architectures for suite "{}"'.format( suite.name)) # every suite has the "all" architecture, so add it straight away if 'all' not in arch_names: arch_names.insert(0, 'all') suite.architectures = [] for aname in arch_names: arch = session.query(ArchiveArchitecture) \ .filter(ArchiveArchitecture.name == aname).one_or_none() if not arch: arch = ArchiveArchitecture(aname) session.add(arch) suite.architectures.append(arch) parent_suite = None while not parent_suite: parent_suite_name = input_str( 'Set a name of the suite this suite is an overlay to. Leave empty for primary suite. (The overlay suite must have been added first!)', allow_empty=True) if not parent_suite_name: break parent_suite = session.query(ArchiveSuite) \ .filter(ArchiveSuite.name == parent_suite_name).one_or_none() if not parent_suite: print_note( 'Parent suite "{}" was not found.'.format(parent_suite_name)) suite.parent = parent_suite session.add(suite) session.commit()
def database(localconfig): ''' Retrieve a pristine, empty Laniakea database connection. This will wipe the global database, so tests using this can never run in parallel. ''' from laniakea.db import Database, session_scope, ArchiveRepository, ArchiveSuite, \ ArchiveComponent, ArchiveArchitecture from laniakea.db.core import config_set_project_name, config_set_distro_tag db = Database(localconfig) # create singleton, if it didn't exist yet # clear database tables so test function has a pristine database to work with with session_scope() as session: session.execute('DROP owned BY lkdbuser_test;') db.downgrade('base') db.create_tables() # add core configuration data to the database config_set_project_name('Test Project') config_set_distro_tag('test') with session_scope() as session: # master repository, currently the only one we support repo = ArchiveRepository('master') session.add(repo) # components acpt_main = ArchiveComponent('main') acpt_contrib = ArchiveComponent('contrib') acpt_nonfree = ArchiveComponent('non-free') acpt_contrib.parent_component = acpt_main acpt_nonfree.parent_component = acpt_main all_components = [acpt_main, acpt_contrib, acpt_nonfree] session.add_all(all_components) # architectures arch_all = ArchiveArchitecture('all') arch_amd64 = ArchiveArchitecture('amd64') arch_arm64 = ArchiveArchitecture('arm64') all_architectures = [arch_all, arch_amd64, arch_arm64] session.add_all(all_architectures) # add 'unstable' suite suite_us = ArchiveSuite() suite_us.name = 'unstable' suite_us.repos = [repo] suite_us.components = all_components suite_us.architectures = all_architectures suite_us.accept_uploads = True session.add(suite_us) # add 'testing' suite suite_te = ArchiveSuite() suite_te.name = 'testing' suite_te.repos = [repo] suite_te.components = all_components suite_te.architectures = all_architectures suite_te.devel_target = True session.add(suite_te) # add 'experimental' suite suite_ex = ArchiveSuite() suite_ex.name = 'experimental' suite_ex.repos = [repo] suite_ex.components = all_components suite_ex.architectures = [arch_all, arch_amd64] suite_ex.accept_uploads = True suite_ex.parent = suite_us session.add(suite_ex) return db