diff options
author | Jeremy Bettis <jbettis@google.com> | 2022-05-26 12:15:45 -0600 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-05-28 02:26:04 +0000 |
commit | 4291d5db2674333acd44476396ec1aab010f90cd (patch) | |
tree | 51872f0f65d4b4ef13c8f274b14637b2f765332b | |
parent | 25446795c76cb334002d8fe11789d4725ba55612 (diff) | |
download | autotest-4291d5db2674333acd44476396ec1aab010f90cd.tar.gz |
servo: For all commands that read stdout, decode
I found this in a moblab repair log:
```
Traceback (most recent call last):
File "/usr/local/autotest/client/common_lib/hosts/repair.py", line 668, in _repair_host
self.repair(host)
File "/usr/local/autotest/server/hosts/cros_firmware.py", line 191, in repair
self._run_repair(host, build)
File "/usr/local/autotest/server/hosts/cros_firmware.py", line 228, in _run_repair
if host._servo_host.validate_image_usbkey() != build:
File "/usr/local/autotest/server/hosts/servo_host.py", line 518, in validate_image_usbkey
return self.get_image_name_from_usbkey(usb_dev)
File "/usr/local/autotest/server/hosts/servo_host.py", line 341, in get_image_name_from_usbkey
if not re.search(r'RELEASE_TRACK=.*test', release_content):
File "/usr/local/lib/python3.7/re.py", line 185, in search
return _compile(pattern, flags).search(string)
TypeError: cannot use a string pattern on a bytes-like object
```
To fix this, check all stdout strings to make sure they are not bytes.
BUG=b:217780680
TEST=None
Change-Id: Ib37eecd5f74617801f57cb2b1355be35121861a3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/autotest/+/3671361
Reviewed-by: Prasad Vuppalapu <prasadv@chromium.org>
Commit-Queue: Jeremy Bettis <jbettis@chromium.org>
Reviewed-by: Jesse McGuire <jessemcguire@google.com>
Tested-by: Jeremy Bettis <jbettis@chromium.org>
-rw-r--r-- | server/hosts/servo_host.py | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/server/hosts/servo_host.py b/server/hosts/servo_host.py index ede3c4f6fe..860242cfd9 100644 --- a/server/hosts/servo_host.py +++ b/server/hosts/servo_host.py @@ -301,6 +301,13 @@ class ServoHost(base_servohost.BaseServoHost): self.rpc_server_tracker.disconnect(self.servo_port) self._servo = None + def _to_str(self, maybe_str): + """If the param is bytes, convert it to a str.""" + # b/217780680, Make this compatible with python3, + if isinstance(maybe_str, bytes): + return maybe_str.decode('utf-8', errors='replace') + return maybe_str + def _maybe_create_servod_ssh_tunnel_proxy(self): """Create a xmlrpc proxy for use with a ssh tunnel. A lock is used to safely create a singleton proxy. @@ -390,9 +397,9 @@ class ServoHost(base_servohost.BaseServoHost): logging.debug('Unexpected error occurred on mount usb drive.') return '' - release_content = self.run( - 'cat %s/etc/lsb-release' % mount_dst, - ignore_status=True).stdout.strip() + release_content = self._to_str( + self.run('cat %s/etc/lsb-release' % mount_dst, + ignore_status=True).stdout.strip()) if not re.search(r'RELEASE_TRACK=.*test', release_content): logging.info('The image on usbkey is not a test image') @@ -430,7 +437,8 @@ class ServoHost(base_servohost.BaseServoHost): updater_bin = os.path.join(mount_dst, 'usr/sbin/chromeos-firmwareupdate') self.run('%s --unpack %s' % (updater_bin, fw_dst)) - return self.run('%s --manifest' % updater_bin).stdout + return self._to_str(self.run('%s --manifest' % updater_bin).stdout) + finally: self._unmount_drive(mount_dst) @@ -899,15 +907,16 @@ class ServoHost(base_servohost.BaseServoHost): """Helper function to handle non-zero servodtool response. """ if re.search(servo_constants.ERROR_MESSAGE_USB_HUB_NOT_COMPATIBLE, - response.stdout): + self._to_str(response.stdout)): logging.error('The servo is not plugged on a usb hub that supports' ' power-cycle!') # change the flag so we can update this label in later process. self.smart_usbhub = False return - if re.search(servo_constants.ERROR_MESSAGE_DEVICE_NOT_FOUND % - self.servo_serial, response.stdout): + if re.search( + servo_constants.ERROR_MESSAGE_DEVICE_NOT_FOUND % + self.servo_serial, self._to_str(response.stdout)): logging.error('No servo with serial %s found!', self.servo_serial) return @@ -936,7 +945,8 @@ class ServoHost(base_servohost.BaseServoHost): if resp.exit_status != 0: self._process_servodtool_error(resp) return '' - usb_path = resp.stdout.strip() + usb_path = self._to_str(resp.stdout.strip()) + logging.info('Usb path of servo %s is %s', self.servo_serial, usb_path) return usb_path @@ -949,7 +959,7 @@ class ServoHost(base_servohost.BaseServoHost): if resp.exit_status != 0: self._process_servodtool_error(resp) return '' - return resp.stdout.strip() + return self._to_str(resp.stdout.strip()) def reboot_servo_v3_on_need(self): """Check and reboot servo_v3 based on below conditions. @@ -1182,7 +1192,7 @@ class ServoHost(base_servohost.BaseServoHost): # Here we failed to find anything. logging.info('Failed to find remote servod logs. Ignoring.') return [] - logfiles = res.stdout.strip().split() + logfiles = self._to_str(res.stdout.strip().split()) timestamps = set() for logfile in logfiles: ts_match = self.TS_EXTRACTOR.match(logfile) @@ -1225,7 +1235,7 @@ class ServoHost(base_servohost.BaseServoHost): logging.warning('Failed to find servod logs on servo host.') logging.warning(res.stderr.strip()) return None - fname = os.path.basename(res.stdout.strip()) + fname = os.path.basename(self._to_str(res.stdout.strip())) # From the fname, ought to extract the timestamp using the TS_EXTRACTOR if type(fname) == type(b' '): fname = fname.decode("utf-8") @@ -1316,7 +1326,7 @@ class ServoHost(base_servohost.BaseServoHost): cmd = 'find %s -maxdepth 1 -name "log.%s*"' % (self.remote_log_dir, instance_ts) res = self.run(cmd, stderr_tee=None, ignore_status=True) - files = res.stdout.strip().split() + files = self._to_str(res.stdout.strip()).split() try: if self.is_containerized_servod(): client = docker_utils.get_docker_client() @@ -1524,7 +1534,7 @@ class ServoHost(base_servohost.BaseServoHost): try: cmd = 'lsusb | grep "%s"' % "\|".join(vid_pids) result = self.run(cmd, ignore_status=True, timeout=30) - if result.exit_status == 0 and result.stdout.strip(): + if result.exit_status == 0 and self._to_str(result.stdout.strip()): logging.debug('The servo board is detected on servo_v3') return True logging.debug('%s; %s', not_detected, result) |