Missing part for reference build 65/131265/1
authorhyokeun <hyokeun.jeon@samsung.com>
Fri, 26 May 2017 05:21:15 +0000 (14:21 +0900)
committerhyokeun <hyokeun.jeon@samsung.com>
Fri, 26 May 2017 05:21:15 +0000 (14:21 +0900)
Change-Id: I5b56726883cef842c18d8f119b8504fe28de42a1

common/snapshot.py
job_pre_release_obs.py
job_submit.py

index dee3766..f0d10fa 100644 (file)
@@ -35,21 +35,37 @@ class SnapshotError(Exception):
 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):
@@ -153,9 +169,9 @@ class Snapshot(object):
             # 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.
index 75e043c..9fe11cc 100755 (executable)
@@ -40,7 +40,7 @@ class LocalError(Exception):
     """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
@@ -71,6 +71,18 @@ def update_ks(imagedata, snapshot_id, pkg_urls):
                                  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)
@@ -132,6 +144,8 @@ def make_repo(project, repo, backenddb, base_url, base_path,
         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'):
@@ -140,19 +154,30 @@ def make_repo(project, repo, backenddb, base_url, base_path,
         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))
 
@@ -175,6 +200,8 @@ def make_repo(project, repo, backenddb, base_url, base_path,
                                        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
@@ -188,9 +215,6 @@ def make_repo(project, repo, backenddb, base_url, base_path,
         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():
@@ -217,7 +241,7 @@ def make_repo(project, repo, backenddb, base_url, base_path,
 
                 #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:
@@ -227,9 +251,19 @@ def make_repo(project, repo, backenddb, base_url, base_path,
         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:
index bd6bbb3..6d7d27a 100755 (executable)
@@ -377,6 +377,18 @@ def create_related_packages(build, obs_target_prj, obs_pre_prj, pre_package):
                 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."""
@@ -390,7 +402,8 @@ def create_project(git_url, git_project, git_tag, git_revision, 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: