t_pkg_image_update.py revision 1431
#!/usr/bin/python2.4
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
import testutils
if __name__ == "__main__":
testutils.setup_environment("../../../proto")
import unittest
import os
class TestImageUpdate(testutils.ManyDepotTestCase):
# Only start/stop the depot once (instead of for every test)
persistent_depot = True
foo10 = """
open foo@1.0,5.11-0
add dir mode=0755 owner=root group=bin path=/lib
close """
foo11 = """
open foo@1.1,5.11-0
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):
testutils.ManyDepotTestCase.setUp(self, ["test1", "test2",
"test3", "test4", "test5"])
durl1 = self.dcs[1].get_depot_url()
durl2 = self.dcs[2].get_depot_url()
durl4 = self.dcs[2].get_depot_url()
durl5 = self.dcs[2].get_depot_url()
self.pkgsend_bulk(durl1, self.foo10 + self.foo11 + \
self.baz11 + self.qux10 + self.qux11 + self.quux10 + \
self.quux11 + self.corge11)
self.pkgsend_bulk(durl2, self.foo10 + self.bar10 + \
self.bar11 + self.baz10 + self.qux10 + self.qux11 + \
self.quux10 + self.quux11 + self.corge10)
self.pkgsend_bulk(durl4, self.foo10 + self.bar10 + \
self.bar11 + self.baz10 + self.qux10 + self.qux11 + \
self.quux10 + self.quux11 + self.corge10)
self.pkgsend_bulk(durl5, self.foo10 + self.bar10 + \
self.bar11 + self.baz10 + self.qux10 + self.qux11 + \
self.quux10 + self.quux11 + self.corge10)
def test_image_update_bad_opts(self):
"""Test image-update with bad options."""
durl1 = self.dcs[1].get_depot_url()
self.image_create(durl1, 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."""
durl1 = self.dcs[1].get_depot_url()
durl2 = self.dcs[2].get_depot_url()
durl3 = self.dcs[3].get_depot_url()
durl4 = self.dcs[4].get_depot_url()
durl5 = self.dcs[5].get_depot_url()
self.image_create(durl1, 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" % durl2)
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" % durl3)
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" % durl4)
self.pkg("set-publisher -O %s test5" % durl5)
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."""
durl1 = self.dcs[1].get_depot_url()
durl2 = self.dcs[2].get_depot_url()
durl3 = self.dcs[3].get_depot_url()
self.image_create(durl1, prefix="test1")
# First, verify that the preferred status of a publisher will
# choose 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" % durl2)
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")
self.pkg("info foo@1.1 | grep test1")
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")
self.pkg("info baz@1.0 | grep test2")
self.pkg("uninstall baz")
# Next, verify that if two non-preferred publishers offer
# the same package, that the publisher it was installed from
# will be chosen for an update and the update will succeed. In
# addition, its dependencies should be selected from the same
# publisher used for the update if that publisher has them and
# the remaining dependencies selected from the first available.
self.pkg("set-publisher -P -O %s test3" % durl3)
self.pkg("install pkg://test1/qux@1.0")
self.pkg("info qux@1.0 | grep test1")
self.pkg("info quux@1.0 | grep test1")
self.pkg("info corge@1.0 | grep test2")
self.pkg("image-update -v")
self.pkg("info qux@1.1 | grep test1")
self.pkg("info quux@1.1 | grep test1")
self.pkg("info corge@1.1 | grep test1")
# Finally, cleanup and verify no packages are installed.
self.pkg("uninstall -vr corge")
self.pkg("list", exit=1)
if __name__ == "__main__":
unittest.main()