Skip to content

Commit 8a44f16

Browse files
committed
Use local_cmd in place of os.system
Signed-off-by: Gaëtan Lehmann <gaetan.lehmann@vates.tech>
1 parent 913fcab commit 8a44f16

3 files changed

Lines changed: 6 additions & 4 deletions

File tree

conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import lib.config as global_config
1818
from lib import pxe
19+
from lib.commands import local_cmd
1920
from lib.common import (
2021
Defer,
2122
DiskDevName,
@@ -322,7 +323,7 @@ def setup_host(hostname_or_ip: str, *, config: pytest.Config | None = None) -> H
322323
assert len(ips) == 1
323324
host_vm.ip = ips[0]
324325

325-
wait_for(lambda: not os.system(f"nc -zw5 {host_vm.ip} 22"),
326+
wait_for(lambda: local_cmd(["nc", "-zw5", str(host_vm.ip), "22"], check=False).returncode == 0,
326327
"Wait for ssh up on nested host", retry_delay_secs=5)
327328

328329
hostname_or_ip = host_vm.ip

scripts/install_xcpng.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# flake8: noqa: E402
1919
sys.path.append(f"{os.path.abspath(os.path.dirname(__file__))}/..")
2020
from lib import pxe
21-
from lib.commands import SSHCommandFailed, ssh
21+
from lib.commands import SSHCommandFailed, local_cmd, ssh
2222
from lib.common import is_uuid, wait_for
2323
from lib.host import Host, host_data
2424
from lib.pool import Pool
@@ -72,7 +72,7 @@ def generate_answerfile(directory: str, installer: str, hostname_or_ip: str, tar
7272
raise Exception(f"Unknown action: `{action}`")
7373

7474
def is_ip_active(ip: str) -> bool:
75-
return not os.system(f"ping -c 3 -W 10 {ip} > /dev/null 2>&1")
75+
return local_cmd(["ping", "-c", "3", "-W", "10", ip], check=False).returncode == 0
7676

7777
def is_ssh_up(ip: str) -> bool:
7878
try:

tests/network/test_vif_allowed_ip.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
import ipaddress
44
import os
55

6+
from lib.commands import local_cmd
67
from lib.vm import VM
78

89
# Requirements:
910
# - one XCP-ng host (--hosts) >= 8.2 (>= 8.3 for the CIDR tests) with no SDN controller configured
1011
# - a VM (--vm)
1112

1213
def ip_responsive(ip: str) -> bool:
13-
return not os.system(f"ping -c 3 -W 10 {ip} > /dev/null 2>&1")
14+
return local_cmd(["ping", "-c", "3", "-W", "10", ip], check=False).returncode == 0
1415

1516
@pytest.mark.small_vm
1617
@pytest.mark.usefixtures("host_no_sdn_controller")

0 commit comments

Comments
 (0)