mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Add tests for yumpkg
This commit is contained in:
parent
b903999af4
commit
b2525aa042
2 changed files with 1144 additions and 68 deletions
|
@ -14,6 +14,7 @@ Support for YUM/DNF
|
|||
|
||||
.. versionadded:: 3003
|
||||
Support for ``tdnf`` on Photon OS.
|
||||
|
||||
"""
|
||||
|
||||
|
||||
|
@ -43,13 +44,6 @@ import salt.utils.versions
|
|||
from salt.exceptions import CommandExecutionError, MinionError, SaltInvocationError
|
||||
from salt.utils.versions import LooseVersion
|
||||
|
||||
try:
|
||||
import yum
|
||||
|
||||
HAS_YUM = True
|
||||
except ImportError:
|
||||
HAS_YUM = False
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
__HOLD_PATTERN = r"[\w+]+(?:[.-][^-]+)*"
|
||||
|
@ -353,67 +347,48 @@ def _get_yum_config(strict_parser=True):
|
|||
This is currently only used to get the reposdir settings, but could be used
|
||||
for other things if needed.
|
||||
|
||||
If the yum python library is available, use that, which will give us all of
|
||||
the options, including all of the defaults not specified in the yum config.
|
||||
Additionally, they will all be of the correct object type.
|
||||
|
||||
If the yum library is not available, we try to read the yum.conf
|
||||
directly ourselves with a minimal set of "defaults".
|
||||
We try to read the yum.conf directly ourselves with a minimal set of
|
||||
"defaults".
|
||||
"""
|
||||
# in case of any non-fatal failures, these defaults will be used
|
||||
conf = {
|
||||
"reposdir": ["/etc/yum/repos.d", "/etc/yum.repos.d"],
|
||||
}
|
||||
|
||||
if HAS_YUM:
|
||||
try:
|
||||
yb = yum.YumBase()
|
||||
yb.preconf.init_plugins = False
|
||||
for name, value in yb.conf.items():
|
||||
conf[name] = value
|
||||
except (AttributeError, yum.Errors.ConfigError) as exc:
|
||||
raise CommandExecutionError("Could not query yum config: {}".format(exc))
|
||||
except yum.Errors.YumBaseError as yum_base_error:
|
||||
raise CommandExecutionError(
|
||||
"Error accessing yum or rpmdb: {}".format(yum_base_error)
|
||||
)
|
||||
else:
|
||||
# fall back to parsing the config ourselves
|
||||
# Look for the config the same order yum does
|
||||
fn = None
|
||||
paths = (
|
||||
"/etc/yum/yum.conf",
|
||||
"/etc/yum.conf",
|
||||
"/etc/dnf/dnf.conf",
|
||||
"/etc/tdnf/tdnf.conf",
|
||||
# fall back to parsing the config ourselves
|
||||
# Look for the config the same order yum does
|
||||
fn = None
|
||||
paths = (
|
||||
"/etc/yum/yum.conf",
|
||||
"/etc/yum.conf",
|
||||
"/etc/dnf/dnf.conf",
|
||||
"/etc/tdnf/tdnf.conf",
|
||||
)
|
||||
for path in paths:
|
||||
if os.path.exists(path):
|
||||
fn = path
|
||||
break
|
||||
|
||||
if not fn:
|
||||
raise CommandExecutionError(
|
||||
"No suitable yum config file found in: {}".format(paths)
|
||||
)
|
||||
for path in paths:
|
||||
if os.path.exists(path):
|
||||
fn = path
|
||||
break
|
||||
|
||||
if not fn:
|
||||
raise CommandExecutionError(
|
||||
"No suitable yum config file found in: {}".format(paths)
|
||||
)
|
||||
cp = configparser.ConfigParser(strict=strict_parser)
|
||||
try:
|
||||
cp.read(fn)
|
||||
except OSError as exc:
|
||||
raise CommandExecutionError("Unable to read from {}: {}".format(fn, exc))
|
||||
|
||||
cp = configparser.ConfigParser(strict=strict_parser)
|
||||
try:
|
||||
cp.read(fn)
|
||||
except OSError as exc:
|
||||
raise CommandExecutionError("Unable to read from {}: {}".format(fn, exc))
|
||||
|
||||
if cp.has_section("main"):
|
||||
for opt in cp.options("main"):
|
||||
if opt in ("reposdir", "commands", "excludes"):
|
||||
# these options are expected to be lists
|
||||
conf[opt] = [x.strip() for x in cp.get("main", opt).split(",")]
|
||||
else:
|
||||
conf[opt] = cp.get("main", opt)
|
||||
else:
|
||||
log.warning(
|
||||
"Could not find [main] section in %s, using internal defaults", fn
|
||||
)
|
||||
if cp.has_section("main"):
|
||||
for opt in cp.options("main"):
|
||||
if opt in ("reposdir", "commands", "excludes"):
|
||||
# these options are expected to be lists
|
||||
conf[opt] = [x.strip() for x in cp.get("main", opt).split(",")]
|
||||
else:
|
||||
conf[opt] = cp.get("main", opt)
|
||||
else:
|
||||
log.warning("Could not find [main] section in %s, using internal defaults", fn)
|
||||
|
||||
return conf
|
||||
|
||||
|
@ -2861,7 +2836,7 @@ def group_install(name, skip=(), include=(), **kwargs):
|
|||
if not pkgs:
|
||||
return {}
|
||||
|
||||
return install(pkgs=pkgs, **kwargs)
|
||||
return install(pkgs=list(set(pkgs)), **kwargs)
|
||||
|
||||
|
||||
groupinstall = salt.utils.functools.alias_function(group_install, "groupinstall")
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue