diff --git a/salt/modules/rpm.py b/salt/modules/rpm.py index 3c9a885ef1..d898f32eb2 100644 --- a/salt/modules/rpm.py +++ b/salt/modules/rpm.py @@ -688,14 +688,29 @@ def version_cmp(ver1, ver2, ignore_epoch=False): 'more accurate version comparisons' ) else: - cmp_result = cmp_func(salt.utils.str_version_to_evr(ver1), - salt.utils.str_version_to_evr(ver2)) - if cmp_result not in (-1, 0, 1): - raise CommandExecutionError( - 'Comparison result \'{0}\' is invalid'.format(cmp_result) - ) + else: + # If one EVR is missing a release but not the other and they + # otherwise would be equal, assume they are equal. This can + # happen if e.g. you are checking if a package version 3.2 is + # satisfied by a 3.2-1. + (ver1_e, ver1_v, ver1_r) = salt.utils.str_version_to_evr(ver1) + (ver2_e, ver2_v, ver2_r) = salt.utils.str_version_to_evr(ver2) + if not ver1_r or not ver2_r: + tmp_cmp = cmp_func((ver1_e, ver1_v, ''), (ver2_e, ver2_v, '')) + if tmp_cmp not in (-1, 0, 1): + raise CommandExecutionError( + 'Comparison result \'{0}\' is invalid'.format(tmp_cmp) + ) + if tmp_cmp == 0: + return 0 - return cmp_result + cmp_result = cmp_func((ver1_e, ver1_v, ver1_r), + (ver2_e, ver2_v, ver2_r)) + if cmp_result not in (-1, 0, 1): + raise CommandExecutionError( + 'Comparison result \'{0}\' is invalid'.format(cmp_result) + ) + return cmp_result except Exception as exc: log.warning(