def cpaas_label_compare(left, right): if type(left) is not tuple or type(right) is not tuple: raise ValueError('cpaas_label_compare requires two tuples') if len(left) != 3 or len(right) != 3: raise ValueError('cpaas_label_compare requires two tuples of length 3') l_r = _cpaas_truncate(left[2]) r_r = _cpaas_truncate(right[2]) return rpmLabelCompare((left[0], left[1], l_r), (right[0], right[1], r_r))
def test_labelCompare(self): a = ('0', '6.0.0', '2.el7ost') b = ('0', '6.0.1', '0.20170222164853.el7ost') c = ('0', '6.0.0', '0.20170217223245.0rc1.el7ost') d = ('0', '6.1.10', '0.20170222164853.el7ost') e = ('0', '6.1.9', '1.el7ost') f = ('0', '6.0.0', '0.2.0rc2.el7ost') g = ('0', '6.0.0', '0.3.0rc2.el7ost') # new dlrn new_dlrn = ('0', '6.1.1', '0.2.20170217063119.ad33b59.el7ost') # DLRN build vs not should be different self.assertEqual(rpmLabelCompare(a, b), -1) self.assertEqual(labelCompare(a, b), 1) # Reverse self.assertEqual(labelCompare(b, a), -1) # Two dlrn builds should be compared the same self.assertEqual(rpmLabelCompare(b, c), labelCompare(b, c)) # One dlrn build and one not with same version # should not matter self.assertEqual(rpmLabelCompare(a, c), labelCompare(a, c)) self.assertEqual(rpmLabelCompare(new_dlrn, d), labelCompare(new_dlrn, d)) self.assertEqual(rpmLabelCompare(new_dlrn, e), labelCompare(new_dlrn, e)) self.assertEqual(rpmLabelCompare(new_dlrn, b), labelCompare(new_dlrn, b)) # Micro release difference should work even if it goes from # 1-2 digits (or 2-3, etc.) self.assertEqual(rpmLabelCompare(d, e), 1) self.assertEqual(labelCompare(d, e), -1) # Reverse self.assertEqual(labelCompare(e, d), 1) # Release candidate DLRN builds > dlrn builds # e.g. 0.2.0rc1 needs to be > 0.2348349839021890.abc444 self.assertEqual(rpmLabelCompare(b, f), 1) self.assertEqual(rpmLabelCompare(b, g), 1) self.assertEqual(labelCompare(b, f), -1)
def cpaas_label_compare(left, right): if type(left) is not tuple or type(right) is not tuple: raise ValueError('cpaas_label_compare requires two tuples') if len(left) != 3 or len(right) != 3: raise ValueError('cpaas_label_compare requires two tuples of length 3') rx = re.compile(r'\.[0-9]+$') l_m = rx.search(left[2]) r_m = rx.search(right[2]) if l_m: l_r = left[2][0:l_m.span()[0]] else: l_r = left[2] if r_m: r_r = right[2][0:r_m.span()[0]] else: r_r = right[2] return rpmLabelCompare((left[0], left[1], l_r), (right[0], right[1], r_r))
def test_labelCompare(self): a = ('0', '6.0.0', '2.el7ost') b = ('0', '6.0.1', '0.20170222164853.el7ost') c = ('0', '6.0.0', '0.20170217223245.0rc1.el7ost') d = ('0', '6.1.10', '0.20170222164853.el7ost') e = ('0', '6.1.9', '1.el7ost') f = ('0', '6.0.0', '0.2.0rc2.el7ost') new_dlrn = ('0', '6.1.1', '0.2.20170217063119.ad33b59.el7ost') self.assertEqual(rpmLabelCompare(a, b), labelCompare(a, b)) # Two dlrn builds should be compared the same self.assertEqual(rpmLabelCompare(b, c), labelCompare(b, c)) # One dlrn build and one not with same version # should not matter self.assertEqual(rpmLabelCompare(a, c), labelCompare(a, c)) self.assertEqual(rpmLabelCompare(new_dlrn, d), labelCompare(new_dlrn, d)) self.assertEqual(rpmLabelCompare(new_dlrn, e), labelCompare(new_dlrn, e)) self.assertEqual(rpmLabelCompare(new_dlrn, b), labelCompare(new_dlrn, b)) self.assertEqual(rpmLabelCompare(d, e), labelCompare(d, e)) # Release candidate DLRN builds > dlrn builds # e.g. 0.2.0rc1 needs to be > 0.2348349839021890.abc444 self.assertEqual(rpmLabelCompare(b, f), labelCompare(b, f)) # known prior test cases that were broken prior to previous # dlrn_label_compare commits a = ('0', '1.2.0', '0.20191009110244.6090753.el8ost') b = ('0', '1.1.0', '1.20201113133400.6e1ba65.el8ost') self.assertEqual(rpmLabelCompare(a, b), labelCompare(a, b)) self.assertEqual(rpmLabelCompare(a, b), dlrn_label_compare(a, b)[0]) a = ('0', '2.3.2', '0.20191004134845.41e2a2b.el8ost') b = ('0', '2.3.1', '1.20201113163517.41e2a2b.el8ost') self.assertEqual(rpmLabelCompare(a, b), labelCompare(a, b)) self.assertEqual(rpmLabelCompare(a, b), dlrn_label_compare(a, b)[0])
def label_compare(l, r): return rpmLabelCompare(l, r)
def dlrn_label_compare(l, r): warnings.warn("dlrn_label_compare() is deprecated; use label_compare().", DeprecationWarning) if type(l) is not tuple or type(r) is not tuple: raise ValueError('dlrn_label_compare requires two tuples') l_is_dlrn = False r_is_dlrn = False l_is_rc = False r_is_rc = False l_is_ga = False r_is_ga = False lx = l[0] lv = l[1] lr = l[2] dlrn_regex = r'^[012](\.[0-9]{1,2})?\.[0-9]{14}\.[0-9a-f]{7}\.' if re.match(dlrn_regex, lr): l_is_dlrn = True elif re.match(r'^0\.[0-9]{1,2}\.0rc[123](\.|$)', lr): l_is_rc = True elif re.match(r'^0\.[0-9]{1,2}(\.|$)', lr): l_is_ga = True rx = r[0] rv = r[1] rr = r[2] if re.match(dlrn_regex, rr): r_is_dlrn = True elif re.match(r'^0\.[0-9]{1,2}\.0rc[123](\.|$)', rr): r_is_rc = True elif re.match(r'^0\.[0-9]{1,2}(\.|$)', rr): r_is_ga = True if r_is_dlrn == l_is_dlrn: return (rpmLabelCompare(l, r), False) altered = False if l_is_dlrn: if r_is_rc: # print 'fudging DLRN release for right to 1 (RC build)' rr = '1' altered = True if r_is_ga: # print 'fudging DLRN release for left to 0 (GA build)' lr = '0' altered = True if rv[:-1] == lv[:-1] and \ ord(lv[-1:]) - ord(rv[-1:]) == 1: # print 'fudging DLRN build version (type 1l)' return (rpmLabelCompare((lx, rv, lr), (rx, rv, rr)), True) x = lv.rfind('.') if lv[:x] == rv: # 6.2-2.el6ost > 6.2.1-0.20171313131313 # print 'fudging DLRN build version (type 2l.b)' return (rpmLabelCompare((lx, lv, lr), (rx, lv, rr)), True) if lv[:x] == rv[:x]: # 6.0.9-1.el7ost > 6.0.10-0.201713131313131 lm = int(lv[x + 1:]) rm = int(rv[x + 1:]) if (lm - rm) == 1: # print 'fudging DLRN build version (type 2l)' return (rpmLabelCompare((lx, lv, lr), (rx, lv, rr)), True) if r_is_dlrn: if l_is_rc: # print 'fudging DLRN release for left to 1 (RC build)' lr = '1' altered = True if l_is_ga: # print 'fudging DLRN release for right to 0 (GA build)' rr = '0' altered = True if rv[:-1] == lv[:-1] and \ ord(rv[-1:]) - ord(lv[-1:]) == 1: # print 'fudging DLRN build version (type 1r)' return (rpmLabelCompare((lx, lv, lr), (rx, lv, rr)), True) x = rv.rfind('.') if rv[:x] == lv: # 6.2.1-0.20171313131313 < 6.2-2.el7ost # print 'fudging DLRN build version (type 2r.b)' return (rpmLabelCompare((lx, lv, lr), (rx, lv, rr)), True) if lv[:x] == rv[:x]: # 6.0.10-0.201713131313131 < 6.0.9-1.el7ost lm = int(lv[x + 1:]) rm = int(rv[x + 1:]) if (rm - lm) == 1: # print 'fudging DLRN build version (type 2r)' return (rpmLabelCompare((lx, lv, lr), (rx, lv, rr)), True) # Version are equal, but maybe we altered release return (rpmLabelCompare((lx, lv, lr), (rx, rv, rr)), altered)