t_pkg_depotd.py revision 1899
#
# 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
#
#
#
import testutils
if __name__ == "__main__":
import pkg5unittest
import httplib
import os
import shutil
import tempfile
import time
import unittest
import urllib
import urllib2
import urlparse
foo10 = """
open foo@1.0,5.11-0
close """
bar10 = """
open bar@1.0,5.11-0
close """
quux10 = """
open quux@1.0,5.11-0
add dir mode=0755 owner=root group=bin path=/bin
close """
info10 = """
open info@1.0,5.11-0
close """
update10 = """
open update@1.0,5.11-0
close """
update11 = """
open update@1.1,5.11-0
close """
system10 = """
add set name="description" value="Package to test package names with slashes"
add depend type=require fmri=pkg:/SUNWcsl
close """
# This suite, for obvious reasons, actually needs a depot.
def test_depot_ping(self):
""" Ping the depot several times """
def testStartStop(self):
""" Start and stop the depot several times """
def test_bug_1876(self):
""" Send package quux@1.0 an action at a time, restarting the
depot server after each one is sent, to ensure that
transactions work across depot restart. Then verify that
the package was successfully added by performing some
basic operations. """
if line == "":
continue
try:
except:
raise
if not line == "close":
def test_bad_fmris(self):
def test_bug_3365(self):
f.close()
f.close()
def test_bug_4489(self):
"""Publish a package and then verify that the depot /info
operation doesn't fail."""
def test_bug_3739(self):
"""Verify that a depot will return a 400 (Bad Request) error
whenever it is provided malformed FMRIs."""
"BRCMbnx%400.5.11%2C5.11-0.101%3A20081119T231649a"):
try:
raise
def test_bug_5366(self):
"""Publish a package with slashes in the name, and then verify
that the depot manifest and info operations work regardless of
the encoding."""
# First, try it un-encoded.
# Second, try it encoded.
def test_bug_5707(self):
"""Testing depotcontroller.refresh()."""
def test_face_root(self):
"""Verify that files outside of the package content web root
cannot be accessed, and that files inside can be."""
# any attempts to go outside that directory should fail
# with a 404 error.
try:
raise
f.close()
def test_repo_create(self):
"""Verify that starting a depot server in readonly mode with
a non-existent or empty repo_dir fails and that permissions
errors are handled correctly during creation. Then verify
that starting a depot with the same directory in publishing
mode works and then a readonly depot again after that works.
"""
# First, test readonly mode with a repo_dir that doesn't exist.
# Next, test readonly mode with a repo_dir that is empty.
# Next, test readwrite (publishing) mode with a non-existent
# repo_dir.
# Next, test readwrite (publishing) mode with a non-existent
# repo_dir for an unprivileged user.
try:
finally:
# Even if this test fails, this wrapper must be reset.
# Next, test readwrite (publishing) mode with an empty repo_dir.
# Finally, re-test readonly mode now that the repository has
# been created.
# Cleanup.
"/usr/lib/pkg.depotd")
try:
except:
pass
def testStartStop(self):
def test_cfg_file(self):
def test_writable_root(self):
"""Tests whether the index and feed cache file are written to
the writable root parameter."""
"writ_root")
timeout = 10
def check_state(check_feed):
if check_feed:
try:
def testBadArgs(self):
def test_disable_ops(self):
"""Verify that disable-ops works as expected."""
# For this disabled case, /catalog/1/ should return
# a NOT_FOUND error.
try:
# For this disabled case, all /catalog/ operations should return
# a NOT_FOUND error.
try:
# In the normal case, /catalog/1/ should return
# a FORBIDDEN error.
try:
# A bogus operation should prevent the depot from starting.
# Since these tests are output sensitive, the depots should be purged
# after each one is run.
quux10 = """
open quux@1.0,5.11-0
add dir mode=0755 owner=root group=bin path=/bin
close """
info10 = """
open info@1.0,5.11-0
close """
file10 = """
open file@1.0,5.11-0
add dir mode=0755 owner=root group=bin path=/var
close """
system10 = """
add set name="description" value="Package to test package names with slashes"
add depend type=require fmri=pkg:/SUNWcsl
close """
zfsextras10 = """
open zfs-extras@1.0,5.11-0
close """
zfsutils10 = """
close """
repo_cfg = {
"publisher": {
"alias": "pending",
"prefix": "org.opensolaris.pending"
},
"repository": {
"collection_type": "supplemental",
"description":
"Development packages for the contrib repository.",
"legal_uris": [
],
"mirrors": [],
"name": """"Pending" Repository""",
"origins": [], # Has to be set during setUp for correct origin.
"refresh_seconds": 86400,
"registration_uri": "",
"related_uris": [
]
}
}
# All of the tests will start depot if needed.
# Prevent override of custom configuration;
# tests will set as needed.
# Set repository origins.
def test_0_depot_bui_output(self):
"""Verify that a non-error response and valid HTML is returned
for each known BUI page in every available depot mode."""
# A list of tuples containing the name of the method used to set
# the mode, and then the method needed to unset that mode.
mode_methods = [
("set_readwrite", None),
("set_mirror", "unset_mirror"),
("set_readonly", "set_readwrite"),
]
pages = [
"index.shtml",
"en/catalog.shtml",
"en/index.shtml",
"en/search.shtml",
"en/stats.shtml",
]
if with_packages:
if set_method:
# Any error responses will cause an
# exception.
if unset_method:
def __update_repo_config(self):
"""Helper function to generate test repository configuration."""
# Find and load the repository configuration.
# Update the configuration with our sample data.
# Save it.
def test_1_depot_publisher(self):
"""Verify the output of the depot /publisher operation."""
# Now update the repository configuration while the depot is
# stopped so changes won't be overwritten on exit.
# Start the depot.
# Now verify that the parsed response has the expected data.
uris = []
for u in returned:
def test_2_depot_p5i(self):
"""Verify the output of the depot /publisher operation."""
# Now update the repository configuration while the depot is
# stopped so changes won't be overwritten on exit.
# Start the depot.
# Then, publish some packages we can abuse for testing.
# Now, for each published package, attempt to get a p5i file
# and then verify that the parsed response has the expected
# package information under the expected publisher.
for p in plist:
# p5i files contain non-qualified FMRIs as the FMRIs
# are already grouped by publisher.
# Try again, but only using package stems.
for p in plist:
# Try again, but using wildcards (which will return a list of
# matching package stems).
# Finally, verify that a non-existent package will error out
# with a httplib.NOT_FOUND.
try:
"p5i/0/nosuchpackage"))
raise
def test_3_headers(self):
"""Ensure expected headers are present for client operations
(excluding publication)."""
# Now update the repository configuration while the depot is
# stopped so changes won't be overwritten on exit.
# Start the depot.
"5.11")
def get_headers(req_path):
try:
except Exception, e:
raise RuntimeError("retrieval of %s "
'search/1/False_2_None_None_%2Fvar%2Ffile',
"catalog/0", "catalog/1/catalog.attrs",
"file/0/3aad0bca6f3a6f502c175700ebe90ef36e312d7e",
"filelist/0"):
# Fields must be referenced in lowercase.
"no-cache, no-transform, must-revalidate")
"no-cache")
else:
"no-transform, max-age="))
def test_bug_15482(self):
"""Test to make sure BUI search doesn't trigger a traceback."""
# Now update the repository configuration while the depot is
# stopped so changes won't be overwritten on exit.
# Start the depot.
# Then, publish some packages we can abuse for testing.
"en/search.shtml?action=Search&token=*")
"en/advanced_search.shtml?action=Search&token=*")
"en/advanced_search.shtml?token=*&show=a&rpp=50&"
"action=Advanced+Search")
if __name__ == "__main__":