Ejemplo n.º 1
0
def main(argv):

    if (len(argv) < 3):
        print "usage: installWatcher.py <ip address> <localfilename>"
        sys.exit(1)

    ip_addr = argv[1]
    path_to_main_apk = argv[2]

    dm = droid.DroidSUT(ip_addr)
    if not dm:
        log.error("could not get device manager!")
        return 1
    devRoot = checkDeviceRoot(dm)

    if install(dm, devRoot, path_to_main_apk, "com.mozilla.watcher"):
        log.error("install failed")
        return 1

    dm.reboot()
    waitForDevice(dm)

    # we can't use the following dm.getFile method, since only Watcher runtime user has read access
    # to this file, so we need to be root to read it, hence the slightly more convoluted version
    # using dm._runCmds below...
    # cannot use -> print dm.getFile('/data/data/com.mozilla.watcher/files/version.txt')
    status = dm._runCmds([{
        'cmd':
        'exec su -c "cat /data/data/com.mozilla.watcher/files/version.txt"'
    }]).split('\n')
    log.info('Watcher version: %s' % status)
    return 0
Ejemplo n.º 2
0
def isMozpoolReady(device):
    """ Checks if the mozpool server is available and the device is in 'ready' state

    Returns MOZPOOL_STATE_READY if Mozpool is indeed listing device as ready
    Returns MOZPOOL_STATE_UNKNOWN if Mozpool claims the device is in a non-ready state
    Returns MOZPOOL_STATE_ERROR if Mozpool reports some other error.
    Returns MOZPOOL_STATE_MISSING if there is no Mozpool server found in DNS.
    """
    import socket
    default_timeout = socket.getdefaulttimeout()
    socket.setdefaulttimeout(5)  # Don't let networking delay us too long
    try:
        socket.gethostbyname(MOZPOOL_CNAME)
    except:
        log.info("No mozpool server in this VLAN")
        return MOZPOOL_STATE_MISSING
    finally:
        # Set socket timeout back
        socket.setdefaulttimeout(default_timeout)

    mpc = MozpoolHandler("http://%s" % MOZPOOL_CNAME, log)
    try:
        result = mpc.query_device_state(device)
    except MozpoolException as e:
        log.error("Unable to get mozpool state, mozpool returned error: %s" %
                  sys.exc_info()[1])
        return MOZPOOL_STATE_ERROR

    if result['state'] == "ready":
        log.debug("Mozpool state is 'ready'")
        return MOZPOOL_STATE_READY
    else:
        log.error("Mozpool state is '%s'" % result['state'])
        return MOZPOOL_STATE_UNKNOWN
Ejemplo n.º 3
0
def canPing(device):
    """ Check a device is reachable by ping

    Returns False on failure, True on Success
    """
    curRetry = 0
    log.info("INFO: attempting to ping device")
    while curRetry < MAX_RETRIES:
        ret, _ = pingDevice(device)
        if not ret:
            curRetry += 1
            if curRetry == MAX_RETRIES:
                setFlag(
                    errorFile,
                    "Automation Error: Unable to ping device after %s attempts"
                    % MAX_RETRIES)
                return False
            else:
                log.info(
                    "INFO: Unable to ping device after %s try. Sleeping for 90s then retrying"
                    % curRetry)
                time.sleep(90)
        else:
            break  # we're done here
    return True
Ejemplo n.º 4
0
def canTelnet(device):
    """ Checks if we can establish a Telnet session (via devicemanager)

    Sets global `dm`
    Returns False on failure, True on Success
    """
    global dm
    curRetry = 0
    sleepDuration = 0
    while curRetry < MAX_RETRIES:
        try:
            dm = connect(device, sleepDuration)
        except:
            curRetry += 1
            if curRetry == MAX_RETRIES:
                setFlag(
                    errorFile,
                    "Automation Error: Unable to connect to device after %s attempts"
                    % MAX_RETRIES)
                return False
            else:
                log.info("INFO: Unable to connect to device after %s try" %
                         curRetry)
                sleepDuration = 90
        else:
            break  # We're done here
    return True
Ejemplo n.º 5
0
def main(argv):

    if (len(argv) < 3):
        print "usage: installWatcher.py <ip address> <localfilename>"
        sys.exit(1)

    ip_addr = argv[1]
    path_to_main_apk = argv[2]

    dm = droid.DroidSUT(ip_addr)
    if not dm:
        log.error("could not get device manager!")
        return 1
    devRoot = checkDeviceRoot(dm)

    if install(dm, devRoot, path_to_main_apk, "com.mozilla.watcher"):
        log.error("install failed")
        return 1

    dm.reboot()
    waitForDevice(dm)

    # we can't use the following dm.getFile method, since only Watcher runtime user has read access
    # to this file, so we need to be root to read it, hence the slightly more convoluted version
    # using dm._runCmds below...
    # cannot use -> print dm.getFile('/data/data/com.mozilla.watcher/files/version.txt')
    status = dm._runCmds([{'cmd': 'exec su -c "cat /data/data/com.mozilla.watcher/files/version.txt"'}]).split('\n')
    log.info('Watcher version: %s' % status)
    return 0
Ejemplo n.º 6
0
def checkSDCard(dm):
    """ Attempt to write a temp file to the SDCard

    We use this existing verify script as the source of the temp file

    Returns False on failure, True on Success
    """
    if not dmAlive(dm):
        return False

    try:
        if not dm.dirExists("/mnt/sdcard"):
            setFlag(errorFile, "Remote Device Error: Mount of sdcard does not seem to exist")
            return False
        if dm.fileExists("/mnt/sdcard/writetest"):
            log.info("INFO: /mnt/sdcard/writetest left over from previous run, cleaning")
            dm.removeFile("/mnt/sdcard/writetest")
        log.info("INFO: attempting to create file /mnt/sdcard/writetest")
        if not dm.pushFile(os.path.join(os.path.abspath(os.path.dirname(__file__)), "verify.py"), "/mnt/sdcard/writetest"):
            setFlag(
                errorFile, "Remote Device Error: unable to write to sdcard")
            return False
        if not dm.fileExists("/mnt/sdcard/writetest"):
            setFlag(errorFile, "Remote Device Error: Written tempfile doesn't exist on inspection")
            return False
        if not dm.removeFile("/mnt/sdcard/writetest"):
            setFlag(errorFile, "Remote Device Error: Unable to cleanup from written tempfile")
            return False
    except Exception, e:
        setFlag(errorFile, "Remote Device Error: Unknown error while testing ability to write to "
                           "sdcard, see following exception: %s" % e)
        return False
Ejemplo n.º 7
0
def main(argv):
    global ip_addr

    if (len(argv) < 4):
        log.info(
            "usage: logcat.py <device ip address> <output filename> <logcat options>"
        )
        return 1
    ip_addr = argv[1]
    output_filename = argv[2]
    logcat_options = argv[3]
    max_runtime = 3600  # 3600 seconds == 1 hour

    status = 0
    dm = devicemanager.DeviceManagerSUT(ip_addr)
    if not dm:
        log.error("logcat.py: unable to open device manager")
        return 2
    command = 'execext su t=%d logcat %s' % (max_runtime, logcat_options)
    log.debug('logcat.py running SUT command: %s' % command)
    try:
        with open(output_filename, 'w') as f:
            dm._sendCmds([{'cmd': command}], f)
    except devicemanager.DMError, e:
        log.error("Remote Device Error: Exception caught running logcat: %s" %
                  str(e))
        status = -1
Ejemplo n.º 8
0
def setWatcherINI(dm):
    """ If necessary Installs the (correct) watcher.ini for our infra

    Returns False on failure, True on Success
    """
    import hashlib
    realLoc = "/data/data/com.mozilla.watcher/files/watcher.ini"
    currentHash = hashlib.md5(watcherINI).hexdigest()

    def watcherDataCurrent():
        remoteFileHash = dm._getRemoteHash(realLoc)
        if currentHash != remoteFileHash:
            return False
        else:
            return True

    if not dmAlive(dm):
        return False

    try:
        if watcherDataCurrent():
            return True
    except:
        setFlag(errorFile, "Unable to identify if watcher.ini is current")
        return False

    tmpname = '/mnt/sdcard/watcher.ini'
    try:
        dm._runCmds([{'cmd': 'push %s %s' % (tmpname, len(
            watcherINI)), 'data': watcherINI}])
    except devicemanager.AgentError, err:
        log.info("Error while pushing watcher.ini: %s" % err)
        setFlag(errorFile, "Unable to properly upload the watcher.ini")
        return False
Ejemplo n.º 9
0
def isMozpoolReady(device):
    """ Checks if the mozpool server is available and the device is in 'ready' state

    Returns MOZPOOL_STATE_READY if Mozpool is indeed listing device as ready
    Returns MOZPOOL_STATE_UNKNOWN if Mozpool claims the device is in a non-ready state
    Returns MOZPOOL_STATE_ERROR if Mozpool reports some other error.
    Returns MOZPOOL_STATE_MISSING if there is no Mozpool server found in DNS.
    """
    import socket
    default_timeout = socket.getdefaulttimeout()
    socket.setdefaulttimeout(5)  # Don't let networking delay us too long
    try:
        socket.gethostbyname(MOZPOOL_CNAME)
    except:
        log.info("No mozpool server in this VLAN")
        return MOZPOOL_STATE_MISSING
    finally:
        # Set socket timeout back
        socket.setdefaulttimeout(default_timeout)

    mpc = MozpoolHandler("http://%s" % MOZPOOL_CNAME, log)
    try:
        result = mpc.query_device_state(device)
    except MozpoolException as e:
        log.error("Unable to get mozpool state, mozpool returned error: %s" % sys.exc_info()[1])
        return MOZPOOL_STATE_ERROR

    if result['state'] == "ready":
        log.debug("Mozpool state is 'ready'")
        return MOZPOOL_STATE_READY
    else:
        log.error("Mozpool state is '%s'" % result['state'])
        return MOZPOOL_STATE_UNKNOWN
Ejemplo n.º 10
0
def checkAndFixScreen(dm, device):
    """ Verify the screen is set as we expect

    If the screen is incorrectly set, this function attempts to fix it,
    which ends up requiring a reboot of the device.

    Returns False if screen is wrong, True if correct
    """
    if not dmAlive(dm):
        return False

    # Verify we have the expected screen resolution
    info = dm.getInfo("screen")
    if not info["screen"][0] == EXPECTED_DEVICE_SCREEN:
        setFlag(
            errorFile,
            "Remote Device Error: Unexpected Screen on device, got '%s' expected '%s'"
            % (info["screen"][0], EXPECTED_DEVICE_SCREEN))
        if not dm.adjustResolution(**EXPECTED_DEVICE_SCREEN_ARGS):
            setFlag(errorFile, "Command to update resolution returned failure")
        else:
            soft_reboot(dm=dm, device=device)
            # Reboot sooner than cp would trigger a hard Reset
        return False
    log.info("INFO: Got expected screen size '%s'" % EXPECTED_DEVICE_SCREEN)
    return True
Ejemplo n.º 11
0
def doUpdate(dm):
    _oldDebug = dm.debug
    log.info("updateSUT.py: We're going to try to install SUTAgentAndroid Version %s" % target_version)
    try:
        data = download_apk()
    except Exception, e:
        log.error("Automation Error: updateSUT.py: We have failed to retrieve the SUT Agent. %s" % str(e))
        return RETCODE_APK_DL_FAILED
Ejemplo n.º 12
0
def doUpdate(dm):
    _oldDebug = dm.debug
    log.info("updateSUT.py: We're going to try to install SUTAgentAndroid Version %s" % target_version)
    try:
        data = download_apk()
    except Exception, e:
        log.error("Automation Error: updateSUT.py: We have failed to retrieve the SUT Agent. %s" % str(e))
        return RETCODE_APK_DL_FAILED
Ejemplo n.º 13
0
def download_apk():
    url = 'http://talos-bundles.pvt.build.mozilla.org/mobile/sutAgentAndroid.%s.apk' % target_version
    log.info("INFO: updateSUT.py: We're downloading the apk: %s" % url)
    req = urllib2.Request(url)
    try:
        f = urllib2.urlopen(req)
    except urllib2.URLError, e:
        reason = getattr(e, "reason", "SUT-Undef")
        code = getattr(e, "code", "SUT-Undef")
        raise Exception("Automation Error: updateSUT.py: code: %s; reason: %s" % (code, reason))
Ejemplo n.º 14
0
def download_apk():
    url = 'http://talos-bundles.pvt.build.mozilla.org/mobile/sutAgentAndroid.%s.apk' % target_version
    log.info("INFO: updateSUT.py: We're downloading the apk: %s" % url)
    req = urllib2.Request(url)
    try:
        f = urllib2.urlopen(req)
    except urllib2.URLError, e:
        reason = getattr(e, "reason", "SUT-Undef")
        code = getattr(e, "code", "SUT-Undef")
        raise Exception("Automation Error: updateSUT.py: code: %s; reason: %s" % (code, reason))
Ejemplo n.º 15
0
def cleanupDevice(device=None, dm=None):
    assert ((device is not None) or (dm is not None))  # Require one to be set

    if not device:
        device = os.environ['SUT_NAME']
    pidDir = os.path.join('/builds/', device)
    errorFile = os.path.join(pidDir, 'error.flg')
    reboot_needed = False

    processNames = [
        'org.mozilla.fennec_aurora',
        'org.mozilla.fennec_unofficial',
        'org.mozilla.fennec',
        'org.mozilla.firefox_beta',
        'org.mozilla.firefox',
        'org.mozilla.roboexample.test',
    ]

    if dm is None:
        log.info("Connecting to: " + device)
        dm = devicemanager.DeviceManagerSUT(device)
        dm.debug = 5

    packages = dm._runCmds([{'cmd': 'exec pm list packages'}])
    for package in packages.split('\n'):
        if not package.strip().startswith("package:"):
            continue  # unknown entry
        package_basename = package.strip()[8:]
        for proc in processNames:
            if package_basename == "%s" % proc or \
                    package_basename.startswith("%s_" % proc):
                log.info("Uninstalling %s..." % package_basename)
                try:
                    if 'panda' in device:
                        dm.uninstallApp(package_basename)
                        reboot_needed = True
                    else:
                        dm.uninstallAppAndReboot(package_basename)
                        waitForDevice(dm)
                except devicemanager.DMError, err:
                    setFlag(
                        errorFile,
                        "Remote Device Error: Unable to uninstall %s and reboot: %s"
                        % (package_basename, err))
                    return RETCODE_ERROR
                finally:
                    break  # Don't try this proc again, since we already matched
Ejemplo n.º 16
0
def checkVersion(dm, flag=False):
    """ Verify SUTAgent Version

    Returns False on failure, True on Success
    """
    if not dmAlive(dm):
        return False

    ver = updateSUT.version(dm)
    if not updateSUT.isVersionCorrect(ver=ver):
        if flag:
            setFlag(errorFile, "Remote Device Error: Unexpected ver on device, got '%s' expected '%s'" %
                    (ver, "SUTAgentAndroid Version %s" % updateSUT.target_version))
        return False
    log.info(
        "INFO: Got expected SUTAgent version '%s'" % updateSUT.target_version)
    return True
Ejemplo n.º 17
0
def cleanupDevice(device=None, dm=None):
    assert ((device is not None) or (dm is not None))  # Require one to be set

    if not device:
        device = os.environ['SUT_NAME']
    pidDir = os.path.join('/builds/', device)
    errorFile = os.path.join(pidDir, 'error.flg')
    reboot_needed = False

    processNames = ['org.mozilla.fennec_aurora',
                    'org.mozilla.fennec_unofficial',
                    'org.mozilla.fennec',
                    'org.mozilla.firefox_beta',
                    'org.mozilla.firefox',
                    'org.mozilla.roboexample.test',
                    ]

    if dm is None:
        log.info("Connecting to: " + device)
        dm = devicemanager.DeviceManagerSUT(device)
        dm.debug = 5

    packages = dm._runCmds([{'cmd': 'exec pm list packages'}])
    for package in packages.split('\n'):
        if not package.strip().startswith("package:"):
            continue  # unknown entry
        package_basename = package.strip()[8:]
        for proc in processNames:
            if package_basename == "%s" % proc or \
                    package_basename.startswith("%s_" % proc):
                log.info("Uninstalling %s..." % package_basename)
                try:
                    if 'panda' in device:
                        dm.uninstallApp(package_basename)
                        reboot_needed = True
                    else:
                        dm.uninstallAppAndReboot(package_basename)
                        waitForDevice(dm)
                except devicemanager.DMError, err:
                    setFlag(errorFile,
                            "Remote Device Error: Unable to uninstall %s and reboot: %s" % (package_basename, err))
                    return RETCODE_ERROR
                finally:
                    break  # Don't try this proc again, since we already matched
Ejemplo n.º 18
0
def canPing(device):
    """ Check a device is reachable by ping

    Returns False on failure, True on Success
    """
    curRetry = 0
    log.info("INFO: attempting to ping device")
    while curRetry < MAX_RETRIES:
        ret, _ = pingDevice(device)
        if not ret:
            curRetry += 1
            if curRetry == MAX_RETRIES:
                setFlag(errorFile, "Automation Error: Unable to ping device after %s attempts" % MAX_RETRIES)
                return False
            else:
                log.info("INFO: Unable to ping device after %s try. Sleeping for 90s then retrying" % curRetry)
                time.sleep(90)
        else:
            break  # we're done here
    return True
Ejemplo n.º 19
0
def main(argv):

    if len(argv) < 2:
        print "usage: installWatcher.py <ip address>"
        sys.exit(1)

    ip_addr = argv[1]

    dm = droid.DroidSUT(ip_addr)
    if not dm:
        log.error("could not get device manager!")
        return 1
    devRoot = checkDeviceRoot(dm)

    # we can't use the following dm.getFile method, since only Watcher runtime user has read access
    # to this file, so we need to be root to read it, hence the slightly more convoluted version
    # using dm._runCmds below...
    # cannot use -> print dm.getFile('/data/data/com.mozilla.watcher/files/version.txt')
    status = dm._runCmds([{"cmd": 'exec su -c "cat /data/data/com.mozilla.watcher/files/version.txt"'}]).split("\n")
    log.info("Watcher version: %s" % status)
    return 0
Ejemplo n.º 20
0
def installOneApp(dm, devRoot, app_file_local_path, errorFile, logcat=True):

    source = app_file_local_path
    filename = os.path.basename(source)
    target = os.path.join(devRoot, filename)

    log.info("Installing %s" % target)
    if dm.pushFile(source, target):
        status = dm.installApp(target)
        if status is None:
            log.info('-' * 42)
            log.info('installApp() done - gathering debug info')
            dm.getInfo('process')
            dm.getInfo('memory')
            dm.getInfo('uptime')
            if logcat:
                try:
                    print dm._runCmds([{'cmd': 'exec su -c "logcat -d -v time *:W"'}])
                except devicemanager.DMError, e:
                    setFlag(errorFile, "Remote Device Error: Exception hit while trying to run logcat: %s" % str(e))
                    return 1
        else:
            setFlag(errorFile,
                    "Remote Device Error: updateApp() call failed - exiting")
            return 1
Ejemplo n.º 21
0
def installOneApp(dm, devRoot, app_file_local_path, errorFile, logcat=True):

    source = app_file_local_path
    filename = os.path.basename(source)
    target = os.path.join(devRoot, filename)

    log.info("Installing %s" % target)
    if dm.pushFile(source, target):
        status = dm.installApp(target)
        if status is None:
            log.info('-' * 42)
            log.info('installApp() done - gathering debug info')
            dm.getInfo('process')
            dm.getInfo('memory')
            dm.getInfo('uptime')
            if logcat:
                try:
                    print dm._runCmds([{
                        'cmd':
                        'exec su -c "logcat -d -v time *:W"'
                    }])
                except devicemanager.DMError, e:
                    setFlag(
                        errorFile,
                        "Remote Device Error: Exception hit while trying to run logcat: %s"
                        % str(e))
                    return 1
        else:
            setFlag(errorFile,
                    "Remote Device Error: updateApp() call failed - exiting")
            return 1
