def __init__(self, location, repo_name=None, trusted_keyrings: list[str] = None, entity=None): if not trusted_keyrings: trusted_keyrings = [] lconf = LocalConfig() if not repo_name: repo_name = 'unknown' if is_remote_url(location): self._root_dir = os.path.join(lconf.cache_dir, 'repo_cache', repo_name) os.makedirs(self._root_dir, exist_ok=True) self._repo_url = location else: self._root_dir = location self._repo_url = None self._keyrings = trusted_keyrings self._trusted = False self._name = repo_name if entity: self._repo_entity = entity else: self._repo_entity = ArchiveRepository(self._name) self._inrelease: dict[str, Repository.InReleaseData] = {}
def ask_settings(options): from laniakea.db.core import config_set_project_name, config_set_distro_tag from laniakea.db import ArchiveRepository, ArchiveSuite database_init(options) print_header('Configuring base settings for Laniakea') session = session_factory() config_set_project_name(input_str('Name of this project')) # we only support one repository at time, so add the default repo = session.query(ArchiveRepository) \ .filter(ArchiveRepository.name == 'master').one_or_none() if not repo: repo = ArchiveRepository('master') session.add(repo) session.commit() add_suite = True while add_suite: _add_new_suite(session) add_suite = input_bool('Add another suite?') incoming_suite = None while not incoming_suite: incoming_suite_name = input_str( 'Name of the \'incoming\' suite which new packages are usually uploaded to' ) incoming_suite = session.query(ArchiveSuite) \ .filter(ArchiveSuite.name == incoming_suite_name).one_or_none() if not incoming_suite: print_note('Suite with the name "{}" was not found.'.format( incoming_suite_name)) incoming_suite.accept_uploads = True devel_suite = None while not devel_suite: devel_suite_name = input_str( 'Name of the "development" suite which is rolling or will become a final release' ) devel_suite = session.query(ArchiveSuite) \ .filter(ArchiveSuite.name == devel_suite_name).one_or_none() if not devel_suite: print_note('Suite with the name "{}" was not found.'.format( devel_suite_name)) devel_suite.devel_target = True config_set_distro_tag( input_str( 'Distribution version tag (commonly found in package versions, e.g. \'tanglu\' for OS \'Tanglu\' with versions like \'1.0-0tanglu1\'' )) session.commit()
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 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