aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Lin <simonlin@google.com>2022-07-19 23:51:20 +0800
committerGitHub <noreply@github.com>2022-07-19 08:51:20 -0700
commit6242a1e68ed09fdbb3d078423b22cf584a5456d9 (patch)
tree16fd85a3abed23f4114a345198201b12578eb47d
parent095f530bd7ef1a6d012179a087514757141e8e6e (diff)
downloadopenthread-6242a1e68ed09fdbb3d078423b22cf584a5456d9.tar.gz
[thci] allow to specify custom commands (#7912)
This commit uses `Param9` to specify custom commands for Thread BR THCI to control `otbr-agent`.
-rw-r--r--tools/harness-thci/OpenThread.py33
-rw-r--r--tools/harness-thci/OpenThread_BR.py9
2 files changed, 38 insertions, 4 deletions
diff --git a/tools/harness-thci/OpenThread.py b/tools/harness-thci/OpenThread.py
index 6769a0eb4..86bcb46cf 100644
--- a/tools/harness-thci/OpenThread.py
+++ b/tools/harness-thci/OpenThread.py
@@ -30,7 +30,7 @@
>> Device : OpenThread THCI
>> Class : OpenThread
"""
-
+import base64
import functools
import ipaddress
import logging
@@ -39,6 +39,7 @@ import traceback
import re
import socket
import time
+import json
from abc import abstractmethod
import serial
@@ -405,6 +406,7 @@ class OpenThreadTHCI(object):
self.mac = params.get('EUI')
self.backboneNetif = params.get('Param8') or 'eth0'
+ self.extraParams = self.__parseExtraParams(params.get('Param9'))
self.UIStatusMsg = ''
self.AutoDUTEnable = False
@@ -446,6 +448,35 @@ class OpenThreadTHCI(object):
else:
return '[%s]' % self.port
+ @watched
+ def __parseExtraParams(self, Param9):
+ """
+ Parse `Param9` for extra THCI parameters.
+
+ `Param9` should be a JSON string encoded in URL-safe base64 encoding.
+
+ Defined Extra THCI Parameters:
+ - "cmd-start-otbr-agent" : The command to start otbr-agent (default: systemctl start otbr-agent)
+ - "cmd-stop-otbr-agent" : The command to stop otbr-agent (default: systemctl stop otbr-agent)
+ - "cmd-restart-otbr-agent" : The command to restart otbr-agent (default: systemctl restart otbr-agent)
+
+ For example, Param9 can be generated as below:
+ Param9 = base64.urlsafe_b64encode(json.dumps({
+ "cmd-start-otbr-agent": "service otbr-agent start",
+ "cmd-stop-otbr-agent": "service otbr-agent stop",
+ "cmd-restart-otbr-agent": "service otbr-agent restart",
+ }))
+
+ :param Param9: A JSON string encoded in URL-safe base64 encoding.
+ :return: A dict containing extra THCI parameters.
+ """
+ if not Param9 or not Param9.strip():
+ return {}
+
+ jsonStr = base64.urlsafe_b64decode(Param9)
+ params = json.loads(jsonStr)
+ return params
+
@API
def closeConnection(self):
"""close current serial port connection"""
diff --git a/tools/harness-thci/OpenThread_BR.py b/tools/harness-thci/OpenThread_BR.py
index 4de7dd789..a867f7d18 100644
--- a/tools/harness-thci/OpenThread_BR.py
+++ b/tools/harness-thci/OpenThread_BR.py
@@ -620,7 +620,8 @@ class OpenThread_BR(OpenThreadTHCI, IThci):
self.__cli_output_lines.append(line)
def __restartAgentService(self):
- self.bash('systemctl restart otbr-agent')
+ restart_cmd = self.extraParams.get('cmd-restart-otbr-agent', 'systemctl restart otbr-agent')
+ self.bash(restart_cmd)
def __truncateSyslog(self):
self.bash('truncate -s 0 /var/log/syslog')
@@ -653,14 +654,16 @@ class OpenThread_BR(OpenThreadTHCI, IThci):
@API
def powerDown(self):
self.log('Powering down BBR')
- self.bash('systemctl stop otbr-agent')
super(OpenThread_BR, self).powerDown()
+ stop_cmd = self.extraParams.get('cmd-stop-otbr-agent', 'systemctl stop otbr-agent')
+ self.bash(stop_cmd)
# Override powerUp
@API
def powerUp(self):
self.log('Powering up BBR')
- self.bash('systemctl start otbr-agent')
+ start_cmd = self.extraParams.get('cmd-start-otbr-agent', 'systemctl start otbr-agent')
+ self.bash(start_cmd)
super(OpenThread_BR, self).powerUp()
# Override forceSetSlaac