Fix ValueError on cross-platform minion / master

* Rework __virtual__ grains check logic
* Remove rpm import
This commit is contained in:
Aaron Tygart 2012-12-31 14:26:26 -06:00
parent ff2861243c
commit 720cf93d87

View File

@ -2,7 +2,6 @@
Support for YUM Support for YUM
:depends: - yum Python module :depends: - yum Python module
- rpm Python module
- rpmUtils Python module - rpmUtils Python module
''' '''
@ -12,7 +11,6 @@ import logging
# Import third party libs # Import third party libs
try: try:
import yum import yum
import rpm # XXX: Is this import really needed. It's not used.
from rpmUtils.arch import getBaseArch from rpmUtils.arch import getBaseArch
HAS_YUMDEPS = True HAS_YUMDEPS = True
except (ImportError, AttributeError): except (ImportError, AttributeError):
@ -29,18 +27,21 @@ def __virtual__():
return False return False
# Work only on RHEL/Fedora based distros with python 2.6 or greater # Work only on RHEL/Fedora based distros with python 2.6 or greater
# TODO: Someone decide if we can just test os_family and pythonversion
os_grain = __grains__['os'] os_grain = __grains__['os']
os_family = __grains__['os_family'] os_family = __grains__['os_family']
os_major_release = int(__grains__['osrelease'].split('.')[0]) try:
os_major = int(__grains__['osrelease'].split('.')[0])
except ValueError:
os_major = 0
if os_grain == 'Amazon':
return 'pkg'
elif os_grain == 'Fedora':
# Fedora <= 10 used Python 2.5 and below # Fedora <= 10 used Python 2.5 and below
if os_grain == 'Fedora' and os_major_release >= 11: if os_major >= 11:
return 'pkg' return 'pkg'
elif os_grain == 'Amazon': elif os_family == 'RedHat' and os_major >= 6:
return 'pkg'
else:
if os_family == 'RedHat' and os_grain != 'Fedora':
if os_major_release >= 6:
return 'pkg' return 'pkg'
return False return False