mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #31032 from terminalmage/issue31001
(2015.5 branch) yumpkg: ensure that dnf-plugins-core >= 0.1.15 is installed
This commit is contained in:
commit
e56c402c0c
5 changed files with 689 additions and 510 deletions
File diff suppressed because it is too large
Load diff
|
@ -327,27 +327,34 @@ def _find_install_targets(name=None,
|
|||
if not (name in cur_pkgs and version in (None, cur_pkgs[name]))
|
||||
])
|
||||
if not_installed:
|
||||
problems = _preflight_check(not_installed, **kwargs)
|
||||
comments = []
|
||||
if problems.get('no_suggest'):
|
||||
comments.append(
|
||||
'The following package(s) were not found, and no possible '
|
||||
'matches were found in the package db: '
|
||||
'{0}'.format(', '.join(sorted(problems['no_suggest'])))
|
||||
)
|
||||
if problems.get('suggest'):
|
||||
for pkgname, suggestions in six.iteritems(problems['suggest']):
|
||||
try:
|
||||
problems = _preflight_check(not_installed, **kwargs)
|
||||
except CommandExecutionError:
|
||||
pass
|
||||
else:
|
||||
comments = []
|
||||
if problems.get('no_suggest'):
|
||||
comments.append(
|
||||
'Package \'{0}\' not found (possible matches: {1})'
|
||||
.format(pkgname, ', '.join(suggestions))
|
||||
'The following package(s) were not found, and no '
|
||||
'possible matches were found in the package db: '
|
||||
'{0}'.format(
|
||||
', '.join(sorted(problems['no_suggest']))
|
||||
)
|
||||
)
|
||||
if comments:
|
||||
if len(comments) > 1:
|
||||
comments.append('')
|
||||
return {'name': name,
|
||||
'changes': {},
|
||||
'result': False,
|
||||
'comment': '. '.join(comments).rstrip()}
|
||||
if problems.get('suggest'):
|
||||
for pkgname, suggestions in \
|
||||
six.iteritems(problems['suggest']):
|
||||
comments.append(
|
||||
'Package \'{0}\' not found (possible matches: '
|
||||
'{1})'.format(pkgname, ', '.join(suggestions))
|
||||
)
|
||||
if comments:
|
||||
if len(comments) > 1:
|
||||
comments.append('')
|
||||
return {'name': name,
|
||||
'changes': {},
|
||||
'result': False,
|
||||
'comment': '. '.join(comments).rstrip()}
|
||||
|
||||
# Check current versions against desired versions
|
||||
targets = {}
|
||||
|
|
34
salt/utils/itertools.py
Normal file
34
salt/utils/itertools.py
Normal file
|
@ -0,0 +1,34 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
Helpful generators and other tools
|
||||
'''
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
import re
|
||||
|
||||
|
||||
def split(orig, sep=None):
|
||||
'''
|
||||
Generator function for iterating through large strings, particularly useful
|
||||
as a replacement for str.splitlines().
|
||||
|
||||
See http://stackoverflow.com/a/3865367
|
||||
'''
|
||||
exp = re.compile(r'\s+' if sep is None else re.escape(sep))
|
||||
pos = 0
|
||||
length = len(orig)
|
||||
while True:
|
||||
match = exp.search(orig, pos)
|
||||
if not match:
|
||||
if pos < length or sep is not None:
|
||||
val = orig[pos:]
|
||||
if val:
|
||||
# Only yield a value if the slice was not an empty string,
|
||||
# because if it is then we've reached the end. This keeps
|
||||
# us from yielding an extra blank value at the end.
|
||||
yield val
|
||||
break
|
||||
if pos < match.start() or sep is not None:
|
||||
yield orig[pos:match.start()]
|
||||
pos = match.end()
|
4
salt/utils/pkg/__init__.py
Normal file
4
salt/utils/pkg/__init__.py
Normal file
|
@ -0,0 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
Helper modules used by lowpkg modules
|
||||
'''
|
102
salt/utils/pkg/rpm.py
Normal file
102
salt/utils/pkg/rpm.py
Normal file
|
@ -0,0 +1,102 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
Common functions for working with RPM packages
|
||||
'''
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
import collections
|
||||
import logging
|
||||
|
||||
# Import salt libs
|
||||
from salt._compat import subprocess
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
# These arches compiled from the rpmUtils.arch python module source
|
||||
ARCHES_64 = ('x86_64', 'athlon', 'amd64', 'ia32e', 'ia64', 'geode')
|
||||
ARCHES_32 = ('i386', 'i486', 'i586', 'i686')
|
||||
ARCHES_PPC = ('ppc', 'ppc64', 'ppc64iseries', 'ppc64pseries')
|
||||
ARCHES_S390 = ('s390', 's390x')
|
||||
ARCHES_SPARC = (
|
||||
'sparc', 'sparcv8', 'sparcv9', 'sparcv9v', 'sparc64', 'sparc64v'
|
||||
)
|
||||
ARCHES_ALPHA = (
|
||||
'alpha', 'alphaev4', 'alphaev45', 'alphaev5', 'alphaev56',
|
||||
'alphapca56', 'alphaev6', 'alphaev67', 'alphaev68', 'alphaev7'
|
||||
)
|
||||
ARCHES_ARM = ('armv5tel', 'armv5tejl', 'armv6l', 'armv7l')
|
||||
ARCHES_SH = ('sh3', 'sh4', 'sh4a')
|
||||
|
||||
ARCHES = ARCHES_64 + ARCHES_32 + ARCHES_PPC + ARCHES_S390 + \
|
||||
ARCHES_ALPHA + ARCHES_ARM + ARCHES_SH
|
||||
|
||||
# EPOCHNUM can't be used until RHEL5 is EOL as it is not present
|
||||
QUERYFORMAT = '%{NAME}_|-%{EPOCH}_|-%{VERSION}_|-%{RELEASE}_|-%{ARCH}_|-%{REPOID}'
|
||||
|
||||
|
||||
def get_osarch():
|
||||
'''
|
||||
Get the os architecture using rpm --eval
|
||||
'''
|
||||
ret = subprocess.Popen(
|
||||
'rpm --eval "%{_host_cpu}"',
|
||||
shell=True,
|
||||
close_fds=True,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE).communicate()[0]
|
||||
return ret or 'unknown'
|
||||
|
||||
|
||||
def check_32(arch, osarch=None):
|
||||
'''
|
||||
Returns True if both the OS arch and the passed arch are 32-bit
|
||||
'''
|
||||
if osarch is None:
|
||||
osarch = get_osarch()
|
||||
return all(x in ARCHES_32 for x in (osarch, arch))
|
||||
|
||||
|
||||
def pkginfo(name, version, arch, repoid):
|
||||
'''
|
||||
Build and return a pkginfo namedtuple
|
||||
'''
|
||||
pkginfo_tuple = collections.namedtuple(
|
||||
'PkgInfo',
|
||||
('name', 'version', 'arch', 'repoid')
|
||||
)
|
||||
return pkginfo_tuple(name, version, arch, repoid)
|
||||
|
||||
|
||||
def resolve_name(name, arch, osarch=None):
|
||||
'''
|
||||
Resolve the package name and arch into a unique name referred to by salt.
|
||||
For example, on a 64-bit OS, a 32-bit package will be pkgname.i386.
|
||||
'''
|
||||
if osarch is None:
|
||||
osarch = get_osarch()
|
||||
|
||||
if not check_32(arch, osarch) and arch not in (osarch, 'noarch'):
|
||||
name += '.{0}'.format(arch)
|
||||
return name
|
||||
|
||||
|
||||
def parse_pkginfo(line, osarch=None):
|
||||
'''
|
||||
A small helper to parse an rpm/repoquery command's output. Returns a
|
||||
pkginfo namedtuple.
|
||||
'''
|
||||
try:
|
||||
name, epoch, version, release, arch, repoid = line.split('_|-')
|
||||
# Handle unpack errors (should never happen with the queryformat we are
|
||||
# using, but can't hurt to be careful).
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
name = resolve_name(name, arch, osarch)
|
||||
if release:
|
||||
version += '-{0}'.format(release)
|
||||
if epoch not in ('(none)', '0'):
|
||||
version = ':'.join((epoch, version))
|
||||
|
||||
return pkginfo(name, version, arch, repoid)
|
Loading…
Add table
Reference in a new issue