t_pkg_depotd.py revision 3329
#
# 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 datetime
import os
import shutil
import six
import tempfile
import time
import unittest
import re
import subprocess
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 """
entire10 = """
open entire@1.0,5.11-0
add depend type=incorporate fmri=pkg:/foo
close """
info20 = """
open info@2.0,5.11-0
add set name="description" value="Test for checking info_0 consistency"
add set name="pkg.human-version" value="test of human version"
add dir mode=0755 owner=root group=bin path=/bin
close"""
# test_info() parses dates,
# so set expected locale before starting depots
# 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:
except HTTPError as e:
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.
plist[0]))
# Second, try it encoded.
"""Testing information showed in /info/0."""
# Get text from content.
info_dic = {}
attr_list = [
'Name',
'Summary',
'Publisher',
'Version',
'Build Release',
'Branch',
'Packaging Date',
'Size',
'Compressed Size',
'FMRI'
]
if attr == "License":
break
else:
# Read manifest.
# Check if FMRI is empty.
# Human version.
hum_ver = ""
if '(' in version:
# Compare each attribute.
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:
except HTTPError as e:
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.
def test_append_reopen(self):
"""Test that if a depot has a partially finished append
transaction, that it reopens it correctly."""
def test_nonsig_append(self):
"""Test that sending a non-signature action to an append
transaction results in an error."""
def test_root_link(self):
"""Verify that the depot server accepts a link to a
directory as a repository root."""
# Create a link to the repository and verify that
# the depot server allows it.
# Reset for any tests that might execute afterwards.
def test_empty_incorp_depend(self):
""" Bug 16304629
Test that a version-less incorporate dependency in a package
doesn't cause a traceback and a 404 in the BUI.
"""
"/en/catalog.shtml?version={0}&action=Browse".format(
quote("entire@1.0,5.11-0")))
def test_publisher_prefix(self):
"""Test that various publisher prefixes can be understood
by CherryPy's dispatcher."""
for p in pubs:
repopath, p))
for p in pubs:
# test that the catalog file can be found
"{0}/catalog/1/catalog.attrs".format(p))
"/usr/lib/pkg.depotd")
"prefix": "test" }})
def _get_repo_index_dir(self):
return rstore.index_root
def _get_repo_writ_dir(self):
return rstore.writable_root
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):
"index")
"feed.xml")
if check_feed:
try:
except:
raise RuntimeError("Feed cache file "
if pub:
try:
pub))
except HTTPError as e:
if not pub_repo:
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:
except HTTPError as e:
# For this disabled case, all /catalog/ operations should return
# a NOT_FOUND error.
try:
except HTTPError as e:
# In the normal case, /catalog/1/ should return
# a FORBIDDEN error.
try:
except HTTPError as e:
# 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": {
"prefix": "org.opensolaris.pending"
},
}
pub_repo_cfg = {
"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": [
]
}
# Prevent override of custom configuration;
# tests will set as needed.
"""Helper function: start a depot daemon and return a handler
for its parent process and the port number it is running on.
The parent process is a ctrun process. It is the user's
responsibility to call depot_daemon_stop to stop the process.
ctrun is used to kill the depot daemon process after finishing
testing. It is needed because the double fork machanism of the
daemonizer make the daemonized depot server indenpendent from
its parent process.
repopath: The repository path that a depot daemon will run on.
out_path: The depot daemon stdout log file path.
err_path: The depot daemon stderr log file path."""
# Make sure the PKGDEPOT_CONTROLLER is not set in the newenv.
# Start a depot daemon process.
try:
"start depot")
check_interval = 0.20
"unexpectedly")
try:
break
except URLError as e:
if not daemon_started:
if depot_handle:
"access depot daemon")
# Read the msgs from the err log file to verify log
# msgs.
"empty. Check if the previous "
"ctrun process shut down "
"properly")
return (depot_handle, curport)
except:
try:
if depot_handle:
except:
pass
raise
"""Helper function: stop the depot daemon process by sending
signal to its handle."""
# Terminate the depot daemon. If failed, kill it.
try:
if depot_handle:
except:
try:
if depot_handle:
except:
pass
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."""
pub = "test"
# 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",
]
# Create repository and set publisher origins.
if with_packages:
if set_method:
# Any error responses will cause an
# exception.
# Because the 'role' attribute used for
# screen readers and other accessibility
# tools isn't part of the official XHTML
# 1.x standards, it has to be dropped
# for the document to be validated.
# Setting 'drop_prop_attrs' to True here
# does that while ensuring that the
# output of the depot is otherwise
# standards-compliant.
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.
# Apply publisher properties and update.
try:
except sr.RepositoryUnknownPublisher:
if not pub_repo:
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 /p5i 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"))
except HTTPError as e:
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.
# Wait for search indexing to complete.
def get_headers(req_path):
try:
except HTTPError as e:
except Exception as e:
raise RuntimeError("retrieval of {0} "
for req_path in ("publisher/0",
'search/1/False_2_None_None_%2Fvar%2Ffile',
"catalog/1/catalog.attrs",
"file/0/3aad0bca6f3a6f502c175700ebe90ef36e312d7e"):
# Fields must be referenced in lowercase.
"no-transform, max-age="),
for req_path in ("catalog/1/catalog.hatters",
"file/0/3aad0bca6f3a6f502c175700ebe90ef36e312d7f"):
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")
def test_address(self):
"""Verify that depot address can be set."""
# Check that IPv6 address can be used.
# Check that we can retrieve something.
def test_log_depot_daemon(self):
"""Verify that depot daemon works properly and the error
message is logged properly."""
# Create a test repo.
depot_handle = None
try:
# Issue a bad request to trigger the server logging
# the error msg.
try:
except URLError as e:
pass
# Stop the depot daemon.
# Read the msgs from the err log file to verify log
# msgs.
"failed")
except:
raise
if __name__ == "__main__":