Skip to content

Commit

Permalink
Added downstream mappings in qcow_client
Browse files Browse the repository at this point in the history
Added downstream mapping of osp release
versions in qcow_client.py file.

Change-Id: Ibcd069e0a2a50e073d84e5e740e81234456b7ece
Signed-off-by: Amol Kahat <amolkahat@gmail.com>
  • Loading branch information
amolkahat authored and Zuul CI committed Jul 12, 2021
1 parent 975ca44 commit f8eb765
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
9 changes: 9 additions & 0 deletions ci-scripts/dlrnapi_promoter/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,12 @@ def get_log_file(env, release_config, log=None):
default_config_file = yaml.safe_load(open(default_path))
conf_template = jinja2.Template(default_config_file['log_file'])
return conf_template.render(config_file)


def get_release_map(release):
downstream_release_map = {'osp16-2': 'rhos-16.2',
'osp17': 'rhos-17'}
if release.startswith("osp"):
return downstream_release_map[release]
else:
return release
30 changes: 20 additions & 10 deletions ci-scripts/dlrnapi_promoter/qcow_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import os

import paramiko
from common import PromotionError
from common import PromotionError, get_release_map


class QcowConnectionClient(object):
Expand Down Expand Up @@ -61,11 +61,8 @@ class QcowClient(object):

def __init__(self, config):
self.config = config

self.release = config.release
self.git_root = self.config.git_root
self.promote_script = os.path.join(self.git_root,
'ci-scripts', 'promote-images.sh')

self.distro_name = self.config.distro_name
self.distro_version = self.config.distro_version
self.rollback_links = {}
Expand All @@ -74,11 +71,14 @@ def __init__(self, config):
self.user = server_conf[qcow_server]['user']
self.root = server_conf[qcow_server]['root']
self.host = server_conf[qcow_server]['host']
self.release = get_release_map(self.release)

self.client = QcowConnectionClient(server_conf[qcow_server])
self.images_dir = os.path.join(
os.path.join(config.stage_root, self.root),
config.distro, config.release, "rdo_trunk")
config.distro, self.release, "rdo_trunk")
if self.config.release.startswith('osp'):
self.images_dir = self.images_dir.rstrip("/rdo_trunk")

def validate_qcows(self, dlrn_hash, name=None, assume_valid=False):
"""
Expand Down Expand Up @@ -182,14 +182,16 @@ def promote(self, candidate_hash, target_label, candidate_label=None,
self.validate_qcows(candidate_hash)

self.client.chdir(self.images_dir)

self.log.debug("Changing dir: {}".format(self.images_dir))
log_header = "Qcow promote '{}' to {}:".format(candidate_hash,
target_label)
self.log.info("%s Attempting promotion", log_header)

# Check if candidate_hash dir is present
try:
self.client.stat(candidate_hash.full_hash)
self.log.debug("Checking candidate hash dir: "
"{}".format(candidate_hash.full_hash))
except EnvironmentError as ex:
self.log.error("%s images dir for hash %s not present or not "
"accessible", log_header, candidate_hash)
Expand All @@ -202,6 +204,7 @@ def promote(self, candidate_hash, target_label, candidate_label=None,
current_hash = None
try:
current_hash = self.client.readlink(target_label)
self.log.debug("Checking target link: {}".format(current_hash))
except EnvironmentError:
self.log.debug("%s No link named %s exists", log_header,
target_label)
Expand All @@ -211,6 +214,7 @@ def promote(self, candidate_hash, target_label, candidate_label=None,
self.rollback_links['target_label'] = current_hash
try:
self.client.remove(target_label)
self.log.debug("Removing label: {}".format(target_label))
except EnvironmentError as ex:
self.log.debug("Unable to remove the target_label: %s",
target_label)
Expand All @@ -223,6 +227,7 @@ def promote(self, candidate_hash, target_label, candidate_label=None,
previous_hash = None
try:
previous_hash = self.client.readlink(previous_label)
self.log.debug("Previous hash: {}".format(previous_hash))
except EnvironmentError:
self.log.debug("%s No previous-link named %s exists",
log_header,
Expand All @@ -234,6 +239,8 @@ def promote(self, candidate_hash, target_label, candidate_label=None,
self.rollback_links[previous_label] = previous_hash
try:
self.client.remove(previous_label)
self.log.debug("Removing previous label: "
"{}".format(previous_label))
except EnvironmentError as ex:
self.log.debug("Unable to remove the target_label: %s",
target_label)
Expand All @@ -245,6 +252,8 @@ def promote(self, candidate_hash, target_label, candidate_label=None,
raise
try:
self.client.symlink(current_hash, previous_label)
self.log.debug("Created symlink: "
"{} -> {}".format(current_hash, previous_label))
except EnvironmentError as ex:
self.log.error("%s failed to link %s to %s", log_header,
previous_label, current_hash)
Expand All @@ -257,9 +266,10 @@ def promote(self, candidate_hash, target_label, candidate_label=None,

# Finally the effective promotion
try:
c_hash = os.path.join(self.images_dir, candidate_hash.full_hash)
self.client.symlink(c_hash, target_label)
self.log.debug("Created link {} -> {}".format(
self.client.symlink(os.path.join(self.images_dir,
candidate_hash.full_hash),
target_label)
self.log.debug("Created symlink {} -> {}".format(
candidate_hash.full_hash, target_label))
except EnvironmentError as ex:
self.log.error("%s failed to link %s to %s", log_header,
Expand Down
7 changes: 2 additions & 5 deletions ci-scripts/dlrnapi_promoter/repo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os

import yaml
from common import get_release_map

try:
# Python3 imports
Expand Down Expand Up @@ -212,11 +213,7 @@ def load_excludes(self, full_list):

# Check for downstream release and set appropriate release for the
# same, for osp16-2 -> rhos-16.2 and osp-17 -> rhos-17
downstream_release_map = {'osp16-2': 'rhos-16.2',
'osp-17': 'rhos-17'}

if self.release.startswith('osp'):
self.release = downstream_release_map[self.release]
self.release = get_release_map(self.release)

if exclude_content:
try:
Expand Down

0 comments on commit f8eb765

Please sign in to comment.