Handle non-posix local executor
Signed-off-by: Daniel Madej <daniel.madej@huawei.com>
This commit is contained in:
parent
452000c03c
commit
a7c7cd3d84
@ -3,23 +3,26 @@
|
|||||||
# Copyright(c) 2024 Huawei Technologies Co., Ltd.
|
# Copyright(c) 2024 Huawei Technologies Co., Ltd.
|
||||||
# SPDX-License-Identifier: BSD-3-Clause
|
# SPDX-License-Identifier: BSD-3-Clause
|
||||||
#
|
#
|
||||||
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
from connection.base_executor import BaseExecutor
|
from connection.base_executor import BaseExecutor
|
||||||
from core.test_run import TestRun
|
from core.test_run import TestRun
|
||||||
from test_utils.output import Output
|
from test_tools.fs_utils import copy
|
||||||
|
from test_utils.output import Output, CmdException
|
||||||
|
|
||||||
|
|
||||||
class LocalExecutor(BaseExecutor):
|
class LocalExecutor(BaseExecutor):
|
||||||
def _execute(self, command, timeout):
|
def __init__(self):
|
||||||
bash_path = TestRun.config.get("bash_path", "/bin/bash")
|
default_executable_path = "/bin/bash" if os.name == 'posix' else None
|
||||||
|
self._executable_path = TestRun.config.get("executable_path", default_executable_path)
|
||||||
|
|
||||||
|
def _execute(self, command, timeout):
|
||||||
completed_process = subprocess.run(
|
completed_process = subprocess.run(
|
||||||
command,
|
command,
|
||||||
shell=True,
|
shell=True,
|
||||||
executable=bash_path,
|
executable=self._executable_path,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE,
|
stderr=subprocess.PIPE,
|
||||||
timeout=timeout.total_seconds(),
|
timeout=timeout.total_seconds(),
|
||||||
@ -41,7 +44,6 @@ class LocalExecutor(BaseExecutor):
|
|||||||
dut_to_controller=False,
|
dut_to_controller=False,
|
||||||
):
|
):
|
||||||
options = []
|
options = []
|
||||||
bash_path = TestRun.config.get("bash_path", "/bin/bash")
|
|
||||||
|
|
||||||
if delete:
|
if delete:
|
||||||
options.append("--delete")
|
options.append("--delete")
|
||||||
@ -53,14 +55,10 @@ class LocalExecutor(BaseExecutor):
|
|||||||
for exclude in exclude_list:
|
for exclude in exclude_list:
|
||||||
options.append(f"--exclude {exclude}")
|
options.append(f"--exclude {exclude}")
|
||||||
|
|
||||||
completed_process = subprocess.run(
|
output = self._execute(f'rsync -r {src} {dst} {" ".join(options)}', timeout)
|
||||||
f'rsync -r {src} {dst} {" ".join(options)}',
|
|
||||||
shell=True,
|
|
||||||
executable=bash_path,
|
|
||||||
stdout=subprocess.PIPE,
|
|
||||||
stderr=subprocess.PIPE,
|
|
||||||
timeout=timeout.total_seconds(),
|
|
||||||
)
|
|
||||||
|
|
||||||
if completed_process.returncode:
|
if output.exit_code:
|
||||||
raise Exception(f"rsync failed:\n{completed_process}")
|
raise CmdException("rsync failed", output)
|
||||||
|
|
||||||
|
def _copy(self, src, dst, dut_to_controller: bool):
|
||||||
|
copy(src, dst, recursive=True)
|
||||||
|
Loading…
Reference in New Issue
Block a user