From f2844854e6d8bbb328801538c3ae0f505291c6ec Mon Sep 17 00:00:00 2001 From: Yann Dirson Date: Fri, 28 Mar 2025 18:19:20 +0100 Subject: [PATCH 1/2] backend: split determineRepositories out of performInstallation This is a first step before calling this code earlier. Signed-off-by: Yann Dirson --- backend.py | 72 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/backend.py b/backend.py index edf9ccce..a7a6bd4b 100644 --- a/backend.py +++ b/backend.py @@ -289,6 +289,42 @@ def progressCallback(x): doCleanup(answers['cleanup']) del answers['cleanup'] +def determineRepositories(answers, answers_pristine, main_repositories, update_repositories): + def add_repos(main_repositories, update_repositories, repos): + """Add repositories to the appropriate list, ensuring no duplicates, + that the main repository is at the beginning, and that the order of the + rest is maintained.""" + + for repo in repos: + if isinstance(repo, repository.UpdateYumRepository): + repo_list = update_repositories + else: + repo_list = main_repositories + + if repo not in repo_list: + if repo.identifier() == MAIN_REPOSITORY_NAME: + repo_list.insert(0, repo) + else: + repo_list.append(repo) + + # A list of sources coming from the answerfile + if 'sources' in answers_pristine: + for i in answers_pristine['sources']: + repos = repository.repositoriesFromDefinition(i['media'], i['address']) + add_repos(main_repositories, update_repositories, repos) + + # A single source coming from an interactive install + if 'source-media' in answers_pristine and 'source-address' in answers_pristine: + repos = repository.repositoriesFromDefinition(answers_pristine['source-media'], answers_pristine['source-address']) + add_repos(main_repositories, update_repositories, repos) + + for media, address in answers_pristine['extra-repos']: + repos = repository.repositoriesFromDefinition(media, address) + add_repos(main_repositories, update_repositories, repos) + + if not main_repositories or main_repositories[0].identifier() != MAIN_REPOSITORY_NAME: + raise RuntimeError("No main repository found") + def performInstallation(answers, ui_package, interactive): logger.log("INPUT ANSWERS DICTIONARY:") prettyLogAnswers(answers) @@ -374,41 +410,7 @@ def handleRepos(repos, ans): # needed to ensure that there are no duplicates. main_repositories = [] update_repositories = [] - - def add_repos(main_repositories, update_repositories, repos): - """Add repositories to the appropriate list, ensuring no duplicates, - that the main repository is at the beginning, and that the order of the - rest is maintained.""" - - for repo in repos: - if isinstance(repo, repository.UpdateYumRepository): - repo_list = update_repositories - else: - repo_list = main_repositories - - if repo not in repo_list: - if repo.identifier() == MAIN_REPOSITORY_NAME: - repo_list.insert(0, repo) - else: - repo_list.append(repo) - - # A list of sources coming from the answerfile - if 'sources' in answers_pristine: - for i in answers_pristine['sources']: - repos = repository.repositoriesFromDefinition(i['media'], i['address']) - add_repos(main_repositories, update_repositories, repos) - - # A single source coming from an interactive install - if 'source-media' in answers_pristine and 'source-address' in answers_pristine: - repos = repository.repositoriesFromDefinition(answers_pristine['source-media'], answers_pristine['source-address']) - add_repos(main_repositories, update_repositories, repos) - - for media, address in answers_pristine['extra-repos']: - repos = repository.repositoriesFromDefinition(media, address) - add_repos(main_repositories, update_repositories, repos) - - if not main_repositories or main_repositories[0].identifier() != MAIN_REPOSITORY_NAME: - raise RuntimeError("No main repository found") + determineRepositories(answers, answers_pristine, main_repositories, update_repositories) handleMainRepos(main_repositories, answers) if update_repositories: From deccfa331b78491d565f6daf1a1cc89f9b76984d Mon Sep 17 00:00:00 2001 From: Yann Dirson Date: Fri, 28 Mar 2025 18:24:06 +0100 Subject: [PATCH 2/2] backend: call determineRepositories() before getPrepSequence() The former actually does some checks which can cause an upgrade to abort (although with very low probability), and running the latter first would leave a host in a broken state, in need for a Restore before attempting a new upgrade. Signed-off-by: Yann Dirson --- backend.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/backend.py b/backend.py index a7a6bd4b..9af79461 100644 --- a/backend.py +++ b/backend.py @@ -388,9 +388,17 @@ def performInstallation(answers, ui_package, interactive): assert answers['net-admin-interface'].startswith("eth") answers['net-admin-bridge'] = "xenbr%s" % answers['net-admin-interface'][3:] + # A list needs to be used rather than a set since the order of updates is + # important. However, since the same repository might exist in multiple + # locations or the same location might be listed multiple times, care is + # needed to ensure that there are no duplicates. + main_repositories = [] + update_repositories = [] + answers_pristine = answers.copy() + determineRepositories(answers, answers_pristine, main_repositories, update_repositories) + # perform installation: prep_seq = getPrepSequence(answers, interactive) - answers_pristine = answers.copy() executeSequence(prep_seq, "Preparing for installation...", answers, ui_package, False) # install from main repositories: @@ -404,14 +412,6 @@ def handleRepos(repos, ans): answers['installed-repos'] = {} - # A list needs to be used rather than a set since the order of updates is - # important. However, since the same repository might exist in multiple - # locations or the same location might be listed multiple times, care is - # needed to ensure that there are no duplicates. - main_repositories = [] - update_repositories = [] - determineRepositories(answers, answers_pristine, main_repositories, update_repositories) - handleMainRepos(main_repositories, answers) if update_repositories: handleRepos(update_repositories, answers)