#
# 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
# 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
#
#
#
from . import testutils
if __name__ == "__main__":
import pkg5unittest
import os
import unittest
foo1 = """
open foo@1,5.11-0
close """
foo10 = """
open foo@1.0,5.11-0
close """
foo11 = """
open foo@1.1,5.11-0
close """
foo12 = """
open foo@1.2,5.11-0
close """
foo121 = """
open foo@1.2.1,5.11-0
close """
food12 = """
open food@1.2,5.11-0
close """
newpkg10 = """
open newpkg@1.0
close """
hierfoo10 = """
close """
if errout:
"-q must print fatal errors!")
else:
"-q should only print fatal errors!")
"test2"])
# Ensure that the second repo's packages have exactly the same
# timestamps as those in the first ... by copying the repo over.
# If the repos need to have some contents which are different,
# send those changes after restarting depot 2.
# The new repository won't have a catalog, so rebuild it.
# The third repository should remain empty and not be
# published to.
# Next, create the image and configure publishers.
# Should only print fatal errors when using -q.
"""Verify that sort order and content of a full list matches
expected."""
expected = \
("foo 1.2.1-0 ---\n"
"foo (test2) 1.2.1-0 ---\n"
"food 1.2-0 ---\n"
"food (test2) 1.2-0 ---\n"
# Should only print fatal errors when using -q.
expected = \
("foo 1.2.1-0 ---\n"
"foo 1.2-0 ---\n"
"foo 1.1-0 ---\n"
"foo 1.0-0 ---\n"
"foo 1-0 ---\n"
"foo (test2) 1.2.1-0 ---\n"
"foo (test2) 1.2-0 ---\n"
"foo (test2) 1.1-0 ---\n"
"foo (test2) 1.0-0 ---\n"
"foo (test2) 1-0 ---\n"
"food 1.2-0 ---\n"
"food (test2) 1.2-0 ---\n"
# Put options in different order to ensure output still matches.
"""List all "foo@1.0" from auth "test1"."""
expected = \
"foo 1.0-0 ---\n"
# Test 'rooted' name.
"""List all "foo@1.0", regardless of publisher, with "pkg:/"
or '/' prefix."""
expected = \
"foo 1.0-0 ---\n" \
"foo (test2) 1.0-0 ---\n"
# Test 'rooted' name.
"""List all "foo@1.0", regardless of publisher, without "pkg:/"
prefix."""
expected = \
"foo 1.0-0 ---\n" \
"foo (test2) 1.0-0 ---\n"
"""List all versions of package foo, regardless of publisher."""
expected = \
"foo 1.2.1-0 ---\n" \
"foo 1.2-0 ---\n" \
"foo 1.1-0 ---\n" \
"foo 1.0-0 ---\n" \
"foo 1-0 ---\n" \
"foo (test2) 1.2.1-0 ---\n" \
"foo (test2) 1.2-0 ---\n" \
"foo (test2) 1.1-0 ---\n" \
"foo (test2) 1.0-0 ---\n" \
"foo (test2) 1-0 ---\n" \
expected = \
"foo 1.2.1-0 ---\n" \
"foo (test2) 1.2.1-0 ---\n" \
"""Show foo@1.0 from both depots, but 1.1 only from test2."""
expected = \
"foo 1.0-0 ---\n" \
"foo (test2) 1.1-0 ---\n" \
"foo (test2) 1.0-0 ---\n" \
expected = \
"foo 1.0-0 ---\n" \
"foo (test2) 1.1-0 ---\n" \
"foo (test2) 1.0-0 ---\n" \
"""Show versions 1.0 and 1.1 of foo only from publisher test2."""
expected = \
"foo (test2) 1.2.1-0 ---\n" \
"foo (test2) 1.2-0 ---\n" \
"foo (test2) 1.1-0 ---\n" \
"foo (test2) 1.0-0 ---\n" \
"foo (test2) 1-0 ---\n"
expected = \
"foo (test2) 1.2.1-0 ---\n"
"""List all foo@1 from test1, but all foo@1.2(.x), and only list
the latter once."""
expected = \
"foo 1.2.1-0 ---\n" \
"foo 1.2-0 ---\n" \
"foo 1.1-0 ---\n" \
"foo 1.0-0 ---\n" \
"foo 1-0 ---\n" \
"foo (test2) 1.2.1-0 ---\n" \
"foo (test2) 1.2-0 ---\n"
expected = \
"foo 1.2.1-0 ---\n" + \
"foo (test2) 1.2.1-0 ---\n"
"""Install a package from a publisher which is also offered by
another publisher. Then alter or remove the installed package's
publisher, and verify that list still shows the package
as installed."""
# Install a package from the second publisher.
# Should only print fatal errors when using -q.
# Change the origin of the publisher of an installed package to
# that of an empty repository. The package should still be
# shown for test1 and installed for test2.
expected = \
"foo 1.0-0 ---\n" + \
"foo (test2) 1.0-0 i--\n"
# Remove the publisher of an installed package, then add the
# publisher back, but with an empty repository. The package
# should still be shown as for test1 and installed for test2.
expected = \
"foo 1.0-0 ---\n" + \
"foo (test2) 1.0-0 i--\n"
# With the publisher of an installed package unknown, add a new
# publisher using the repository the package was originally
# installed from. The pkg should be shown as for test1,
# installed for test2, and test3 shouldn't be listed since the
# packages in the specified repository are for publisher test2.
# Uninstall the package so any remaining tests won't be
# impacted.
"""Verify that a list operation performed when a publisher's
metadata needs refresh works as expected."""
# Package should not exist as an unprivileged user or as a
# privileged user since it hasn't been published yet.
# Should only print fatal errors when using -q.
# Package should not exist as an unprivileged user or as a
# privileged user since the publisher doesn't need a refresh
# yet.
# Remove the last_refreshed file for one of the publishers so
# that it will be seen as needing refresh.
# Package should not exist as an unprivileged user since the
# metadata for the publisher has not yet been refreshed and
# cannot be.
# pkg list should work as an unprivileged user even though one
# or more publishers need their metadata refreshed.
# Package should exist as a privileged user since the metadata
# for the publisher needs to be refreshed and can be.
# Package should now exist for unprivileged user since the
# metadata has been refreshed.
# Should only print fatal errors when using -q.
"""Verify that we generate an error if the path to the
last_refreshed file contains a symlink."""
# Remove the last_refreshed file for one of the publishers so
# that it will be seen as needing refresh.
# We will create last_refreshed as symlink to verify with
# pkg operations.
# Verify that both pkg install and refresh generate an error
# if the last_refreshed file is a symlink.
# Remove the temporary file and the lock file
"""Verify that a failed implicit refresh will not prevent pkg
list from working properly when appropriate."""
# Set test2's origin to an unreachable URI.
"test2")
# Verify pkg list -a works as expected for an unprivileged user
# when a permissions failure is encountered.
# Verify pkg list -a fails for a privileged user when a
# publisher's repository is unreachable.
# Should only print fatal errors when using -q.
# Reset test2's origin.
"""Verify that pkg list pattern matching works as expected."""
expected = \
"foo 1.2.1-0 ---\n" \
"foo 1.2-0 ---\n" \
"foo 1.1-0 ---\n" \
"foo 1.0-0 ---\n" \
"foo 1-0 ---\n" \
"foo (test2) 1.2.1-0 ---\n" \
"foo (test2) 1.2-0 ---\n" \
"foo (test2) 1.1-0 ---\n" \
"foo (test2) 1.0-0 ---\n" \
"foo (test2) 1-0 ---\n" \
"food 1.2-0 ---\n" \
"food (test2) 1.2-0 ---\n"
expected += \
expected = \
"foo 1.2.1-0 ---\n" \
"foo (test2) 1.2.1-0 ---\n" \
"food 1.2-0 ---\n" \
"food (test2) 1.2-0 ---\n" \
expected += \
("foo bogus", 3), ("foo food bogus", 3),
("bogus quirky names", 1), ("'fo*' bogus", 3),
("'fo*' food bogus", 3), ("'f?o*' bogus", 3)):
"""Test for multiple name match listing."""
expected = \
"foo 1.2.1-0 ---\n" + \
"foo 1.2-0 ---\n" + \
"foo (test2) 1.2.1-0 ---\n" + \
"foo (test2) 1.2-0 ---\n" + \
"food 1.2-0 ---\n" + \
"food (test2) 1.2-0 ---\n"
expected = \
"foo 1.2.1-0 ---\n" + \
"foo (test2) 1.2.1-0 ---\n" + \
"food 1.2-0 ---\n" + \
"food (test2) 1.2-0 ---\n"
"""Verify that invalid input is handled gracefully."""
# First, test individually.
# Next, test invalid input but with options. The option
# should not be in the error output. (If it is, the FMRI
# parsing has parsed the option too.)
# Should only print fatal errors when using -q.
# Last, test all at once.
"""Verify that FMRIs using @latest work as expected and
that -n provides the same results."""
expected = \
"foo 1.2.1-0 ---\n" \
"foo (test2) 1.2.1-0 ---\n" \
expected = \
"foo 1.2.1-0 ---\n" \
"foo 1.1-0 ---\n" \
"foo (test2) 1.2.1-0 ---\n" \
"foo (test2) 1.2-0 ---\n" \
"foo (test2) 1.1-0 ---\n" \
expected = \
"foo 1.2.1-0 ---\n" \
"""Verify that pkg list -u works as expected."""
# 'foo' should be listed since 1.2.1 is available.
expected = \
"foo 1.0-0 i--\n"
# 'foo' should be listed since 1.2.1 is available.
# Should not print anything if using -q.
# Upgrade foo.
# Should return error as newest version is now installed.
# Should not print anything if using -q.
"""Verify that pkg list -v works as expected."""
# FMRI with no branch component should be displayed correctly.
# Destroy test space every time.
foo10 = """
open foo@1.0,5.11-0
close """
unsupp10 = """
open unsupported@1.0
add depend type=require fmri=foo@1.0
close """
if errout:
"-q must print fatal errors!")
else:
"-q should only print fatal errors!")
""" pkg list should fail in an empty image """
# Should not print anything if using -q.
# Publish a package and then add some unsupported action data
# to the repository's copy of the manifest and catalog.
mcontent = None
# Update the catalog signature.
# Update the catalog actions.
# Write out the new catalog.
"""Verify that packages with invalid or unsupported actions are
handled gracefully.
"""
# Base package needed for testing.
# Verify that a package with unsupported content doesn't cause
# a problem.
newact = "depend type=new-type fmri=foo@1.1"
# Now create a new image and verify that pkg list will
# list both packages even though one of them has an
# unparseable manifest.
expected = \
"foo 1.0-0 ---\n" \
"unsupported 1.0 ---\n"
# Verify that a package with invalid content doesn't cause
# a problem.
newact = "depend notvalid"
expected = \
"foo 1.0-0 ---\n" \
"unsupported 1.0 ---\n" \
"unsupported 1.0 ---\n"
if __name__ == "__main__":