Skip to content

Commit 40f3299

Browse files
author
xianglongfei
committed
Fixed the issue in sysinfo where the dmidecode and fdisk -l commands were executed.
Signed-off-by: xianglongfei <xianglongfei@uniontech.com>
2 parents e774811 + 43cf978 commit 40f3299

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

avocado/core/sysinfo.py

Lines changed: 5 additions & 5 deletions
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 <jadmanski@google.com>
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
@@ -83,7 +83,7 @@ def __init__(self, basedir=None, log_packages=None, profiler=None):
8383
else:
8484
log.debug("sudo_distros config is empty or missing")
8585

86-
def _load_sudo_list(raw_value, key):
86+
def _load_sudo_list(raw_value, key):
8787
# pylint: disable=wrong-spelling-in-docstring
8888
"""
8989
If `raw_value` is a path to an INI file, read `[sysinfo] / key`
@@ -92,9 +92,9 @@ def _load_sudo_list(raw_value, key):
9292
if not raw_value:
9393
return ""
9494
if os.path.isfile(raw_value):
95-
config = configparser.ConfigParser()
96-
config.read(raw_value)
97-
return config.get("sysinfo", key, fallback="")
95+
parser = configparser.ConfigParser()
96+
parser.read(raw_value)
97+
return parser.get("sysinfo", key, fallback="")
9898
return raw_value
9999

100100
# Retrieve the actual sudo commands and distros values from the config files,

avocado/utils/sysinfo.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
# John Admanski <jadmanski@google.com>
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,14 +138,21 @@ 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
145145
self.timeout = timeout
146146
self.locale = locale
147147
self.sudo_commands = sudo_commands
148148
self.sudo_distros = sudo_distros
149+
self._sysinfo_cmd = None
150+
151+
@property
152+
def _sudo_helper(self):
153+
if self._sysinfo_cmd is None and self.sudo_commands and self.sudo_distros:
154+
self._sysinfo_cmd = SysinfoCommand(self.sudo_commands, self.sudo_distros)
155+
return self._sysinfo_cmd
149156

150157
def __repr__(self):
151158
r = "Command(%r, %r)"
@@ -179,9 +186,8 @@ def collect(self):
179186

180187
# Determine whether to run with sudo (do not mutate the command string)
181188
sudo_flag = False
182-
if self.sudo_commands and self.sudo_distros:
183-
sysinfo_cmd = SysinfoCommand(self.sudo_commands, self.sudo_distros)
184-
sudo_flag = sysinfo_cmd.use_sudo() and sysinfo_cmd.is_sudo_cmd(self.cmd)
189+
if self._sudo_helper:
190+
sudo_flag = self._sudo_helper.use_sudo() and self._sudo_helper.is_sudo_cmd(self.cmd)
185191
log.info("Executing Command%s: %s", " (sudo)" if sudo_flag else "", self.cmd)
186192

187193
try:

0 commit comments

Comments
 (0)