Changeset 258611 in webkit


Ignore:
Timestamp:
Mar 17, 2020 5:01:42 PM (4 years ago)
Author:
aakash_jain@apple.com
Message:

[ews] Resubmit patches to commit-queue which were cq- by commit-queue and later cq+
https://bugs.webkit.org/show_bug.cgi?id=208920

Reviewed by Jonathan Bedard.

  • BuildSlaveSupport/ews-app/ews/common/buildbot.py:

(Buildbot.update_builder_name_to_id_mapping): Method to generate builder name to id mapping.
(Buildbot.fetch_pending_and_inprogress_builds): Method to fetch pendign and in-progress builds from buildbot.
(Buildbot.get_patches_in_queue): Method to fetch list of patches which are pending or are in-progress on buildbot.

  • BuildSlaveSupport/ews-app/ews/common/bugzilla.py:

(Bugzilla.get_cq_plus_timestamp): Get UTC timestamp when cq+ flag was set.

  • BuildSlaveSupport/ews-app/ews/fetcher.py:

(FetchLoop.run): Update builder name to id mapping. We just need to update it one-time, since we need the id only
for commit-queue which isn't expected to change.
(BugzillaPatchFetcher.fetch_commit_queue_patches):
(BugzillaPatchFetcher.send_patches_to_buildbot): Allow sending the patch again to commit-queue.
(BugzillaPatchFetcher.patches_to_send_to_commit_queue): Find patches which needs to be sent to commit-queue. Filter
out patches which are already waiting or in-progress on commit-queue, or whose recent build was completed after
setting cq+ flag on bugzilla.

