--- a/src/tests/cli/t_pkgdiff.py Tue Jan 03 14:13:43 2017 +0530
+++ b/src/tests/cli/t_pkgdiff.py Thu Dec 08 03:40:53 2016 +0530
@@ -21,7 +21,7 @@
#
#
-# Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
#
import testutils
@@ -74,6 +74,16 @@
file tmp/empty mode=0555 owner=root group=bin path=/etc/empty
file tmp/truck1 mode=0444 owner=root group=bin path=/etc/trailer"""
+ hashed10 = """
+ set name=pkg.fmri [email protected]:20130804T203459Z
+ license 6aba708bd383553aa84bba4fefe8495239927767 chash=60c3aa47dce2ba0132efdace8d3b88b6589767f4 license=lic_OTN
+ file 4ab5de3107a63f5cf454485f720cac025f1b7002 chash=dc03afd488e3b3e4c4993d2403d7e15603b0a391 path=etc/motd"""
+
+ hashed20 = """
+ set name=pkg.fmri [email protected]:20130904T203001Z
+ license 7ab6de3107a63f5cf454485f720cac025f1b7001 chash=cc05afd488e3b3e4c4993d2403d7e15603b0a398 license=lic_OTN
+ file 3aba408bd383553aa84bba4fefe8495239927763 chash=f0c2aa47dce2ba0132efdace8d3b88b6589767f3 path=etc/motd"""
+
def setUp(self):
pkg5unittest.SingleDepotTestCase.setUp(self)
tfiles = self.make_misc_files(["tmp/empty", "tmp/truck1",
@@ -83,6 +93,8 @@
self.tree10_p5m = self.make_manifest(self.tree10)
self.tree20_p5m = self.make_manifest(self.tree20)
self.tree30_p5m = self.make_manifest(self.tree30)
+ self.hashed10_p5m = self.make_manifest(self.hashed10)
+ self.hashed20_p5m = self.make_manifest(self.hashed20)
self.bogus_p5m = os.path.join(self.test_root, "nosuch.p5m")
self.noaccess_p5m = self.make_misc_files(
["tmp/noaccess.p5m"])[0]
@@ -186,6 +198,73 @@
self.pkgdiff(" ".join(("-t file", self.stub1_p5m,
self.stub2_p5m)), exit=1)
+ def test_03_hash(self):
+ """Verify that hash attributes are compared as expected."""
+
+ # Verify no differences for same manifest.
+ self.pkgdiff(" ".join(("-t file", self.hashed10_p5m,
+ self.hashed10_p5m)))
+
+ # Verify differences found for file actions between 1.0 and 2.0;
+ # in particular, that the 'old' hash values match 1.0 and the
+ # 'new' hash values match 2.0.
+ self.pkgdiff(" ".join(("-t file", self.hashed10_p5m,
+ self.hashed20_p5m)), exit=1)
+ expected = """\
+file path=etc/motd
+ - 4ab5de3107a63f5cf454485f720cac025f1b7002
+ + 3aba408bd383553aa84bba4fefe8495239927763
+ - chash=dc03afd488e3b3e4c4993d2403d7e15603b0a391
+ + chash=f0c2aa47dce2ba0132efdace8d3b88b6589767f3
+"""
+ actual = self.reduceSpaces(self.output)
+ self.assertEqualDiff(expected, actual)
+
+ # Again, but only comparing hash attribute.
+ self.pkgdiff(" ".join(("-t file -o hash", self.hashed10_p5m,
+ self.hashed20_p5m)), exit=1)
+ expected = """\
+file path=etc/motd
+ - 4ab5de3107a63f5cf454485f720cac025f1b7002
+ + 3aba408bd383553aa84bba4fefe8495239927763
+"""
+ actual = self.reduceSpaces(self.output)
+ self.assertEqualDiff(expected, actual)
+
+ # Again, ignoring hash attributes (should find no differences).
+ self.pkgdiff(" ".join(("-t file -i hash -i chash",
+ self.hashed10_p5m, self.hashed20_p5m)), exit=0)
+
+ # Verify differences found for license actions between 2.0 and 1.0;
+ # in particular, that the 'old' hash values match 2.0 and the
+ # 'new' hash values match 1.0.
+ self.pkgdiff(" ".join(("-t license", self.hashed20_p5m,
+ self.hashed10_p5m)), exit=1)
+ expected = """\
+license license=lic_OTN
+ - 7ab6de3107a63f5cf454485f720cac025f1b7001
+ + 6aba708bd383553aa84bba4fefe8495239927767
+ - chash=cc05afd488e3b3e4c4993d2403d7e15603b0a398
+ + chash=60c3aa47dce2ba0132efdace8d3b88b6589767f4
+"""
+ actual = self.reduceSpaces(self.output)
+ self.assertEqualDiff(expected, actual)
+
+ # Again, but only comparing hash attribute.
+ self.pkgdiff(" ".join(("-t license -o hash", self.hashed20_p5m,
+ self.hashed10_p5m)), exit=1)
+ expected = """\
+license license=lic_OTN
+ - 7ab6de3107a63f5cf454485f720cac025f1b7001
+ + 6aba708bd383553aa84bba4fefe8495239927767
+"""
+ actual = self.reduceSpaces(self.output)
+ self.assertEqualDiff(expected, actual)
+
+ # Again, ignoring hash attributes (should find no differences).
+ self.pkgdiff(" ".join(("-t license -i hash -i chash",
+ self.hashed20_p5m, self.hashed10_p5m)), exit=0)
+
if __name__ == "__main__":
unittest.main()
--- a/src/util/publish/pkgdiff.py Tue Jan 03 14:13:43 2017 +0530
+++ b/src/util/publish/pkgdiff.py Thu Dec 08 03:40:53 2016 +0530
@@ -21,7 +21,7 @@
#
#
-# Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
#
import getopt
@@ -81,7 +81,8 @@
elif opt == "-v":
args = arg.split("=")
if len(args) != 2:
- usage(_("variant option incorrect %s") % arg)
+ usage(_("variant option incorrect %s") %
+ arg)
if not args[0].startswith("variant."):
args[0] = "variant." + args[0]
varattrs[args[0]].add(args[1])
@@ -102,7 +103,8 @@
for v in varattrs:
if len(varattrs[v]) > 1:
- usage(_("For any variant, only one value may be specified."))
+ usage(_("For any variant, only one value may be "
+ "specified."))
varattrs[v] = varattrs[v].pop()
ignoreattrs = set(ignoreattrs)
@@ -149,13 +151,13 @@
v1 = manifest1.get_all_variants()
v2 = manifest2.get_all_variants()
for vname in varattrs:
- for path, v, m in zip(pargs, (v1, v2), (manifest1, manifest2)):
+ for _path, v, m in zip(pargs, (v1, v2), (manifest1, manifest2)):
if vname not in v:
continue
filt = varattrs[vname]
if filt not in v[vname]:
- usage(_("Manifest %(path)s doesn't support variant %(vname)s=%(filt)s" %
- locals()))
+ usage(_("Manifest %(path)s doesn't support "
+ "variant %(vname)s=%(filt)s" % locals()))
# remove the variant tag
def rip(a):
a.attrs.pop(vname, None)
@@ -219,7 +221,7 @@
# License action still causes spurious diffs... check again for now.
real_diffs = [
- (a,b)
+ (a, b)
for a, b in diffs
if a is None or b is None or a.different(b)
]
@@ -237,7 +239,8 @@
if res:
return res
# sort by variant
- res = cmp(sorted(list(a.get_variant_template())), sorted(list(b.get_variant_template())))
+ res = cmp(sorted(list(a.get_variant_template())),
+ sorted(list(b.get_variant_template())))
if res:
return res
else:
@@ -266,8 +269,11 @@
v = attrs[k]
if isinstance(v, list) or isinstance(v, set):
- out = " ".join(["%s=%s" %
- (k, q(lmt)) for lmt in sorted(v) if lmt not in elide_iter])
+ out = " ".join([
+ "%s=%s" % (k, q(lmt))
+ for lmt in sorted(v)
+ if lmt not in elide_iter
+ ])
elif " " in v or v == "":
out = k + "=\"" + v + "\""
else:
@@ -296,35 +302,43 @@
s = []
if not onlyattrs:
- if hasattr(old, "hash") and "hash" not in ignoreattrs:
+ if (hasattr(old, "hash") and
+ "hash" not in ignoreattrs):
if old.hash != new.hash:
- s.append(" - %s" % new.hash)
- s.append(" + %s" % old.hash)
- attrdiffs = set(new.differences(old)) - ignoreattrs
- attrsames = sorted(list(set(old.attrs.keys() + new.attrs.keys()) -
+ s.append(" - %s" % old.hash)
+ s.append(" + %s" % new.hash)
+ attrdiffs = (set(new.differences(old)) -
+ ignoreattrs)
+ attrsames = sorted( list(set(old.attrs.keys() +
+ new.attrs.keys()) -
set(new.differences(old))))
else:
- if hasattr(old, "hash") and "hash" in onlyattrs:
+ if hasattr(old, "hash") and "hash" in onlyattrs:
if old.hash != new.hash:
- s.append(" - %s" % new.hash)
- s.append(" + %s" % old.hash)
- attrdiffs = set(new.differences(old)) & onlyattrs
- attrsames = sorted(list(set(old.attrs.keys() + new.attrs.keys()) -
+ s.append(" - %s" % old.hash)
+ s.append(" + %s" % new.hash)
+ attrdiffs = (set(new.differences(old)) &
+ onlyattrs)
+ attrsames = sorted(list(set(old.attrs.keys() +
+ new.attrs.keys()) -
set(new.differences(old))))
for a in sorted(attrdiffs):
if a in old.attrs and a in new.attrs and \
isinstance(old.attrs[a], list) and \
isinstance(new.attrs[a], list):
- elide_set = set(old.attrs[a]) & set(new.attrs[a])
+ elide_set = (set(old.attrs[a]) &
+ set(new.attrs[a]))
else:
elide_set = set()
if a in old.attrs:
- diff_str = attrval(old.attrs, a, elide_iter=elide_set)
+ diff_str = attrval(old.attrs, a,
+ elide_iter=elide_set)
if diff_str:
s.append(" - %s" % diff_str)
if a in new.attrs:
- diff_str = attrval(new.attrs, a, elide_iter=elide_set)
+ diff_str = attrval(new.attrs, a,
+ elide_iter=elide_set)
if diff_str:
s.append(" + %s" % diff_str)
# print out part of action that is the same