| |
@@ -21,6 +21,7 @@
|
| |
#
|
| |
# Written by Jan Kaluza <jkaluza@redhat.com>
|
| |
|
| |
+ import errno
|
| |
import koji
|
| |
import os
|
| |
import threading
|
| |
@@ -218,6 +219,7 @@
|
| |
compose.transition(COMPOSE_STATES["removed"], state_reason)
|
| |
if not compose.reused_id:
|
| |
self._remove_compose_dir(compose.toplevel_dir)
|
| |
+ remove_compose_symlink(compose)
|
| |
|
| |
# In case of ODCS error, there might be left-over directories
|
| |
# belonging to already expired composes. Try to find them in the
|
| |
@@ -662,6 +664,74 @@
|
| |
log.info("%r: Compose done", compose)
|
| |
|
| |
|
| |
+ def generate_compose_symlink(compose):
|
| |
+ """
|
| |
+ Generates symlink(s) for compose based on its `compose.pungi_compose_id`.
|
| |
+
|
| |
+ It generates following symlinks pointing to the compose:
|
| |
+ - $conf.target_dir/$compose.compose_type/$compose.pungi_compose_id
|
| |
+ - $conf.target_dir/$compose.compose_type/latest-$name-version
|
| |
+
|
| |
+ If the latest-* symlink exists, it is replaced with new one pointing to
|
| |
+ the `composes`.
|
| |
+ """
|
| |
+ symlink_dir = os.path.join(conf.target_dir, compose.compose_type)
|
| |
+ odcs.server.utils.makedirs(symlink_dir)
|
| |
+
|
| |
+ # Generate the non-latest symlink.
|
| |
+ compose_dir = os.path.relpath(compose.toplevel_work_dir, symlink_dir)
|
| |
+ symlink = os.path.join(symlink_dir, compose.pungi_compose_id)
|
| |
+ log.info("%r: Generating %s symlink.", compose, symlink)
|
| |
+ os.symlink(compose_dir, symlink)
|
| |
+
|
| |
+ # Generate the latest-* symlink.
|
| |
+ latest_name = "latest-%s" % "-".join(compose.pungi_compose_id.split("-")[:2])
|
| |
+ symlink = os.path.join(symlink_dir, latest_name)
|
| |
+ try:
|
| |
+ os.unlink(symlink)
|
| |
+ except OSError as e:
|
| |
+ if e.errno != errno.ENOENT:
|
| |
+ raise
|
| |
+ log.info("%r: Generating %s symlink.", compose, symlink)
|
| |
+ os.symlink(compose_dir, symlink)
|
| |
+
|
| |
+
|
| |
+ def remove_compose_symlink(compose):
|
| |
+ """
|
| |
+ Removes non-latest symlink generated by the `generate_compose_symlink`.
|
| |
+ """
|
| |
+ # Do not try to remove symlinks from old composes which do not have
|
| |
+ # the compose_type and pungi_compose_id set.
|
| |
+ if not compose.compose_type or not compose.pungi_compose_id:
|
| |
+ return
|
| |
+
|
| |
+ symlink_dir = os.path.join(conf.target_dir, compose.compose_type)
|
| |
+ symlink = os.path.join(symlink_dir, compose.pungi_compose_id)
|
| |
+
|
| |
+ # Check if latest_symlink points to the same directory as the non-latest
|
| |
+ # symlink. In this case, we will remove the latest-symlink later too.
|
| |
+ latest_name = "latest-%s" % "-".join(compose.pungi_compose_id.split("-")[:2])
|
| |
+ latest_symlink = os.path.join(symlink_dir, latest_name)
|
| |
+ remove_latest_symlink = os.path.realpath(symlink) == os.path.realpath(latest_symlink)
|
| |
+
|
| |
+ # Remove non-latest symlink.
|
| |
+ log.info("%r: Removing %s symlink.", compose, symlink)
|
| |
+ try:
|
| |
+ os.unlink(symlink)
|
| |
+ except OSError as e:
|
| |
+ if e.errno != errno.ENOENT:
|
| |
+ raise
|
| |
+
|
| |
+ # Remove latest symlink.
|
| |
+ if remove_latest_symlink:
|
| |
+ log.info("%r: Removing %s symlink.", compose, latest_symlink)
|
| |
+ try:
|
| |
+ os.unlink(latest_symlink)
|
| |
+ except OSError as e:
|
| |
+ if e.errno != errno.ENOENT:
|
| |
+ raise
|
| |
+
|
| |
+
|
| |
def generate_pungi_compose(compose):
|
| |
"""
|
| |
Generates the compose of KOJI, TAG, or REPO type using the Pungi tool.
|
| |
@@ -727,6 +797,10 @@
|
| |
# Raises an exception if invalid
|
| |
validate_pungi_compose(compose)
|
| |
|
| |
+ # Generate symlinks pointing to latest build of raw_config compose.
|
| |
+ if compose.source_type == PungiSourceType.RAW_CONFIG:
|
| |
+ generate_compose_symlink(compose)
|
| |
+
|
| |
# If there is no exception generated by the pungi.run() and if
|
| |
# validation didn't fail, then we know the compose has been
|
| |
# successfully generated.
|
| |
This commit adds code to generate symlinks for raw_config composes in the following
format:
The goal is to make it easier for end-user to consume raw_config
composes in the future and to find out the latest successfull
raw_config compose.
Signed-off-by: Jan Kaluza jkaluza@redhat.com