[RBS] Handling multiple tools repositories for the same project
authorhyokeun <hyokeun.jeon@samsung.com>
Tue, 7 Aug 2018 01:57:27 +0000 (10:57 +0900)
committerYonghee Han <onstudy@samsung.com>
Thu, 31 Jan 2019 01:21:23 +0000 (10:21 +0900)
Change-Id: I5c1bf2e7ad7e6cab3b1afc5849d6a37f6231536e

job_create_sdkrootstrap.py

index aed3bf9..dfbc6ee 100755 (executable)
@@ -58,6 +58,8 @@ class LocalError(Exception):
 def setup_profile(project):
     """ Setup profile """
 
+    profile_list = []
+
     if os.getenv('RBS_PROFILES'):
         profiles = ast.literal_eval(os.getenv('RBS_PROFILES'))
     else:
@@ -68,9 +70,10 @@ def setup_profile(project):
         if project == l['project']:
             profile = l
             print 'project = %s' % (project)
-            return profile
+            #return profile
+            profile_list.append(profile)
 
-    return False
+    return profile_list
 
 def send_mail(title, msg, receiver):
     """ post message back to gerrit and send mail to tag owner """
@@ -479,72 +482,74 @@ def main():
             print 'Error: TRIGGER_INFO doesn\'t contain %s' % field
             return -1
     
-    profile = setup_profile(fields['project'])
-    if not profile:
-        print 'Skip TRIGGER job for the project %s' % fields['project']
-        return 0
-
-    vm_image = os.getenv("RBS_VM_IMAGE")
-
-    if not vm_image:
-       print 'VM not vm_image'
-       return -1
+    profile_list = setup_profile(fields['project'])
 
-    if not os.access(vm_image, os.R_OK):
-       print 'VM not access'
-       return -1
+    for profile in profile_list:
+        if not profile:
+            print 'Skip TRIGGER job for the project %s' % fields['project']
+            return 0
 
-    # check if tarball exists
-    if not vm_image or not os.access(vm_image, os.R_OK):
-        print 'VM image %s is not found' % vm_image
-        return -1
+        vm_image = os.getenv("RBS_VM_IMAGE")
 
-    # clone git sdk-image
-    git_prj = profile['git_rs_prj']
+        if not vm_image:
+           print 'VM not vm_image'
+           return -1
 
-    git_cache = os.getenv("GIT_CACHE_DIR")
-    print 'Cloning %s' % git_prj
-    if not clone_gitproject(git_prj, \
-            os.path.join(git_cache, git_prj)):
-        raise LocalError('Error cloning %s' % git_prj)
+        if not os.access(vm_image, os.R_OK):
+           print 'VM not access'
+           return -1
 
-    mygit = Git(os.path.join(git_cache, git_prj))
+        # check if tarball exists
+        if not vm_image or not os.access(vm_image, os.R_OK):
+            print 'VM image %s is not found' % vm_image
+            return -1
 
-    status = 'succeeded'
-    reason = 'ok'
-    #### Make Rootstrap Snapshot (PRIVATE)####
-    status = make_rs_snapshot_private(git_prj, git_cache, mygit, fields, profile, vm_image)
+        # clone git sdk-image
+        git_prj = profile['git_rs_prj']
 
-    if status == 'succeeded':
-        print "The RBS(Internal) build was successful."
-    else:
-        print "The RBS(Internal) build was failed."
-        reason = 'RBS build fail'
+        git_cache = os.getenv("GIT_CACHE_DIR")
+        print 'Cloning %s' % git_prj
+        if not clone_gitproject(git_prj, \
+                os.path.join(git_cache, git_prj)):
+            raise LocalError('Error cloning %s' % git_prj)
 
-    try:
-        update_dashboard(fields['project'], \
-                         fields['build_id'].split('_')[-1], 
-                         status, reason,
-                         fields.get('infra', 'LOCAL')
-                         )
-    except Exception as err:
-        print repr(err)
+        mygit = Git(os.path.join(git_cache, git_prj))
 
-    status = 'succeeded'
-    #### Make Rootstrap Snapshot (PUBLIC)####
-    status = make_rs_snapshot_public(git_prj, git_cache, mygit, fields, profile, vm_image)
+        status = 'succeeded'
+        reason = 'ok'
+        #### Make Rootstrap Snapshot (PRIVATE)####
+        status = make_rs_snapshot_private(git_prj, git_cache, mygit, fields, profile, vm_image)
 
-    #### Misc public rootstraps ####
-    if profile.get('misc_branches'):
-        for mb in profile.get('misc_branches'):
-            status_1 = make_rs_snapshot_public(git_prj, git_cache, mygit, fields, profile, vm_image, specific_branch=mb)
-            if status_1 != 'succeeded':
-                status = status_1
+        if status == 'succeeded':
+            print "The RBS(Internal) build was successful."
+        else:
+            print "The RBS(Internal) build was failed."
+            reason = 'RBS build fail'
 
-    if status == 'succeeded':
-        print "The RBS(Public) build was successful."
-    else:
-        print "The RBS(Public) build was failed."
+        try:
+            update_dashboard(fields['project'], \
+                             fields['build_id'].split('_')[-1], 
+                             status, reason,
+                             fields.get('infra', 'LOCAL')
+                             )
+        except Exception as err:
+            print repr(err)
+
+        status = 'succeeded'
+        #### Make Rootstrap Snapshot (PUBLIC)####
+        status = make_rs_snapshot_public(git_prj, git_cache, mygit, fields, profile, vm_image)
+
+        #### Misc public rootstraps ####
+        if profile.get('misc_branches'):
+            for mb in profile.get('misc_branches'):
+                status_1 = make_rs_snapshot_public(git_prj, git_cache, mygit, fields, profile, vm_image, specific_branch=mb)
+                if status_1 != 'succeeded':
+                    status = status_1
+
+        if status == 'succeeded':
+            print "The RBS(Public) build was successful."
+        else:
+            print "The RBS(Public) build was failed."
 
     return 0