Fix: UnboundLocalError for raw_json variable 23/73423/5 v0.37.11
authorKevin Sandi <ksandi@contractor.linuxfoundation.org>
Fri, 28 Feb 2025 21:28:07 +0000 (15:28 -0600)
committerKevin Sandi <ksandi@contractor.linuxfoundation.org>
Fri, 14 Mar 2025 22:53:14 +0000 (16:53 -0600)
Signed-off-by: Kevin Sandi <ksandi@contractor.linuxfoundation.org>
Change-Id: I66bf2664ed596a64d479549a6046f3431ac89927

lftools/nexus/release_docker_hub.py
releasenotes/notes/fix-nexus-bug-859c2a73679e52e7.yaml [new file with mode: 0644]
tests/test_deploy.py
tests/test_version.py
tox.ini

index 5cb3c82..4381d62 100644 (file)
@@ -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 (file)
index 0000000..d35c3f4
--- /dev/null
@@ -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.
index 168257c..919ddd7 100644 (file)
@@ -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={})
index bc50fdf..80a7ab7 100644 (file)
@@ -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 e6566fc..a68b732 100644 (file)
--- 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