3316N/A#!/usr/bin/python
3316N/A#
3316N/A# CDDL HEADER START
3316N/A#
3316N/A# The contents of this file are subject to the terms of the
3316N/A# Common Development and Distribution License (the "License").
3316N/A# You may not use this file except in compliance with the License.
3316N/A#
3316N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
3316N/A# or http://www.opensolaris.org/os/licensing.
3316N/A# See the License for the specific language governing permissions
3316N/A# and limitations under the License.
3316N/A#
3316N/A# When distributing Covered Code, include this CDDL HEADER in each
3316N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
3316N/A# If applicable, add the following below this CDDL HEADER, with the
3316N/A# fields enclosed by brackets "[]" replaced with your own identifying
3316N/A# information: Portions Copyright [yyyy] [name of copyright owner]
3316N/A#
3316N/A# CDDL HEADER END
3316N/A#
3316N/A
3316N/A# Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
3316N/A
3339N/Afrom . import testutils
3316N/Aif __name__ == "__main__":
3316N/A testutils.setup_environment("../../../proto")
3316N/Aimport pkg5unittest
3316N/A
3316N/Aimport os
3316N/Aimport unittest
3316N/A
3316N/Aclass TestPkgModified(pkg5unittest.SingleDepotTestCase):
3316N/A # Tests in this suite use the read only data directory.
3316N/A need_ro_data = True
3316N/A
3316N/A foo10 = """
3316N/A open foo@1.0,5.11-0
3316N/A add dir mode=0755 owner=root group=bin path=etc
3316N/A add file tmp/cat mode=0644 owner=root group=bin path=etc/motd
3316N/A close """
3316N/A
3316N/A misc_files = ["tmp/cat"]
3316N/A
3316N/A def setUp(self):
3316N/A pkg5unittest.SingleDepotTestCase.setUp(self)
3316N/A self.make_misc_files(self.misc_files)
3316N/A
3316N/A def __assert_image_modified(self, api_inst, omtime, modified):
3316N/A mfpath = os.path.join(api_inst.img.imgdir, "modified")
3316N/A nmtime = os.stat(mfpath).st_mtime
3316N/A if modified:
3316N/A self.assertNotEqual(omtime, nmtime)
3316N/A else:
3316N/A self.assertEqual(omtime, nmtime)
3316N/A return nmtime
3316N/A
3316N/A def test_modified(self):
3316N/A """Verify that $IMGDIR/modified is updated whenever an
3316N/A image-modifying operation is completed."""
3316N/A
3316N/A api_inst = self.image_create(self.rurl)
3316N/A mfpath = os.path.join(api_inst.img.imgdir, "modified")
3316N/A
3316N/A # Assert /var/pkg/modified exists.
3316N/A self.file_exists(mfpath)
3316N/A omtime = os.stat(mfpath).st_mtime
3316N/A
3316N/A self.pkgsend_bulk(self.rurl, self.foo10)
3316N/A
3316N/A # Now perform various operations and assert the image was marked
3316N/A # as modified or not depending on operation.
3316N/A self.__assert_image_modified(api_inst, omtime, False)
3316N/A
3316N/A self.pkg("refresh")
3316N/A omtime = self.__assert_image_modified(api_inst, omtime, True)
3316N/A
3316N/A #
3316N/A # Operations that should not mark image as modified.
3316N/A #
3316N/A for op, op_ret in (
3316N/A ("facet", 0),
3316N/A ("contents", 1),
3316N/A ("history", 0),
3316N/A ("info", 1),
3316N/A ("info -r \*", 0),
3316N/A ("list", 1),
3316N/A ("mediator", 0),
3316N/A ("property", 0),
3316N/A ("unset-property no-such-property", 1),
3316N/A ("publisher", 0),
3316N/A ("refresh no-such-publisher", 1),
3316N/A ("variant", 0)
3316N/A ):
3316N/A self.pkg(op, exit=op_ret)
3316N/A self.__assert_image_modified(api_inst, omtime, False)
3316N/A
3316N/A self.pkg("version", use_img_root=False)
3316N/A self.__assert_image_modified(api_inst, omtime, False)
3316N/A
3316N/A #
3316N/A # Now perform various combos of operations testing modification.
3316N/A #
3316N/A self.pkg("refresh")
3316N/A omtime = self.__assert_image_modified(api_inst, omtime, False)
3316N/A
3316N/A self.pkg("install -nv foo")
3316N/A omtime = self.__assert_image_modified(api_inst, omtime, False)
3316N/A
3316N/A self.pkg("install --reject foo foo", exit=1)
3316N/A omtime = self.__assert_image_modified(api_inst, omtime, False)
3316N/A
3316N/A self.pkg("install foo")
3316N/A omtime = self.__assert_image_modified(api_inst, omtime, True)
3316N/A
3316N/A self.pkg("set-mediator -I postfix sendmail")
3316N/A omtime = self.__assert_image_modified(api_inst, omtime, True)
3316N/A
3316N/A self.pkg("unset-mediator -I sendmail")
3316N/A omtime = self.__assert_image_modified(api_inst, omtime, True)
3316N/A
3316N/A self.pkg("unset-mediator -I sendmail", exit=4)
3316N/A omtime = self.__assert_image_modified(api_inst, omtime, False)
3316N/A
3316N/A # this should not register a modification; compliance tool
3316N/A # relies on that
3316N/A self.pkg("verify foo")
3316N/A omtime = self.__assert_image_modified(api_inst, omtime, False)
3316N/A
3316N/A self.pkg("fix foo", exit=4)
3316N/A omtime = self.__assert_image_modified(api_inst, omtime, False)
3316N/A
3316N/A # this should not register a modification; compliance tool
3316N/A # relies on that
3316N/A self.pkg("revert -n /etc/motd", exit=4)
3316N/A omtime = self.__assert_image_modified(api_inst, omtime, False)
3316N/A
3316N/A # modify etc/motd; fix should register modification
3316N/A self.file_append("etc/motd", "foo")
3316N/A self.pkg("fix foo")
3316N/A omtime = self.__assert_image_modified(api_inst, omtime, True)
3316N/A
3316N/A # modify etc/motd; revert should register modification
3316N/A self.file_append("etc/motd", "foo")
3316N/A self.pkg("revert /etc/motd")
3316N/A omtime = self.__assert_image_modified(api_inst, omtime, True)
3316N/A
3316N/A self.pkg("revert /etc/motd", exit=4)
3316N/A omtime = self.__assert_image_modified(api_inst, omtime, False)
3316N/A
3316N/A self.pkg("fix foo", exit=4)
3316N/A omtime = self.__assert_image_modified(api_inst, omtime, False)
3316N/A
3316N/A self.pkg("freeze foo")
3316N/A omtime = self.__assert_image_modified(api_inst, omtime, True)
3316N/A
3316N/A self.pkg("unfreeze foo")
3316N/A omtime = self.__assert_image_modified(api_inst, omtime, True)
3316N/A
3316N/A self.pkg("uninstall foo")
3316N/A omtime = self.__assert_image_modified(api_inst, omtime, True)
3316N/A
3316N/A self.pkg("avoid foo")
3316N/A omtime = self.__assert_image_modified(api_inst, omtime, True)
3316N/A
3316N/A self.pkg("unavoid foo")
3316N/A omtime = self.__assert_image_modified(api_inst, omtime, True)
3316N/A
3316N/A self.pkg("set-property be-policy always-new")
3316N/A omtime = self.__assert_image_modified(api_inst, omtime, True)
3316N/A
3316N/A self.pkg("unset-property be-policy")
3316N/A omtime = self.__assert_image_modified(api_inst, omtime, True)
3316N/A
3316N/A self.pkg("change-facet wombat=false")
3316N/A omtime = self.__assert_image_modified(api_inst, omtime, True)
3316N/A
3316N/A self.pkg("change-facet wombat=None")
3316N/A omtime = self.__assert_image_modified(api_inst, omtime, True)
3316N/A
3316N/A self.pkg("change-variant osnet.debug=true")
3316N/A omtime = self.__assert_image_modified(api_inst, omtime, True)
3316N/A
3316N/A self.pkg("change-variant osnet.debug=None")
3316N/A omtime = self.__assert_image_modified(api_inst, omtime, True)
3316N/A
3316N/A # Remove the last_refreshed file for one of the publishers so
3316N/A # that it will be seen as needing refresh.
3316N/A pub = api_inst.get_publisher("test")
3316N/A os.remove(os.path.join(pub.meta_root, "last_refreshed"))
3316N/A self.pkgsend_bulk(self.rurl, self.foo10)
3316N/A self.pkg("list -a")
3316N/A omtime = self.__assert_image_modified(api_inst, omtime, True)
3316N/A
3316N/A # Add, remove, and modify publishers.
3316N/A self.pkg("unset-publisher test")
3316N/A omtime = self.__assert_image_modified(api_inst, omtime, True)
3316N/A
3316N/A self.pkg("set-publisher -p {0}".format(self.rurl))
3316N/A omtime = self.__assert_image_modified(api_inst, omtime, True)
3316N/A
3316N/A self.pkg("set-publisher -G {0} test".format(self.rurl))
3316N/A omtime = self.__assert_image_modified(api_inst, omtime, True)
3316N/A
3316N/A self.pkg("set-publisher -g {0} test".format(self.rurl))
3316N/A omtime = self.__assert_image_modified(api_inst, omtime, True)
3316N/A
3316N/A self.pkg("set-publisher --sticky test")
3316N/A omtime = self.__assert_image_modified(api_inst, omtime, True)
3316N/A
3316N/A self.pkg("set-publisher --non-sticky test")
3316N/A omtime = self.__assert_image_modified(api_inst, omtime, True)
3316N/A
3316N/A
3316N/Aif __name__ == "__main__":
3316N/A unittest.main()