From 5156317e801c6516e89c71eb112dd85b0b1c52ce Mon Sep 17 00:00:00 2001 From: "jintae.son" Date: Thu, 26 Sep 2019 18:02:53 +0900 Subject: [PATCH] Add exclude ref repo option Change-Id: If9cd2c1b8bd4836726a0fdd39c97ab60ba1abac2 --- job_pre_release_obs.py | 70 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 45 insertions(+), 25 deletions(-) diff --git a/job_pre_release_obs.py b/job_pre_release_obs.py index a6141c4..0d69cd1 100755 --- a/job_pre_release_obs.py +++ b/job_pre_release_obs.py @@ -41,7 +41,7 @@ class LocalError(Exception): """Local error exception.""" pass -def update_ks(imagedata, snapshot_id, pkg_urls, base_project=None): +def update_ks(imagedata, snapshot_id, pkg_urls, base_project=None, exclude_ref_repo=None): """ update the repo url point to right URL and add prerelease repo url with highest priority @@ -64,27 +64,38 @@ def update_ks(imagedata, snapshot_id, pkg_urls, base_project=None): # skip architectures without repos continue new_ks_lines = [] - for line in content.splitlines(): - if line.startswith('repo ') and \ - 'baseurl=' in line and \ - '@BUILD_ID@' in line: - match = re.match(r"repo --name=([\w\-\.]*) --baseurl=.*", - line) - if match: - line = re.sub(r'@BUILD_ID@', snapshot_id, line) - elif line.startswith('repo ') and \ - 'baseurl=' in line: - match = re.match(r"repo --name=([\w\-\.]*) --baseurl=.*", - line) - #BASE replace - if base_project and base_project != 'latest': - match = re.match(r"repo --name=base([\w\-\.]*) --baseurl=.*/latest/repos/.*", + if exclude_ref_repo: + for line in content.splitlines(): + if line.startswith('repo ') and \ + 'baseurl=' in line: + match = re.match(r"repo --name=([\w\-\.]*) --baseurl=.*", line) + if match: + continue + + new_ks_lines.append(line) + + else: + for line in content.splitlines(): + if line.startswith('repo ') and \ + 'baseurl=' in line and \ + '@BUILD_ID@' in line: + match = re.match(r"repo --name=([\w\-\.]*) --baseurl=.*", line) if match: - base_path = [ x for x in base_project.lower().split(':') if x != 'ref' ] - line = line.replace('/latest/', '/%s/' % ('-'.join(base_path[0:-1]) + '_' + base_path[-1])) + line = re.sub(r'@BUILD_ID@', snapshot_id, line) + elif line.startswith('repo ') and \ + 'baseurl=' in line: + match = re.match(r"repo --name=([\w\-\.]*) --baseurl=.*", + line) + #BASE replace + if base_project and base_project != 'latest': + match = re.match(r"repo --name=base([\w\-\.]*) --baseurl=.*/latest/repos/.*", + line) + if match: + base_path = [ x for x in base_project.lower().split(':') if x != 'ref' ] + line = line.replace('/latest/', '/%s/' % ('-'.join(base_path[0:-1]) + '_' + base_path[-1])) - new_ks_lines.append(line) + new_ks_lines.append(line) new_ks_lines.insert(new_ks_lines.index('%packages')-1, repo_line) # Update the ks files in imagedata @@ -268,13 +279,22 @@ def make_repo(project, repo, backenddb, base_url, base_path, imagedatas[repo['Name']] = repomaker.imagedata repos.update(repomaker.repos) - # Update ks files - if os.getenv("REF_USE_FOR_PRERELEASE","0") == "1" and basebuildid: - images_ks = update_ks(repomaker.imagedata, prerelease.snap_buildid, - prerelease.pkg_urls(repo['Name']), - base_project) + if 'basechecker' in project: + if os.getenv("REF_USE_FOR_PRERELEASE","0") == "1" and basebuildid: + images_ks = update_ks(repomaker.imagedata, prerelease.snap_buildid, + prerelease.pkg_urls(repo['Name']), + base_project, exclude_ref_repo=True) + else: + images_ks = update_ks(repomaker.imagedata, snapshot.build_id, + prerelease.pkg_urls(repo['Name']), exclude_ref_repo=True) else: - images_ks = update_ks(repomaker.imagedata, snapshot.build_id, + # Update ks files + if os.getenv("REF_USE_FOR_PRERELEASE","0") == "1" and basebuildid: + images_ks = update_ks(repomaker.imagedata, prerelease.snap_buildid, + prerelease.pkg_urls(repo['Name']), + base_project) + else: + images_ks = update_ks(repomaker.imagedata, snapshot.build_id, prerelease.pkg_urls(repo['Name'])) -- 2.7.4