2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen#!/usr/bin/python
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen#
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen# CDDL HEADER START
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen#
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen# The contents of this file are subject to the terms of the
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen# Common Development and Distribution License (the "License").
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen# You may not use this file except in compliance with the License.
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen#
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2d49f150b4bce6f2f59a84e268e4777901c3e42cTimo Sirainen# or http://www.opensolaris.org/os/licensing.
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen# See the License for the specific language governing permissions
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen# and limitations under the License.
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen#
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen# When distributing Covered Code, include this CDDL HEADER in each
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen# If applicable, add the following below this CDDL HEADER, with the
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen# fields enclosed by brackets "[]" replaced with your own identifying
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen# information: Portions Copyright [yyyy] [name of copyright owner]
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen#
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen# CDDL HEADER END
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen#
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen# Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainenfrom . import testutils
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainenif __name__ == "__main__":
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen testutils.setup_environment("../../../proto")
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainenimport pkg5unittest
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainenimport os
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainenimport unittest
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainenclass TestPkgCollidingLinks(pkg5unittest.SingleDepotTestCase):
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen # Only start/stop the depot once (instead of for every test)
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen persistent_setup = True
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen pkg_A = """
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen open pkg_A@1.0,5.11-0
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen add file tmp/link_target_0 mode=0555 owner=root group=bin path=link_target_0
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen add file tmp/link_target_1 mode=0555 owner=root group=bin path=link_target_1
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen add file tmp/link_target_2 mode=0555 owner=root group=bin path=link_target_2
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen close"""
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen pkg_B = """
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen open pkg_B@1.0,5.11-0
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen add link path=0 target=./link_target_0
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen add link path=1 target=./link_target_1
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen add link path=2 target=./link_target_2
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen close"""
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen pkg_C = """
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen open pkg_C@1.0,5.11-0
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen add link path=0 target=./link_target_0
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen add link path=1 target=./link_target_1
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen add link path=/2 target=./link_target_2
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen close"""
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen misc_files = [p for p in pkg_A.split() if "tmp/link_target" in p]
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
b0be0bead3d6963149f7f2a9504b8ab5aced9af5Timo Sirainen def setUp(self):
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen pkg5unittest.SingleDepotTestCase.setUp(self)
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen self.make_misc_files(self.misc_files)
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen self.pkgsend_bulk(self.rurl, (self.pkg_A, self.pkg_B,
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen self.pkg_C))
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen def test_1(self):
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen """Verify symlinks are correctly reference counted
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen during installation & removal of packages"""
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen # create an image
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen self.image_create(self.rurl)
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen # install packages and verify
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen self.pkg("install pkg_A pkg_B")
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen self.pkg("verify")
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen # add a pkg w/ duplicate links
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen self.pkg("install pkg_C")
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen self.pkg("verify")
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen # cause trouble.
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen self.pkg("uninstall pkg_C")
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen self.pkg("verify")
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen # readd a pkg w/ duplicate links
b0be0bead3d6963149f7f2a9504b8ab5aced9af5Timo Sirainen self.pkg("install pkg_C")
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen self.pkg("verify")
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen self.pkg("uninstall pkg_B pkg_C")
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen self.pkg("verify")
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainenclass TestPkgCollidingHardLinks(pkg5unittest.SingleDepotTestCase):
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen # Only start/stop the depot once (instead of for every test)
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen persistent_setup = True
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen pkg_A = """
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen open pkg_A@1.0,5.11-0
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen add file tmp/link_target_0 mode=0555 owner=root group=bin path=link_target_0
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen add file tmp/link_target_1 mode=0555 owner=root group=bin path=link_target_1
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen add file tmp/link_target_2 mode=0555 owner=root group=bin path=link_target_2
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen close
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen open pkg_A@2.0,5.11-0
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen add file tmp/link_target_3 mode=0555 owner=root group=bin path=link_target_0
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen add file tmp/link_target_4 mode=0555 owner=root group=bin path=link_target_1
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen add file tmp/link_target_5 mode=0555 owner=root group=bin path=link_target_2
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen close"""
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen pkg_B = """
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen open pkg_B@1.0,5.11-0
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen add hardlink path=0 target=./link_target_0
b0be0bead3d6963149f7f2a9504b8ab5aced9af5Timo Sirainen add hardlink path=1 target=./link_target_1
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen add hardlink path=2 target=./link_target_2
b0be0bead3d6963149f7f2a9504b8ab5aced9af5Timo Sirainen add depend type=require fmri=pkg_A@1.0,5.11-0
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen close"""
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen pkg_C = """
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen open pkg_C@1.0,5.11-0
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen add hardlink path=0 target=./link_target_0
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen add hardlink path=1 target=./link_target_1
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen add hardlink path=2 target=./link_target_2
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen add depend type=require fmri=pkg_A@1.0,5.11-0
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen close"""
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen misc_files = [p for p in pkg_A.split() if "tmp/link_target" in p]
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen def setUp(self):
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen pkg5unittest.SingleDepotTestCase.setUp(self)
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen self.make_misc_files(self.misc_files)
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen self.pkgsend_bulk(self.rurl, (self.pkg_A, self.pkg_B,
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen self.pkg_C))
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen def check_link_count(self, n):
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen """ Make sure link count is what we think it should be"""
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen for f in ("link_target_{0:d}".format(i) for i in range(3)):
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen self.assertEqual(os.stat(os.path.join(self.get_img_path(),
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen f)).st_nlink, n)
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen def test_1(self):
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen """Verify hardlinks are correctly reference counted
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen during installation & removal of packages"""
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen # create an image
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen self.image_create(self.rurl)
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen # install packages and verify
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen self.pkg("install pkg_A@1.0")
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen self.check_link_count(1)
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen self.pkg("install pkg_B")
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen self.pkg("verify")
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen self.check_link_count(2)
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen # add a pkg w/ duplicate links
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen self.pkg("install pkg_C")
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen self.pkg("verify")
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen self.check_link_count(2)
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen # cause trouble.
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen self.pkg("uninstall pkg_C")
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen self.pkg("verify")
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen self.check_link_count(2)
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen # readd a pkg w/ duplicate links
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen self.pkg("install pkg_C")
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen self.pkg("verify")
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen self.check_link_count(2)
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen # update the files the links all point to
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen self.pkg("install pkg_A@2.0")
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen self.pkg("verify")
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen
2498b8003eb181001b0c4fd45763c462b45493d1Timo Sirainen self.pkg("uninstall pkg_B pkg_C")
2498b8003eb181001b0c4fd45763c462b45493d1Timo Sirainen self.pkg("verify")
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen self.check_link_count(1)
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainenif __name__ == "__main__":
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen unittest.main()
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen