def check_sudo_status_with_retry()

in src/core/src/bootstrap/Bootstrapper.py [0:0]


    def check_sudo_status_with_retry(self, raise_if_not_sudo=True):
        # type:(bool) -> any
        """ retry to invoke sudo check """
        for attempts in range(1, Constants.MAX_CHECK_SUDO_RETRY_COUNT + 1):
            try:
                sudo_status = self.check_sudo_status(raise_if_not_sudo=raise_if_not_sudo)

                if sudo_status and attempts > 1:
                    self.composite_logger.log_debug("Sudo Check Successfully [RetryCount={0}][MaxRetryCount={1}]".format(str(attempts), Constants.MAX_CHECK_SUDO_RETRY_COUNT))
                    return sudo_status

                elif sudo_status is None or sudo_status is False:
                    if attempts < Constants.MAX_CHECK_SUDO_RETRY_COUNT:
                        self.composite_logger.log_debug("Retrying sudo status check after a delay of [ElapsedTimeInSeconds={0}][RetryCount={1}]".format(Constants.MAX_CHECK_SUDO_INTERVAL_IN_SEC, str(attempts)))
                        time.sleep(Constants.MAX_CHECK_SUDO_INTERVAL_IN_SEC)
                        continue

                    elif attempts >= Constants.MAX_CHECK_SUDO_RETRY_COUNT:
                        raise

            except Exception as exception:
                if attempts >= Constants.MAX_CHECK_SUDO_RETRY_COUNT:
                    self.composite_logger.log_error("Customer environment error (sudo failure). [Exception={0}][MaxRetryCount={1}]".format(str(exception), str(attempts)))
                    if raise_if_not_sudo:
                        raise
                self.composite_logger.log_debug("Retrying sudo status check after a delay of [ElapsedTimeInSeconds={0}][RetryCount={1}]".format(Constants.MAX_CHECK_SUDO_INTERVAL_IN_SEC, str(attempts)))
                time.sleep(Constants.MAX_CHECK_SUDO_INTERVAL_IN_SEC)