Пример #1
0
def GetStatus(connection, status):
    """Get the status variable from the database, retrying on failure.

  @param connection: MySQLdb cursor to query with.
  @param status: Name of the status variable.
  @returns The mysql query result.
  """
    def _GetStatusWithoutRetry(connection, s):
        """Gets the status variable from the database."""
        connection.cursor.execute('SHOW GLOBAL STATUS LIKE "%s";' % s)
        output = connection.cursor.fetchone()[1]

        if not output:
            logging.error('Cannot find any global status like %s', s)
        return int(output)

    get_status = retry.retry(
        MySQLdb.OperationalError,
        delay_sec=GET_STATUS_SLEEP_SECONDS,
        timeout_min=GET_STATUS_MAX_TIMEOUT_SECONDS,
        callback=connection.Reconnect)(_GetStatusWithoutRetry)

    return get_status(connection, status)
Пример #2
0
from autotest_lib.client.cros.graphics import graphics_utils
from autotest_lib.client.cros.multimedia import facade_resource
from autotest_lib.client.cros.multimedia import image_generator
from telemetry.internal.browser import web_contents


class TimeoutException(Exception):
    """Timeout Exception class."""
    pass


_FLAKY_CALL_RETRY_TIMEOUT_SEC = 60
_FLAKY_DISPLAY_CALL_RETRY_DELAY_SEC = 2

_retry_display_call = retry.retry(
    (KeyError, error.CmdError),
    timeout_min=_FLAKY_CALL_RETRY_TIMEOUT_SEC / 60.0,
    delay_sec=_FLAKY_DISPLAY_CALL_RETRY_DELAY_SEC)


class DisplayFacadeNative(object):
    """Facade to access the display-related functionality.

    The methods inside this class only accept Python native types.
    """

    CALIBRATION_IMAGE_PATH = '/tmp/calibration.svg'
    MINIMUM_REFRESH_RATE_EXPECTED = 25.0
    DELAY_TIME = 3

    def __init__(self, resource):
        """Initializes a DisplayFacadeNative.
Пример #3
0
"""A module providing common resources for different facades."""

import exceptions
import logging
import time

from autotest_lib.client.bin import utils
from autotest_lib.client.common_lib.cros import chrome
from autotest_lib.client.common_lib.cros import retry
from autotest_lib.client.cros import constants

_FLAKY_CALL_RETRY_TIMEOUT_SEC = 60
_FLAKY_CHROME_CALL_RETRY_DELAY_SEC = 1

retry_chrome_call = retry.retry(
    (chrome.Error, exceptions.IndexError, exceptions.Exception),
    timeout_min=_FLAKY_CALL_RETRY_TIMEOUT_SEC / 60.0,
    delay_sec=_FLAKY_CHROME_CALL_RETRY_DELAY_SEC)


class FacadeResoureError(Exception):
    """Error in FacadeResource."""
    pass


_FLAKY_CHROME_START_RETRY_TIMEOUT_SEC = 120
_FLAKY_CHROME_START_RETRY_DELAY_SEC = 10

# Telemetry sometimes fails to start Chrome.
retry_start_chrome = retry.retry(
    (Exception, ),
    timeout_min=_FLAKY_CHROME_START_RETRY_TIMEOUT_SEC / 60.0,
# Copyright 2015 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""A module providing common resources for different facades."""

import exceptions

from autotest_lib.client.common_lib.cros import chrome
from autotest_lib.client.common_lib.cros import retry
from autotest_lib.client.cros import constants

_FLAKY_CALL_RETRY_TIMEOUT_SEC = 60
_FLAKY_CHROME_CALL_RETRY_DELAY_SEC = 1

retry_chrome_call = retry.retry(
    (chrome.Error, exceptions.IndexError, exceptions.Exception),
    timeout_min=_FLAKY_CALL_RETRY_TIMEOUT_SEC / 60.0,
    delay_sec=_FLAKY_CHROME_CALL_RETRY_DELAY_SEC)


class FacadeResource(object):
    """This class provides access to telemetry chrome wrapper."""

    EXTRA_BROWSER_ARGS = ['--enable-gpu-benchmarking']

    def __init__(self, chrome_object=None, restart=False):
        """Initializes a FacadeResource.

        @param chrome_object: A chrome.Chrome object or None.
        @param restart: Preserve the previous browser state.

        """
 def RetryWith(self, func):
     """Run a function, retrying on OperationalError."""
     return retry.retry(MySQLdb.OperationalError,
                        delay_sec=self.INITIAL_SLEEP_SECONDS,
                        timeout_min=self.MAX_TIMEOUT_SECONDS,
                        callback=self.Reconnect)(func)()