Ejemplo n.º 22
0
def smoketest(device_name, number):
    global dm
    global appFileName, processName

    dm = devicemanager.DeviceManagerSUT(device_name, 20701)
    deviceRoot = dm.getDeviceRoot()

    # This does all the steps of verify.py including the cleanup.
    if verifyDevice(device_name, checksut=False, doCheckStalled=False) is False:
        log.error("failed to run verify on %s" % (device_name))
        return 1  # Not ok to proceed
    log.info("Successfully verified the device")

    if dm._sock:
        dm._sock.close()
    time.sleep(30)
    dm = devicemanager.DeviceManagerSUT(device_name, 20701)
    print "in smoketest, going to call installOneApp with dm: %s, %s" \
          % (dm, dm._sock)
    if installOneApp(dm, deviceRoot, os.path.abspath(appFileName), None, logcat=False):
        log.error("failed to install %s on device %s" % (appFileName, device_name))
        return 1
    log.info("Successfully installed the application")

    if not runTests(device_name, processName, number):
        log.error("failed to run dom tests on %s" % (device_name))
        return 1
    log.info("Successfully ran the mochitests")
    return 0
Ejemplo n.º 23
0
def smoketest(device_name, number):
    global dm
    global appFileName, processName

    dm = devicemanager.DeviceManagerSUT(device_name, 20701)
    deviceRoot = dm.getDeviceRoot()

    # This does all the steps of verify.py including the cleanup.
    if verifyDevice(device_name, checksut=False,
                    doCheckStalled=False) is False:
        log.error("failed to run verify on %s" % (device_name))
        return 1  # Not ok to proceed
    log.info("Successfully verified the device")

    if dm._sock:
        dm._sock.close()
    time.sleep(30)
    dm = devicemanager.DeviceManagerSUT(device_name, 20701)
    print "in smoketest, going to call installOneApp with dm: %s, %s" \
          % (dm, dm._sock)
    if installOneApp(dm,
                     deviceRoot,
                     os.path.abspath(appFileName),
                     None,
                     logcat=False):
        log.error("failed to install %s on device %s" %
                  (appFileName, device_name))
        return 1
    log.info("Successfully installed the application")

    if not runTests(device_name, processName, number):
        log.error("failed to run dom tests on %s" % (device_name))
        return 1
    log.info("Successfully ran the mochitests")
    return 0
Ejemplo n.º 24
0
def checkAndFixScreen(dm, device):
    """ Verify the screen is set as we expect

    If the screen is incorrectly set, this function attempts to fix it,
    which ends up requiring a reboot of the device.

    Returns False if screen is wrong, True if correct
    """
    if not dmAlive(dm):
        return False

    # Verify we have the expected screen resolution
    info = dm.getInfo("screen")
    if not info["screen"][0] == EXPECTED_DEVICE_SCREEN:
        setFlag(errorFile, "Remote Device Error: Unexpected Screen on device, got '%s' expected '%s'" %
               (info["screen"][0], EXPECTED_DEVICE_SCREEN))
        if not dm.adjustResolution(**EXPECTED_DEVICE_SCREEN_ARGS):
            setFlag(errorFile, "Command to update resolution returned failure")
        else:
            soft_reboot(dm=dm, device=device)
                        # Reboot sooner than cp would trigger a hard Reset
        return False
    log.info("INFO: Got expected screen size '%s'" % EXPECTED_DEVICE_SCREEN)
    return True
Ejemplo n.º 25
0
def install(dm, devRoot, app_file_local_path, package):
    source = app_file_local_path
    filename = os.path.basename(source)
    target = os.path.join(devRoot, filename)

    log.info("Pushing new apk to the device: %s" % target)
    status = dm.pushFile(source, target)

    dm.shellCheckOutput(["dd", "if=%s" % target, "of=/data/local/watcher.apk"], root=True)
    dm.shellCheckOutput(["chmod", "666", "/data/local/watcher.apk"], root=True)

    log.info("Uninstalling %s" % package)
    try:
        dm.uninstallApp(package)
        log.info('uninstallation successful')
    except devicemanager.DMError, e:
        log.info('uninstallation failed -- maybe not installed? '+str(e))
Ejemplo n.º 26
0
def canTelnet(device):
    """ Checks if we can establish a Telnet session (via devicemanager)

    Sets global `dm`
    Returns False on failure, True on Success
    """
    global dm
    curRetry = 0
    sleepDuration = 0
    while curRetry < MAX_RETRIES:
        try:
            dm = connect(device, sleepDuration)
        except:
            curRetry += 1
            if curRetry == MAX_RETRIES:
                setFlag(errorFile, "Automation Error: Unable to connect to device after %s attempts" % MAX_RETRIES)
                return False
            else:
                log.info("INFO: Unable to connect to device after %s try" %
                         curRetry)
                sleepDuration = 90
        else:
            break  # We're done here
    return True
Ejemplo n.º 27
0
def main(argv):
    global ip_addr

    if (len(argv) < 4):
        log.info("usage: logcat.py <device ip address> <output filename> <logcat options>")
        return 1
    ip_addr = argv[1]
    output_filename = argv[2]
    logcat_options = argv[3]
    max_runtime = 3600   # 3600 seconds == 1 hour

    status = 0
    dm = devicemanager.DeviceManagerSUT(ip_addr)
    if not dm:
        log.error("logcat.py: unable to open device manager")
        return 2
    command = 'execext su t=%d logcat %s' % (max_runtime, logcat_options)
    log.debug('logcat.py running SUT command: %s' % command)
    try:
        with open(output_filename, 'w') as f:
            dm._sendCmds([{'cmd': command}], f)
    except devicemanager.DMError, e:
        log.error("Remote Device Error: Exception caught running logcat: %s" % str(e))
        status = -1
Ejemplo n.º 28
0
def install(dm, devRoot, app_file_local_path, package):
    source = app_file_local_path
    filename = os.path.basename(source)
    target = os.path.join(devRoot, filename)

    log.info("Pushing new apk to the device: %s" % target)
    status = dm.pushFile(source, target)

    dm.shellCheckOutput(
        ["dd", "if=%s" % target, "of=/data/local/watcher.apk"], root=True)
    dm.shellCheckOutput(["chmod", "666", "/data/local/watcher.apk"], root=True)

    log.info("Uninstalling %s" % package)
    try:
        dm.uninstallApp(package)
        log.info('uninstallation successful')
    except devicemanager.DMError, e:
        log.info('uninstallation failed -- maybe not installed? ' + str(e))
Ejemplo n.º 29
0
def runTests(device, proc_name, number):
    numfailed = -1
    log.info("Starting to run tests")
    httpport = 8000 + int(number)

    # TODO: fix the host/port information so we don't have conflicts in
    # parallel runs
    cmd = [
        "python",
        os.path.join(os.path.dirname(__file__),
                     "tests/mochitest/runtestsremote.py"),
        "--app=%s" % proc_name,
        "--deviceIP=%s" % device,
        "--xre-path=%s" % os.path.join(os.path.dirname(__file__), "xre"),
        "--utility-path=%s" % os.path.join(os.path.dirname(__file__), "bin"),
        # "--test-path=dom/tests/mochitest/dom-level0",
        "--test-path=dom/tests/mochitest",
        "--http-port=%s" % httpport
    ]
    log.info("Going to run test: %s" % subprocess.list2cmdline(cmd))
    proc = ""
    try:
        p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
        proc = p.communicate()[0]
    except:
        log.error("Exception found while running unittests: %s" %
                  sys.exc_info()[1])
    log.info("Finished running mochitests")
    refinished = re.compile('([0-9]+) INFO SimpleTest FINISHED')
    refailed = re.compile('([0-9]+) INFO Failed: ([0-9]+)')
    for line in proc.split('\n'):
        log.debug(line)
        finished = refinished.match(line)
        failed = refailed.match(line)
        if failed:
            numfailed = int(failed.group(2))
        if finished:
            if numfailed > 0:
                log.error("Found %s failures while running mochitest" %
                          numfailed)
                return False
            return True
    return False
Ejemplo n.º 30
0
def runTests(device, proc_name, number):
    numfailed = -1
    log.info("Starting to run tests")
    httpport = 8000 + int(number)

    # TODO: fix the host/port information so we don't have conflicts in
    # parallel runs
    cmd = ["python",
           os.path.join(os.path.dirname(__file__), "tests/mochitest/runtestsremote.py"),
           "--app=%s" % proc_name,
           "--deviceIP=%s" % device,
           "--xre-path=%s" % os.path.join(os.path.dirname(__file__), "xre"),
           "--utility-path=%s" % os.path.join(os.path.dirname(__file__), "bin"),
           # "--test-path=dom/tests/mochitest/dom-level0",
           "--test-path=dom/tests/mochitest",
           "--http-port=%s" % httpport]
    log.info("Going to run test: %s" % subprocess.list2cmdline(cmd))
    proc = ""
    try:
        p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
        proc = p.communicate()[0]
    except:
        log.error("Exception found while running unittests: %s" % sys.exc_info()[1])
    log.info("Finished running mochitests")
    refinished = re.compile('([0-9]+) INFO SimpleTest FINISHED')
    refailed = re.compile('([0-9]+) INFO Failed: ([0-9]+)')
    for line in proc.split('\n'):
        log.debug(line)
        finished = refinished.match(line)
        failed = refailed.match(line)
        if failed:
            numfailed = int(failed.group(2))
        if finished:
            if numfailed > 0:
                log.error("Found %s failures while running mochitest"
                          % numfailed)
                return False
            return True
    return False
Ejemplo n.º 31
0
    packages = dm._runCmds([{'cmd': 'exec pm list packages'}])
    for package in packages.split('\n'):
        for proc in processNames:
            if package == "package:%s" % proc:
                setFlag(errorFile, "Remote Device Error: Unable to properly uninstall %s" % proc)
                return RETCODE_ERROR

    devRoot = checkDeviceRoot(dm)

    if not str(devRoot).startswith("/mnt/sdcard"):
        setFlag(errorFile, "Remote Device Error: devRoot from devicemanager [%s] is not correct" % str(devRoot))
        return RETCODE_ERROR

    if dm.dirExists(devRoot):
        status = dm.removeDir(devRoot)
        log.info("removeDir() returned [%s]" % status)
        if status is None or not status:
            setFlag(errorFile, "Remote Device Error: call to removeDir() returned [%s]" % status)
            return RETCODE_ERROR
        if dm.dirExists(devRoot):
            setFlag(errorFile, "Remote Device Error: Unable to properly remove %s" % devRoot)
            return RETCODE_ERROR

    # cleanup the downloads directory
    downloadDir = '/mnt/sdcard/Download'
    if dm.dirExists(downloadDir):
        log.info("Cleaning up %s" % downloadDir)
        files = dm.listFiles(downloadDir)
        for f in files:
            name = "%s/%s" % (downloadDir, f)
            type = "File"
Ejemplo n.º 32
0

if __name__ == '__main__':
    device_name = os.getenv('SUT_NAME')
    from optparse import OptionParser
    parser = OptionParser(usage="usage: %prog [options] [device_name]")
    parser.add_option(
        "--success-if-mozpool-ready",
        action="store_true",
        dest="skipWhenMozpoolReady",
        default=False,
        help="if mozpool reports device is 'ready' skip all device checks")
    (options, args) = parser.parse_args()
    if (len(args) != 2):
        if device_name in (None, ''):
            parser.print_help()
            print "   Must have $SUT_NAME set in environ to omit device name"
            sys.exit(1)
        else:
            log.info("INFO: Using device '%s' found in env variable" %
                     device_name)
    else:
        device_name = args[0]

    if verifyDevice(
            device_name,
            skipWhenMozpoolReady=options.skipWhenMozpoolReady) is False:
        sys.exit(1)  # Not ok to proceed

    sys.exit(0)
Ejemplo n.º 33
0
def version(dm):
    ver = dm._runCmds([{'cmd': 'ver'}]).split("\n")[0]
    log.info("INFO: updateSUT.py: We're running %s" % ver)
    return ver
Ejemplo n.º 34
0
            ipAddr=proxyIP,
            port=proxyPort,
            silent=True
        )
        log.info(status)
    except:
        log.info("Failure while rebooting device")
        setFlag(errorFile,
                "Remote Device Error: Device failed to recover after reboot",
                True)
        return 1

    sys.stdout.flush()
    return 0

if __name__ == '__main__':
    if (len(sys.argv) != 2):
        print "usage: reboot.py <ip address>"
        sys.exit(1)

    deviceIP = sys.argv[1]
    dm = None
    try:
        log.info("connecting to: %s" % deviceIP)
        dm = devicemanager.DeviceManagerSUT(deviceIP)
        dm.debug = 0
        dm.default_timeout = 30  # Set our timeout lower for deviceManager here
    except:
        pass
    sys.exit(reboot(dm))
Ejemplo n.º 35
0
def reboot(dm):
    cwd = os.getcwd()
    deviceName = os.path.basename(cwd)
    errorFile = os.path.join(cwd, '..', 'error.flg')
    proxyIP = getOurIP()
    proxyPort = calculatePort()

    if 'panda' not in deviceName:
        # Attempt to set devicename via env variable 'SUT_NAME'
        sname = os.getenv('SUT_NAME')
        if sname.strip():
            deviceName = sname.strip()
        else:
            log.info("Unable to find a proper devicename, will attempt to "
                     "reboot device")

    if dm is not None:
        try:
            dm.getInfo('process')
            log.info(dm._runCmds(
                [{'cmd': 'exec su -c "logcat -d -v time *:W"'}], timeout=10))
        except:
            log.info("Failure trying to run logcat on device")
    else:
        log.info("We were unable to connect to device %s, skipping logcat" %
                 deviceName)

    try:
        log.info('forcing device %s reboot' % deviceName)
        status = powermanagement.soft_reboot_and_verify(
            dm=dm,
            device=deviceName,
            ipAddr=proxyIP,
            port=proxyPort,
            silent=True
        )
        log.info(status)
    except:
        log.info("Failure while rebooting device")
        setFlag(errorFile,
                "Remote Device Error: Device failed to recover after reboot",
                True)
        return 1

    sys.stdout.flush()
    return 0
Ejemplo n.º 36
0
    if not cleanupDevice(device, dm):
        log.info("verifyDevice: failing to cleanup device")
        return False

    return True

if __name__ == '__main__':
    device_name = os.getenv('SUT_NAME')
    from optparse import OptionParser
    parser = OptionParser(usage="usage: %prog [options] [device_name]")
    parser.add_option("--success-if-mozpool-ready",
                      action="store_true", dest="skipWhenMozpoolReady", default=False,
                      help="if mozpool reports device is 'ready' skip all device checks")
    (options, args) = parser.parse_args()
    if (len(args) != 2):
        if device_name in (None, ''):
            parser.print_help()
            print "   Must have $SUT_NAME set in environ to omit device name"
            sys.exit(1)
        else:
            log.info(
                "INFO: Using device '%s' found in env variable" % device_name)
    else:
        device_name = args[0]

    if verifyDevice(device_name,
                    skipWhenMozpoolReady=options.skipWhenMozpoolReady) is False:
        sys.exit(1)  # Not ok to proceed

    sys.exit(0)
Ejemplo n.º 37
0
                    "Remote Device Error: Unable to properly uninstall %s" %
                    proc)
                return RETCODE_ERROR

    devRoot = checkDeviceRoot(dm)

    if not str(devRoot).startswith("/mnt/sdcard"):
        setFlag(
            errorFile,
            "Remote Device Error: devRoot from devicemanager [%s] is not correct"
            % str(devRoot))
        return RETCODE_ERROR

    if dm.dirExists(devRoot):
        status = dm.removeDir(devRoot)
        log.info("removeDir() returned [%s]" % status)
        if status is None or not status:
            setFlag(
                errorFile,
                "Remote Device Error: call to removeDir() returned [%s]" %
                status)
            return RETCODE_ERROR
        if dm.dirExists(devRoot):
            setFlag(
                errorFile,
                "Remote Device Error: Unable to properly remove %s" % devRoot)
            return RETCODE_ERROR

    # cleanup the downloads directory
    downloadDir = '/mnt/sdcard/Download'
    if dm.dirExists(downloadDir):
Ejemplo n.º 38
0
def version(dm):
    ver = dm._runCmds([{'cmd': 'ver'}]).split("\n")[0]
    log.info("INFO: updateSUT.py: We're running %s" % ver)
    return ver
Ejemplo n.º 39
0
    log.info("Pushing new apk to the device: %s" % target)
    status = dm.pushFile(source, target)

    dm.shellCheckOutput(["dd", "if=%s" % target, "of=/data/local/watcher.apk"], root=True)
    dm.shellCheckOutput(["chmod", "666", "/data/local/watcher.apk"], root=True)

    log.info("Uninstalling %s" % package)
    try:
        dm.uninstallApp(package)
        log.info('uninstallation successful')
    except devicemanager.DMError, e:
        log.info('uninstallation failed -- maybe not installed? '+str(e))

    osversion = dm.getInfo('os')['os'][0].split()[0]
    if osversion == 'pandaboard-eng':
        log.info('installing %s on panda' % target)
        status = dm._runCmds([{'cmd': 'exec su -c "export LD_LIBRARY_PATH=/vendor/lib:/system/lib; pm install /data/local/watcher.apk; am start -a android.intent.action.MAIN -n com.mozilla.watcher/.WatcherMain"'}]).split('\n')
    else:
        log.info('installing %s on tegra' % target)
        status = dm._runCmds([{'cmd': 'exec su -c "pm install /data/local/watcher.apk; am start -a android.intent.action.MAIN -n com.mozilla.watcher/.WatcherMain"'}]).split('\n')

    if len(status) > 2 and status[1].strip() == 'Success':
        log.info('-' * 42)
        log.info('installation successful')
    else:
        log.error('installApp() failed: %s' % status)
        return 1

    time.sleep(15)
    return 0
Ejemplo n.º 40
0
def reboot(dm):
    cwd = os.getcwd()
    deviceName = os.path.basename(cwd)
    errorFile = os.path.join(cwd, '..', 'error.flg')
    proxyIP = getOurIP()
    proxyPort = calculatePort()

    if 'panda' not in deviceName:
        # Attempt to set devicename via env variable 'SUT_NAME'
        sname = os.getenv('SUT_NAME')
        if sname.strip():
            deviceName = sname.strip()
        else:
            log.info("Unable to find a proper devicename, will attempt to "
                     "reboot device")

    if dm is not None:
        try:
            dm.getInfo('process')
            log.info(
                dm._runCmds([{
                    'cmd': 'exec su -c "logcat -d -v time *:W"'
                }],
                            timeout=10))
        except:
            log.info("Failure trying to run logcat on device")
    else:
        log.info("We were unable to connect to device %s, skipping logcat" %
                 deviceName)

    try:
        log.info('forcing device %s reboot' % deviceName)
        status = powermanagement.soft_reboot_and_verify(dm=dm,
                                                        device=deviceName,
                                                        ipAddr=proxyIP,
                                                        port=proxyPort,
                                                        silent=True)
        log.info(status)
    except:
        log.info("Failure while rebooting device")
        setFlag(errorFile,
                "Remote Device Error: Device failed to recover after reboot",
                True)
        return 1

    sys.stdout.flush()
    return 0
Ejemplo n.º 41
0
    status = dm.pushFile(source, target)

    dm.shellCheckOutput(
        ["dd", "if=%s" % target, "of=/data/local/watcher.apk"], root=True)
    dm.shellCheckOutput(["chmod", "666", "/data/local/watcher.apk"], root=True)

    log.info("Uninstalling %s" % package)
    try:
        dm.uninstallApp(package)
        log.info('uninstallation successful')
    except devicemanager.DMError, e:
        log.info('uninstallation failed -- maybe not installed? ' + str(e))

    osversion = dm.getInfo('os')['os'][0].split()[0]
    if osversion == 'pandaboard-eng':
        log.info('installing %s on panda' % target)
        status = dm._runCmds([{
            'cmd':
            'exec su -c "export LD_LIBRARY_PATH=/vendor/lib:/system/lib; pm install /data/local/watcher.apk; am start -a android.intent.action.MAIN -n com.mozilla.watcher/.WatcherMain"'
        }]).split('\n')
    else:
        log.info('installing %s on tegra' % target)
        status = dm._runCmds([{
            'cmd':
            'exec su -c "pm install /data/local/watcher.apk; am start -a android.intent.action.MAIN -n com.mozilla.watcher/.WatcherMain"'
        }]).split('\n')

    if len(status) > 2 and status[1].strip() == 'Success':
        log.info('-' * 42)
        log.info('installation successful')
    else:
Ejemplo n.º 42
0
def one_time_setup(ip_addr, major_source):
    ''' One time setup of state

    ip_addr - of the device we want to install app at
    major_source - we've hacked this script to install
            may-also-be-needed tools, but the source we're asked to
            install has the meta data we need

    Side Effects:
        global, needed for error reporting:
            errorFile
    '''

    # set up the flag files, used throughout
    cwd = os.getcwd()
    global errorFile
    errorFile = os.path.join(cwd, '..', 'error.flg')
    deviceName = os.path.basename(cwd)

    proxyIP = getOurIP()
    proxyPort = calculatePort()

    workdir = os.path.dirname(major_source)
    inifile = os.path.join(workdir, 'fennec', 'application.ini')
    remoteappini = os.path.join(workdir, 'talos', 'remoteapp.ini')
    log.info('copying %s to %s' % (inifile, remoteappini))
    runCommand(['cp', inifile, remoteappini])

    log.info("connecting to: %s" % ip_addr)
    dm = devicemanager.DeviceManagerSUT(ip_addr)
    # Moar data!
    dm.debug = 3

    devRoot = checkDeviceRoot(dm)

    if devRoot is None or devRoot == '/tests':
        setFlag(
            errorFile,
            "Remote Device Error: devRoot from devicemanager [%s] is not correct - exiting"
            % devRoot)
        return None, None

    try:
        log.info("%s, %s" % (proxyIP, proxyPort))
        getDeviceTimestamp(dm)
        setDeviceTimestamp(dm)
        getDeviceTimestamp(dm)
        dm.getInfo('process')
        dm.getInfo('memory')
        dm.getInfo('uptime')

        width, height = getResolution(dm)
        # adjust resolution down to allow fennec to install without memory
        # issues
        if (width == 1600 or height == 1200):
            dm.adjustResolution(1024, 768, 'crt')
            log.info('forcing device reboot')
            if not powermanagement.soft_reboot_and_verify(
                    device=deviceName, dm=dm, ipAddr=proxyIP, port=proxyPort):
                return None, None

            width, height = getResolution(dm)
            if width != 1024 and height != 768:
                setFlag(
                    errorFile,
                    "Remote Device Error: Resolution change failed.  Should be %d/%d but is %d/%d"
                    % (1024, 768, width, height))
                return None, None

    except devicemanager.AgentError, err:
        log.error(
            "remoteDeviceError: while doing one time setup for installation: %s"
            % err)
        return None, None
Ejemplo n.º 43
0
def one_time_setup(ip_addr, major_source):
    ''' One time setup of state

    ip_addr - of the device we want to install app at
    major_source - we've hacked this script to install
            may-also-be-needed tools, but the source we're asked to
            install has the meta data we need

    Side Effects:
        global, needed for error reporting:
            errorFile
    '''

    # set up the flag files, used throughout
    cwd = os.getcwd()
    global errorFile
    errorFile = os.path.join(cwd, '..', 'error.flg')
    deviceName = os.path.basename(cwd)

    proxyIP = getOurIP()
    proxyPort = calculatePort()

    workdir = os.path.dirname(major_source)
    inifile = os.path.join(workdir, 'fennec', 'application.ini')
    remoteappini = os.path.join(workdir, 'talos', 'remoteapp.ini')
    log.info('copying %s to %s' % (inifile, remoteappini))
    runCommand(['cp', inifile, remoteappini])

    log.info("connecting to: %s" % ip_addr)
    dm = devicemanager.DeviceManagerSUT(ip_addr)
# Moar data!
    dm.debug = 3

    devRoot = checkDeviceRoot(dm)

    if devRoot is None or devRoot == '/tests':
        setFlag(errorFile, "Remote Device Error: devRoot from devicemanager [%s] is not correct - exiting" % devRoot)
        return None, None

    try:
        log.info("%s, %s" % (proxyIP, proxyPort))
        getDeviceTimestamp(dm)
        setDeviceTimestamp(dm)
        getDeviceTimestamp(dm)
        dm.getInfo('process')
        dm.getInfo('memory')
        dm.getInfo('uptime')

        width, height = getResolution(dm)
        # adjust resolution down to allow fennec to install without memory
        # issues
        if (width == 1600 or height == 1200):
            dm.adjustResolution(1024, 768, 'crt')
            log.info('forcing device reboot')
            if not powermanagement.soft_reboot_and_verify(device=deviceName, dm=dm, ipAddr=proxyIP, port=proxyPort):
                return None, None

            width, height = getResolution(dm)
            if width != 1024 and height != 768:
                setFlag(errorFile, "Remote Device Error: Resolution change failed.  Should be %d/%d but is %d/%d" % (1024, 768, width, height))
                return None, None

    except devicemanager.AgentError, err:
        log.error("remoteDeviceError: while doing one time setup for installation: %s" % err)
        return None, None
Ejemplo n.º 44
0
        log.error("Automation Error: updateSUT.py: %s" % e)
        return RETCODE_REVERIFY_FAILED

    dm.debug = _oldDebug  # Restore it

    if ver == None:
        log.error(
            "Automation Error: updateSUT.py: We should have been able to connect and determine the version."
        )
        return RETCODE_REVERIFY_FAILED
    elif not isVersionCorrect(ver=ver):
        log.error("Automation Error: updateSUT.py: We should have had the %s version but instead we have %s" % \
              (target_version, ver))
        return RETCODE_REVERIFY_WRONG
    else:
        log.info("updateSUT.py: We're now running %s" % ver)
        return RETCODE_SUCCESS


def main(device):
    dm = connect(device)

    if not isVersionCorrect(dm=dm):
        return doUpdate(dm)
    else:
        # The SUT Agent was already up-to-date
        return RETCODE_SUCCESS


def version(dm):
    ver = dm._runCmds([{'cmd': 'ver'}]).split("\n")[0]
Ejemplo n.º 45
0
def verifyDevice(device,
                 checksut=True,
                 doCheckStalled=True,
                 skipWhenMozpoolReady=False):
    # Returns False on failure, True on Success
    global dm, errorFile
    devicePath = os.path.join('/builds', device)
    errorFile = os.path.join(devicePath, 'error.flg')

    if doCheckStalled:
        if not cleanupFoopy(device):
            log.info("verifyDevice: failing to cleanup foopy")
            return False

    mozpool_state = isMozpoolReady(device)
    if skipWhenMozpoolReady and mozpool_state is MOZPOOL_STATE_READY:
        log.info("Mozpool State is ready skipping device checks")
        return True
    elif mozpool_state is MOZPOOL_STATE_READY:
        log.info(
            "Mozpool claims device is ready, continuing to verify device...")
    elif mozpool_state is MOZPOOL_STATE_UNKNOWN:
        log.info(
            "Mozpool knows about device, but claims we're not safe to continue"
        )
        return False
    elif mozpool_state in (MOZPOOL_STATE_ERROR, MOZPOOL_STATE_MISSING):
        log.info(
            "Unable to determine state from Mozpool, falling back to device checks"
        )
    else:
        log.info("Unexpected Mozpool State returned, hard stop.")
        return False

    if not canPing(device):
        log.info("verifyDevice: failing to ping")
        # See if we can recover the device with a reboot.
        soft_reboot(dm=dm, device=device)
        return False

    if not canTelnet(device):
        log.info("verifyDevice: failing to telnet")
        return False

    if not checkSDCard(dm):
        log.info("verifyDevice: failing to check SD card")
        return False

    if checksut and not checkVersion(dm):
        if not updateSUTVersion(dm):
            log.info("verifyDevice: failing to updateSUT")
            return False

    # Resolution Check disabled for now; Bug 737427
    if False and not checkAndFixScreen(dm, device):
        log.info("verifyDevice: failing to fix screen")
        return False

    if not cleanupDevice(device, dm):
        log.info("verifyDevice: failing to cleanup device")
        return False

    return True
Ejemplo n.º 46
0
    except Exception, e:
        log.error("Automation Error: updateSUT.py: We should have been able to get the version")
        log.error("Automation Error: updateSUT.py: %s" % e)
        return RETCODE_REVERIFY_FAILED

    dm.debug = _oldDebug  # Restore it

    if ver is None:
        log.error("Automation Error: updateSUT.py: We should have been able to connect and determine the version.")
        return RETCODE_REVERIFY_FAILED
    elif not isVersionCorrect(ver=ver):
        log.error("Automation Error: updateSUT.py: We should have had the %s version but instead we have %s" %
                 (target_version, ver))
        return RETCODE_REVERIFY_WRONG
    else:
        log.info("updateSUT.py: We're now running %s" % ver)
        return RETCODE_SUCCESS


def main(device):
    dm = connect(device)

    if not isVersionCorrect(dm=dm):
        return doUpdate(dm)
    else:
        # The SUT Agent was already up-to-date
        return RETCODE_SUCCESS


def version(dm):
    ver = dm._runCmds([{'cmd': 'ver'}]).split("\n")[0]
Ejemplo n.º 47
0
def verifyDevice(device, checksut=True, doCheckStalled=True, watcherINI=False,
                 skipWhenMozpoolReady=False):
    # Returns False on failure, True on Success
    global dm, errorFile
    devicePath = os.path.join('/builds', device)
    errorFile = os.path.join(devicePath, 'error.flg')

    if doCheckStalled:
        if not cleanupFoopy(device):
            log.info("verifyDevice: failing to cleanup foopy")
            return False

    mozpool_state = isMozpoolReady(device)
    if skipWhenMozpoolReady and mozpool_state is MOZPOOL_STATE_READY:
        log.info("Mozpool State is ready skipping device checks")
        return True
    elif mozpool_state is MOZPOOL_STATE_READY:
        log.info("Mozpool claims device is ready, continuing to verify device...")
    elif mozpool_state is MOZPOOL_STATE_UNKNOWN:
        log.info("Mozpool knows about device, but claims we're not safe to continue")
        return False
    elif mozpool_state in (MOZPOOL_STATE_ERROR, MOZPOOL_STATE_MISSING):
        log.info("Unable to determine state from Mozpool, falling back to device checks")
    else:
        log.info("Unexpected Mozpool State returned, hard stop.")
        return False

    if not canPing(device):
        # TODO Reboot via PDU if ping fails
        log.info("verifyDevice: failing to ping")
        return False

    if not canTelnet(device):
        log.info("verifyDevice: failing to telnet")
        return False

    if not checkSDCard(dm):
        log.info("verifyDevice: failing to check SD card")
        return False

    if checksut and not checkVersion(dm):
        if not updateSUTVersion(dm):
            log.info("verifyDevice: failing to updateSUT")
            return False

    # Resolution Check disabled for now; Bug 737427
    if False and not checkAndFixScreen(dm, device):
        log.info("verifyDevice: failing to fix screen")
        return False

    if not cleanupDevice(device, dm):
        log.info("verifyDevice: failing to cleanup device")
        return False

    if watcherINI:
        if not setWatcherINI(dm):
            log.info("verifyDevice: failing to set watcher.ini")
            return False

    return True
Ejemplo n.º 48
0
        return False

    tmpname = '/mnt/sdcard/watcher.ini'
    try:
        dm._runCmds([{'cmd': 'push %s %s' % (tmpname, len(
            watcherINI)), 'data': watcherINI}])
    except devicemanager.AgentError, err:
        log.info("Error while pushing watcher.ini: %s" % err)
        setFlag(errorFile, "Unable to properly upload the watcher.ini")
        return False

    try:
        dm._runCmds(
            [{'cmd': 'exec su -c "dd if=%s of=%s"' % (tmpname, realLoc)}])
    except devicemanager.AgentError, err:
        log.info("Error while moving watcher.ini to %s: %s" % (realLoc, err))
        setFlag(errorFile, "Unable to properly upload the watcher.ini")
        return False

    try:
        dm._runCmds([{'cmd': 'exec su -c "chmod 0777 %s"' % realLoc}])
    except devicemanager.AgentError, err:
        log.info("Error while setting permissions for %s: %s" % (realLoc, err))
        setFlag(errorFile, "Unable to properly upload the watcher.ini")
        return False

    try:
        if watcherDataCurrent():
            return True
    except:
        pass
Ejemplo n.º 49
0
                                                        ipAddr=proxyIP,
                                                        port=proxyPort,
                                                        silent=True)
        log.info(status)
    except:
        log.info("Failure while rebooting device")
        setFlag(errorFile,
                "Remote Device Error: Device failed to recover after reboot",
                True)
        return 1

    sys.stdout.flush()
    return 0


if __name__ == '__main__':
    if (len(sys.argv) != 2):
        print "usage: reboot.py <ip address>"
        sys.exit(1)

    deviceIP = sys.argv[1]
    dm = None
    try:
        log.info("connecting to: %s" % deviceIP)
        dm = devicemanager.DeviceManagerSUT(deviceIP)
        dm.debug = 0
        dm.default_timeout = 30  # Set our timeout lower for deviceManager here
    except:
        pass
    sys.exit(reboot(dm))
Ejemplo n.º 50
0
def verifyDevice(device, checksut=True, doCheckStalled=True, watcherINI=False):
    # Returns False on failure, True on Success
    global dm, errorFile
    devicePath = os.path.join('/builds', device)
    errorFile = os.path.join(devicePath, 'error.flg')

    if doCheckStalled:
        if not cleanupFoopy(device):
            log.info("verifyDevice: failing to cleanup foopy")
            return False

    if not canPing(device):
        # TODO Reboot via PDU if ping fails
        log.info("verifyDevice: failing to ping")
        return False

    if not canTelnet(device):
        log.info("verifyDevice: failing to telnet")
        return False

    if not checkSDCard(dm):
        log.info("verifyDevice: failing to check SD card")
        return False

    if checksut and not checkVersion(dm):
        if not updateSUTVersion(dm):
            log.info("verifyDevice: failing to updateSUT")
            return False

    # Resolution Check disabled for now; Bug 737427
    if False and not checkAndFixScreen(dm, device):
        log.info("verifyDevice: failing to fix screen")
        return False

    if not cleanupDevice(device, dm):
        log.info("verifyDevice: failing to cleanup device")
        return False

    if watcherINI:
        if not setWatcherINI(dm):
            log.info("verifyDevice: failing to set watcher.ini")
            return False

    return True