From 98d9b455cc65da4a4735fe831f34b2b2678d835b Mon Sep 17 00:00:00 2001 From: Simon Lin Date: Fri, 25 Jun 2021 12:18:14 +0800 Subject: [PATCH] [otci] fix command issue after `factoryreset` (#6670) --- tools/otci/otci/command_handlers.py | 9 ++++++++- tools/otci/otci/otci.py | 8 -------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/tools/otci/otci/command_handlers.py b/tools/otci/otci/command_handlers.py index 582bcef57..676144962 100644 --- a/tools/otci/otci/command_handlers.py +++ b/tools/otci/otci/command_handlers.py @@ -95,7 +95,10 @@ class OtCliCommandRunner(OTCommandHandler): def execute_command(self, cmd, timeout=10) -> List[str]: self.__otcli.writeline(cmd) - if cmd in {'reset', 'factoryreset'}: + if cmd in ('reset', 'factoryreset'): + self.wait(3) + self.__otcli.writeline('extaddr') + self.wait(1) return [] if self.__expect_command_echoback: @@ -210,6 +213,10 @@ class OtbrSshCommandRunner(OTCommandHandler): raise CommandError(cmd, [err]) output = [l.rstrip('\r\n') for l in cmd_out.readlines()] + + if cmd in ('reset', 'factoryreset'): + self.wait(3) + return output def close(self): diff --git a/tools/otci/otci/otci.py b/tools/otci/otci/otci.py index 727770fd8..901fd97c4 100644 --- a/tools/otci/otci/otci.py +++ b/tools/otci/otci/otci.py @@ -29,7 +29,6 @@ import ipaddress import logging import re -import time from collections import Counter from typing import List, Collection, Union, Tuple, Optional, Dict, Pattern, Any @@ -105,7 +104,6 @@ class OTCI(object): self.__logger and self.__logger.info('%s', line) if cmd in ('reset', 'factoryreset'): - self.__wait_reset() return output if output[-1] == 'Done': @@ -2335,12 +2333,6 @@ class OTCI(object): s = s.replace(char, '\\%s' % char) return s - def __wait_reset(self): - # reset would restart the otbr-agent executable. It's risky to send commands after reset too quickly because - # it might cause ot-ctl to quit abnormally. - # So we sleep for a while after reset. - time.sleep(3) - def __txt_to_hex(self, txt: Dict[str, Union[str, bytes, bool]]) -> str: txt_bin = b'' for k, v in txt.items():