From 807b6ca72756a701814eed7ee68fdf15e47d7b40 Mon Sep 17 00:00:00 2001 From: Kevin Sandi Date: Fri, 28 Feb 2025 15:28:07 -0600 Subject: [PATCH] Fix: UnboundLocalError for raw_json variable Signed-off-by: Kevin Sandi Change-Id: I66bf2664ed596a64d479549a6046f3431ac89927 --- lftools/nexus/release_docker_hub.py | 13 ++++++++----- releasenotes/notes/fix-nexus-bug-859c2a73679e52e7.yaml | 8 ++++++++ tests/test_deploy.py | 6 ++++-- tests/test_version.py | 4 ++-- tox.ini | 12 ++++++------ 5 files changed, 28 insertions(+), 15 deletions(-) create mode 100644 releasenotes/notes/fix-nexus-bug-859c2a73679e52e7.yaml diff --git a/lftools/nexus/release_docker_hub.py b/lftools/nexus/release_docker_hub.py index 5cb3c821..4381d620 100644 --- a/lftools/nexus/release_docker_hub.py +++ b/lftools/nexus/release_docker_hub.py @@ -312,6 +312,7 @@ class DockerTagClass(TagClass): still_more = True docker_tag_url = _docker_base + "/" + repo_name + "/tags" while still_more: + raw_json = None retries = 0 while retries < 20: try: @@ -346,15 +347,17 @@ class DockerTagClass(TagClass): tag_name = result["name"] self.add_tag(tag_name) log.debug("Docker {} has tag {}".format(combined_repo_name, tag_name)) + + if raw_json["next"]: + docker_tag_url = raw_json["next"] + still_more = True + else: + still_more = False except Exception: log.debug("Issue fetching tags for {}".format(combined_repo_name)) else: self.repository_exist = False - if raw_json["next"]: - docker_tag_url = raw_json["next"] - still_more = True - else: - still_more = False + return class ProjectClass: diff --git a/releasenotes/notes/fix-nexus-bug-859c2a73679e52e7.yaml b/releasenotes/notes/fix-nexus-bug-859c2a73679e52e7.yaml new file mode 100644 index 00000000..d35c3f45 --- /dev/null +++ b/releasenotes/notes/fix-nexus-bug-859c2a73679e52e7.yaml @@ -0,0 +1,8 @@ +--- +fixes: + - | + Initialize raw_json variable before first usage otherwise we will get + UnboundLocalError. Additionally move some logic using the raw_json to + a position where it makes more sense. + Pytest configuration was outdated so it was required to upgrade plugin + versions and tests code in order to get a healthy Gerrit change. diff --git a/tests/test_deploy.py b/tests/test_deploy.py index 168257c2..919ddd70 100644 --- a/tests/test_deploy.py +++ b/tests/test_deploy.py @@ -55,7 +55,8 @@ def test_copy_archive_dir(cli_runner, datafiles): """Test copy_archives() command to ensure archives dir is copied.""" os.chdir(str(datafiles)) workspace_dir = os.path.join(str(datafiles), "workspace") - stage_dir = str(datafiles.mkdir("stage_archive")) + stage_dir = os.path.join(str(datafiles), "stage_archive") + os.mkdir(stage_dir) os.chdir(stage_dir) result = cli_runner.invoke(cli.cli, ["--debug", "deploy", "copy-archives", workspace_dir], obj={}) @@ -71,7 +72,8 @@ def test_copy_archive_pattern(cli_runner, datafiles): """Test copy_archives() command to ensure glob patterns are copied.""" os.chdir(str(datafiles)) workspace_dir = os.path.join(str(datafiles), "workspace") - stage_dir = str(datafiles.mkdir("stage_archive")) + stage_dir = os.path.join(str(datafiles), "stage_archive") + os.mkdir(stage_dir) os.chdir(stage_dir) result = cli_runner.invoke(cli.cli, ["--debug", "deploy", "copy-archives", workspace_dir, "**/*.txt"], obj={}) diff --git a/tests/test_version.py b/tests/test_version.py index bc50fdf5..80a7ab73 100644 --- a/tests/test_version.py +++ b/tests/test_version.py @@ -31,7 +31,7 @@ def test_version_bump(cli_runner, datafiles): os.chdir(str(datafiles)) cli_runner.invoke(cli.cli, ["version", "bump", "TestRelease"], obj={}) - for _file in datafiles.listdir(): + for _file in datafiles.iterdir(): pom = str(_file) + "/pom.xml" expected_pom = str(_file) + "/pom.xml.expected" # noqa: B101 . @@ -46,7 +46,7 @@ def test_version_release(cli_runner, datafiles): os.chdir(str(datafiles)) cli_runner.invoke(cli.cli, ["version", "release", "TestRelease"], obj={}) - for _file in datafiles.listdir(): + for _file in datafiles.iterdir(): pom = str(_file) + "/pom.xml" expected_pom = str(_file) + "/pom.xml.expected" # noqa: B101 . diff --git a/tox.ini b/tox.ini index e6566fc9..a68b7321 100644 --- a/tox.ini +++ b/tox.ini @@ -21,12 +21,12 @@ addopts = basepython = python3 # This needs to mirror the test section of pyproject.toml deps = - pytest==5.3.5 - pytest-click==0.3 - pytest-cov - pytest-datafiles==2.0 - pytest-mock==2.0.0 - pytest-responses==0.4.0 + pytest==8.3.5 + pytest-click==1.1.0 + pytest-cov==5.0.0 + pytest-datafiles==3.0.0 + pytest-mock==3.14.0 + pytest-responses==0.5.1 commands = pytest usedevelop = true -- 2.16.6