class Prerelease(object):
"""Handle prerelease meta data."""
- def __init__(self, snapshot, base_url, tstamp):
+ def __init__(self, snapshot, base_url, tstamp, buildid=None):
self.snapshot = snapshot
self.base_url = base_url
self.tstamp = tstamp
+ if buildid:
+ self.buildid = buildid
+ self.snap_buildid = '%s_%s' % (self.snapshot.repo['Release'], self.buildid)
+ else:
+ self.buildid = None
+ self.snap_buildid = None
@property
def build_id(self):
"""Prerelease build id."""
- return '%s.%s' % (self.snapshot.build_id, self.tstamp)
+ if self.buildid:
+ return '%s_%s.%s' % (self.snapshot.repo['Release'], self.buildid, self.tstamp)
+ else:
+ return '%s.%s' % (self.snapshot.build_id, self.tstamp)
@property
def dir(self):
"""Prerelease directory."""
- return os.path.join(self.snapshot.repo['PrereleaseDir'],
- self.snapshot.build_id)
+ if self.snapshot.repo['PrereleaseDir']:
+ if self.snap_buildid:
+ return os.path.join(self.snapshot.repo['PrereleaseDir'],
+ self.snap_buildid)
+ else:
+ return os.path.join(self.snapshot.repo['PrereleaseDir'],
+ self.snapshot.build_id)
+ else:
+ return False
@property
def path(self):
# datetime changed - set number to 1
self.release_id = '%s.1' % cdtime
- def get_prerelease(self, base_url, tstamp):
+ def get_prerelease(self, base_url, tstamp, buildid=None):
"""Factory for Prerelease object."""
- return Prerelease(self, base_url, tstamp)
+ return Prerelease(self, base_url, tstamp, buildid)
def snapshot_project_enabled(backenddb, obs_project):
"""Check if project is enabled for OBS project.
"""Local error exception."""
pass
-def update_ks(imagedata, snapshot_id, pkg_urls):
+def update_ks(imagedata, snapshot_id, pkg_urls, base_project=None):
"""
update the repo url point to right URL and add prerelease repo
url with highest priority
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/.*",
+ 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.insert(new_ks_lines.index('%packages')-1, repo_line)
LocalError if can't create repos or can't find image configurations
"""
images_count = 0
+ repos = {}
+ imagedatas = {}
build_info = build.get_info(project)
if build_info.get('download_num'):
current_download_num = int(1)
print 'Current download_num = %d' % current_download_num
+ # Set obs_target_prj to ref project if it is enabled
+ basebuildid = None
+ base_project = None
+ if os.getenv("REF_CREATE_PRJ_OBS_ENABLE","0") == "1":
+ if ':ref:' in build_info.get('obs_target_prj'):
+ basebuildid = build_info.get('obs_target_prj').split(':ref:')[1]
+ base_project = build_info.get('base', 'latest')
+ print 'BASE PROJECT : %s' % (base_project)
+ print 'basebuildid=%s' % basebuildid
+
# Make build id from latest snapshot + project suffix
target_project, tstamp = get_info_from_prerelease_name(project)
- repos = {}
- imagedatas = {}
-
try:
snapshot = Snapshot(backenddb, base_path, obs_project=target_project)
except SnapshotError, err:
raise LocalError("Error getting snapshot info: %s" % str(err))
try:
- prerelease = snapshot.get_prerelease(base_url, tstamp)
+ # Set obs_target_prj to ref project if it is enabled
+ if os.getenv("REF_CREATE_PRJ_OBS_ENABLE","0") == "1":
+ prerelease = snapshot.get_prerelease(base_url, tstamp, basebuildid)
+ else:
+ prerelease = snapshot.get_prerelease(base_url, tstamp)
except SnapshotError, err:
raise LocalError("Error getting prerelease info: %s" % str(err))
bm_snapshot_name)
for repo in targets:
+ print 'Processing repo:%s' % repo['Name']
+ sys.stdout.flush()
if block:
repos.update({repo['Name']: {'archs': list(set(repo['Architectures']))}})
continue
except RepoMakerError, err:
raise LocalError("Unable to create download repo: %s" % err)
- repos.update(repomaker.repos)
- imagedatas[repo['Name']] = repomaker.imagedata
-
# Assuming that there can be just one image-configurations-
# rpm in the repo
if not repomaker.has_images():
#raise LocalError("Image configuration not found in %s" %
# snapshot.path)
- print "Image configuration not found in %s" %( snapshot.path)
+ print "Image configuration not found in %s, repo:%s" %(snapshot.path, repo['Name'])
continue
for rpm in img_conf_list:
if not repomaker.has_images():
continue
+ # trigger post snapshot creation job with repo data
+ # buildlogs.job
+ imagedatas[repo['Name']] = repomaker.imagedata
+ repos.update(repomaker.repos)
+
# Update ks files
- images_ks = update_ks(repomaker.imagedata, snapshot.build_id,
- prerelease.pkg_urls(repo['Name']))
+ if os.getenv("REF_CREATE_PRJ_OBS_ENABLE","0") == "1":
+ 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']))
if buildmonitor_enabled:
build.create_link_pac(obs_pre_prj, pre_package, \
obs_pre_prj, package)
+def get_base_project(build, _project):
+ _meta = build.get_meta(_project)
+ xml_meta = ElementTree.fromstringlist(_meta)
+ _base_prj = ''
+ for repos in xml_meta.findall('repository'):
+ for path in repos.findall('path'):
+ if 'base' not in path.get('project').lower(): continue
+ print 'Found base project %s for %s' % (path.get('project'), \
+ _project)
+ return path.get('project')
+ return None
+
def create_project(git_url, git_project, git_tag, git_revision, build,
obs_target_prj, obs_project, submitter, package, build_flag=True):
"""Create prerelease OBS project and upload sources for the build."""
'git_commit': git_revision,
'obs_url': os.path.join(os.getenv('OBS_URL_EXTERNAL'), \
'project/show?project=%s' % obs_project),
- 'images': []}
+ 'images': [],
+ 'base': get_base_project(build, obs_target_prj)}
if build.exists(obs_project):
if submitter: