# Lint as: python2, python3 # Copyright (c) 2013 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. # # Expects to be run in an environment with sudo and no interactive password # prompt, such as within the Chromium OS development chroot. """This file provides core logic for servo verify/repair process.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function import logging import os import re import tarfile import threading import json import time import six import six.moves.xmlrpc_client import calendar from autotest_lib.client.bin import utils from autotest_lib.client.common_lib import error from autotest_lib.client.common_lib import hosts from autotest_lib.client.common_lib import lsbrelease_utils from autotest_lib.client.common_lib.cros import retry from autotest_lib.client.common_lib.cros.network import ping_runner from autotest_lib.server.cros.servo import servo from autotest_lib.server.hosts import servo_repair from autotest_lib.server.hosts import base_servohost from autotest_lib.server.hosts import servo_constants from autotest_lib.server.cros.faft.utils import config from autotest_lib.client.common_lib import global_config from autotest_lib.site_utils.admin_audit import servo_updater from autotest_lib.server.cros.servo.topology import servo_topology try: from chromite.lib import metrics except ImportError: metrics = utils.metrics_mock _CONFIG = global_config.global_config class ServoHost(base_servohost.BaseServoHost): """Host class for a servo host(e.g. beaglebone, labstation) that with a servo instance for a specific port. @type _servo: servo.Servo | None """ DEFAULT_PORT = int(os.getenv('SERVOD_PORT', '9999')) # Timeout for initializing servo signals. INITIALIZE_SERVO_TIMEOUT_SECS = 60 # Default timeout for run terminal command. DEFAULT_TERMINAL_TIMEOUT = 30 # Ready test function SERVO_READY_METHOD = 'get_version' # Directory prefix on the servo host where the servod logs are stored. SERVOD_LOG_PREFIX = '/var/log/servod' # Exit code to use when symlinks for servod logs are not found. NO_SYMLINKS_CODE = 9 # Directory in the job's results directory to dump the logs into. LOG_DIR = 'servod' # Prefix for joint loglevel files in the logs. JOINT_LOG_PREFIX = 'log' # Regex group to extract timestamp from logfile name. TS_GROUP = 'ts' # This regex is used to extract the timestamp from servod logs. # files always start with log. TS_RE = (r'log.' # The timestamp is of format %Y-%m-%d--%H-%M-%S.MS r'(?P<%s>\d{4}(\-\d{2}){2}\-(-\d{2}){3}.\d{3})' # The loglevel is optional depending on labstation version. r'(.(INFO|DEBUG|WARNING))?' % TS_GROUP) TS_EXTRACTOR = re.compile(TS_RE) # Regex group to extract MCU name from logline in servod logs. MCU_GROUP = 'mcu' # Regex group to extract logline from MCU logline in servod logs. LINE_GROUP = 'line' # This regex is used to extract the mcu and the line content from an # MCU logline in servod logs. e.g. EC or servo_v4 console logs. # Here is an example log-line: # # 2020-01-23 13:15:12,223 - servo_v4 - EC3PO.Console - DEBUG - # console.py:219:LogConsoleOutput - /dev/pts/9 - cc polarity: cc1 # # Here is conceptually how they are formatted: # #