|
11 | 11 | # This code was inspired in the autotest project, |
12 | 12 | # client/shared/settings.py |
13 | 13 | # Author: John Admanski <[email protected]> |
| 14 | +import configparser |
14 | 15 | import filecmp |
15 | 16 | import logging |
16 | 17 | import os |
17 | 18 | import time |
18 | | -import configparser |
19 | 19 |
|
20 | 20 | from avocado.core import output |
21 | 21 | from avocado.core.settings import settings |
@@ -84,6 +84,47 @@ def __init__(self, basedir=None, log_packages=None, profiler=None): |
84 | 84 | log.debug("sudo_distros config is empty or missing") |
85 | 85 |
|
86 | 86 | 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): |
87 | 128 | # pylint: disable=wrong-spelling-in-docstring |
88 | 129 | """ |
89 | 130 | If `raw_value` is a path to an INI file, read `[sysinfo] / key` |
|
0 commit comments