From cc011d878925a191d08a422dbe96f6e8a411f586 Mon Sep 17 00:00:00 2001 From: Sitong Liu Date: Tue, 25 Sep 2018 20:16:35 +0800 Subject: [PATCH] Python 3: fix a byte-str issue of utils.service Fix issue: re.search(r"Loaded: loaded", output) failed | TypeError: cannot use a string pattern on a bytes-like object Signed-off-by: Sitong Liu --- avocado/utils/service.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/avocado/utils/service.py b/avocado/utils/service.py index ed8d2ada..13ad77d7 100644 --- a/avocado/utils/service.py +++ b/avocado/utils/service.py @@ -118,16 +118,16 @@ def sys_v_init_result_parser(command): # If service is stopped, exit_status is also not zero. # So, we can't use exit_status to check result. # Returns None if XXX is unrecognized. - if re.search(r"unrecognized", cmd_result.stderr.lower()): + if re.search(b"unrecognized", cmd_result.stderr.lower()): return None # Returns False if XXX is stopped. output = cmd_result.stdout.lower() - dead_flags = [r"stopped", r"not running", r"dead"] + dead_flags = [b"stopped", b"not running", b"dead"] for flag in dead_flags: if re.search(flag, output): return False # If output does not contain a dead flag, check it with "running". - return bool(re.search(r"running", output)) + return bool(re.search(b"running", output)) return method elif command == "list": def method(cmd_result): @@ -208,10 +208,10 @@ def systemd_result_parser(command): # So, we can't use exit_status to check result. output = cmd_result.stdout # Returns None if XXX is not loaded. - if not re.search(r"Loaded: loaded", output): + if not re.search(b"Loaded: loaded", output): return None # Check it with Active status. - return output.count("Active: active") > 0 + return output.count(b"Active: active") > 0 return method elif command == "list": def method(cmd_result): -- GitLab