Skip to content

Commit

Permalink
Error handling corrections and small code cleanup of unused stuff (os…
Browse files Browse the repository at this point in the history
…ism#658)

fixes osism#657

Signed-off-by: Robin van der Linden <[email protected]>
  • Loading branch information
lindenb1 authored Sep 19, 2023
1 parent 4aa9fca commit 363448c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
43 changes: 21 additions & 22 deletions openstack_image_manager/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from natsort import natsorted
from yamale import YamaleError
from openstack.image.v2.image import Image
from openstack.exceptions import DuplicateResource


class ImageManager:
Expand Down Expand Up @@ -291,48 +290,48 @@ def process_images(self, images) -> set:
versions = dict()
for version in image["versions"]:
versions[str(version["version"])] = {"url": version["url"]}

if "mirror_url" in version:
versions[version["version"]]["mirror_url"] = version[
"mirror_url"
]
versions[version["version"]]["mirror_url"] = version["mirror_url"]

if "visibility" in version:
versions[version["version"]]["visibility"] = version[
"visibility"
]
versions[version["version"]]["visibility"] = version["visibility"]

if "os_version" in version:
versions[version["version"]]["os_version"] = version[
"os_version"
]
versions[version["version"]]["os_version"] = version["os_version"]

if "hidden" in version:
versions[version["version"]]["hidden"] = version["hidden"]
if version["version"] == "latest":

if version["version"] == "latest":#
if "checksums_url" in version:
versions[version["version"]]["checksums_url"] = version[
"checksums_url"
]
versions[version["version"]]["checksums_url"] = version["checksums_url"]
else:
raise Exception()
raise ValueError('Key "checksums_url" is required when using version "latest"')

if "meta" in version:
versions[version["version"]]["meta"] = version["meta"]
else:
versions[version["version"]]["meta"] = {}

if "url" in version:
url = version["url"]
# strip any directory path for file: urls in order to
# avoid exposing local filesystem details to other users
if url.startswith("file:") and "/" in url:
url = "file:%s" % url.rsplit("/", 1)[1]
versions[version["version"]]["meta"]["image_source"] = url

if "build_date" in version:
versions[version["version"]]["meta"][
"image_build_date"
] = date.isoformat(version["build_date"])
versions[version["version"]]["meta"]["image_build_date"] = date.isoformat(version["build_date"])

if "id" in version:
versions[version["version"]]["id"] = version["id"]
except Exception:
logger.error(
'Key "checksums_url" is required when using version "latest"'
)
except ValueError as e:
logger.error(str(e))
continue
except Exception as e:
logger.error(f"An unexpected error occurred: {e}")
continue

sorted_versions = natsorted(versions.keys())
Expand Down
1 change: 0 additions & 1 deletion openstack_image_manager/mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ def main(
filename += fileextension

if fileextension2 == ".tar":
filename2 = filename
filename = os.path.basename(url.path)

logging.debug("dirname: %s" % dirname)
Expand Down

0 comments on commit 363448c

Please sign in to comment.