1) Retry create_project(...) three times if it faild. 61/70861/1
authorYonghee Han <onstudy@samsung.com>
Mon, 23 May 2016 05:44:23 +0000 (14:44 +0900)
committerYonghee Han <onstudy@samsung.com>
Mon, 23 May 2016 05:44:23 +0000 (14:44 +0900)
2) Merge person list then send meta update request only once. (instead of sending multiple requests)
Tested : Retry routine check OK.
Tested : Update meta for person check OK.

Change-Id: I7646b57dee077d3a2b2def4c0ef36e81c8eef04b

common/buildservice.py
job_submit.py

index 779157f..6bbecca 100755 (executable)
@@ -809,7 +809,6 @@ class BuildService(OSC):
 
         u = core.makeurl(self.apiurl, ['source', prj], query=query)
         try:
-            print u
             f = core.http_POST(u)
         except urllib2.HTTPError, e:
             e.osc_msg = 'could not trigger disable build flag for project \'%s\'' % (prj)
@@ -828,10 +827,38 @@ class BuildService(OSC):
 
         u = core.makeurl(self.apiurl, ['source', prj], query=query)
         try:
-            print u
             f = core.http_POST(u)
         except urllib2.HTTPError, e:
             e.osc_msg = 'could not trigger default build flag for project \'%s\'' % (prj)
             raise
         return
 
+    def addPerson(self, prj, users):
+        """
+        add persons to a project
+        users = {'userid': ['maintainer', 'bugowner', ...], ...}
+        """
+
+        path = core.quote_plus(prj),
+        kind = 'prj'
+        data = core.meta_exists(metatype=kind,
+                                path_args=path,
+                                template_args=None,
+                                create_new=False)
+        if not data:
+            return
+
+        root = ElementTree.fromstring(''.join(data))
+        for user in users:
+            for role in users[user]:
+                found = False
+                for person in root.getiterator('person'):
+                    if person.get('userid') == user and person.get('role') == role:
+                        found = True
+                        break
+                if not found:
+                    root.insert(2, ElementTree.Element('person', role=role, userid=user))
+        core.edit_meta(metatype=kind,
+                       path_args=path,
+                       data=ElementTree.tostring(root))
+
index 4d16c13..d4ede1c 100755 (executable)
@@ -28,6 +28,7 @@ import base64
 import re
 import xml.etree.cElementTree as ElementTree
 from xml.sax.saxutils import escape
+from time import sleep
 
 from osc import core
 from gitbuildsys.errors import ObsError
@@ -90,10 +91,15 @@ def copy_person_project_meta(build, obs_target_prj, obs_project):
     src_meta_xml = build.get_meta(obs_target_prj)
     src_xml_root = ElementTree.fromstringlist(src_meta_xml)
     # get peron list from obs_target_prj meta
+    person_dict = {}
     for person in src_xml_root.findall('person'):
-        # add person to prerelease project
-        core.addPerson(build.apiurl, obs_project, None, person.get('userid'),
-                       person.get('role'))
+        if person.get('userid') in person_dict:
+            person_dict[person.get('userid')].append(person.get('role'))
+        else:
+            person_dict[person.get('userid')] = [person.get('role')]
+    # add person to prerelease project
+    if person_dict:
+        build.addPerson(obs_project, person_dict)
 
 def create_related_packages(build, obs_target_prj, obs_pre_prj, pre_package):
     """create the 'link' package that relate the original package
@@ -254,15 +260,27 @@ def main(build_type):
                     submitter = gerrit_account_name
                     if gerrit_account_email:
                         submitter += ' <%s>' % gerrit_account_email
-                create_project(url, gerrit_project, git_tag, gerrit_newrev,
-                        build, obs_target_prj, project, submitter, package)
-                if pub_enabled:
-                    rest.publish_event("pre_created", {
-                        "project": project,
-                        "tag": git_tag,
-                        "product": obs_target_prj,
-                        "gitpath": gerrit_project,
-                        })
+                retry_count = 3
+                while retry_count > 0:
+                    try:
+                        create_project(url, gerrit_project, git_tag, gerrit_newrev,
+                                build, obs_target_prj, project, submitter, package)
+                        if pub_enabled:
+                            rest.publish_event("pre_created", {
+                                "project": project,
+                                "tag": git_tag,
+                                "product": obs_target_prj,
+                                "gitpath": gerrit_project,
+                                })
+                        break
+                    except Exception, err:
+                        print 'obs operation failed, retrying...'
+                        print err
+                        sleep(5)
+                        retry_count -= 1
+                if not retry_count:
+                    print 'retrying failed'
+                    return 1
         elif build_type == 'snapshot':
             if not is_ref_deleted(gerrit_oldrev, gerrit_newrev):
                 if build.exists(obs_target_prj):