testutils.py revision 267
#
# 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
#
# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
import unittest
import os
import sys
import subprocess
import shutil
import errno
topdivider = \
",---------------------------------------------------------------------\n"
botdivider = \
"`---------------------------------------------------------------------\n"
def format_comment(comment):
if comment is not None:
comm = ""
if line == "":
continue
return comm + "\n"
else:
return "<no comment>\n\n"
str = " Output Follows:\n"
str += topdivider
if command is not None:
str += "| <no output>\n"
else:
str += botdivider
return str
def format_debug(output):
str = " Debug Buffer Follows:\n"
str += topdivider
str += "| <no debug buffer>\n"
else:
str += botdivider
return str
class DepotTracebackException(Exception):
str = "During this test, a depot Traceback was detected.\n"
str += "Log file output is:\n"
return str
class TracebackException(Exception):
debug = None):
str = ""
return str
class UnexpectedExitCodeException(Exception):
str = ""
str += " Expected exit status: %d. Got: %d." % \
return str
class PkgSendOpenException(Exception):
self.__image_dir = None
# XXX Windows portability issue
else:
def get_img_path(self):
return self.__img_path
def get_test_prefix(self):
return self.__test_prefix
self.__debug_buf += s
if not s.endswith("\n"):
if retcode != 0:
def get_debugbuf(self):
return self.__debug_buf
assert self.__img_path
cmdline = "pkg image-create -F -a test=%s %s" % \
if retcode == 99:
if retcode != 0:
return retcode
def image_destroy(self):
if retcode == 99:
return retcode
# XXX may need to be smarter.
if retcode == 0:
assert arr
# retcode != 0 will be handled below
else:
if retcode == 99:
return retcode
""" Send a series of packaging commands; useful for
quickly doing a bulk-load of stuff into the repo.
We expect that the commands will all work; if not,
the transaction is abandoned. """
try:
if line == "":
continue
except (TracebackException, UnexpectedExitCodeException):
raise
class SingleDepotTestCase(pkg5TestCase):
"depot_logdir")
try:
except OSError, e:
raise e
def check_traceback(self):
""" Scan the depot logfile looking for tracebacks.
Raise a DepotTracebackException if one is seen.
"""
try:
finally:
if __name__ == "__main__":