From 3990d8a34f91c1afae5d72a5a3c4d487d846220f Mon Sep 17 00:00:00 2001 From: Sergey Kulanov Date: Sun, 27 Mar 2016 17:32:07 +0300 Subject: [PATCH] Fix repos list processing flow We must not modify lists in `for` loops because one builds a completely new list and then gives it the same name the old list has [1] [1]. https://docs.python.org/2/reference/compound_stmts.html#for Change-Id: Id77ed7814701d4cac83c4c9d72c667a839ed05f9 Closes-bug: #1562530 --- fuelweb_test/helpers/replace_repos.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/fuelweb_test/helpers/replace_repos.py b/fuelweb_test/helpers/replace_repos.py index 6ea61c821..78caebf32 100644 --- a/fuelweb_test/helpers/replace_repos.py +++ b/fuelweb_test/helpers/replace_repos.py @@ -38,9 +38,8 @@ def replace_ubuntu_repos(repos_attr, upstream_host): if help_data.EXTRA_DEB_REPOS: repos = add_ubuntu_extra_mirrors(repos=repos) if help_data.PATCHING_DISABLE_UPDATES: - for repo in repos: - if repo['name'] in ('mos-updates', 'mos-security'): - repos.remove(repo) + repos = [repo for repo in repos if repo['name'] + not in ('mos-updates', 'mos-security')] return repos @@ -66,9 +65,8 @@ def replace_centos_repos(repos_attr, upstream_host): if help_data.EXTRA_RPM_REPOS: repos = add_centos_extra_mirrors(repos=repos) if help_data.PATCHING_DISABLE_UPDATES: - for repo in repos: - if repo['name'] in ('mos-updates', 'mos-security'): - repos.remove(repo) + repos = [repo for repo in repos if repo['name'] + not in ('mos-updates', 'mos-security')] return repos @@ -134,10 +132,10 @@ def add_ubuntu_extra_mirrors(repos=None, prefix='extra', if repo_value and check_new_ubuntu_repo(repos, repo_value): # Remove repos that use the same name - for repo in repos: - if repo["name"] == repo_value["name"]: - repos.remove(repo) + repos = [repo for repo in repos + if repo["name"] != repo_value["name"]] repos.append(repo_value) + return repos @@ -151,10 +149,10 @@ def add_centos_extra_mirrors(repos=None, repo_value = parse_centos_repo(repo_str, priority) if repo_value and check_new_centos_repo(repos, repo_value): # Remove repos that use the same name - for repo in repos: - if repo["name"] == repo_value["name"]: - repos.remove(repo) + repos = [repo for repo in repos + if repo["name"] != repo_value["name"]] repos.append(repo_value) + return repos