3110N/A#!/usr/bin/python
3110N/A#
3110N/A# CDDL HEADER START
3110N/A#
3110N/A# The contents of this file are subject to the terms of the
3110N/A# Common Development and Distribution License (the "License").
3110N/A# You may not use this file except in compliance with the License.
3110N/A#
3110N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
3110N/A# or http://www.opensolaris.org/os/licensing.
3110N/A# See the License for the specific language governing permissions
3110N/A# and limitations under the License.
3110N/A#
3110N/A# When distributing Covered Code, include this CDDL HEADER in each
3110N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
3110N/A# If applicable, add the following below this CDDL HEADER, with the
3110N/A# fields enclosed by brackets "[]" replaced with your own identifying
3110N/A# information: Portions Copyright [yyyy] [name of copyright owner]
3110N/A#
3110N/A# CDDL HEADER END
3110N/A#
3110N/A
3110N/A#
3339N/A# Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
3110N/A#
3110N/A
3339N/Afrom . import testutils
3110N/Aif __name__ == "__main__":
3110N/A testutils.setup_environment("../../../proto")
3110N/Aimport pkg5unittest
3110N/A
3110N/Aimport pkg.client.api_errors as api_errors
3110N/A
3110N/A
3110N/Aclass TestPkgApiHydrate(pkg5unittest.SingleDepotTestCase):
3110N/A
3110N/A dev10 = """
3110N/A open dev@1.0,5.11-0
3110N/A add dir mode=0755 owner=root group=bin path=dev
3110N/A add dir mode=0755 owner=root group=bin path=dev/cfg
3110N/A add file dev/cfg/bar path=dev/cfg/bar mode=0644 owner=root group=bin preserve=true
3110N/A add file dev/cfg/bar1 path=dev/cfg/bar1 mode=0555 owner=root group=bin
3110N/A add file dev/cfg/bar2 path=dev/cfg/bar2 mode=0644 owner=root group=bin overlay=true
3110N/A add hardlink path=dev/cfg/bar2.hlink target=bar2
3110N/A close
3110N/A """
3110N/A
3110N/A misc_files = ["dev/cfg/bar", "dev/cfg/bar1", "dev/cfg/bar2",
3110N/A "dev/cfg/bar2.hlink"]
3110N/A
3110N/A def setUp(self):
3110N/A pkg5unittest.SingleDepotTestCase.setUp(self)
3110N/A self.make_misc_files(self.misc_files)
3110N/A self.pkgsend_bulk(self.rurl, self.dev10)
3110N/A
3110N/A def test_01_basic(self):
3110N/A api_inst = self.image_create(self.rurl)
3110N/A self._api_install(api_inst, ["dev"])
3110N/A
3110N/A self._api_dehydrate(api_inst)
3110N/A
3110N/A # Verify that files are deleted or remained as expected.
3110N/A self.file_exists("dev/cfg/bar")
3110N/A self.file_doesnt_exist("dev/cfg/bar1")
3110N/A self.file_exists("dev/cfg/bar2")
3110N/A self.file_doesnt_exist("dev/cfg/bar2.hlink")
3110N/A
3110N/A self._api_rehydrate(api_inst)
3110N/A self.pkg("verify")
3110N/A
3110N/A def test_bad_publishers(self):
3110N/A api_inst = self.image_create(self.rurl)
3110N/A self._api_install(api_inst, ["dev"])
3110N/A
3110N/A # Test that dehydrate will raise a PlanCreationException when
3110N/A # encountering bad publishers.
3110N/A self.assertRaises(api_errors.PlanCreationException,
3110N/A lambda *args, **kwargs: list(
3110N/A api_inst.gen_plan_dehydrate(*args, **kwargs)),
3110N/A ["-p nosuch", "-p unknown", "-p test"])
3110N/A
3110N/A # Test that rehydrate will raise a PlanCreationException when
3110N/A # encountering bad publishers.
3110N/A self.assertRaises(api_errors.PlanCreationException,
3110N/A lambda *args, **kwargs: list(
3110N/A api_inst.gen_plan_rehydrate(*args, **kwargs)),
3110N/A ["-p nosuch", "-p unknown", "-p test"])
3110N/A
3110N/A
3110N/Aif __name__ == "__main__":
3110N/A unittest.main()