Skip to content

Commit 4d7fc4f

Browse files
author
xianglongfei
committed
Fixed the issue in sysinfo where the dmidecode and fdisk -l commands were executed.
Signed-off-by: xianglongfei <[email protected]>
2 parents e774811 + 43cf978 commit 4d7fc4f

File tree

2 files changed

+46
-5
lines changed

2 files changed

+46
-5
lines changed

avocado/core/sysinfo.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
# This code was inspired in the autotest project,
1212
# client/shared/settings.py
1313
# Author: John Admanski <[email protected]>
14+
import configparser
1415
import filecmp
1516
import logging
1617
import os
1718
import time
18-
import configparser
1919

2020
from avocado.core import output
2121
from avocado.core.settings import settings
@@ -84,6 +84,47 @@ def __init__(self, basedir=None, log_packages=None, profiler=None):
8484
log.debug("sudo_distros config is empty or missing")
8585

8686
def _load_sudo_list(raw_value, key):
87+
# pylint: disable=wrong-spelling-in-docstring
88+
"""
89+
If `raw_value` is a path to an INI file, read `[sysinfo] / key`
90+
from it; otherwise, treat `raw_value` itself as a CSV list.
91+
"""
92+
if not raw_value:
93+
return ""
94+
if os.path.isfile(raw_value):
95+
parser = configparser.ConfigParser()
96+
parser.read(raw_value)
97+
return parser.get("sysinfo", key, fallback="")
98+
return raw_value
99+
100+
# Retrieve the actual sudo commands and distros values from the config files,
101+
# falling back to empty string if the keys are missing
102+
sudo_commands_value = _load_sudo_list(sudo_commands_conf, "sudo_commands")
103+
sudo_distros_value = _load_sudo_list(sudo_distros_conf, "sudo_distros")
104+
105+
self.sudo_commands = {
106+
cmd.strip().lower() for cmd in sudo_commands_value.split(",") if cmd.strip()
107+
}
108+
109+
self.sudo_distros = {
110+
dst.strip().lower() for dst in sudo_distros_value.split(",") if dst.strip()
111+
}
112+
113+
# Retrieve the configured paths for sudo commands and distros from the settings dictionary
114+
sudo_commands_conf = self.config.get("sysinfo.sudo_commands", "")
115+
sudo_distros_conf = self.config.get("sysinfo.sudo_distros", "")
116+
117+
if sudo_commands_conf:
118+
log.info("sudo_commands loaded from config: %s", sudo_commands_conf)
119+
else:
120+
log.debug("sudo_commands config is empty or missing")
121+
122+
if sudo_distros_conf:
123+
log.info("sudo_distros loaded from config: %s", sudo_distros_conf)
124+
else:
125+
log.debug("sudo_distros config is empty or missing")
126+
127+
def _load_sudo_list(raw_value, key):
87128
# pylint: disable=wrong-spelling-in-docstring
88129
"""
89130
If `raw_value` is a path to an INI file, read `[sysinfo] / key`

avocado/utils/sysinfo.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
# John Admanski <[email protected]>
1515

1616
import json
17+
import logging
1718
import os
19+
import platform
1820
import shlex
1921
import subprocess
2022
import tempfile
21-
import platform
22-
import logging
23-
2423
from abc import ABC, abstractmethod
24+
2525
from avocado.utils import astring, process
2626
from avocado.utils.process import can_sudo
2727

@@ -138,7 +138,7 @@ class Command(Collectible):
138138

139139
def __init__(
140140
self, cmd, timeout=-1, locale="C", sudo_commands=None, sudo_distros=None
141-
): # pylint: disable=R0913
141+
): # pylint: disable=R0913
142142
super().__init__(cmd)
143143
self._name = self.log_path
144144
self.cmd = cmd

0 commit comments

Comments
 (0)