t_pkg_image_update.py revision 1895
6407N/A#!/usr/bin/python
6407N/A#
6407N/A# CDDL HEADER START
10846N/A#
10846N/A# The contents of this file are subject to the terms of the
10846N/A# Common Development and Distribution License (the "License").
10846N/A# You may not use this file except in compliance with the License.
10846N/A#
10846N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10846N/A# or http://www.opensolaris.org/os/licensing.
10846N/A# See the License for the specific language governing permissions
10846N/A# and limitations under the License.
10846N/A#
10846N/A# When distributing Covered Code, include this CDDL HEADER in each
10846N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
10846N/A# If applicable, add the following below this CDDL HEADER, with the
10846N/A# fields enclosed by brackets "[]" replaced with your own identifying
10846N/A# information: Portions Copyright [yyyy] [name of copyright owner]
10846N/A#
6407N/A# CDDL HEADER END
10846N/A#
10846N/A
10846N/A# Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
10846N/A
10846N/Aimport testutils
10846N/Aif __name__ == "__main__":
10846N/A testutils.setup_environment("../../../proto")
10846N/Aimport pkg5unittest
10846N/A
10846N/Aimport unittest
10846N/Aimport os
10846N/A
10846N/A
10846N/Aclass TestImageUpdate(pkg5unittest.ManyDepotTestCase):
10846N/A # Only start/stop the depot once (instead of for every test)
10846N/A persistent_setup = True
10846N/A
12283N/A foo10 = """
7871N/A open foo@1.0,5.11-0
17461N/A add dir mode=0755 owner=root group=bin path=/lib
6407N/A close """
6407N/A
7871N/A foo11 = """
6407N/A open foo@1.1,5.11-0
6407N/A add dir mode=0755 owner=root group=bin path=/lib
close """
bar10 = """
open bar@1.0,5.11-0
add dir mode=0755 owner=root group=bin path=/bin
close """
bar11 = """
open bar@1.1,5.11-0
add dir mode=0755 owner=root group=bin path=/bin
close """
baz10 = """
open baz@1.0,5.11-0
add dir mode=0755 owner=root group=bin path=/lib
close """
baz11 = """
open baz@1.1,5.11-0
add dir mode=0755 owner=root group=bin path=/lib
close """
qux10 = """
open qux@1.0,5.11-0
add depend type=require fmri=pkg:/quux@1.0
add dir mode=0755 owner=root group=bin path=/lib
close """
qux11 = """
open qux@1.1,5.11-0
add depend type=require fmri=pkg:/quux@1.1
add dir mode=0755 owner=root group=bin path=/lib
close """
quux10 = """
open quux@1.0,5.11-0
add depend type=require fmri=pkg:/corge@1.0
add dir mode=0755 owner=root group=bin path=/usr
close """
quux11 = """
open quux@1.1,5.11-0
add depend type=require fmri=pkg:/corge@1.1
add dir mode=0755 owner=root group=bin path=/usr
close """
corge10 = """
open corge@1.0,5.11-0
add dir mode=0755 owner=root group=bin path=/bin
close """
corge11 = """
open corge@1.1,5.11-0
add dir mode=0755 owner=root group=bin path=/bin
close """
def setUp(self):
# Two repositories are created for test2.
pkg5unittest.ManyDepotTestCase.setUp(self, ["test1", "test2",
"test2", "test4", "test5"])
self.rurl1 = self.dcs[1].get_repo_url()
self.rurl2 = self.dcs[2].get_repo_url()
self.rurl3 = self.dcs[3].get_repo_url()
self.rurl4 = self.dcs[4].get_repo_url()
self.rurl5 = self.dcs[5].get_repo_url()
self.pkgsend_bulk(self.rurl1, (self.foo10, self.foo11,
self.baz11, self.qux10, self.qux11, self.quux10,
self.quux11, self.corge11))
self.pkgsend_bulk(self.rurl2, (self.foo10, self.bar10,
self.bar11, self.baz10, self.qux10, self.qux11,
self.quux10, self.quux11, self.corge10))
# Copy contents of repository 2 to repos 4 and 5.
for i in (4, 5):
self.copy_repository(self.dcs[2].get_repodir(), "test1",
self.dcs[i].get_repodir(), "test%d" % i)
self.dcs[i].get_repo(auto_create=True).rebuild()
def test_image_update_bad_opts(self):
"""Test image-update with bad options."""
self.image_create(self.rurl1, prefix="test1")
self.pkg("image-update -@", exit=2)
self.pkg("image-update -vq", exit=2)
self.pkg("image-update foo", exit=2)
def test_01_after_pub_removal(self):
"""Install packages from multiple publishers, then verify that
removal of the second publisher will not prevent an
image-update."""
self.image_create(self.rurl1, prefix="test1")
# Install a package from the preferred publisher.
self.pkg("install foo@1.0")
# Install a package from a second publisher.
self.pkg("set-publisher -O %s test2" % self.rurl2)
self.pkg("install bar@1.0")
# Remove the publisher of an installed package, then add the
# publisher back, but with an empty repository. An image-update
# should still be possible.
self.pkg("unset-publisher test2")
self.pkg("set-publisher -O %s test2" % self.rurl3)
self.pkg("image-update -nv")
# Add two publishers with the same packages as a removed one;
# an image-update should be possible despite the conflict (as
# the newer versions will simply be ignored).
self.pkg("unset-publisher test2")
self.pkg("set-publisher -O %s test4" % self.rurl4)
self.pkg("set-publisher -O %s test5" % self.rurl5)
self.pkg("image-update -nv")
# Remove one of the conflicting publishers. An image-update
# should still be possible even though the conflicts no longer
# exist and the original publisher is unknown (see bug 6856).
self.pkg("unset-publisher test4")
self.pkg("image-update -nv")
# Remove the remaining test publisher.
self.pkg("unset-publisher test5")
def test_02_update_multi_publisher(self):
"""Verify that image-updates work as expected when different
publishers offer the same package."""
self.image_create(self.rurl1, prefix="test1")
# First, verify that the preferred status of a publisher will
# not affect which source is used for image-update when two
# publishers offer the same package and the package publisher
# was preferred at the time of install.
self.pkg("set-publisher -P -O %s test2" % self.rurl2)
self.pkg("install foo@1.0")
self.pkg("info foo@1.0 | grep test2")
self.pkg("set-publisher -P test1")
self.pkg("image-update -v", exit=4)
self.pkg("info foo@1.1 | grep test1", exit=1)
self.pkg("uninstall foo")
# Next, verify that the preferred status of a publisher will
# not cause an upgrade of a package if the newer version is
# offered by the preferred publisher and the package publisher
# was not preferred at the time of isntall and was not used
# to install the package.
self.pkg("install baz@1.0")
self.pkg("info baz@1.0 | grep test2")
self.pkg("image-update -v", exit=4)
self.pkg("info baz@1.0 | grep test2")
# Finally, cleanup and verify no packages are installed.
self.pkg("uninstall '*'")
self.pkg("list", exit=1)
if __name__ == "__main__":
unittest.main()