Location:
trunk/Tools
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/BuildSlaveSupport/ews-app/ews/common/bugzilla.py

    r258407 r258611  
    3434import ews.common.util as util
    3535import ews.config as config
     36import dateutil.parser
    3637
    3738_log = logging.getLogger(__name__)
     
    5051        attachment_json['path'] = Bugzilla.file_path_for_patch(attachment_id)
    5152        return attachment_json
     53
     54    @classmethod
     55    def get_cq_plus_timestamp(cls, attachment_id):
     56        attachment_json = Bugzilla._fetch_attachment_json(attachment_id)
     57        if not attachment_json:
     58            _log.warn('Unable to fetch attachment {}.'.format(attachment_id))
     59            return None
     60
     61        for flag in attachment_json.get('flags'):
     62            if flag.get('name') == 'commit-queue' and flag.get('status') == '+':
     63                try:
     64                    return dateutil.parser.parse(flag.get('modification_date'))
     65                except:
     66                    _log.error('Unable to parse timestamp: {}'.format(flag.get('modification_date')))
     67        return None
    5268
    5369    @classmethod
  • trunk/Tools/BuildSlaveSupport/ews-app/ews/common/buildbot.py

    r255269 r258611  
    4040    SUCCESS, WARNINGS, FAILURE, SKIPPED, EXCEPTION, RETRY, CANCELLED = ALL_RESULTS
    4141    icons_for_queues_mapping = {}
     42    builder_name_to_id_mapping = {}
    4243
    4344    @classmethod
     
    100101            Buildbot.icons_for_queues_mapping[shortname] = builder.get('icon')
    101102
    102         return Buildbot.icons_for_queues_mapping
     103    @classmethod
     104    def update_builder_name_to_id_mapping(cls):
     105        url = 'https://{}/api/v2/builders'.format(config.BUILDBOT_SERVER_HOST)
     106        builders_data = util.fetch_data_from_url(url)
     107        if not builders_data:
     108            return
     109        for builder in builders_data.json().get('builders', []):
     110            name = builder.get('name')
     111            Buildbot.builder_name_to_id_mapping[name] = builder.get('builderid')
     112
     113    @classmethod
     114    def fetch_pending_and_inprogress_builds(cls, builder_full_name):
     115        builderid = Buildbot.builder_name_to_id_mapping.get(builder_full_name)
     116        if not builderid:
     117            _log.error('Invalid builder: {}'.format(builder_full_name))
     118            return {}
     119        url = 'https://{}/api/v2/builders/{}/buildrequests?complete=false&property=*'.format(config.BUILDBOT_SERVER_HOST, builderid)
     120        builders_data = util.fetch_data_from_url(url)
     121        if not builders_data:
     122            return {}
     123        return builders_data.json()
     124
     125    @classmethod
     126    def get_patches_in_queue(cls, builder_full_name):
     127        patch_ids = []
     128        builds = cls.fetch_pending_and_inprogress_builds(builder_full_name)
     129        for buildrequest in builds.get('buildrequests', []):
     130            properties = buildrequest.get('properties')
     131            if properties:
     132                patch_ids.append(properties.get('patch_id')[0])
     133        _log.debug('Patches in queue for {}: {}'.format(builder_full_name, patch_ids))
     134        return patch_ids
    103135
    104136    @classmethod
  • trunk/Tools/BuildSlaveSupport/ews-app/ews/fetcher.py

    r255269 r258611  
    2121# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2222
     23import datetime
    2324import logging
     25import pytz
    2426import threading
    2527import time
     
    2830from ews.common.buildbot import Buildbot
    2931from ews.models.patch import Patch
     32from ews.views.statusbubble import StatusBubble
    3033
    3134_log = logging.getLogger(__name__)
     
    4043
    4144    def run(self):
     45        Buildbot.update_builder_name_to_id_mapping()
    4246        while True:
    4347            Buildbot.update_icons_for_queues_mapping()
     
    7074        _log.debug('cq+ patches: {}'.format(patch_ids_commit_queue))
    7175        Patch.save_patches(patch_ids_commit_queue)
    72         patches_to_send = self.patches_to_send_to_buildbot(patch_ids_commit_queue, commit_queue=True)
     76        patches_to_send = self.patches_to_send_to_commit_queue(patch_ids_commit_queue)
    7377        _log.info('{} cq+ patches, {} patches need to be sent to commit queue: {}'.format(len(patch_ids_commit_queue), len(patches_to_send), patches_to_send))
    7478        self.send_patches_to_buildbot(patches_to_send, send_to_commit_queue=True)
     
    8690                Patch.set_obsolete(patch_id)
    8791                continue
    88             if Patch.is_patch_sent_to_buildbot(patch_id, commit_queue=send_to_commit_queue):
    89                 _log.error('Patch {} is already sent to buildbot/commit-queue.'.format(patch_id))
     92            if not send_to_commit_queue and Patch.is_patch_sent_to_buildbot(patch_id):
     93                _log.error('Patch {} is already sent to buildbot.'.format(patch_id))
    9094                continue
    9195            Patch.set_sent_to_buildbot(patch_id, True, commit_queue=send_to_commit_queue)
     
    100104                #FIXME: send an email for this failure
    101105
    102     def patches_to_send_to_buildbot(self, patch_ids, commit_queue=False):
    103         return [patch_id for patch_id in patch_ids if not Patch.is_patch_sent_to_buildbot(patch_id, commit_queue)]
     106    def patches_to_send_to_buildbot(self, patch_ids):
     107        return [patch_id for patch_id in patch_ids if not Patch.is_patch_sent_to_buildbot(patch_id)]
     108
     109    def patches_to_send_to_commit_queue(self, patch_ids):
     110        if not patch_ids:
     111            return patch_ids
     112        patches_in_queue = set(Buildbot.get_patches_in_queue('Commit-Queue'))
     113        patch_ids = [patch_id for patch_id in set(patch_ids) if str(patch_id) not in patches_in_queue]
     114
     115        patch_ids_to_send = []
     116        for patch_id in patch_ids:
     117            patch = Patch.get_patch(patch_id)
     118            recent_build, _ = StatusBubble().get_latest_build_for_queue(patch, 'commit')
     119            if not recent_build:
     120                patch_ids_to_send.append(patch_id)
     121                continue
     122            recent_build_timestamp = datetime.datetime.fromtimestamp(recent_build.complete_at, tz=pytz.UTC)
     123            cq_timestamp = Bugzilla.get_cq_plus_timestamp(patch_id)
     124            if not cq_timestamp:
     125                patch_ids_to_send.append(patch_id)
     126                continue
     127            if cq_timestamp > recent_build_timestamp:
     128                patch_ids_to_send.append(patch_id)
     129        return patch_ids_to_send
    104130
    105131    @classmethod
  • trunk/Tools/ChangeLog

    r258598 r258611  
     12020-03-17  Aakash Jain  <aakash_jain@apple.com>
     2
     3        [ews] Resubmit patches to commit-queue which were cq- by commit-queue and later cq+
     4        https://bugs.webkit.org/show_bug.cgi?id=208920
     5
     6        Reviewed by Jonathan Bedard.
     7
     8        * BuildSlaveSupport/ews-app/ews/common/buildbot.py:
     9        (Buildbot.update_builder_name_to_id_mapping): Method to generate builder name to id mapping.
     10        (Buildbot.fetch_pending_and_inprogress_builds): Method to fetch pendign and in-progress builds from buildbot.
     11        (Buildbot.get_patches_in_queue): Method to fetch list of patches which are pending or are in-progress on buildbot.
     12        * BuildSlaveSupport/ews-app/ews/common/bugzilla.py:
     13        (Bugzilla.get_cq_plus_timestamp): Get UTC timestamp when cq+ flag was set.
     14        * BuildSlaveSupport/ews-app/ews/fetcher.py:
     15        (FetchLoop.run): Update builder name to id mapping. We just need to update it one-time, since we need the id only
     16        for commit-queue which isn't expected to change.
     17        (BugzillaPatchFetcher.fetch_commit_queue_patches):
     18        (BugzillaPatchFetcher.send_patches_to_buildbot): Allow sending the patch again to commit-queue.
     19        (BugzillaPatchFetcher.patches_to_send_to_commit_queue): Find patches which needs to be sent to commit-queue. Filter
     20        out patches which are already waiting or in-progress on commit-queue, or whose recent build was completed after
     21        setting cq+ flag on bugzilla.
     22
    1232020-03-17  Chris Dumez  <cdumez@apple.com>
    224
Note: See TracChangeset for help on using the changeset viewer.