コード例 #1
0
 def test_success(self):
     """
     Given a function that passes, make sure it returns successfully with
     a single retry or greater.
     """
     pass_function = lambda: True
     self.assertTrue(exectools.retry(1, pass_function))
     self.assertTrue(exectools.retry(2, pass_function))
コード例 #2
0
ファイル: rpmcfg.py プロジェクト: sosiouxme/elliott
    def build_rpm(
            self, version, release, terminate_event, scratch=False, retries=3):
        self.set_nvr(version, release)
        self.create_tag(scratch)
        self.tito_setup()
        self.update_spec()
        self.commit_changes()
        action = "build_rpm"
        record = {
            "specfile": self.specfile,
            "source_head": self.source_head,
            "distgit_key": self.distgit_key,
            "rpm": self.rpm_name,
            "version": self.version,
            "release": self.release,
            "message": "Unknown failure",
            "status": -1,
            # Status defaults to failure until explicitly set by succcess. This handles raised exceptions.
        }

        try:
            def wait(n):
                self.logger.info("Async error in rpm build thread [attempt #{}]: {}".format(n + 1, self.qualified_name))
                # Brew does not handle an immediate retry correctly, wait
                # before trying another build, terminating if interrupted.
                if terminate_event.wait(timeout=5 * 60):
                    raise KeyboardInterrupt()
            try:
                exectools.retry(
                    retries=3, wait_f=wait,
                    task_f=lambda: self._build_rpm(
                        scratch, record, terminate_event))
            except exectools.RetryException as err:
                self.logger.error(str(err))
                return False

            record["message"] = "Success"
            record["status"] = 0
            self.build_status = True

        except (Exception, KeyboardInterrupt):
            tb = traceback.format_exc()
            record["message"] = "Exception occurred:\n{}".format(tb)
            self.logger.info("Exception occurred during build:\n{}".format(tb))
            # This is designed to fall through to finally. Since this method is designed to be
            # threaded, we should not throw an exception; instead return False.
        finally:
            self.runtime.add_record(action, **record)

        if self.build_status and not scratch:
            try:
                self.push_tag()
            except Exception:
                raise RuntimeError('Build succeeded but failure pushing RPM tag for {}'.format(self.qualified_name))

        return self.build_status
コード例 #3
0
 def test_return(self):
     """
     Verify that the retry task return value is passed back out faithfully.
     """
     obj = {}
     func = lambda: obj
     self.assertIs(exectools.retry(1, func, check_f=lambda _: True), obj)
コード例 #4
0
ファイル: metadata.py プロジェクト: joeldavis84/elliott
 def fetch_cgit_file(self, filename):
     url = self.cgit_url(filename)
     req = exectools.retry(
         3, lambda: urllib.urlopen(url),
         check_f=lambda req: req.code == 200)
     return req.read()
コード例 #5
0
    def build_rpm(self,
                  version,
                  release,
                  terminate_event,
                  scratch=False,
                  retries=3):
        """
        Builds a package using tito release.

        If the source repository has the necessary tito configuration in .tito, the build can be
        configured to use that in the standard `tito tag` flow.

        The default flow imitates `tito tag`, but instead of creating a release commit and tagging that,
        the tag is added to the existing commit and a release commit is created afterward. In
        this way, the tag can be pushed back to the source, but pushing the commit is optional.
        [lmeyer 2019-04-01] I looked into customizing the tito tagger to support this flow.
        It was not going to be pretty, and even so would probably require doozer to do
        some modification of the spec first. It seems best to limit the craziness to doozer.

        By default, the tag is pushed, then it and the commit are removed locally after the build.
        But optionally the commit can be pushed before the build, so that the actual commit released is in the source.
	"""
        self.set_nvr(version, release)
        self.tito_setup()
        self.update_spec()
        self.commit_changes(scratch)
        action = "build_rpm"
        record = {
            "specfile": self.specfile,
            "source_head": self.source_head,
            "distgit_key": self.distgit_key,
            "rpm": self.rpm_name,
            "version": self.version,
            "release": self.release,
            "message": "Unknown failure",
            "status": -1,
            # Status defaults to failure until explicitly set by succcess. This handles raised exceptions.
        }

        try:

            def wait(n):
                self.logger.info(
                    "Async error in rpm build thread [attempt #{}]: {}".format(
                        n + 1, self.qualified_name))
                # Brew does not handle an immediate retry correctly, wait
                # before trying another build, terminating if interrupted.
                if terminate_event.wait(timeout=5 * 60):
                    raise KeyboardInterrupt()

            try:
                exectools.retry(retries=3,
                                wait_f=wait,
                                task_f=lambda: self._build_rpm(
                                    scratch, record, terminate_event))
            except exectools.RetryException as err:
                self.logger.error(str(err))
                return (self.distgit_key, False)

            record["message"] = "Success"
            record["status"] = 0
            self.build_status = True

        except (Exception, KeyboardInterrupt):
            tb = traceback.format_exc()
            record["message"] = "Exception occurred:\n{}".format(tb)
            self.logger.info("Exception occurred during build:\n{}".format(tb))
            # This is designed to fall through to finally. Since this method is designed to be
            # threaded, we should not throw an exception; instead return False.
        finally:
            self.runtime.add_record(action, **record)

        self.post_build(scratch)

        return (self.distgit_key, self.build_status)