src/tests/pkg5unittest.py
author Brock Pytlik <brock.pytlik@oracle.com>
Wed, 09 Feb 2011 15:25:24 -0800
changeset 2218 f025ba1faae7
parent 2215 b4355e8c5097
child 2219 60ad60f7592c
permissions -rw-r--r--
16856 need to check keyUsage for leaf certs (fix api versions)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1516
8c950a3b4171 10485 move pkg(5) to Python 2.6
Rich Burridge <rich.burridge@sun.com>
parents: 1513
diff changeset
     1
#!/usr/bin/python
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
     2
430
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
     3
# CDDL HEADER START
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
     4
#
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
     5
# The contents of this file are subject to the terms of the
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
     6
# Common Development and Distribution License (the "License").
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
     7
# You may not use this file except in compliance with the License.
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
     8
#
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
     9
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
    10
# or http://www.opensolaris.org/os/licensing.
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
    11
# See the License for the specific language governing permissions
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
    12
# and limitations under the License.
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
    13
#
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
    14
# When distributing Covered Code, include this CDDL HEADER in each
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
    15
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
    16
# If applicable, add the following below this CDDL HEADER, with the
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
    17
# fields enclosed by brackets "[]" replaced with your own identifying
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
    18
# information: Portions Copyright [yyyy] [name of copyright owner]
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
    19
#
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
    20
# CDDL HEADER END
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
    21
#
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
    22
2183
21ae45e8dfcf 17581 There should be a way of removing a package as part of upgrade
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2158
diff changeset
    23
# Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
430
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
    24
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
    25
import baseline
2085
10a27146ebc2 16802 pkglint should check the value of info.classification in manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 2081
diff changeset
    26
import ConfigParser
502
3f98e94acc4a 2690 test suite depot starting/stopping
Brad Hall <bhall@eng.sun.com>
parents: 448
diff changeset
    27
import copy
1730
c12580e62699 14347 Add tests to exercise the new -F tsv option for pkg publisher
Gary Pennington <gary.pennington@sun.com>
parents: 1715
diff changeset
    28
import difflib
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
    29
import errno
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
    30
import gettext
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1970
diff changeset
    31
import hashlib
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
    32
import logging
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
    33
import os
1859
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1839
diff changeset
    34
import pprint
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
    35
import shutil
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
    36
import signal
1832
df15686547e4 6795 pkg fix should fix file modes for some preserved files
Shawn Walker <shawn.walker@oracle.com>
parents: 1795
diff changeset
    37
import stat
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
    38
import subprocess
430
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
    39
import sys
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
    40
import tempfile
448
bcfa99ac18b0 2664 test suite baseline enhancements
Brad Hall <bhall@eng.sun.com>
parents: 436
diff changeset
    41
import time
430
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
    42
import unittest
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
    43
import platform
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
    44
import pwd
1730
c12580e62699 14347 Add tests to exercise the new -F tsv option for pkg publisher
Gary Pennington <gary.pennington@sun.com>
parents: 1715
diff changeset
    45
import re
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
    46
import textwrap
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
    47
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
    48
EmptyI = tuple()
1859
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1839
diff changeset
    49
EmptyDict = dict()
616
6d307b088d92 4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents: 571
diff changeset
    50
2046
2522cde7adc2 13536 We need a way to audit one or more packages
Tim Foster <tim.s.foster@oracle.com>
parents: 2034
diff changeset
    51
# relative to our proto area
2522cde7adc2 13536 We need a way to audit one or more packages
Tim Foster <tim.s.foster@oracle.com>
parents: 2034
diff changeset
    52
path_to_pub_util = "../../src/util/publish"
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1970
diff changeset
    53
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
    54
#
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
    55
# These are initialized by pkg5testenv.setup_environment.
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
    56
#
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
    57
g_proto_area = "TOXIC"
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
    58
# User's value for TEMPDIR
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
    59
g_tempdir = "/tmp"
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
    60
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
    61
g_debug_output = False
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
    62
if "DEBUG" in os.environ:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
    63
        g_debug_output = True
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
    64
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
    65
#
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
    66
# XXX?
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
    67
#
1946
8ef3acf32d54 16132 various bits of pkg specify non-existent domains to gettext.install
Richard Lowe <richlowe@richlowe.net>
parents: 1908
diff changeset
    68
gettext.install("pkg", "/usr/share/locale")
430
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
    69
2073
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2047
diff changeset
    70
OUTPUT_DOTS = 0         # Dots ...
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2047
diff changeset
    71
OUTPUT_VERBOSE = 1      # Verbose
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2047
diff changeset
    72
OUTPUT_PARSEABLE = 2    # Machine readable
430
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
    73
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
    74
class TestStopException(Exception):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
    75
        """An exception used to signal that all testing should cease.
2073
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2047
diff changeset
    76
        This is a framework-internal exception that tests should not
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2047
diff changeset
    77
        raise"""
435
461b1c739de9 1753 An exception thrown during the teardown phase of the test program leaves pkg.depot running.
Brock Pytlik <bpytlik@sun.com>
parents: 430
diff changeset
    78
        pass
461b1c739de9 1753 An exception thrown during the teardown phase of the test program leaves pkg.depot running.
Brock Pytlik <bpytlik@sun.com>
parents: 430
diff changeset
    79
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
    80
class TestSkippedException(Exception):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
    81
        """An exception used to signal that a test was skipped.
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
    82
        Should be initialized with a string giving a more detailed
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
    83
        reason.  Test cases can raise this to the framework
2073
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2047
diff changeset
    84
        that some prerequisite of the test is unsatisfied.  A string
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2047
diff changeset
    85
        explaining the error should be passed at construction.  """
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2047
diff changeset
    86
        def __str__(self):
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2047
diff changeset
    87
                return "Test Skipped: " + " ".join(self.args)
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
    88
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
    89
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
    90
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
    91
#
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
    92
# Errors for which the traceback is likely not useful.
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
    93
#
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
    94
import pkg.depotcontroller as depotcontroller
1832
df15686547e4 6795 pkg fix should fix file modes for some preserved files
Shawn Walker <shawn.walker@oracle.com>
parents: 1795
diff changeset
    95
import pkg.portable as portable
1859
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1839
diff changeset
    96
import pkg.client.api
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1839
diff changeset
    97
import pkg.client.progress
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1839
diff changeset
    98
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1839
diff changeset
    99
# Version test suite is known to work with.
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1839
diff changeset
   100
PKG_CLIENT_NAME = "pkg"
2218
f025ba1faae7 16856 need to check keyUsage for leaf certs (fix api versions)
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2215
diff changeset
   101
CLIENT_API_VERSION = 52
1859
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1839
diff changeset
   102
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   103
ELIDABLE_ERRORS = [ TestSkippedException, depotcontroller.DepotStateException ]
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   104
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   105
class Pkg5CommonException(AssertionError):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   106
        def __init__(self, com = ""):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   107
                Pkg5TestCase.failureException.__init__(self, com)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   108
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   109
        topdivider = \
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   110
        ",---------------------------------------------------------------------\n"
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   111
        botdivider = \
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   112
        "`---------------------------------------------------------------------\n"
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   113
        def format_comment(self, comment):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   114
                if comment is not None:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   115
                        comment = comment.expandtabs()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   116
                        comm = ""
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   117
                        for line in comment.splitlines():
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   118
                                line = line.strip()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   119
                                if line == "":
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   120
                                        continue
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   121
                                comm += "  " + line + "\n"
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   122
                        return comm + "\n"
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   123
                else:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   124
                        return "<no comment>\n\n"
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   125
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   126
        def format_output(self, command, output):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   127
                str = "  Output Follows:\n"
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   128
                str += self.topdivider
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   129
                if command is not None:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   130
                        str += "| $ " + command + "\n"
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   131
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   132
                if output is None or output == "":
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   133
                        str += "| <no output>\n"
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   134
                else:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   135
                        for line in output.split("\n"):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   136
                                str += "| " + line.rstrip() + "\n"
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   137
                str += self.botdivider
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   138
                return str
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   139
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   140
        def format_debug(self, output):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   141
                str = "  Debug Buffer Follows:\n"
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   142
                str += self.topdivider
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   143
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   144
                if output is None or output == "":
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   145
                        str += "| <no debug buffer>\n"
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   146
                else:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   147
                        for line in output.split("\n"):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   148
                                str += "| " + line.rstrip() + "\n"
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   149
                str += self.botdivider
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   150
                return str
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   151
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   152
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   153
class AssFailException(Pkg5CommonException):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   154
        def __init__(self, comment = None, debug=None):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   155
                Pkg5CommonException.__init__(self, comment)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   156
                self.__comment = comment
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   157
                self.__debug = debug
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   158
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   159
        def __str__(self):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   160
                str = ""
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   161
                if self.__comment is None:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   162
                        str += Exception.__str__(self)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   163
                else:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   164
                        str += self.format_comment(self.__comment)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   165
                if self.__debug is not None and self.__debug != "":
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   166
                        str += self.format_debug(self.__debug)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   167
                return str
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   168
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   169
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
   170
class DebugLogHandler(logging.Handler):
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
   171
        """This class is a special log handler to redirect logger output to
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
   172
        the test case class' debug() method.
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
   173
        """
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
   174
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
   175
        def __init__(self, test_case):
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
   176
                self.test_case = test_case
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
   177
                logging.Handler.__init__(self)
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
   178
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
   179
        def emit(self, record):
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
   180
                self.test_case.debug(record)
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
   181
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
   182
def setup_logging(test_case):
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
   183
        # Ensure logger messages output by unit tests are redirected
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
   184
        # to debug output so they are not shown by default.
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
   185
        from pkg.client import global_settings
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
   186
        log_handler = DebugLogHandler(test_case)
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
   187
        global_settings.info_log_handler = log_handler
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
   188
        global_settings.error_log_handler = log_handler
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
   189
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
   190
430
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
   191
class Pkg5TestCase(unittest.TestCase):
502
3f98e94acc4a 2690 test suite depot starting/stopping
Brad Hall <bhall@eng.sun.com>
parents: 448
diff changeset
   192
3f98e94acc4a 2690 test suite depot starting/stopping
Brad Hall <bhall@eng.sun.com>
parents: 448
diff changeset
   193
        # Needed for compatability
3f98e94acc4a 2690 test suite depot starting/stopping
Brad Hall <bhall@eng.sun.com>
parents: 448
diff changeset
   194
        failureException = AssertionError
3f98e94acc4a 2690 test suite depot starting/stopping
Brad Hall <bhall@eng.sun.com>
parents: 448
diff changeset
   195
683
5e5d509f00e3 4422 t_pkg_authority pinging extant node accidentally
Brock Pytlik <bpytlik@sun.com>
parents: 616
diff changeset
   196
        bogus_url = "test.invalid"
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   197
        __debug_buf = ""
683
5e5d509f00e3 4422 t_pkg_authority pinging extant node accidentally
Brock Pytlik <bpytlik@sun.com>
parents: 616
diff changeset
   198
430
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
   199
        def __init__(self, methodName='runTest'):
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
   200
                super(Pkg5TestCase, self).__init__(methodName)
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   201
                self.__test_root = None
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   202
                self.__pid = os.getpid()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   203
                self.__pwd = os.getcwd()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   204
                self.__didteardown = False
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
   205
                setup_logging(self)
430
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
   206
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
   207
        def __str__(self):
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
   208
                return "%s.py %s.%s" % (self.__class__.__module__,
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   209
                    self.__class__.__name__, self._testMethodName)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   210
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   211
        #
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   212
        # Uses property() to implements test_root as a read-only attribute.
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   213
        #
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   214
        test_root = property(fget=lambda self: self.__test_root)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   215
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1970
diff changeset
   216
        def __get_ro_data_root(self):
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1970
diff changeset
   217
                if not self.__test_root:
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1970
diff changeset
   218
                        return None
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1970
diff changeset
   219
                return os.path.join(self.__test_root, "ro_data")
2183
21ae45e8dfcf 17581 There should be a way of removing a package as part of upgrade
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2158
diff changeset
   220
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1970
diff changeset
   221
        ro_data_root = property(fget=__get_ro_data_root)
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1970
diff changeset
   222
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   223
        def cmdline_run(self, cmdline, comment="", coverage=True, exit=0,
2046
2522cde7adc2 13536 We need a way to audit one or more packages
Tim Foster <tim.s.foster@oracle.com>
parents: 2034
diff changeset
   224
            handle=False, out=False, prefix="", raise_error=True, su_wrap=None,
2522cde7adc2 13536 We need a way to audit one or more packages
Tim Foster <tim.s.foster@oracle.com>
parents: 2034
diff changeset
   225
            stderr=False):
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   226
                wrapper = ""
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   227
                if coverage:
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   228
                        wrapper = self.coverage_cmd
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   229
                su_wrap, su_end = self.get_su_wrapper(su_wrap=su_wrap)
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   230
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   231
                cmdline = "%s%s%s %s%s" % (prefix, su_wrap, wrapper,
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   232
                    cmdline, su_end)
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   233
                self.debugcmd(cmdline)
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   234
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   235
                newenv = os.environ.copy()
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   236
                if coverage:
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   237
                        newenv.update(self.coverage_env)
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   238
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   239
                p = subprocess.Popen(cmdline,
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   240
                    env=newenv,
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   241
                    shell=True,
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   242
                    stdout=subprocess.PIPE,
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   243
                    stderr=subprocess.PIPE)
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   244
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   245
                if handle:
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   246
                        # Do nothing more.
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   247
                        return p
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   248
                self.output, self.errout = p.communicate()
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   249
                retcode = p.returncode
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   250
                self.debugresult(retcode, exit, self.output)
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   251
                if self.errout != "":
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   252
                        self.debug(self.errout)
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   253
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   254
                if raise_error and retcode == 99:
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   255
                        raise TracebackException(cmdline, self.output +
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   256
                            self.errout, comment)
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   257
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   258
                if not isinstance(exit, list):
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   259
                        exit = [exit]
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   260
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   261
                if raise_error and retcode not in exit:
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   262
                        raise UnexpectedExitCodeException(cmdline,
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   263
                            exit, retcode, self.output + self.errout,
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   264
                            comment)
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   265
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   266
                if out:
2046
2522cde7adc2 13536 We need a way to audit one or more packages
Tim Foster <tim.s.foster@oracle.com>
parents: 2034
diff changeset
   267
                        if stderr:
2522cde7adc2 13536 We need a way to audit one or more packages
Tim Foster <tim.s.foster@oracle.com>
parents: 2034
diff changeset
   268
                                return retcode, self.output, self.errout
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   269
                        return retcode, self.output
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   270
                return retcode
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   271
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   272
        def debug(self, s):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   273
                s = str(s)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   274
                for x in s.splitlines():
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   275
                        if g_debug_output:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   276
                                print >> sys.stderr, "# %s" % x
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   277
                        self.__debug_buf += x + "\n"
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   278
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   279
        def debugcmd(self, cmdline):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   280
                wrapper = textwrap.TextWrapper(initial_indent="$ ",
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   281
                    subsequent_indent="\t",
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   282
                    break_long_words=False,
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   283
                    break_on_hyphens=False)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   284
                res = wrapper.wrap(cmdline.strip())
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   285
                self.debug(" \\\n".join(res))
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   286
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   287
        def debugfilecreate(self, content, path):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   288
                lines = content.splitlines()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   289
                if lines == []:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   290
                        lines = [""]
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   291
                if len(lines) > 1:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   292
                        ins = " [+%d lines...]" % (len(lines) - 1)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   293
                else:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   294
                        ins = ""
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   295
                self.debugcmd(
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   296
                    "echo '%s%s' > %s" % (lines[0], ins, path))
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   297
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   298
        def debugresult(self, retcode, expected, output):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   299
                if output.strip() != "":
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   300
                        self.debug(output.strip())
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   301
                if not isinstance(expected, list):
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   302
                        expected = [expected]
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   303
                if retcode is None or retcode != 0 or \
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   304
                    retcode not in expected:
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   305
                        self.debug("[exited %s, expected %s]" %
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   306
                            (retcode, ", ".join(str(e) for e in expected)))
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   307
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   308
        def get_debugbuf(self):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   309
                return self.__debug_buf
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   310
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   311
        def get_su_wrapper(self, su_wrap=None):
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   312
                if su_wrap:
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   313
                        if su_wrap == True:
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   314
                                su_wrap = get_su_wrap_user()
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   315
                        cov_env = " ".join(
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   316
                            ("%s=%s" % e for e in self.coverage_env.items()))
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   317
                        su_wrap = "su %s -c 'LD_LIBRARY_PATH=%s %s " % \
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   318
                            (su_wrap, os.getenv("LD_LIBRARY_PATH", ""), cov_env)
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   319
                        su_end = "'"
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   320
                else:
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   321
                        su_wrap = ""
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   322
                        su_end = ""
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   323
                return su_wrap, su_end
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   324
502
3f98e94acc4a 2690 test suite depot starting/stopping
Brad Hall <bhall@eng.sun.com>
parents: 448
diff changeset
   325
        def getTeardownFunc(self):
3f98e94acc4a 2690 test suite depot starting/stopping
Brad Hall <bhall@eng.sun.com>
parents: 448
diff changeset
   326
                return (self, self.tearDown)
3f98e94acc4a 2690 test suite depot starting/stopping
Brad Hall <bhall@eng.sun.com>
parents: 448
diff changeset
   327
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   328
        def getSetupFunc(self):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   329
                return (self, self.setUp)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   330
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   331
        def setUp(self):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   332
                self.__test_root = os.path.join(g_tempdir,
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   333
                    "ips.test.%d" % self.__pid)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   334
                self.__didtearDown = False
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   335
                try:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   336
                        os.makedirs(self.__test_root, 0755)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   337
                except OSError, e:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   338
                        if e.errno != errno.EEXIST:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   339
                                raise e
2046
2522cde7adc2 13536 We need a way to audit one or more packages
Tim Foster <tim.s.foster@oracle.com>
parents: 2034
diff changeset
   340
                test_relative = os.path.sep.join(["..", "..", "src", "tests"])
2522cde7adc2 13536 We need a way to audit one or more packages
Tim Foster <tim.s.foster@oracle.com>
parents: 2034
diff changeset
   341
                test_src = os.path.join(g_proto_area, test_relative)
2522cde7adc2 13536 We need a way to audit one or more packages
Tim Foster <tim.s.foster@oracle.com>
parents: 2034
diff changeset
   342
                shutil.copytree(os.path.join(test_src, "ro_data"),
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1970
diff changeset
   343
                    self.ro_data_root)
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   344
                #
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   345
                # TMPDIR affects the behavior of mkdtemp and mkstemp.
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   346
                # Setting this here should ensure that tests will make temp
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   347
                # files and dirs inside the test directory rather than
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   348
                # polluting /tmp.
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   349
                #
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   350
                os.environ["TMPDIR"] = self.__test_root
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   351
                tempfile.tempdir = self.__test_root
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
   352
                setup_logging(self)
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   353
2085
10a27146ebc2 16802 pkglint should check the value of info.classification in manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 2081
diff changeset
   354
                self.configure_rcfile( "%s/usr/share/lib/pkg/pkglintrc" %
10a27146ebc2 16802 pkglint should check the value of info.classification in manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 2081
diff changeset
   355
                    g_proto_area,
10a27146ebc2 16802 pkglint should check the value of info.classification in manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 2081
diff changeset
   356
                    {"info_classification_path":
10a27146ebc2 16802 pkglint should check the value of info.classification in manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 2081
diff changeset
   357
                    "%s/usr/share/package-manager/data/opensolaris.org.sections" %
10a27146ebc2 16802 pkglint should check the value of info.classification in manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 2081
diff changeset
   358
                    g_proto_area}, self.test_root, section="pkglint")
10a27146ebc2 16802 pkglint should check the value of info.classification in manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 2081
diff changeset
   359
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   360
        def impl_tearDown(self):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   361
                # impl_tearDown exists so that we can ensure that this class's
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   362
                # teardown is actually called.  Sometimes, subclasses will
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   363
                # implement teardown but forget to call the superclass teardown.
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   364
                if self.__didteardown:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   365
                        return
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   366
                self.__didteardown = True
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   367
                try:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   368
                        os.chdir(self.__pwd)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   369
                except OSError:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   370
                        # working directory of last resort.
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   371
                        os.chdir(g_tempdir)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   372
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   373
                #
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   374
                # Kill depots before blowing away test dir-- otherwise
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   375
                # the depot can race with the shutil.rmtree()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   376
                #
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   377
                if hasattr(self, "killalldepots"):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   378
                        try:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   379
                                self.killalldepots()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   380
                        except Exception, e:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   381
                                print >> sys.stderr, str(e)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   382
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   383
                #
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   384
                # We have some sloppy subclasses which don't call the superclass
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   385
                # setUp-- in which case the dir might not exist.  Tolerate it.
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   386
                #
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   387
                if self.__test_root is not None and \
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   388
                    os.path.exists(self.__test_root):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   389
                        shutil.rmtree(self.__test_root)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   390
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   391
        def tearDown(self):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   392
                # In reality this call does nothing.
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   393
                unittest.TestCase.tearDown(self)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   394
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   395
                self.impl_tearDown()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   396
435
461b1c739de9 1753 An exception thrown during the teardown phase of the test program leaves pkg.depot running.
Brock Pytlik <bpytlik@sun.com>
parents: 430
diff changeset
   397
        def run(self, result=None):
436
5f150abbfba7 Shawn's feedback
Brock Pytlik <bpytlik@sun.com>
parents: 435
diff changeset
   398
                if result is None:
5f150abbfba7 Shawn's feedback
Brock Pytlik <bpytlik@sun.com>
parents: 435
diff changeset
   399
                        result = self.defaultTestResult()
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   400
                pwd = os.getcwd()
435
461b1c739de9 1753 An exception thrown during the teardown phase of the test program leaves pkg.depot running.
Brock Pytlik <bpytlik@sun.com>
parents: 430
diff changeset
   401
                result.startTest(self)
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   402
                testMethod = getattr(self, self._testMethodName)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   403
                if getattr(result, "coverage", None) is not None:
1513
3ece69a26155 5032 make coverage should only report on the files in our gate
Danek Duvall <danek.duvall@sun.com>
parents: 1505
diff changeset
   404
                        self.coverage_cmd, self.coverage_env = result.coverage
3ece69a26155 5032 make coverage should only report on the files in our gate
Danek Duvall <danek.duvall@sun.com>
parents: 1505
diff changeset
   405
                else:
3ece69a26155 5032 make coverage should only report on the files in our gate
Danek Duvall <danek.duvall@sun.com>
parents: 1505
diff changeset
   406
                        self.coverage_cmd, self.coverage_env = "", {}
435
461b1c739de9 1753 An exception thrown during the teardown phase of the test program leaves pkg.depot running.
Brock Pytlik <bpytlik@sun.com>
parents: 430
diff changeset
   407
                try:
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   408
                        needtodie = False
571
1a2452c33cb9 3476 Most cli test cases can't be run standalone anymore
Brad Hall <bhall@eng.sun.com>
parents: 516
diff changeset
   409
                        try:
1a2452c33cb9 3476 Most cli test cases can't be run standalone anymore
Brad Hall <bhall@eng.sun.com>
parents: 516
diff changeset
   410
                                self.setUp()
1a2452c33cb9 3476 Most cli test cases can't be run standalone anymore
Brad Hall <bhall@eng.sun.com>
parents: 516
diff changeset
   411
                        except KeyboardInterrupt:
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   412
                                # Try hard to make sure we've done a teardown.
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   413
                                try:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   414
                                        self.tearDown()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   415
                                except:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   416
                                        pass
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   417
                                self.impl_tearDown()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   418
                                raise TestStopException
571
1a2452c33cb9 3476 Most cli test cases can't be run standalone anymore
Brad Hall <bhall@eng.sun.com>
parents: 516
diff changeset
   419
                        except:
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   420
                                # teardown could fail too, esp. if setup failed...
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   421
                                try:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   422
                                        self.tearDown()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   423
                                except:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   424
                                        pass
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   425
                                # Try hard to make sure we've done a teardown.
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   426
                                self.impl_tearDown()
571
1a2452c33cb9 3476 Most cli test cases can't be run standalone anymore
Brad Hall <bhall@eng.sun.com>
parents: 516
diff changeset
   427
                                result.addError(self, sys.exc_info())
1a2452c33cb9 3476 Most cli test cases can't be run standalone anymore
Brad Hall <bhall@eng.sun.com>
parents: 516
diff changeset
   428
                                return
435
461b1c739de9 1753 An exception thrown during the teardown phase of the test program leaves pkg.depot running.
Brock Pytlik <bpytlik@sun.com>
parents: 430
diff changeset
   429
461b1c739de9 1753 An exception thrown during the teardown phase of the test program leaves pkg.depot running.
Brock Pytlik <bpytlik@sun.com>
parents: 430
diff changeset
   430
                        ok = False
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   431
                        error_added = False
435
461b1c739de9 1753 An exception thrown during the teardown phase of the test program leaves pkg.depot running.
Brock Pytlik <bpytlik@sun.com>
parents: 430
diff changeset
   432
                        try:
461b1c739de9 1753 An exception thrown during the teardown phase of the test program leaves pkg.depot running.
Brock Pytlik <bpytlik@sun.com>
parents: 430
diff changeset
   433
                                testMethod()
461b1c739de9 1753 An exception thrown during the teardown phase of the test program leaves pkg.depot running.
Brock Pytlik <bpytlik@sun.com>
parents: 430
diff changeset
   434
                                ok = True
461b1c739de9 1753 An exception thrown during the teardown phase of the test program leaves pkg.depot running.
Brock Pytlik <bpytlik@sun.com>
parents: 430
diff changeset
   435
                        except self.failureException:
502
3f98e94acc4a 2690 test suite depot starting/stopping
Brad Hall <bhall@eng.sun.com>
parents: 448
diff changeset
   436
                                result.addFailure(self, sys.exc_info())
435
461b1c739de9 1753 An exception thrown during the teardown phase of the test program leaves pkg.depot running.
Brock Pytlik <bpytlik@sun.com>
parents: 430
diff changeset
   437
                        except KeyboardInterrupt:
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   438
                                # Try hard to make sure we've done a teardown.
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   439
                                needtodie = True
435
461b1c739de9 1753 An exception thrown during the teardown phase of the test program leaves pkg.depot running.
Brock Pytlik <bpytlik@sun.com>
parents: 430
diff changeset
   440
                        except:
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   441
                                error_added = True
502
3f98e94acc4a 2690 test suite depot starting/stopping
Brad Hall <bhall@eng.sun.com>
parents: 448
diff changeset
   442
                                result.addError(self, sys.exc_info())
435
461b1c739de9 1753 An exception thrown during the teardown phase of the test program leaves pkg.depot running.
Brock Pytlik <bpytlik@sun.com>
parents: 430
diff changeset
   443
571
1a2452c33cb9 3476 Most cli test cases can't be run standalone anymore
Brad Hall <bhall@eng.sun.com>
parents: 516
diff changeset
   444
                        try:
1a2452c33cb9 3476 Most cli test cases can't be run standalone anymore
Brad Hall <bhall@eng.sun.com>
parents: 516
diff changeset
   445
                                self.tearDown()
1a2452c33cb9 3476 Most cli test cases can't be run standalone anymore
Brad Hall <bhall@eng.sun.com>
parents: 516
diff changeset
   446
                        except KeyboardInterrupt:
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   447
                                needtodie = True
571
1a2452c33cb9 3476 Most cli test cases can't be run standalone anymore
Brad Hall <bhall@eng.sun.com>
parents: 516
diff changeset
   448
                        except:
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   449
                                # Try hard to make sure we've done a teardown.
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   450
                                self.impl_tearDown()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   451
                                # Make sure we don't mark this error'd twice.
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   452
                                if not error_added:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   453
                                        result.addError(self, sys.exc_info())
571
1a2452c33cb9 3476 Most cli test cases can't be run standalone anymore
Brad Hall <bhall@eng.sun.com>
parents: 516
diff changeset
   454
                                ok = False
502
3f98e94acc4a 2690 test suite depot starting/stopping
Brad Hall <bhall@eng.sun.com>
parents: 448
diff changeset
   455
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   456
                        if needtodie:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   457
                                try:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   458
                                        self.impl_tearDown()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   459
                                except:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   460
                                        pass
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   461
                                raise TestStopException
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   462
436
5f150abbfba7 Shawn's feedback
Brock Pytlik <bpytlik@sun.com>
parents: 435
diff changeset
   463
                        if ok:
5f150abbfba7 Shawn's feedback
Brock Pytlik <bpytlik@sun.com>
parents: 435
diff changeset
   464
                                result.addSuccess(self)
435
461b1c739de9 1753 An exception thrown during the teardown phase of the test program leaves pkg.depot running.
Brock Pytlik <bpytlik@sun.com>
parents: 430
diff changeset
   465
                finally:
461b1c739de9 1753 An exception thrown during the teardown phase of the test program leaves pkg.depot running.
Brock Pytlik <bpytlik@sun.com>
parents: 430
diff changeset
   466
                        result.stopTest(self)
2073
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2047
diff changeset
   467
                        # make sure we restore our directory if it still exists.
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2047
diff changeset
   468
                        try:
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2047
diff changeset
   469
                                os.chdir(pwd)
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2047
diff changeset
   470
                        except OSError, e:
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2047
diff changeset
   471
                                # If directory doesn't exist anymore it doesn't
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2047
diff changeset
   472
                                # matter.
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2047
diff changeset
   473
                                if e.errno != errno.ENOENT:
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2047
diff changeset
   474
                                        raise
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   475
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   476
        #
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   477
        # The following are utility functions for use by testcases.
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   478
        #
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   479
        def c_compile(self, prog_text, opts, outputfile):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   480
                """Given a C program (as a string), compile it into the
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   481
                executable given by outputfile.  Outputfile should be
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   482
                given as a relative path, and will be located below the
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   483
                test prefix path.  Additional compiler options should be
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   484
                passed in 'opts'.  Suitable for compiling small test
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   485
                programs."""
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   486
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   487
                #
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   488
                # We use a series of likely compilers.  At present we support
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   489
                # this testing with SunStudio.
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   490
                #
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   491
                if os.path.dirname(outputfile) != "":
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   492
                        try:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   493
                                os.makedirs(os.path.dirname(outputfile))
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   494
                        except OSError, e:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   495
                                if e.errno != errno.EEXIST:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   496
                                        raise
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   497
                c_fd, c_path = tempfile.mkstemp(suffix=".c",
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   498
                    dir=self.test_root)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   499
                c_fh = os.fdopen(c_fd, "w")
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   500
                c_fh.write(prog_text)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   501
                c_fh.close()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   502
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   503
                found = False
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   504
                outpath = os.path.join(self.test_root, outputfile)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   505
                compilers = ["/usr/bin/cc", "cc", "$CC"]
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   506
                for compiler in compilers:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   507
                        cmd = [compiler, "-o", outpath]
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   508
                        cmd.extend(opts)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   509
                        cmd.append(c_path)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   510
                        try:
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
   511
                                # Make sure to use shell=True so that env.
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   512
                                # vars and $PATH are evaluated.
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   513
                                self.debugcmd(" ".join(cmd))
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   514
                                s = subprocess.Popen(" ".join(cmd),
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   515
                                    shell=True,
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   516
                                    stdout=subprocess.PIPE,
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   517
                                    stderr=subprocess.STDOUT)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   518
                                sout, serr = s.communicate()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   519
                                rc = s.returncode
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   520
                                if rc != 0 and rc != 127:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   521
                                        try: os.remove(outpath)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   522
                                        except OSError: pass
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   523
                                        try: os.remove(c_path)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   524
                                        except OSError: pass
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   525
                                        raise RuntimeError(
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   526
                                            "Compile failed: %s --> %d\n%s" % \
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   527
                                            (cmd, rc, sout))
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   528
                                if rc == 127:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   529
                                        self.debug("[%s not found]" % compiler)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   530
                                        continue
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   531
                                # so rc == 0
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   532
                                found = True
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   533
                                break
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   534
                        except OSError:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   535
                                continue
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   536
                try:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   537
                        os.remove(c_path)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   538
                except OSError:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   539
                        pass
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   540
                if not found:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   541
                        raise TestSkippedException(
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   542
                            "No suitable Sun Studio compiler found. "
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   543
                            "Tried: %s.  Try setting $CC to a valid"
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   544
                            "compiler." % compilers)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   545
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   546
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   547
        def make_misc_files(self, files, prefix=None, mode=0644):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   548
                """ Make miscellaneous text files.  Files can be a
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   549
                single relative pathname, a list of relative pathnames,
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   550
                or a hash mapping relative pathnames to specific contents.
1839
53bdcdd547cb 11023 DirectoryBundle emits bad paths if basedir has trailing /
Shawn Walker <shawn.walker@oracle.com>
parents: 1832
diff changeset
   551
                If file contents are not specified, the pathname of the
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   552
                file is placed into the file as default content. """
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   553
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   554
                outpaths = []
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   555
                #
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   556
                # If files is a string, make it a list.  Then, if it is
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   557
                # a list, simply turn it into a dict where each file's
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   558
                # contents is its own name, so that we get some uniqueness.
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   559
                #
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   560
                if isinstance(files, basestring):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   561
                        files = [files]
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   562
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   563
                if isinstance(files, list):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   564
                        nfiles = {}
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   565
                        for f in files:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   566
                                nfiles[f] = f
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   567
                        files = nfiles
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   568
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   569
                if prefix is None:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   570
                        prefix = self.test_root
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   571
                else:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   572
                        assert(not prefix.startswith(os.pathsep))
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   573
                        prefix = os.path.join(self.test_root, prefix)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   574
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   575
                for f, content in files.items():
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   576
                        assert not f.startswith("/"), \
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   577
                            ("%s: misc file paths must be relative!" % f)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   578
                        path = os.path.join(prefix, f)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   579
                        if not os.path.exists(os.path.dirname(path)):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   580
                                os.makedirs(os.path.dirname(path))
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   581
                        self.debugfilecreate(content, path)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   582
                        file_handle = open(path, 'wb')
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   583
                        if isinstance(content, unicode):
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
   584
                                content = content.encode("utf-8")
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   585
                        file_handle.write(content)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   586
                        file_handle.close()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   587
                        os.chmod(path, mode)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   588
                        outpaths.append(path)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   589
                return outpaths
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   590
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   591
        def make_manifest(self, content, manifest_dir="manifests"):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   592
                # Trim to ensure nice looking output.
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   593
                content = content.strip()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   594
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   595
                # Place inside of test prefix.
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   596
                manifest_dir = os.path.join(self.test_root,
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   597
                    manifest_dir)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   598
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   599
                if not os.path.exists(manifest_dir):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   600
                        os.makedirs(manifest_dir)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   601
                t_fd, t_path = tempfile.mkstemp(prefix="mfst.", dir=manifest_dir)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   602
                t_fh = os.fdopen(t_fd, "w")
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   603
                t_fh.write(content)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   604
                t_fh.close()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   605
                self.debugfilecreate(content, t_path)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   606
                return t_path
435
461b1c739de9 1753 An exception thrown during the teardown phase of the test program leaves pkg.depot running.
Brock Pytlik <bpytlik@sun.com>
parents: 430
diff changeset
   607
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1970
diff changeset
   608
        @staticmethod
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1970
diff changeset
   609
        def calc_file_hash(pth):
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1970
diff changeset
   610
                # Find the hash of the file.
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1970
diff changeset
   611
                fh = open(pth, "rb")
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1970
diff changeset
   612
                s = fh.read()
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1970
diff changeset
   613
                fh.close()
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1970
diff changeset
   614
                hsh = hashlib.sha1()
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1970
diff changeset
   615
                hsh.update(s)
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1970
diff changeset
   616
                return hsh.hexdigest()
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1970
diff changeset
   617
1730
c12580e62699 14347 Add tests to exercise the new -F tsv option for pkg publisher
Gary Pennington <gary.pennington@sun.com>
parents: 1715
diff changeset
   618
        def reduceSpaces(self, string):
c12580e62699 14347 Add tests to exercise the new -F tsv option for pkg publisher
Gary Pennington <gary.pennington@sun.com>
parents: 1715
diff changeset
   619
                """Reduce runs of spaces down to a single space."""
c12580e62699 14347 Add tests to exercise the new -F tsv option for pkg publisher
Gary Pennington <gary.pennington@sun.com>
parents: 1715
diff changeset
   620
                return re.sub(" +", " ", string)
1946
8ef3acf32d54 16132 various bits of pkg specify non-existent domains to gettext.install
Richard Lowe <richlowe@richlowe.net>
parents: 1908
diff changeset
   621
1730
c12580e62699 14347 Add tests to exercise the new -F tsv option for pkg publisher
Gary Pennington <gary.pennington@sun.com>
parents: 1715
diff changeset
   622
        def assertEqualDiff(self, expected, actual):
c12580e62699 14347 Add tests to exercise the new -F tsv option for pkg publisher
Gary Pennington <gary.pennington@sun.com>
parents: 1715
diff changeset
   623
                """Compare two strings."""
1859
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1839
diff changeset
   624
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1839
diff changeset
   625
                if not isinstance(expected, basestring):
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1839
diff changeset
   626
                        expected = pprint.pformat(expected)
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1839
diff changeset
   627
                if not isinstance(actual, basestring):
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1839
diff changeset
   628
                        actual = pprint.pformat(actual)
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1839
diff changeset
   629
1730
c12580e62699 14347 Add tests to exercise the new -F tsv option for pkg publisher
Gary Pennington <gary.pennington@sun.com>
parents: 1715
diff changeset
   630
                self.assertEqual(expected, actual,
c12580e62699 14347 Add tests to exercise the new -F tsv option for pkg publisher
Gary Pennington <gary.pennington@sun.com>
parents: 1715
diff changeset
   631
                    "Actual output differed from expected output.\n" +
c12580e62699 14347 Add tests to exercise the new -F tsv option for pkg publisher
Gary Pennington <gary.pennington@sun.com>
parents: 1715
diff changeset
   632
                    "\n".join(difflib.unified_diff(
c12580e62699 14347 Add tests to exercise the new -F tsv option for pkg publisher
Gary Pennington <gary.pennington@sun.com>
parents: 1715
diff changeset
   633
                        expected.splitlines(), actual.splitlines(),
c12580e62699 14347 Add tests to exercise the new -F tsv option for pkg publisher
Gary Pennington <gary.pennington@sun.com>
parents: 1715
diff changeset
   634
                        "Expected output", "Actual output", lineterm="")))
1946
8ef3acf32d54 16132 various bits of pkg specify non-existent domains to gettext.install
Richard Lowe <richlowe@richlowe.net>
parents: 1908
diff changeset
   635
2085
10a27146ebc2 16802 pkglint should check the value of info.classification in manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 2081
diff changeset
   636
        def configure_rcfile(self, rcfile, config, test_root, section="DEFAULT",
10a27146ebc2 16802 pkglint should check the value of info.classification in manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 2081
diff changeset
   637
            suffix=""):
10a27146ebc2 16802 pkglint should check the value of info.classification in manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 2081
diff changeset
   638
                """Reads the provided rcfile file, setting key/value
10a27146ebc2 16802 pkglint should check the value of info.classification in manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 2081
diff changeset
   639
                pairs in the provided section those from the 'config'
10a27146ebc2 16802 pkglint should check the value of info.classification in manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 2081
diff changeset
   640
                dictionary. The new config file is written to the supplied
10a27146ebc2 16802 pkglint should check the value of info.classification in manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 2081
diff changeset
   641
                test_root, returning the name of that new file.
10a27146ebc2 16802 pkglint should check the value of info.classification in manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 2081
diff changeset
   642
10a27146ebc2 16802 pkglint should check the value of info.classification in manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 2081
diff changeset
   643
                Used to set keys to point to paths beneath our test_root,
10a27146ebc2 16802 pkglint should check the value of info.classification in manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 2081
diff changeset
   644
                which would otherwise be shipped as hard-coded paths, relative
10a27146ebc2 16802 pkglint should check the value of info.classification in manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 2081
diff changeset
   645
                to /.
10a27146ebc2 16802 pkglint should check the value of info.classification in manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 2081
diff changeset
   646
                """
10a27146ebc2 16802 pkglint should check the value of info.classification in manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 2081
diff changeset
   647
10a27146ebc2 16802 pkglint should check the value of info.classification in manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 2081
diff changeset
   648
                new_rcfile = file("%s/%s%s" % (test_root, os.path.basename(rcfile),
10a27146ebc2 16802 pkglint should check the value of info.classification in manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 2081
diff changeset
   649
                    suffix), "w")
10a27146ebc2 16802 pkglint should check the value of info.classification in manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 2081
diff changeset
   650
10a27146ebc2 16802 pkglint should check the value of info.classification in manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 2081
diff changeset
   651
                conf = ConfigParser.SafeConfigParser()
10a27146ebc2 16802 pkglint should check the value of info.classification in manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 2081
diff changeset
   652
                conf.readfp(open(rcfile))
10a27146ebc2 16802 pkglint should check the value of info.classification in manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 2081
diff changeset
   653
10a27146ebc2 16802 pkglint should check the value of info.classification in manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 2081
diff changeset
   654
                for key in config:
10a27146ebc2 16802 pkglint should check the value of info.classification in manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 2081
diff changeset
   655
                        conf.set(section, key, config[key])
10a27146ebc2 16802 pkglint should check the value of info.classification in manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 2081
diff changeset
   656
10a27146ebc2 16802 pkglint should check the value of info.classification in manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 2081
diff changeset
   657
                conf.write(new_rcfile)
10a27146ebc2 16802 pkglint should check the value of info.classification in manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 2081
diff changeset
   658
                return new_rcfile.name
10a27146ebc2 16802 pkglint should check the value of info.classification in manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 2081
diff changeset
   659
1730
c12580e62699 14347 Add tests to exercise the new -F tsv option for pkg publisher
Gary Pennington <gary.pennington@sun.com>
parents: 1715
diff changeset
   660
430
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
   661
class _Pkg5TestResult(unittest._TextTestResult):
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
   662
        baseline = None
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
   663
        machsep = "|"
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   664
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   665
        def __init__(self, stream, output, baseline, bailonfail=False,
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   666
            show_on_expected_fail=False, archive_dir=None):
430
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
   667
                unittest.TestResult.__init__(self)
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
   668
                self.stream = stream
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
   669
                self.output = output
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
   670
                self.baseline = baseline
448
bcfa99ac18b0 2664 test suite baseline enhancements
Brad Hall <bhall@eng.sun.com>
parents: 436
diff changeset
   671
                self.success = []
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   672
                self.mismatches = []
1421
d6733f41c267 3961 Test suite should have a flag that makes it stop after encountering a failure
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents: 1101
diff changeset
   673
                self.bailonfail = bailonfail
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   674
                self.show_on_expected_fail = show_on_expected_fail
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   675
                self.archive_dir = archive_dir
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   676
2073
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2047
diff changeset
   677
        def getDescription(self, test):
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2047
diff changeset
   678
                return str(test)
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   679
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   680
        # Override the unittest version of this so that success is
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   681
        # considered "matching the baseline"
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   682
        def wasSuccessful(self):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   683
                return len(self.mismatches) == 0
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   684
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   685
        def dobailout(self, test):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   686
                """ Pull the ejection lever.  Stop execution, doing as
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   687
                much forcible cleanup as possible. """
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   688
                inst, tdf = test.getTeardownFunc()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   689
                try:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   690
                        tdf()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   691
                except Exception, e:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   692
                        print >> sys.stderr, str(e)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   693
                        pass
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   694
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   695
                if getattr(test, "persistent_setup", None):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   696
                        try:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   697
                                test.reallytearDown()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   698
                        except Exception, e:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   699
                                print >> sys.stderr, str(e)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   700
                                pass
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   701
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   702
                if hasattr(inst, "killalldepots"):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   703
                        try:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   704
                                inst.killalldepots()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   705
                        except Exception, e:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   706
                                print >> sys.stderr, str(e)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   707
                                pass
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   708
                raise TestStopException()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   709
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   710
        def fmt_parseable(self, match, actual, expected):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   711
                if match == baseline.BASELINE_MATCH:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   712
                        mstr = "MATCH"
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   713
                else:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   714
                        mstr = "MISMATCH"
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   715
                return "%s|%s|%s" % (mstr, actual, expected)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   716
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   717
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   718
        @staticmethod
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   719
        def fmt_prefix_with(instr, prefix):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   720
                res = ""
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   721
                for s in instr.splitlines():
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   722
                        res += "%s%s\n" % (prefix, s)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   723
                return res
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   724
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   725
        @staticmethod
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   726
        def fmt_box(instr, title, prefix=""):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   727
                trailingdashes = (50 - len(title)) * "-"
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   728
                res = "\n.---" + title + trailingdashes + "\n"
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   729
                for s in instr.splitlines():
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   730
                        if s.strip() == "":
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   731
                                continue
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   732
                        res += "| %s\n" % s
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   733
                res += "`---" + len(title) * "-" + trailingdashes
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   734
                return _Pkg5TestResult.fmt_prefix_with(res, prefix)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   735
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   736
        def do_archive(self, test, info):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   737
                assert self.archive_dir
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   738
                if not os.path.exists(self.archive_dir):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   739
                        os.makedirs(self.archive_dir, mode=0755)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   740
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   741
                archive_path = os.path.join(self.archive_dir,
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   742
                    "%d" % os.getpid())
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   743
                if not os.path.exists(archive_path):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   744
                        os.makedirs(archive_path, mode=0755)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   745
                archive_path = os.path.join(archive_path, test.id())
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   746
                if g_debug_output:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   747
                        self.stream.writeln("# Archiving to %s" % archive_path)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   748
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   749
                if os.path.exists(test.test_root):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   750
                        shutil.copytree(test.test_root, archive_path,
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   751
                            symlinks=True)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   752
                else:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   753
                        # If the test has failed without creating its directory,
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   754
                        # make it manually, so that we have a place to write out
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   755
                        # ERROR_INFO.
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   756
                        os.makedirs(archive_path, mode=0755)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   757
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   758
                f = open(os.path.join(archive_path, "ERROR_INFO"), "w")
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   759
                f.write("------------------DEBUG LOG---------------\n")
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   760
                f.write(test.get_debugbuf())
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   761
                if info is not None:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   762
                        f.write("\n\n------------------EXCEPTION---------------\n")
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   763
                        f.write(info)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   764
                f.close()
448
bcfa99ac18b0 2664 test suite baseline enhancements
Brad Hall <bhall@eng.sun.com>
parents: 436
diff changeset
   765
430
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
   766
        def addSuccess(self, test):
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
   767
                unittest.TestResult.addSuccess(self, test)
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   768
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   769
                # If we're debugging, we'll have had output since we
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   770
                # announced the name of the test, so restate it.
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   771
                if g_debug_output:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   772
                        self.statename(test)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   773
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   774
                errinfo = self.format_output_and_exc(test, None)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   775
430
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
   776
                bresult = self.baseline.handleresult(str(test), "pass")
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   777
                expected = self.baseline.expectedresult(str(test))
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   778
                if self.output == OUTPUT_PARSEABLE:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   779
                        res = self.fmt_parseable(bresult, "pass", expected)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   780
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   781
                elif self.output == OUTPUT_VERBOSE:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   782
                        if bresult == baseline.BASELINE_MATCH:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   783
                                res = "match pass"
430
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
   784
                        else:
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   785
                                res = "MISMATCH pass (expected: %s)" % \
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   786
                                    expected
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   787
                                res = self.fmt_box(errinfo,
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   788
                                    "Successful Test", "# ")
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   789
                else:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   790
                        assert self.output == OUTPUT_DOTS
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   791
                        res = "."
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   792
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   793
                if self.output != OUTPUT_DOTS:
430
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
   794
                        self.stream.writeln(res)
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   795
                else:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   796
                        self.stream.write(res)
448
bcfa99ac18b0 2664 test suite baseline enhancements
Brad Hall <bhall@eng.sun.com>
parents: 436
diff changeset
   797
                self.success.append(test)
430
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
   798
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   799
                if bresult == baseline.BASELINE_MISMATCH:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   800
                        self.mismatches.append(test)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   801
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   802
                if bresult == baseline.BASELINE_MISMATCH and self.archive_dir:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   803
                        self.do_archive(test, None)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   804
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   805
                # Bail out completely if the 'bail on fail' flag is set
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   806
                # but iff the result disagrees with the baseline.
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   807
                if self.bailonfail and bresult == baseline.BASELINE_MISMATCH:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   808
                        self.dobailout(test)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   809
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   810
430
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
   811
        def addError(self, test, err):
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   812
                errtype, errval = err[:2]
2073
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2047
diff changeset
   813
                # for a few special exceptions, we delete the traceback so
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2047
diff changeset
   814
                # as to elide it.  use only when the traceback itself
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2047
diff changeset
   815
                # is not likely to be useful.
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2047
diff changeset
   816
                if errtype in ELIDABLE_ERRORS:
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2047
diff changeset
   817
                        unittest.TestResult.addError(self, test,
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2047
diff changeset
   818
                            (err[0], err[1], None))
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2047
diff changeset
   819
                else:
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2047
diff changeset
   820
                        unittest.TestResult.addError(self, test, err)
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   821
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   822
                # If we're debugging, we'll have had output since we
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   823
                # announced the name of the test, so restate it.
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   824
                if g_debug_output:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   825
                        self.statename(test)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   826
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   827
                errinfo = self.format_output_and_exc(test, err)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   828
1002
56ab3be9a8b7 3488 Test suite should supress expected failures (or notate them more clearly)
Danek Duvall <danek.duvall@sun.com>
parents: 683
diff changeset
   829
                bresult = self.baseline.handleresult(str(test), "error")
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   830
                expected = self.baseline.expectedresult(str(test))
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   831
                if self.output == OUTPUT_PARSEABLE:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   832
                        if errtype in ELIDABLE_ERRORS:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   833
                                res = self.fmt_parseable(bresult, "ERROR", expected)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   834
                                res += "\n# %s\n" % str(errval).strip()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   835
                        else:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   836
                                res = self.fmt_parseable(bresult, "ERROR", expected)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   837
                                res += "\n"
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   838
                                if bresult == baseline.BASELINE_MISMATCH \
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   839
                                   or self.show_on_expected_fail:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   840
                                        res += self.fmt_prefix_with(errinfo, "# ")
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   841
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   842
                elif self.output == OUTPUT_VERBOSE:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   843
                        if bresult == baseline.BASELINE_MATCH:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   844
                                b = "match"
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   845
                        else:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   846
                                b = "MISMATCH"
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   847
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   848
                        if errtype in ELIDABLE_ERRORS:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   849
                                res = "%s ERROR\n" % b
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   850
                                res += "#\t%s" % str(errval)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   851
                        else:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   852
                                res = "%s ERROR\n" % b
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   853
                                if bresult == baseline.BASELINE_MISMATCH \
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   854
                                   or self.show_on_expected_fail:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   855
                                        res += self.fmt_box(errinfo,
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   856
                                            "Error Information", "# ")
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   857
430
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
   858
                elif self.output == OUTPUT_DOTS:
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   859
                        if bresult == baseline.BASELINE_MATCH:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   860
                                res = "e"
1002
56ab3be9a8b7 3488 Test suite should supress expected failures (or notate them more clearly)
Danek Duvall <danek.duvall@sun.com>
parents: 683
diff changeset
   861
                        else:
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   862
                                res = "E"
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   863
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   864
                if self.output == OUTPUT_DOTS:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   865
                        self.stream.write(res)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   866
                else:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   867
                        self.stream.writeln(res)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   868
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   869
                if bresult == baseline.BASELINE_MISMATCH:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   870
                        self.mismatches.append(test)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   871
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   872
                # Check to see if we should archive this baseline mismatch.
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   873
                if bresult == baseline.BASELINE_MISMATCH and self.archive_dir:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   874
                        self.do_archive(test, self._exc_info_to_string(err, test))
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   875
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   876
                # Bail out completely if the 'bail on fail' flag is set
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   877
                # but iff the result disagrees with the baseline.
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   878
                if self.bailonfail and bresult == baseline.BASELINE_MISMATCH:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   879
                        self.dobailout(test)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   880
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   881
        def format_output_and_exc(self, test, error):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   882
                res = ""
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   883
                dbgbuf = test.get_debugbuf()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   884
                if dbgbuf != "":
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   885
                        res += dbgbuf
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   886
                if error is not None:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   887
                        res += self._exc_info_to_string(error, test)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   888
                return res
430
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
   889
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
   890
        def addFailure(self, test, err):
2073
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2047
diff changeset
   891
                unittest.TestResult.addFailure(self, test, err)
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   892
430
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
   893
                bresult = self.baseline.handleresult(str(test), "fail")
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   894
                expected = self.baseline.expectedresult(str(test))
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   895
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   896
                # If we're debugging, we'll have had output since we
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   897
                # announced the name of the test, so restate it.
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   898
                if g_debug_output:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   899
                        self.statename(test)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   900
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   901
                errinfo = self.format_output_and_exc(test, err)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   902
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   903
                if self.output == OUTPUT_PARSEABLE:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   904
                        res = self.fmt_parseable(bresult, "FAIL", expected)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   905
                        res += "\n"
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   906
                        if bresult == baseline.BASELINE_MISMATCH \
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   907
                           or self.show_on_expected_fail:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   908
                                res += self.fmt_prefix_with(errinfo, "# ")
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   909
                elif self.output == OUTPUT_VERBOSE:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   910
                        if bresult == baseline.BASELINE_MISMATCH:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   911
                                res = "MISMATCH FAIL (expected: %s)" % expected
430
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
   912
                        else:
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   913
                                res = "match FAIL (expected: FAIL)"
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   914
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   915
                        if bresult == baseline.BASELINE_MISMATCH \
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   916
                           or self.show_on_expected_fail:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   917
                                res += self.fmt_box(errinfo,
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   918
                                    "Failure Information", "# ")
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   919
430
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
   920
                elif self.output == OUTPUT_DOTS:
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   921
                        if bresult == baseline.BASELINE_MATCH:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   922
                                res = "f"
1002
56ab3be9a8b7 3488 Test suite should supress expected failures (or notate them more clearly)
Danek Duvall <danek.duvall@sun.com>
parents: 683
diff changeset
   923
                        else:
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   924
                                res = "F"
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   925
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   926
                if self.output == OUTPUT_DOTS:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   927
                        self.stream.write(res)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   928
                else:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   929
                        self.stream.writeln(res)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   930
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   931
                if bresult == baseline.BASELINE_MISMATCH:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   932
                        self.mismatches.append(test)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   933
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   934
                # Check to see if we should archive this baseline mismatch.
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   935
                if bresult == baseline.BASELINE_MISMATCH and self.archive_dir:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   936
                        self.do_archive(test, self._exc_info_to_string(err, test))
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   937
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   938
                # Bail out completely if the 'bail on fail' flag is set
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   939
                # but iff the result disagrees with the baseline.
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   940
                if self.bailonfail and bresult == baseline.BASELINE_MISMATCH:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   941
                        self.dobailout(test)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   942
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   943
        def addPersistentSetupError(self, test, err):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   944
                errtype, errval = err[:2]
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   945
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   946
                errinfo = self.format_output_and_exc(test, err)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   947
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   948
                res = "# ERROR during persistent setup for %s\n" % test.id()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   949
                res += "# As a result, all test cases in this class will " \
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   950
                    "result in errors."
430
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
   951
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   952
                if errtype in ELIDABLE_ERRORS:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   953
                        res += "#   " + str(errval)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   954
                else:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   955
                        res += self.fmt_box(errinfo, \
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   956
                            "Persistent Setup Error Information", "# ")
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   957
                self.stream.writeln(res)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   958
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   959
        def addPersistentTeardownError(self, test, err):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   960
                errtype, errval = err[:2]
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   961
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   962
                errinfo = self.format_output_and_exc(test, err)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   963
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   964
                res = "# ERROR during persistent teardown for %s\n" % test.id()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   965
                if errtype in ELIDABLE_ERRORS:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   966
                        res += "#   " + str(errval)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   967
                else:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   968
                        res += self.fmt_box(errinfo, \
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   969
                            "Persistent Teardown Error Information", "# ")
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   970
                self.stream.writeln(res)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   971
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   972
        def statename(self, test, prefix=""):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   973
                name = self.getDescription(test)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   974
                if self.output == OUTPUT_VERBOSE:
2073
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2047
diff changeset
   975
                        name = name.ljust(65) + "  "
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   976
                elif self.output == OUTPUT_PARSEABLE:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   977
                        name += "|"
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   978
                elif self.output == OUTPUT_DOTS:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   979
                        return
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   980
                self.stream.write(name)
430
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
   981
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
   982
        def startTest(self, test):
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
   983
                unittest.TestResult.startTest(self, test)
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   984
                test.debug("_" * 75)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   985
                test.debug("Start:   %s" % \
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   986
                    self.getDescription(test))
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   987
                if test._testMethodDoc is not None:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   988
                        docs = ["  " + x.strip() \
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   989
                            for x in test._testMethodDoc.splitlines()]
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   990
                        while len(docs) > 0 and docs[-1] == "":
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   991
                                del docs[-1]
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   992
                        for x in docs:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   993
                                test.debug(x)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   994
                test.debug("_" * 75)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   995
                test.debug("")
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   996
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   997
                if not g_debug_output:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
   998
                        self.statename(test)
430
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
   999
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
  1000
        def printErrors(self):
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
  1001
                self.stream.writeln()
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
  1002
                self.printErrorList('ERROR', self.errors)
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
  1003
                self.printErrorList('FAIL', self.failures)
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
  1004
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
  1005
        def printErrorList(self, flavour, errors):
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
  1006
                for test, err in errors:
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
  1007
                        self.stream.writeln(self.separator1)
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
  1008
                        self.stream.writeln("%s: %s" %
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
  1009
                            (flavour, self.getDescription(test)))
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
  1010
                        self.stream.writeln(self.separator2)
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
  1011
                        self.stream.writeln("%s" % err)
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
  1012
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
  1013
class Pkg5TestRunner(unittest.TextTestRunner):
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
  1014
        """TestRunner for test suites that we want to be able to compare
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
  1015
        against a result baseline."""
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
  1016
        baseline = None
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
  1017
1101
35f360e2ee19 5247 Test suite should provide timing info
Brock Pytlik <bpytlik@sun.com>
parents: 1002
diff changeset
  1018
        def __init__(self, baseline, stream=sys.stderr, output=OUTPUT_DOTS,
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1019
            timing_file=None, bailonfail=False, coverage=None,
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1020
            show_on_expected_fail=False, archive_dir=None):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1021
                """Set up the test runner"""
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1022
                # output is one of OUTPUT_DOTS, OUTPUT_VERBOSE, OUTPUT_PARSEABLE
430
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
  1023
                super(Pkg5TestRunner, self).__init__(stream)
448
bcfa99ac18b0 2664 test suite baseline enhancements
Brad Hall <bhall@eng.sun.com>
parents: 436
diff changeset
  1024
                self.baseline = baseline
430
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
  1025
                self.output = output
1101
35f360e2ee19 5247 Test suite should provide timing info
Brock Pytlik <bpytlik@sun.com>
parents: 1002
diff changeset
  1026
                self.timing_file = timing_file
1421
d6733f41c267 3961 Test suite should have a flag that makes it stop after encountering a failure
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents: 1101
diff changeset
  1027
                self.bailonfail = bailonfail
1513
3ece69a26155 5032 make coverage should only report on the files in our gate
Danek Duvall <danek.duvall@sun.com>
parents: 1505
diff changeset
  1028
                self.coverage = coverage
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1029
                self.show_on_expected_fail = show_on_expected_fail
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1030
                self.archive_dir = archive_dir
430
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
  1031
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
  1032
        def _makeResult(self):
1421
d6733f41c267 3961 Test suite should have a flag that makes it stop after encountering a failure
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents: 1101
diff changeset
  1033
                return _Pkg5TestResult(self.stream, self.output, self.baseline,
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1034
                    bailonfail=self.bailonfail,
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1035
                    show_on_expected_fail=self.show_on_expected_fail,
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1036
                    archive_dir=self.archive_dir)
430
3fb945d3bff3 2627 Test suite should have support for baselining
Brad Hall <bhall@eng.sun.com>
parents:
diff changeset
  1037
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1038
        @staticmethod
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1039
        def __write_timing_info(stream, suite_name, class_list, method_list):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1040
                if not class_list and not method_list:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1041
                        return
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1042
                tot = 0
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1043
                print >> stream, "Tests run for '%s' Suite, " \
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1044
                    "broken down by class:\n" % suite_name
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1045
                for secs, cname in class_list:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1046
                        print >> stream, "%6.2f %s.%s" % (secs, suite_name, cname)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1047
                        tot += secs
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1048
                        for secs, mcname, mname in method_list:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1049
                                if mcname != cname:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1050
                                        continue
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1051
                                print >> stream, \
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1052
                                    "    %6.2f %s" % (secs, mname)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1053
                        print >> stream
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1054
                print >> stream, "%6.2f Total time\n" % tot
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1055
                print >> stream, "=" * 60
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1056
                print >> stream, "\nTests run for '%s' Suite, " \
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1057
                    "sorted by time taken:\n" % suite_name
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1058
                for secs, cname, mname in method_list:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1059
                        print >> stream, "%6.2f %s %s" % (secs, cname, mname)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1060
                print >> stream, "%6.2f Total time\n" % tot
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1061
                print >> stream, "=" * 60
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1062
                print >> stream, ""
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1063
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1064
        def _do_timings(self, test):
1101
35f360e2ee19 5247 Test suite should provide timing info
Brock Pytlik <bpytlik@sun.com>
parents: 1002
diff changeset
  1065
                timing = {}
35f360e2ee19 5247 Test suite should provide timing info
Brock Pytlik <bpytlik@sun.com>
parents: 1002
diff changeset
  1066
                lst = []
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1067
                suite_name = None
1101
35f360e2ee19 5247 Test suite should provide timing info
Brock Pytlik <bpytlik@sun.com>
parents: 1002
diff changeset
  1068
                for t in test._tests:
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1069
                        for (sname, cname, mname), secs in t.timing.items():
1101
35f360e2ee19 5247 Test suite should provide timing info
Brock Pytlik <bpytlik@sun.com>
parents: 1002
diff changeset
  1070
                                lst.append((secs, cname, mname))
35f360e2ee19 5247 Test suite should provide timing info
Brock Pytlik <bpytlik@sun.com>
parents: 1002
diff changeset
  1071
                                if cname not in timing:
35f360e2ee19 5247 Test suite should provide timing info
Brock Pytlik <bpytlik@sun.com>
parents: 1002
diff changeset
  1072
                                        timing[cname] = 0
35f360e2ee19 5247 Test suite should provide timing info
Brock Pytlik <bpytlik@sun.com>
parents: 1002
diff changeset
  1073
                                timing[cname] += secs
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1074
                                suite_name = sname
1101
35f360e2ee19 5247 Test suite should provide timing info
Brock Pytlik <bpytlik@sun.com>
parents: 1002
diff changeset
  1075
                lst.sort()
35f360e2ee19 5247 Test suite should provide timing info
Brock Pytlik <bpytlik@sun.com>
parents: 1002
diff changeset
  1076
                clst = sorted((secs, cname) for cname, secs in timing.items())
35f360e2ee19 5247 Test suite should provide timing info
Brock Pytlik <bpytlik@sun.com>
parents: 1002
diff changeset
  1077
35f360e2ee19 5247 Test suite should provide timing info
Brock Pytlik <bpytlik@sun.com>
parents: 1002
diff changeset
  1078
                if self.timing_file:
35f360e2ee19 5247 Test suite should provide timing info
Brock Pytlik <bpytlik@sun.com>
parents: 1002
diff changeset
  1079
                        try:
35f360e2ee19 5247 Test suite should provide timing info
Brock Pytlik <bpytlik@sun.com>
parents: 1002
diff changeset
  1080
                                fh = open(self.timing_file, "ab+")
35f360e2ee19 5247 Test suite should provide timing info
Brock Pytlik <bpytlik@sun.com>
parents: 1002
diff changeset
  1081
                                opened = True
35f360e2ee19 5247 Test suite should provide timing info
Brock Pytlik <bpytlik@sun.com>
parents: 1002
diff changeset
  1082
                        except KeyboardInterrupt:
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1083
                                raise TestStopException()
1101
35f360e2ee19 5247 Test suite should provide timing info
Brock Pytlik <bpytlik@sun.com>
parents: 1002
diff changeset
  1084
                        except Exception:
35f360e2ee19 5247 Test suite should provide timing info
Brock Pytlik <bpytlik@sun.com>
parents: 1002
diff changeset
  1085
                                fh = sys.stderr
35f360e2ee19 5247 Test suite should provide timing info
Brock Pytlik <bpytlik@sun.com>
parents: 1002
diff changeset
  1086
                                opened = False
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1087
                        self.__write_timing_info(fh, suite_name, clst, lst)
1101
35f360e2ee19 5247 Test suite should provide timing info
Brock Pytlik <bpytlik@sun.com>
parents: 1002
diff changeset
  1088
                        if opened:
35f360e2ee19 5247 Test suite should provide timing info
Brock Pytlik <bpytlik@sun.com>
parents: 1002
diff changeset
  1089
                                fh.close()
35f360e2ee19 5247 Test suite should provide timing info
Brock Pytlik <bpytlik@sun.com>
parents: 1002
diff changeset
  1090
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1091
        def run(self, test):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1092
                "Run the given test case or test suite."
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1093
                result = self._makeResult()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1094
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1095
                startTime = time.time()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1096
                result.coverage = self.coverage
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1097
                try:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1098
                        test.run(result)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1099
                finally:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1100
                        stopTime = time.time()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1101
                        timeTaken = stopTime - startTime
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1102
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1103
                        run = result.testsRun
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1104
                        if run > 0:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1105
                                if self.output != OUTPUT_VERBOSE:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1106
                                        result.printErrors()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1107
                                        self.stream.writeln("# " + result.separator2)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1108
                                self.stream.writeln("\n# Ran %d test%s in %.3fs" %
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1109
                                    (run, run != 1 and "s" or "", timeTaken))
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1110
                                self.stream.writeln()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1111
                        if not result.wasSuccessful():
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1112
                                self.stream.write("FAILED (")
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1113
                                success, failed, errored, mismatches = map(len,
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1114
                                    (result.success, result.failures, result.errors,
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1115
                                        result.mismatches))
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1116
                                self.stream.write("successes=%d, " % success)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1117
                                self.stream.write("failures=%d, " % failed)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1118
                                self.stream.write("errors=%d, " % errored)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1119
                                self.stream.write("mismatches=%d" % mismatches)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1120
                                self.stream.writeln(")")
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1121
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1122
                        self._do_timings(test)
448
bcfa99ac18b0 2664 test suite baseline enhancements
Brad Hall <bhall@eng.sun.com>
parents: 436
diff changeset
  1123
                return result
502
3f98e94acc4a 2690 test suite depot starting/stopping
Brad Hall <bhall@eng.sun.com>
parents: 448
diff changeset
  1124
1101
35f360e2ee19 5247 Test suite should provide timing info
Brock Pytlik <bpytlik@sun.com>
parents: 1002
diff changeset
  1125
502
3f98e94acc4a 2690 test suite depot starting/stopping
Brad Hall <bhall@eng.sun.com>
parents: 448
diff changeset
  1126
class Pkg5TestSuite(unittest.TestSuite):
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1127
        """Test suite that extends unittest.TestSuite to handle persistent
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1128
        tests.  Persistent tests are ones that are able to only call their
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1129
        setUp/tearDown functions once per class, instead of before and after
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1130
        every test case.  Aside from actually running the test it defers the
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1131
        majority of its work to unittest.TestSuite.
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1132
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1133
        To make a test class into a persistent one, add this class
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1134
        variable declaration:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1135
                persistent_setup = True
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1136
        """
502
3f98e94acc4a 2690 test suite depot starting/stopping
Brad Hall <bhall@eng.sun.com>
parents: 448
diff changeset
  1137
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1138
        def __init__(self, tests=()):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1139
                unittest.TestSuite.__init__(self, tests)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1140
                self.timing = {}
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1141
1890
011afb71c52a 15037 action parsing can't handle unicode objects which don't decode to ascii
Shawn Walker <shawn.walker@oracle.com>
parents: 1887
diff changeset
  1142
                # The site module deletes the function to change the
011afb71c52a 15037 action parsing can't handle unicode objects which don't decode to ascii
Shawn Walker <shawn.walker@oracle.com>
parents: 1887
diff changeset
  1143
                # default encoding so a forced reload of sys has to
011afb71c52a 15037 action parsing can't handle unicode objects which don't decode to ascii
Shawn Walker <shawn.walker@oracle.com>
parents: 1887
diff changeset
  1144
                # be done at least once.
011afb71c52a 15037 action parsing can't handle unicode objects which don't decode to ascii
Shawn Walker <shawn.walker@oracle.com>
parents: 1887
diff changeset
  1145
                reload(sys)
011afb71c52a 15037 action parsing can't handle unicode objects which don't decode to ascii
Shawn Walker <shawn.walker@oracle.com>
parents: 1887
diff changeset
  1146
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1147
        def cleanup_and_die(self, inst, info):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1148
                print >> sys.stderr, \
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1149
                    "\nCtrl-C: Attempting cleanup during %s" % info
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1150
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1151
                if hasattr(inst, "killalldepots"):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1152
                        print >> sys.stderr, "Killing depots..."
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1153
                        inst.killalldepots()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1154
                print >> sys.stderr, "Stopping tests..."
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1155
                raise TestStopException()
502
3f98e94acc4a 2690 test suite depot starting/stopping
Brad Hall <bhall@eng.sun.com>
parents: 448
diff changeset
  1156
3f98e94acc4a 2690 test suite depot starting/stopping
Brad Hall <bhall@eng.sun.com>
parents: 448
diff changeset
  1157
        def run(self, result):
1101
35f360e2ee19 5247 Test suite should provide timing info
Brock Pytlik <bpytlik@sun.com>
parents: 1002
diff changeset
  1158
                self.timing = {}
502
3f98e94acc4a 2690 test suite depot starting/stopping
Brad Hall <bhall@eng.sun.com>
parents: 448
diff changeset
  1159
                inst = None
3f98e94acc4a 2690 test suite depot starting/stopping
Brad Hall <bhall@eng.sun.com>
parents: 448
diff changeset
  1160
                tdf = None
571
1a2452c33cb9 3476 Most cli test cases can't be run standalone anymore
Brad Hall <bhall@eng.sun.com>
parents: 516
diff changeset
  1161
                try:
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1162
                        persistent_setup = getattr(self._tests[0],
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1163
                            "persistent_setup", False)
571
1a2452c33cb9 3476 Most cli test cases can't be run standalone anymore
Brad Hall <bhall@eng.sun.com>
parents: 516
diff changeset
  1164
                except IndexError:
1890
011afb71c52a 15037 action parsing can't handle unicode objects which don't decode to ascii
Shawn Walker <shawn.walker@oracle.com>
parents: 1887
diff changeset
  1165
                        # No tests; that's ok.
571
1a2452c33cb9 3476 Most cli test cases can't be run standalone anymore
Brad Hall <bhall@eng.sun.com>
parents: 516
diff changeset
  1166
                        return
1a2452c33cb9 3476 Most cli test cases can't be run standalone anymore
Brad Hall <bhall@eng.sun.com>
parents: 516
diff changeset
  1167
1890
011afb71c52a 15037 action parsing can't handle unicode objects which don't decode to ascii
Shawn Walker <shawn.walker@oracle.com>
parents: 1887
diff changeset
  1168
                # This is needed because the import of some modules (such as
011afb71c52a 15037 action parsing can't handle unicode objects which don't decode to ascii
Shawn Walker <shawn.walker@oracle.com>
parents: 1887
diff changeset
  1169
                # pygtk or pango) causes the default encoding for Python to be
011afb71c52a 15037 action parsing can't handle unicode objects which don't decode to ascii
Shawn Walker <shawn.walker@oracle.com>
parents: 1887
diff changeset
  1170
                # changed which can can cause tests to succeed when they should
011afb71c52a 15037 action parsing can't handle unicode objects which don't decode to ascii
Shawn Walker <shawn.walker@oracle.com>
parents: 1887
diff changeset
  1171
                # fail due to unicode issues:
011afb71c52a 15037 action parsing can't handle unicode objects which don't decode to ascii
Shawn Walker <shawn.walker@oracle.com>
parents: 1887
diff changeset
  1172
                #     https://bugzilla.gnome.org/show_bug.cgi?id=132040
011afb71c52a 15037 action parsing can't handle unicode objects which don't decode to ascii
Shawn Walker <shawn.walker@oracle.com>
parents: 1887
diff changeset
  1173
                default_utf8 = getattr(self._tests[0], "default_utf8", False)
011afb71c52a 15037 action parsing can't handle unicode objects which don't decode to ascii
Shawn Walker <shawn.walker@oracle.com>
parents: 1887
diff changeset
  1174
                if not default_utf8:
011afb71c52a 15037 action parsing can't handle unicode objects which don't decode to ascii
Shawn Walker <shawn.walker@oracle.com>
parents: 1887
diff changeset
  1175
                        # Now reset to the default a standard Python
011afb71c52a 15037 action parsing can't handle unicode objects which don't decode to ascii
Shawn Walker <shawn.walker@oracle.com>
parents: 1887
diff changeset
  1176
                        # distribution uses.
011afb71c52a 15037 action parsing can't handle unicode objects which don't decode to ascii
Shawn Walker <shawn.walker@oracle.com>
parents: 1887
diff changeset
  1177
                        sys.setdefaultencoding("ascii")
011afb71c52a 15037 action parsing can't handle unicode objects which don't decode to ascii
Shawn Walker <shawn.walker@oracle.com>
parents: 1887
diff changeset
  1178
                else:
011afb71c52a 15037 action parsing can't handle unicode objects which don't decode to ascii
Shawn Walker <shawn.walker@oracle.com>
parents: 1887
diff changeset
  1179
                        sys.setdefaultencoding("utf-8")
011afb71c52a 15037 action parsing can't handle unicode objects which don't decode to ascii
Shawn Walker <shawn.walker@oracle.com>
parents: 1887
diff changeset
  1180
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1181
                def setUp_donothing():
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1182
                        pass
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1183
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1184
                def tearDown_donothing():
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1185
                        pass
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1186
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1187
                def setUp_dofail():
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1188
                        raise TestSkippedException(
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1189
                            "Persistent setUp Failed, skipping test.")
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1190
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1191
                if persistent_setup:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1192
                        setUpFailed = False
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1193
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1194
                        # Save a reference to the tearDown func and neuter
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1195
                        # normal per-test-function teardown.
502
3f98e94acc4a 2690 test suite depot starting/stopping
Brad Hall <bhall@eng.sun.com>
parents: 448
diff changeset
  1196
                        inst, tdf = self._tests[0].getTeardownFunc()
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1197
                        inst.reallytearDown = tdf
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1198
                        inst.tearDown = tearDown_donothing
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1199
1513
3ece69a26155 5032 make coverage should only report on the files in our gate
Danek Duvall <danek.duvall@sun.com>
parents: 1505
diff changeset
  1200
                        if result.coverage:
3ece69a26155 5032 make coverage should only report on the files in our gate
Danek Duvall <danek.duvall@sun.com>
parents: 1505
diff changeset
  1201
                                inst.coverage_cmd, inst.coverage_env = result.coverage
3ece69a26155 5032 make coverage should only report on the files in our gate
Danek Duvall <danek.duvall@sun.com>
parents: 1505
diff changeset
  1202
                        else:
3ece69a26155 5032 make coverage should only report on the files in our gate
Danek Duvall <danek.duvall@sun.com>
parents: 1505
diff changeset
  1203
                                inst.coverage_cmd, inst.coverage_env = "", {}
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1204
502
3f98e94acc4a 2690 test suite depot starting/stopping
Brad Hall <bhall@eng.sun.com>
parents: 448
diff changeset
  1205
                        try:
3f98e94acc4a 2690 test suite depot starting/stopping
Brad Hall <bhall@eng.sun.com>
parents: 448
diff changeset
  1206
                                inst.setUp()
3f98e94acc4a 2690 test suite depot starting/stopping
Brad Hall <bhall@eng.sun.com>
parents: 448
diff changeset
  1207
                        except KeyboardInterrupt:
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1208
                                self.cleanup_and_die(inst, "persistent setup")
502
3f98e94acc4a 2690 test suite depot starting/stopping
Brad Hall <bhall@eng.sun.com>
parents: 448
diff changeset
  1209
                        except:
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1210
                                result.addPersistentSetupError(inst, sys.exc_info())
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1211
                                setUpFailed = True
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1212
                                # XXX do cleanup?
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1213
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1214
                        # If the setUp function didn't work, then cause
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1215
                        # every test case to fail.
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1216
                        if setUpFailed:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1217
                                inst.setUp = setUp_dofail
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1218
                        else:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1219
                                inst.setUp = setUp_donothing
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1220
502
3f98e94acc4a 2690 test suite depot starting/stopping
Brad Hall <bhall@eng.sun.com>
parents: 448
diff changeset
  1221
                for test in self._tests:
3f98e94acc4a 2690 test suite depot starting/stopping
Brad Hall <bhall@eng.sun.com>
parents: 448
diff changeset
  1222
                        if result.shouldStop:
3f98e94acc4a 2690 test suite depot starting/stopping
Brad Hall <bhall@eng.sun.com>
parents: 448
diff changeset
  1223
                                break
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1224
                        real_test_name = test._testMethodName
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1225
                        suite_name = test._Pkg5TestCase__suite_name
1101
35f360e2ee19 5247 Test suite should provide timing info
Brock Pytlik <bpytlik@sun.com>
parents: 1002
diff changeset
  1226
                        cname = test.__class__.__name__
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1227
502
3f98e94acc4a 2690 test suite depot starting/stopping
Brad Hall <bhall@eng.sun.com>
parents: 448
diff changeset
  1228
                        # Populate test with the data from the instance
3f98e94acc4a 2690 test suite depot starting/stopping
Brad Hall <bhall@eng.sun.com>
parents: 448
diff changeset
  1229
                        # already constructed, but update the method name.
3f98e94acc4a 2690 test suite depot starting/stopping
Brad Hall <bhall@eng.sun.com>
parents: 448
diff changeset
  1230
                        # We need to do this so that we have all the state
3f98e94acc4a 2690 test suite depot starting/stopping
Brad Hall <bhall@eng.sun.com>
parents: 448
diff changeset
  1231
                        # that the object is populated with when setUp() is
3f98e94acc4a 2690 test suite depot starting/stopping
Brad Hall <bhall@eng.sun.com>
parents: 448
diff changeset
  1232
                        # called (depot controller list, etc).
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1233
                        if persistent_setup:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1234
                                name = test._testMethodName
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1235
                                doc = test._testMethodDoc
502
3f98e94acc4a 2690 test suite depot starting/stopping
Brad Hall <bhall@eng.sun.com>
parents: 448
diff changeset
  1236
                                test = copy.copy(inst)
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1237
                                test._testMethodName = name
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1238
                                test._testMethodDoc = doc
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1239
1101
35f360e2ee19 5247 Test suite should provide timing info
Brock Pytlik <bpytlik@sun.com>
parents: 1002
diff changeset
  1240
                        test_start = time.time()
502
3f98e94acc4a 2690 test suite depot starting/stopping
Brad Hall <bhall@eng.sun.com>
parents: 448
diff changeset
  1241
                        test(result)
1101
35f360e2ee19 5247 Test suite should provide timing info
Brock Pytlik <bpytlik@sun.com>
parents: 1002
diff changeset
  1242
                        test_end = time.time()
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1243
                        self.timing[suite_name, cname, real_test_name] = \
1101
35f360e2ee19 5247 Test suite should provide timing info
Brock Pytlik <bpytlik@sun.com>
parents: 1002
diff changeset
  1244
                            test_end - test_start
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1245
                if persistent_setup:
502
3f98e94acc4a 2690 test suite depot starting/stopping
Brad Hall <bhall@eng.sun.com>
parents: 448
diff changeset
  1246
                        try:
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1247
                                inst.reallytearDown()
502
3f98e94acc4a 2690 test suite depot starting/stopping
Brad Hall <bhall@eng.sun.com>
parents: 448
diff changeset
  1248
                        except KeyboardInterrupt:
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1249
                                self.cleanup_and_die(inst, "persistent teardown")
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1250
                        except:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1251
                                result.addPersistentTeardownError(inst, sys.exc_info())
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1252
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1253
                # Try to ensure that all depots have been nuked.
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1254
                if hasattr(inst, "killalldepots"):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1255
                        inst.killalldepots()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1256
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1257
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1258
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1259
def get_su_wrap_user():
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1260
        for u in ["noaccess", "nobody"]:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1261
                try:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1262
                        pwd.getpwnam(u)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1263
                        return u
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1264
                except (KeyError, NameError):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1265
                        pass
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1266
        raise RuntimeError("Unable to determine user for su.")
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1267
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1268
class DepotTracebackException(Pkg5CommonException):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1269
        def __init__(self, logfile, output):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1270
                Pkg5CommonException.__init__(self)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1271
                self.__logfile = logfile
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1272
                self.__output = output
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1273
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1274
        def __str__(self):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1275
                str = "During this test, a depot Traceback was detected.\n"
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1276
                str += "Log file: %s.\n" % self.__logfile
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1277
                str += "Log file output is:\n"
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1278
                str += self.format_output(None, self.__output)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1279
                return str
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1280
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1281
class TracebackException(Pkg5CommonException):
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1730
diff changeset
  1282
        def __init__(self, command, output=None, comment=None, debug=None):
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1283
                Pkg5CommonException.__init__(self)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1284
                self.__command = command
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1285
                self.__output = output
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1286
                self.__comment = comment
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1287
                self.__debug = debug
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1288
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1289
        def __str__(self):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1290
                if self.__comment is None and self.__output is None:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1291
                        return (Exception.__str__(self))
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1292
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1293
                str = ""
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1294
                str += self.format_comment(self.__comment)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1295
                str += self.format_output(self.__command, self.__output)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1296
                if self.__debug is not None and self.__debug != "":
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1297
                        str += self.format_debug(self.__debug)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1298
                return str
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1299
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1300
class UnexpectedExitCodeException(Pkg5CommonException):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1301
        def __init__(self, command, expected, got, output=None, comment=None):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1302
                Pkg5CommonException.__init__(self)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1303
                self.__command = command
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1304
                self.__output = output
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1305
                self.__expected = expected
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1306
                self.__got = got
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1307
                self.__comment = comment
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1308
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1309
        def __str__(self):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1310
                if self.__comment is None and self.__output is None:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1311
                        return (Exception.__str__(self))
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1312
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1313
                str = ""
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1314
                str += self.format_comment(self.__comment)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1315
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1316
                str += "  Invoked: %s\n" % self.__command
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1317
                str += "  Expected exit status: %s.  Got: %d." % \
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1318
                    (self.__expected, self.__got)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1319
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1320
                str += self.format_output(self.__command, self.__output)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1321
                return str
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1322
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1323
        @property
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1324
        def exitcode(self):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1325
                return self.__got
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1326
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1327
class PkgSendOpenException(Pkg5CommonException):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1328
        def __init__(self, com = ""):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1329
                Pkg5CommonException.__init__(self, com)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1330
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1331
class CliTestCase(Pkg5TestCase):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1332
        bail_on_fail = False
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1333
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1334
        def setUp(self):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1335
                Pkg5TestCase.setUp(self)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1336
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1337
                self.image_dir = None
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1338
                self.img_path = os.path.join(self.test_root, "image")
2092
0ef66bf272d3 16852 pkg should look at its image for certs if active image lacks certs
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2089
diff changeset
  1339
                self.image_created = False
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1340
2158
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
  1341
                # Set image path to a path that's not actually an image to
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
  1342
                # force failure of tests that don't explicitly provide an
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
  1343
                # image root either through the default behaviour of the
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
  1344
                # pkg() helper routine or another method.
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
  1345
                os.environ["PKG_IMAGE"] = self.test_root
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
  1346
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1347
        def tearDown(self):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1348
                Pkg5TestCase.tearDown(self)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1349
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1350
        def get_img_path(self):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1351
                return self.img_path
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1352
2144
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2097
diff changeset
  1353
        def get_img_api_obj(self, cmd_path=None, img_path=None):
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2097
diff changeset
  1354
                if not img_path:
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2097
diff changeset
  1355
                        img_path = self.img_path
2092
0ef66bf272d3 16852 pkg should look at its image for certs if active image lacks certs
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2089
diff changeset
  1356
                from pkg.client import global_settings
1895
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1357
                progresstracker = pkg.client.progress.NullProgressTracker()
2092
0ef66bf272d3 16852 pkg should look at its image for certs if active image lacks certs
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2089
diff changeset
  1358
                if not cmd_path:
2144
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2097
diff changeset
  1359
                        cmd_path = os.path.join(img_path, "pkg")
2092
0ef66bf272d3 16852 pkg should look at its image for certs if active image lacks certs
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2089
diff changeset
  1360
                old_val = global_settings.client_args
0ef66bf272d3 16852 pkg should look at its image for certs if active image lacks certs
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2089
diff changeset
  1361
                global_settings.client_args[0] = cmd_path
2144
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2097
diff changeset
  1362
                res = pkg.client.api.ImageInterface(img_path,
1895
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1363
                    CLIENT_API_VERSION, progresstracker, lambda x: False,
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1364
                    PKG_CLIENT_NAME)
2092
0ef66bf272d3 16852 pkg should look at its image for certs if active image lacks certs
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2089
diff changeset
  1365
                global_settings.client_args = old_val
0ef66bf272d3 16852 pkg should look at its image for certs if active image lacks certs
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2089
diff changeset
  1366
                return res
1895
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1367
2092
0ef66bf272d3 16852 pkg should look at its image for certs if active image lacks certs
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2089
diff changeset
  1368
        def image_create(self, repourl, prefix="test", variants=EmptyDict,
0ef66bf272d3 16852 pkg should look at its image for certs if active image lacks certs
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2089
diff changeset
  1369
            destroy=True):
1859
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1839
diff changeset
  1370
                """A convenience wrapper for callers that only need basic image
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1839
diff changeset
  1371
                creation functionality.  This wrapper creates a full (as opposed
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1839
diff changeset
  1372
                to user) image using the pkg.client.api and returns the related
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1839
diff changeset
  1373
                API object."""
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1839
diff changeset
  1374
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1839
diff changeset
  1375
                assert self.img_path
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1839
diff changeset
  1376
                assert self.img_path != "/"
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1839
diff changeset
  1377
2092
0ef66bf272d3 16852 pkg should look at its image for certs if active image lacks certs
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2089
diff changeset
  1378
                if destroy:
0ef66bf272d3 16852 pkg should look at its image for certs if active image lacks certs
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2089
diff changeset
  1379
                        self.image_destroy()
1859
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1839
diff changeset
  1380
                os.mkdir(self.img_path)
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1839
diff changeset
  1381
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1839
diff changeset
  1382
                progtrack = pkg.client.progress.NullProgressTracker()
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1839
diff changeset
  1383
                api_inst = pkg.client.api.image_create(PKG_CLIENT_NAME,
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1839
diff changeset
  1384
                    CLIENT_API_VERSION, self.img_path,
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1839
diff changeset
  1385
                    pkg.client.api.IMG_TYPE_ENTIRE, False, repo_uri=repourl,
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1839
diff changeset
  1386
                    prefix=prefix, progtrack=progtrack, variants=variants)
2092
0ef66bf272d3 16852 pkg should look at its image for certs if active image lacks certs
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2089
diff changeset
  1387
                shutil.copy("%s/usr/bin/pkg" % g_proto_area,
0ef66bf272d3 16852 pkg should look at its image for certs if active image lacks certs
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2089
diff changeset
  1388
                    os.path.join(self.img_path, "pkg"))
0ef66bf272d3 16852 pkg should look at its image for certs if active image lacks certs
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2089
diff changeset
  1389
                self.image_created = True
1859
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1839
diff changeset
  1390
                return api_inst
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1839
diff changeset
  1391
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1839
diff changeset
  1392
        def pkg_image_create(self, repourl, prefix="test", additional_args="",
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1839
diff changeset
  1393
            exit=0):
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1839
diff changeset
  1394
                """Executes pkg(1) client to create a full (as opposed to user)
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1839
diff changeset
  1395
                image; returns exit code of client or raises an exception if
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1839
diff changeset
  1396
                exit code doesn't match 'exit' or equals 99.."""
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1839
diff changeset
  1397
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1398
                assert self.img_path
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1399
                assert self.img_path != "/"
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1400
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1401
                self.image_destroy()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1402
                os.mkdir(self.img_path)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1403
                cmdline = "pkg image-create -F -p %s=%s %s %s" % \
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1404
                    (prefix, repourl, additional_args, self.img_path)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1405
                self.debugcmd(cmdline)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1406
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1407
                p = subprocess.Popen(cmdline, shell=True,
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1408
                    stdout=subprocess.PIPE,
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1409
                    stderr=subprocess.STDOUT)
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1410
                output = p.stdout.read()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1411
                retcode = p.wait()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1412
                self.debugresult(retcode, 0, output)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1413
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1414
                if retcode == 99:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1415
                        raise TracebackException(cmdline, output)
1859
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1839
diff changeset
  1416
                if retcode != exit:
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1417
                        raise UnexpectedExitCodeException(cmdline, 0,
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1418
                            retcode, output)
2092
0ef66bf272d3 16852 pkg should look at its image for certs if active image lacks certs
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2089
diff changeset
  1419
                shutil.copy("%s/usr/bin/pkg" % g_proto_area,
0ef66bf272d3 16852 pkg should look at its image for certs if active image lacks certs
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2089
diff changeset
  1420
                    os.path.join(self.img_path, "pkg"))
0ef66bf272d3 16852 pkg should look at its image for certs if active image lacks certs
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2089
diff changeset
  1421
                self.image_created = True
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1422
                return retcode
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1423
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1424
        def image_set(self, imgdir):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1425
                self.debug("image_set: %s" % imgdir)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1426
                self.img_path = imgdir
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1427
                os.environ["PKG_IMAGE"] = self.img_path
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1428
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1429
        def image_destroy(self):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1430
                self.debug("image_destroy %s" % self.img_path)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1431
                # Make sure we're not in the image.
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1432
                if os.path.exists(self.img_path):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1433
                        os.chdir(self.test_root)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1434
                        shutil.rmtree(self.img_path)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1435
2047
5e1340de1aba 12723 pkg per-subcommand usage/help
Tim Foster <tim.s.foster@oracle.com>
parents: 2046
diff changeset
  1436
        def pkg(self, command, exit=0, comment="", prefix="", su_wrap=None,
2158
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
  1437
            out=False, stderr=False, alt_img_path=None, use_img_root=True):
2092
0ef66bf272d3 16852 pkg should look at its image for certs if active image lacks certs
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2089
diff changeset
  1438
                pth = self.img_path
0ef66bf272d3 16852 pkg should look at its image for certs if active image lacks certs
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2089
diff changeset
  1439
                if alt_img_path:
0ef66bf272d3 16852 pkg should look at its image for certs if active image lacks certs
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2089
diff changeset
  1440
                        pth = alt_img_path
0ef66bf272d3 16852 pkg should look at its image for certs if active image lacks certs
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2089
diff changeset
  1441
                elif not self.image_created:
0ef66bf272d3 16852 pkg should look at its image for certs if active image lacks certs
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2089
diff changeset
  1442
                        pth = "%s/usr/bin" % g_proto_area
2158
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
  1443
                if use_img_root and "-R" not in command and \
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
  1444
                    "image-create" not in command and "version" not in command:
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
  1445
                        command = "-R %s %s" % (self.get_img_path(), command)
2092
0ef66bf272d3 16852 pkg should look at its image for certs if active image lacks certs
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2089
diff changeset
  1446
                cmdline = "%s/pkg %s" % (pth, command)
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
  1447
                return self.cmdline_run(cmdline, exit=exit, comment=comment,
2047
5e1340de1aba 12723 pkg per-subcommand usage/help
Tim Foster <tim.s.foster@oracle.com>
parents: 2046
diff changeset
  1448
                    prefix=prefix, su_wrap=su_wrap, out=out, stderr=stderr)
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1449
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1450
        def pkgdepend_resolve(self, args, exit=0, comment=""):
2158
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
  1451
                ops = ""
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
  1452
                if "-R" not in args:
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
  1453
                        ops = "-R %s" % self.get_img_path()
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
  1454
                cmdline = "%s/usr/bin/pkgdepend %s resolve %s" % (
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
  1455
                    g_proto_area, ops, args)
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
  1456
                return self.cmdline_run(cmdline, comment=comment, exit=exit)
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1457
1908
4bdaf0463bae 15843 pkgdepend can't handle more than one proto area
Brock Pytlik <bpytlik@sun.com>
parents: 1895
diff changeset
  1458
        def pkgdepend_generate(self, args, exit=0, comment=""):
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
  1459
                cmdline = "%s/usr/bin/pkgdepend generate %s" % (g_proto_area,
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
  1460
                    args)
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
  1461
                return self.cmdline_run(cmdline, exit=exit, comment=comment)
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1462
2085
10a27146ebc2 16802 pkglint should check the value of info.classification in manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 2081
diff changeset
  1463
        def pkglint(self, args, exit=0, comment="", testrc=True):
10a27146ebc2 16802 pkglint should check the value of info.classification in manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 2081
diff changeset
  1464
                if testrc:
10a27146ebc2 16802 pkglint should check the value of info.classification in manifests
Tim Foster <tim.s.foster@oracle.com>
parents: 2081
diff changeset
  1465
                        rcpath = "%s/pkglintrc" % self.test_root
2081
f2189c4a03c4 16824 pkglint should remove its workaround for 16811
Tim Foster <tim.s.foster@oracle.com>
parents: 2073
diff changeset
  1466
                        cmdline = "%s/usr/bin/pkglint -f %s %s" % \
f2189c4a03c4 16824 pkglint should remove its workaround for 16811
Tim Foster <tim.s.foster@oracle.com>
parents: 2073
diff changeset
  1467
                            (g_proto_area, rcpath, args)
f2189c4a03c4 16824 pkglint should remove its workaround for 16811
Tim Foster <tim.s.foster@oracle.com>
parents: 2073
diff changeset
  1468
                else:
f2189c4a03c4 16824 pkglint should remove its workaround for 16811
Tim Foster <tim.s.foster@oracle.com>
parents: 2073
diff changeset
  1469
                        cmdline = "%s/usr/bin/pkglint %s" % (g_proto_area, args)
2046
2522cde7adc2 13536 We need a way to audit one or more packages
Tim Foster <tim.s.foster@oracle.com>
parents: 2034
diff changeset
  1470
                return self.cmdline_run(cmdline, exit=exit, out=True,
2522cde7adc2 13536 We need a way to audit one or more packages
Tim Foster <tim.s.foster@oracle.com>
parents: 2034
diff changeset
  1471
                    comment=comment, stderr=True)
2522cde7adc2 13536 We need a way to audit one or more packages
Tim Foster <tim.s.foster@oracle.com>
parents: 2034
diff changeset
  1472
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1473
        def pkgrecv(self, server_url=None, command=None, exit=0, out=False,
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1474
            comment=""):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1475
                args = []
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1476
                if server_url:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1477
                        args.append("-s %s" % server_url)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1478
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1479
                if command:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1480
                        args.append(command)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1481
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
  1482
                cmdline = "%s/usr/bin/pkgrecv %s" % (g_proto_area,
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
  1483
                    " ".join(args))
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
  1484
                return self.cmdline_run(cmdline, comment=comment, exit=exit,
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
  1485
                    out=out)
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1486
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
  1487
        def pkgrepo(self, command, comment="", exit=0, su_wrap=False):
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
  1488
                cmdline = "%s/usr/bin/pkgrepo %s" % (g_proto_area, command)
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
  1489
                return self.cmdline_run(cmdline, comment=comment, exit=exit,
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
  1490
                    su_wrap=su_wrap)
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1491
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1970
diff changeset
  1492
        def pkgsign(self, depot_url, command, exit=0, comment=""):
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1970
diff changeset
  1493
                args = []
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1970
diff changeset
  1494
                if depot_url:
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1970
diff changeset
  1495
                        args.append("-s %s" % depot_url)
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1970
diff changeset
  1496
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1970
diff changeset
  1497
                if command:
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1970
diff changeset
  1498
                        args.append(command)
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1970
diff changeset
  1499
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1970
diff changeset
  1500
                cmdline = "%s/usr/bin/pkgsign %s" % (g_proto_area,
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1970
diff changeset
  1501
                    " ".join(args))
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1970
diff changeset
  1502
                return self.cmdline_run(cmdline, comment=comment, exit=exit)
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1970
diff changeset
  1503
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1504
        def pkgsend(self, depot_url="", command="", exit=0, comment=""):
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1505
                args = []
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1506
                if depot_url:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1507
                        args.append("-s " + depot_url)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1508
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1509
                if command:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1510
                        args.append(command)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1511
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
  1512
                prefix = "cd %s;" % self.test_root
2183
21ae45e8dfcf 17581 There should be a way of removing a package as part of upgrade
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2158
diff changeset
  1513
                cmdline = "%s/usr/bin/pkgsend %s" % (g_proto_area,
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
  1514
                    " ".join(args))
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1515
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
  1516
                retcode, out = self.cmdline_run(cmdline, comment=comment,
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
  1517
                    exit=exit, out=True, prefix=prefix, raise_error=False)
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
  1518
                errout = self.errout
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1519
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1520
                cmdop = command.split(' ')[0]
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1970
diff changeset
  1521
                if cmdop in ("open", "append") and retcode == 0:
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1522
                        out = out.rstrip()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1523
                        assert out.startswith("export PKG_TRANS_ID=")
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1524
                        arr = out.split("=")
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1525
                        assert arr
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1526
                        out = arr[1]
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1527
                        os.environ["PKG_TRANS_ID"] = out
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1528
                        self.debug("$ export PKG_TRANS_ID=%s" % out)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1529
                        # retcode != 0 will be handled below
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1530
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
  1531
                published = None
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1532
                if (cmdop == "close" and retcode == 0) or cmdop == "publish":
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1533
                        os.environ["PKG_TRANS_ID"] = ""
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1534
                        self.debug("$ export PKG_TRANS_ID=")
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1535
                        for l in out.splitlines():
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1536
                                if l.startswith("pkg:/"):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1537
                                        published = l
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1538
                                        break
1839
53bdcdd547cb 11023 DirectoryBundle emits bad paths if basedir has trailing /
Shawn Walker <shawn.walker@oracle.com>
parents: 1832
diff changeset
  1539
                elif (cmdop == "generate" and retcode == 0):
53bdcdd547cb 11023 DirectoryBundle emits bad paths if basedir has trailing /
Shawn Walker <shawn.walker@oracle.com>
parents: 1832
diff changeset
  1540
                        published = out
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1541
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1542
                if retcode == 99:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1543
                        raise TracebackException(cmdline, out, comment)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1544
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1545
                if retcode != exit:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1546
                        raise UnexpectedExitCodeException(cmdline, exit,
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1547
                            retcode, out + errout, comment)
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1548
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1549
                return retcode, published
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1550
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
  1551
        def pkgsend_bulk(self, depot_url, commands, exit=0, comment="",
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1552
            no_catalog=False, refresh_index=False):
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
  1553
                """ Send a series of packaging commands; useful  for quickly
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1554
                    doing a bulk-load of stuff into the repo.  All commands are
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1555
                    expected to work; if not, the transaction is abandoned.  If
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1556
                    'exit' is set, then if none of the actions triggers that
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1557
                    exit code, an UnexpectedExitCodeException is raised.
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1558
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1559
                    A list containing the fmris of any packages that were
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1560
                    published as a result of the commands executed will be
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1561
                    returned; it will be empty if none were. """
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1562
1895
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1563
                if isinstance(commands, (list, tuple)):
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1564
                        commands = "".join(commands)
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1565
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
  1566
                extra_opts = []
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
  1567
                if no_catalog:
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
  1568
                        extra_opts.append("--no-catalog")
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
  1569
                extra_opts = " ".join(extra_opts)
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
  1570
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1571
                plist = []
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1572
                try:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1573
                        accumulate = []
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1574
                        current_fmri = None
2046
2522cde7adc2 13536 We need a way to audit one or more packages
Tim Foster <tim.s.foster@oracle.com>
parents: 2034
diff changeset
  1575
                        retcode = None
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1576
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1577
                        for line in commands.split("\n"):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1578
                                line = line.strip()
1839
53bdcdd547cb 11023 DirectoryBundle emits bad paths if basedir has trailing /
Shawn Walker <shawn.walker@oracle.com>
parents: 1832
diff changeset
  1579
53bdcdd547cb 11023 DirectoryBundle emits bad paths if basedir has trailing /
Shawn Walker <shawn.walker@oracle.com>
parents: 1832
diff changeset
  1580
                                # pkgsend_bulk can't be used w/ import or
53bdcdd547cb 11023 DirectoryBundle emits bad paths if basedir has trailing /
Shawn Walker <shawn.walker@oracle.com>
parents: 1832
diff changeset
  1581
                                # generate.
53bdcdd547cb 11023 DirectoryBundle emits bad paths if basedir has trailing /
Shawn Walker <shawn.walker@oracle.com>
parents: 1832
diff changeset
  1582
                                assert not line.startswith("import"), \
53bdcdd547cb 11023 DirectoryBundle emits bad paths if basedir has trailing /
Shawn Walker <shawn.walker@oracle.com>
parents: 1832
diff changeset
  1583
                                    "pkgsend_bulk cannot be used with import"
53bdcdd547cb 11023 DirectoryBundle emits bad paths if basedir has trailing /
Shawn Walker <shawn.walker@oracle.com>
parents: 1832
diff changeset
  1584
                                assert not line.startswith("generate"), \
53bdcdd547cb 11023 DirectoryBundle emits bad paths if basedir has trailing /
Shawn Walker <shawn.walker@oracle.com>
parents: 1832
diff changeset
  1585
                                    "pkgsend_bulk cannot be used with generate"
53bdcdd547cb 11023 DirectoryBundle emits bad paths if basedir has trailing /
Shawn Walker <shawn.walker@oracle.com>
parents: 1832
diff changeset
  1586
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1587
                                if line == "":
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1588
                                        continue
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1589
                                if line.startswith("add"):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1590
                                        self.assert_(current_fmri != None,
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1591
                                            "Missing open in pkgsend string")
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1592
                                        accumulate.append(line[4:])
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1593
                                        continue
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1594
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1595
                                if current_fmri: # send any content seen so far (can be 0)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1596
                                        fd, f_path = tempfile.mkstemp(dir=self.test_root)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1597
                                        for l in accumulate:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1598
                                                os.write(fd, "%s\n" % l)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1599
                                        os.close(fd)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1600
                                        try:
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
  1601
                                                cmd = "publish %s -d %s %s " \
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
  1602
                                                    "%s" % (extra_opts,
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
  1603
                                                    self.test_root,
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
  1604
                                                    current_fmri, f_path)
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1605
                                                current_fmri = None
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1606
                                                accumulate = []
2073
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2047
diff changeset
  1607
                                                retcode, published = \
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2047
diff changeset
  1608
                                                    self.pkgsend(depot_url, cmd)
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1609
                                                if retcode == 0 and published:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1610
                                                        plist.append(published)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1611
                                        except:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1612
                                                os.remove(f_path)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1613
                                                raise
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1614
                                        os.remove(f_path)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1615
                                if line.startswith("open"):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1616
                                        current_fmri = line[5:].strip()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1617
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1618
                        if exit == 0 and refresh_index:
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1619
                                self.pkgrepo("-s %s refresh --no-catalog" %
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1620
                                    depot_url)
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1621
                except UnexpectedExitCodeException, e:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1622
                        if e.exitcode != exit:
502
3f98e94acc4a 2690 test suite depot starting/stopping
Brad Hall <bhall@eng.sun.com>
parents: 448
diff changeset
  1623
                                raise
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1624
                        retcode = e.exitcode
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1625
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1626
                if retcode != exit:
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1627
                        raise UnexpectedExitCodeException(line, exit, retcode,
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1628
                            self.output + self.errout)
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1629
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1630
                return plist
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1631
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1970
diff changeset
  1632
        def merge(self, args=EmptyI, exit=0):
2046
2522cde7adc2 13536 We need a way to audit one or more packages
Tim Foster <tim.s.foster@oracle.com>
parents: 2034
diff changeset
  1633
                pub_utils = os.path.join(g_proto_area, path_to_pub_util)
2522cde7adc2 13536 We need a way to audit one or more packages
Tim Foster <tim.s.foster@oracle.com>
parents: 2034
diff changeset
  1634
                prog = os.path.join(pub_utils, "merge.py")
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1970
diff changeset
  1635
                cmd = "%s %s" % (prog, " ".join(args))
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1970
diff changeset
  1636
                self.cmdline_run(cmd, exit=exit)
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1970
diff changeset
  1637
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1638
        def copy_repository(self, src, dest, pub_map):
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1639
                """Copies the packages from the src repository to a new
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1640
                destination repository that will be created at dest.  In
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1641
                addition, any packages from the src_pub will be assigned
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1642
                to the dest_pub during the copy.  The new repository will
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1643
                not have a catalog or search indices, so a depot server
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1644
                pointed at the new repository must be started with the
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1645
                --rebuild option.
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1646
                """
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1647
2097
068cc63b4d6e 17055 image configuration should use pkg.config classes
Shawn Walker <shawn.walker@oracle.com>
parents: 2092
diff changeset
  1648
                # Preserve destination repository's configuration if it exists.
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1649
                dest_cfg = os.path.join(dest, "pkg5.repository")
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1730
diff changeset
  1650
                dest_cfg_data = None
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1730
diff changeset
  1651
                if os.path.exists(dest_cfg):
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1730
diff changeset
  1652
                        with open(dest_cfg, "rb") as f:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1730
diff changeset
  1653
                                dest_cfg_data = f.read()
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1654
                shutil.rmtree(dest, True)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1655
                os.makedirs(dest, mode=0755)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1656
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1730
diff changeset
  1657
                # Ensure config is written back out.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1730
diff changeset
  1658
                if dest_cfg_data:
2073
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2047
diff changeset
  1659
                        with open(dest_cfg, "wb") as f:
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2047
diff changeset
  1660
                                f.write(dest_cfg_data)
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1730
diff changeset
  1661
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1662
                def copy_manifests(src_root, dest_root):
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1663
                        # Now copy each manifest and replace any references to
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1664
                        # the old publisher with that of the new publisher as
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1665
                        # they are copied.
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1666
                        src_pkg_root = os.path.join(src_root, "pkg")
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1667
                        dest_pkg_root = os.path.join(dest_root, "pkg")
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1668
                        for stem in os.listdir(src_pkg_root):
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1669
                                src_pkg_path = os.path.join(src_pkg_root, stem)
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1670
                                dest_pkg_path = os.path.join(dest_pkg_root,
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1671
                                    stem)
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1672
                                for mname in os.listdir(src_pkg_path):
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1673
                                        # Ensure destination manifest directory
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1674
                                        # exists.
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1675
                                        if not os.path.isdir(dest_pkg_path):
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1676
                                                os.makedirs(dest_pkg_path,
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1677
                                                    mode=0755)
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1678
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1679
                                        msrc = open(os.path.join(src_pkg_path,
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1680
                                            mname), "rb")
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1681
                                        mdest = open(os.path.join(dest_pkg_path,
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1682
                                            mname), "wb")
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1683
                                        for l in msrc:
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1684
                                                if l.find("pkg://") == -1:
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1685
                                                        mdest.write(l)
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1686
                                                        continue
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1687
                                                nl = l
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1688
                                                for src_pub in pub_map:
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1689
                                                        nl = nl.replace(
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1690
                                                            src_pub,
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1691
                                                            pub_map[src_pub])
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1692
                                                mdest.write(nl)
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1693
                                        msrc.close()
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1694
                                        mdest.close()
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1695
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1696
                src_pub_root = os.path.join(src, "publisher")
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1697
                if os.path.exists(src_pub_root):
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1698
                        dest_pub_root = os.path.join(dest, "publisher")
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1699
                        for pub in os.listdir(src_pub_root):
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1700
                                if pub not in pub_map:
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1701
                                        continue
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1702
                                src_root = os.path.join(src_pub_root, pub)
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1703
                                dest_root = os.path.join(dest_pub_root,
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1704
                                    pub_map[pub])
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1705
                                for entry in os.listdir(src_root):
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1706
                                        # Skip the catalog, index, and pkg
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1707
                                        # directories as they will be copied
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1708
                                        # manually.
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1709
                                        if entry not in ("catalog", "index",
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1710
                                            "pkg", "tmp", "trans"):
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1711
                                                spath = os.path.join(src_root,
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1712
                                                    entry)
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1713
                                                dpath = os.path.join(dest_root,
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1714
                                                    entry)
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1715
                                                shutil.copytree(spath, dpath)
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1716
                                                continue
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1717
                                        if entry != "pkg":
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1718
                                                continue
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1719
                                        copy_manifests(src_root, dest_root)
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1720
2144
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2097
diff changeset
  1721
        def get_img_manifest_cache_dir(self, pfmri, img_path=None):
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2097
diff changeset
  1722
                """Returns the path to the manifest for the given fmri."""
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2097
diff changeset
  1723
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2097
diff changeset
  1724
                img = self.get_img_api_obj(img_path=img_path).img
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2097
diff changeset
  1725
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2097
diff changeset
  1726
                if not pfmri.publisher:
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2097
diff changeset
  1727
                        # Allow callers to not specify a fully-qualified FMRI
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2097
diff changeset
  1728
                        # if it can be asssumed which publisher likely has
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2097
diff changeset
  1729
                        # the package.
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2097
diff changeset
  1730
                        pubs = [
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2097
diff changeset
  1731
                            p.prefix
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2097
diff changeset
  1732
                            for p in img.gen_publishers(inc_disabled=True)
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2097
diff changeset
  1733
                        ]
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2097
diff changeset
  1734
                        assert len(pubs) == 1
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2097
diff changeset
  1735
                        pfmri.publisher = pubs[0]
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2097
diff changeset
  1736
                return img.get_manifest_dir(pfmri)
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2097
diff changeset
  1737
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1970
diff changeset
  1738
        def get_img_manifest_path(self, pfmri, img_path=None):
2073
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2047
diff changeset
  1739
                """Returns the path to the manifest for the given fmri."""
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1970
diff changeset
  1740
2144
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2097
diff changeset
  1741
                img = self.get_img_api_obj(img_path=img_path).img
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1970
diff changeset
  1742
2144
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2097
diff changeset
  1743
                if not pfmri.publisher:
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2097
diff changeset
  1744
                        # Allow callers to not specify a fully-qualified FMRI
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2097
diff changeset
  1745
                        # if it can be asssumed which publisher likely has
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2097
diff changeset
  1746
                        # the package.
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2097
diff changeset
  1747
                        pubs = [
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2097
diff changeset
  1748
                            p.prefix
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2097
diff changeset
  1749
                            for p in img.gen_publishers(inc_disabled=True)
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2097
diff changeset
  1750
                        ]
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2097
diff changeset
  1751
                        assert len(pubs) == 1
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2097
diff changeset
  1752
                        pfmri.publisher = pubs[0]
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2097
diff changeset
  1753
                return img.get_manifest_path(pfmri)
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1970
diff changeset
  1754
1755
8e1ed1373f93 9123 client traceback during install for bad file mode
Shawn Walker <srw@sun.com>
parents: 1736
diff changeset
  1755
        def get_img_manifest(self, pfmri, img_path=None):
8e1ed1373f93 9123 client traceback during install for bad file mode
Shawn Walker <srw@sun.com>
parents: 1736
diff changeset
  1756
                """Retrieves the client's cached copy of the manifest for the
8e1ed1373f93 9123 client traceback during install for bad file mode
Shawn Walker <srw@sun.com>
parents: 1736
diff changeset
  1757
                given package FMRI and returns it as a string.  Callers are
8e1ed1373f93 9123 client traceback during install for bad file mode
Shawn Walker <srw@sun.com>
parents: 1736
diff changeset
  1758
                responsible for all error handling."""
8e1ed1373f93 9123 client traceback during install for bad file mode
Shawn Walker <srw@sun.com>
parents: 1736
diff changeset
  1759
2144
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2097
diff changeset
  1760
                mpath = self.get_img_manifest_path(pfmri, img_path=img_path)
1755
8e1ed1373f93 9123 client traceback during install for bad file mode
Shawn Walker <srw@sun.com>
parents: 1736
diff changeset
  1761
                with open(mpath, "rb") as f:
8e1ed1373f93 9123 client traceback during install for bad file mode
Shawn Walker <srw@sun.com>
parents: 1736
diff changeset
  1762
                        return f.read()
8e1ed1373f93 9123 client traceback during install for bad file mode
Shawn Walker <srw@sun.com>
parents: 1736
diff changeset
  1763
8e1ed1373f93 9123 client traceback during install for bad file mode
Shawn Walker <srw@sun.com>
parents: 1736
diff changeset
  1764
        def write_img_manifest(self, pfmri, mdata, img_path=None):
8e1ed1373f93 9123 client traceback during install for bad file mode
Shawn Walker <srw@sun.com>
parents: 1736
diff changeset
  1765
                """Overwrites the client's cached copy of the manifest for the
8e1ed1373f93 9123 client traceback during install for bad file mode
Shawn Walker <srw@sun.com>
parents: 1736
diff changeset
  1766
                given package FMRI using the provided string.  Callers are
8e1ed1373f93 9123 client traceback during install for bad file mode
Shawn Walker <srw@sun.com>
parents: 1736
diff changeset
  1767
                responsible for all error handling."""
8e1ed1373f93 9123 client traceback during install for bad file mode
Shawn Walker <srw@sun.com>
parents: 1736
diff changeset
  1768
8e1ed1373f93 9123 client traceback during install for bad file mode
Shawn Walker <srw@sun.com>
parents: 1736
diff changeset
  1769
                if not img_path:
8e1ed1373f93 9123 client traceback during install for bad file mode
Shawn Walker <srw@sun.com>
parents: 1736
diff changeset
  1770
                        img_path = self.get_img_path()
8e1ed1373f93 9123 client traceback during install for bad file mode
Shawn Walker <srw@sun.com>
parents: 1736
diff changeset
  1771
2073
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2047
diff changeset
  1772
                mpath = self.get_img_manifest_path(pfmri, img_path=img_path)
2144
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2097
diff changeset
  1773
                mdir = self.get_img_manifest_cache_dir(pfmri, img_path=img_path)
1755
8e1ed1373f93 9123 client traceback during install for bad file mode
Shawn Walker <srw@sun.com>
parents: 1736
diff changeset
  1774
8e1ed1373f93 9123 client traceback during install for bad file mode
Shawn Walker <srw@sun.com>
parents: 1736
diff changeset
  1775
                # Dump the manifest directory for the package to ensure any
8e1ed1373f93 9123 client traceback during install for bad file mode
Shawn Walker <srw@sun.com>
parents: 1736
diff changeset
  1776
                # cached information related to it is gone.
8e1ed1373f93 9123 client traceback during install for bad file mode
Shawn Walker <srw@sun.com>
parents: 1736
diff changeset
  1777
                shutil.rmtree(mdir, True)
8e1ed1373f93 9123 client traceback during install for bad file mode
Shawn Walker <srw@sun.com>
parents: 1736
diff changeset
  1778
                self.assert_(not os.path.exists(mdir))
8e1ed1373f93 9123 client traceback during install for bad file mode
Shawn Walker <srw@sun.com>
parents: 1736
diff changeset
  1779
                os.makedirs(mdir, mode=0755)
8e1ed1373f93 9123 client traceback during install for bad file mode
Shawn Walker <srw@sun.com>
parents: 1736
diff changeset
  1780
8e1ed1373f93 9123 client traceback during install for bad file mode
Shawn Walker <srw@sun.com>
parents: 1736
diff changeset
  1781
                # Finally, write the new manifest.
8e1ed1373f93 9123 client traceback during install for bad file mode
Shawn Walker <srw@sun.com>
parents: 1736
diff changeset
  1782
                with open(mpath, "wb") as f:
8e1ed1373f93 9123 client traceback during install for bad file mode
Shawn Walker <srw@sun.com>
parents: 1736
diff changeset
  1783
                        f.write(mdata)
8e1ed1373f93 9123 client traceback during install for bad file mode
Shawn Walker <srw@sun.com>
parents: 1736
diff changeset
  1784
1832
df15686547e4 6795 pkg fix should fix file modes for some preserved files
Shawn Walker <shawn.walker@oracle.com>
parents: 1795
diff changeset
  1785
        def validate_fsobj_attrs(self, act, target=None, img_path=None):
df15686547e4 6795 pkg fix should fix file modes for some preserved files
Shawn Walker <shawn.walker@oracle.com>
parents: 1795
diff changeset
  1786
                """Used to verify that the target item's mode, attrs, timestamp,
df15686547e4 6795 pkg fix should fix file modes for some preserved files
Shawn Walker <shawn.walker@oracle.com>
parents: 1795
diff changeset
  1787
                etc. match as expected.  The actual"""
df15686547e4 6795 pkg fix should fix file modes for some preserved files
Shawn Walker <shawn.walker@oracle.com>
parents: 1795
diff changeset
  1788
df15686547e4 6795 pkg fix should fix file modes for some preserved files
Shawn Walker <shawn.walker@oracle.com>
parents: 1795
diff changeset
  1789
                if act.name not in ("file", "dir"):
df15686547e4 6795 pkg fix should fix file modes for some preserved files
Shawn Walker <shawn.walker@oracle.com>
parents: 1795
diff changeset
  1790
                        return
df15686547e4 6795 pkg fix should fix file modes for some preserved files
Shawn Walker <shawn.walker@oracle.com>
parents: 1795
diff changeset
  1791
df15686547e4 6795 pkg fix should fix file modes for some preserved files
Shawn Walker <shawn.walker@oracle.com>
parents: 1795
diff changeset
  1792
                if not img_path:
df15686547e4 6795 pkg fix should fix file modes for some preserved files
Shawn Walker <shawn.walker@oracle.com>
parents: 1795
diff changeset
  1793
                        img_path = self.get_img_path()
df15686547e4 6795 pkg fix should fix file modes for some preserved files
Shawn Walker <shawn.walker@oracle.com>
parents: 1795
diff changeset
  1794
                if not target:
df15686547e4 6795 pkg fix should fix file modes for some preserved files
Shawn Walker <shawn.walker@oracle.com>
parents: 1795
diff changeset
  1795
                        target = act.attrs["path"]
df15686547e4 6795 pkg fix should fix file modes for some preserved files
Shawn Walker <shawn.walker@oracle.com>
parents: 1795
diff changeset
  1796
df15686547e4 6795 pkg fix should fix file modes for some preserved files
Shawn Walker <shawn.walker@oracle.com>
parents: 1795
diff changeset
  1797
                fpath = os.path.join(img_path, target)
df15686547e4 6795 pkg fix should fix file modes for some preserved files
Shawn Walker <shawn.walker@oracle.com>
parents: 1795
diff changeset
  1798
                lstat = os.lstat(fpath)
df15686547e4 6795 pkg fix should fix file modes for some preserved files
Shawn Walker <shawn.walker@oracle.com>
parents: 1795
diff changeset
  1799
df15686547e4 6795 pkg fix should fix file modes for some preserved files
Shawn Walker <shawn.walker@oracle.com>
parents: 1795
diff changeset
  1800
                # Verify owner.
df15686547e4 6795 pkg fix should fix file modes for some preserved files
Shawn Walker <shawn.walker@oracle.com>
parents: 1795
diff changeset
  1801
                expected = portable.get_user_by_name(act.attrs["owner"], None,
df15686547e4 6795 pkg fix should fix file modes for some preserved files
Shawn Walker <shawn.walker@oracle.com>
parents: 1795
diff changeset
  1802
                    False)
df15686547e4 6795 pkg fix should fix file modes for some preserved files
Shawn Walker <shawn.walker@oracle.com>
parents: 1795
diff changeset
  1803
                actual = lstat.st_uid
df15686547e4 6795 pkg fix should fix file modes for some preserved files
Shawn Walker <shawn.walker@oracle.com>
parents: 1795
diff changeset
  1804
                self.assertEqual(expected, actual)
df15686547e4 6795 pkg fix should fix file modes for some preserved files
Shawn Walker <shawn.walker@oracle.com>
parents: 1795
diff changeset
  1805
df15686547e4 6795 pkg fix should fix file modes for some preserved files
Shawn Walker <shawn.walker@oracle.com>
parents: 1795
diff changeset
  1806
                # Verify group.
df15686547e4 6795 pkg fix should fix file modes for some preserved files
Shawn Walker <shawn.walker@oracle.com>
parents: 1795
diff changeset
  1807
                expected = portable.get_group_by_name(act.attrs["group"], None,
df15686547e4 6795 pkg fix should fix file modes for some preserved files
Shawn Walker <shawn.walker@oracle.com>
parents: 1795
diff changeset
  1808
                    False)
df15686547e4 6795 pkg fix should fix file modes for some preserved files
Shawn Walker <shawn.walker@oracle.com>
parents: 1795
diff changeset
  1809
                actual = lstat.st_gid
df15686547e4 6795 pkg fix should fix file modes for some preserved files
Shawn Walker <shawn.walker@oracle.com>
parents: 1795
diff changeset
  1810
                self.assertEqual(expected, actual)
df15686547e4 6795 pkg fix should fix file modes for some preserved files
Shawn Walker <shawn.walker@oracle.com>
parents: 1795
diff changeset
  1811
df15686547e4 6795 pkg fix should fix file modes for some preserved files
Shawn Walker <shawn.walker@oracle.com>
parents: 1795
diff changeset
  1812
                # Verify mode.
df15686547e4 6795 pkg fix should fix file modes for some preserved files
Shawn Walker <shawn.walker@oracle.com>
parents: 1795
diff changeset
  1813
                expected = int(act.attrs["mode"], 8)
df15686547e4 6795 pkg fix should fix file modes for some preserved files
Shawn Walker <shawn.walker@oracle.com>
parents: 1795
diff changeset
  1814
                actual = stat.S_IMODE(lstat.st_mode)
df15686547e4 6795 pkg fix should fix file modes for some preserved files
Shawn Walker <shawn.walker@oracle.com>
parents: 1795
diff changeset
  1815
                self.assertEqual(expected, actual)
df15686547e4 6795 pkg fix should fix file modes for some preserved files
Shawn Walker <shawn.walker@oracle.com>
parents: 1795
diff changeset
  1816
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1817
        def validate_html_file(self, fname, exit=0, comment="",
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1818
            options="-quiet -utf8"):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1819
                cmdline = "tidy %s %s" % (options, fname)
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1970
diff changeset
  1820
                return self.cmdline_run(cmdline, comment=comment,
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1970
diff changeset
  1821
                    coverage=False, exit=exit)
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1822
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1823
        def create_repo(self, repodir, properties=EmptyDict, version=None):
1895
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1824
                """ Convenience routine to help subclasses create a package
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1825
                    repository.  Returns a pkg.server.repository.Repository
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1826
                    object. """
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1827
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1828
                # Note that this must be deferred until after PYTHONPATH
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1829
                # is set up.
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1830
                import pkg.server.repository as sr
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1831
                try:
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1832
                        repo = sr.repository_create(repodir,
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1833
                            properties=properties, version=version)
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1834
                        self.debug("created repository %s" % repodir)
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1835
                except sr.RepositoryExistsError:
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1836
                        # Already exists.
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1837
                        repo = sr.Repository(root=repodir,
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1838
                            properties=properties)
1895
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1839
                return repo
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1840
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
  1841
        def get_repo(self, repodir, read_only=False):
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
  1842
                """ Convenience routine to help subclasses retrieve a
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
  1843
                    pkg.server.repository.Repository object for a given
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
  1844
                    path. """
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
  1845
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
  1846
                # Note that this must be deferred until after PYTHONPATH
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
  1847
                # is set up.
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
  1848
                import pkg.server.repository as sr
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1849
                return sr.Repository(read_only=read_only, root=repodir)
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1949
diff changeset
  1850
1895
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1851
        def prep_depot(self, port, repodir, logpath, refresh_index=False,
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1852
            debug_features=EmptyI, properties=EmptyI, start=False):
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1853
                """ Convenience routine to help subclasses prepare
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1854
                    depots.  Returns a depotcontroller. """
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1855
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1856
                # Note that this must be deferred until after PYTHONPATH
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1857
                # is set up.
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1858
                import pkg.depotcontroller as depotcontroller
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1859
1895
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1860
                self.debug("prep_depot: set depot port %d" % port)
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1861
                self.debug("prep_depot: set depot repository %s" % repodir)
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1862
                self.debug("prep_depot: set depot log to %s" % logpath)
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1863
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1864
                dc = depotcontroller.DepotController(
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1865
                    wrapper_start=self.coverage_cmd.split(),
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1866
                    env=self.coverage_env)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1867
                dc.set_depotd_path(g_proto_area + "/usr/lib/pkg.depotd")
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1868
                dc.set_depotd_content_root(g_proto_area + "/usr/share/lib/pkg")
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1869
                for f in debug_features:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1870
                        dc.set_debug_feature(f)
1895
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1871
                dc.set_repodir(repodir)
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1872
                dc.set_logpath(logpath)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1873
                dc.set_port(port)
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1730
diff changeset
  1874
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1875
                for section in properties:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1876
                        for prop, val in properties[section].iteritems():
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1877
                                dc.set_property(section, prop, val)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1878
                if refresh_index:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1879
                        dc.set_refresh_index()
1895
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1880
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1881
                if start:
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1882
                        # If the caller requested the depot be started, then let
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1883
                        # the depot process create the repository.
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1884
                        dc.start()
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1885
                        self.debug("depot on port %s started" % port)
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1886
                else:
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1887
                        # Otherwise, create the repository with the assumption
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1888
                        # that the caller wants that at the least, but doesn't
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1889
                        # need the depot server (yet).
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1890
                        self.create_repo(repodir, properties=properties)
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1891
                return dc
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1892
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1893
        def wait_repo(self, repodir, timeout=5.0):
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1894
                """Wait for the specified repository to complete its current
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1895
                operations before continuing."""
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1896
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1897
                check_interval = 0.20
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1898
                time.sleep(check_interval)
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1899
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1900
                begintime = time.time()
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1901
                ready = False
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1902
                while (time.time() - begintime) <= timeout:
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1903
                        status = self.get_repo(repodir).get_status()
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1904
                        rdata = status.get("repository", {})
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1905
                        repo_status = rdata.get("status", "")
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1906
                        if repo_status == "online":
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1907
                                for pubdata in rdata.get("publishers",
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1908
                                    {}).values():
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1909
                                        if pubdata.get("status", "") != "online":
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1910
                                                ready = False
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1911
                                                break
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1912
                                else:
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1913
                                        # All repository stores were ready.
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1914
                                        ready = True
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1915
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1916
                        if not ready:
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1917
                                time.sleep(check_interval)
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1918
                        else:
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1919
                                break
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1920
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1921
                if not ready:
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1922
                        raise RuntimeError("Repository readiness "
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1923
                            "timeout exceeded.")
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1924
1886
650a8de627ae 15777 pkgdep resolve should provide an option to only resolve against the manifests provided
Brock Pytlik <bpytlik@sun.com>
parents: 1859
diff changeset
  1925
        def _api_install(self, api_obj, pkg_list, **kwargs):
650a8de627ae 15777 pkgdep resolve should provide an option to only resolve against the manifests provided
Brock Pytlik <bpytlik@sun.com>
parents: 1859
diff changeset
  1926
                self.debug("install %s" % " ".join(pkg_list))
650a8de627ae 15777 pkgdep resolve should provide an option to only resolve against the manifests provided
Brock Pytlik <bpytlik@sun.com>
parents: 1859
diff changeset
  1927
                api_obj.plan_install(pkg_list, **kwargs)
650a8de627ae 15777 pkgdep resolve should provide an option to only resolve against the manifests provided
Brock Pytlik <bpytlik@sun.com>
parents: 1859
diff changeset
  1928
                self._api_finish(api_obj)
650a8de627ae 15777 pkgdep resolve should provide an option to only resolve against the manifests provided
Brock Pytlik <bpytlik@sun.com>
parents: 1859
diff changeset
  1929
650a8de627ae 15777 pkgdep resolve should provide an option to only resolve against the manifests provided
Brock Pytlik <bpytlik@sun.com>
parents: 1859
diff changeset
  1930
        def _api_uninstall(self, api_obj, pkg_list, **kwargs):
650a8de627ae 15777 pkgdep resolve should provide an option to only resolve against the manifests provided
Brock Pytlik <bpytlik@sun.com>
parents: 1859
diff changeset
  1931
                self.debug("uninstall %s" % " ".join(pkg_list))
650a8de627ae 15777 pkgdep resolve should provide an option to only resolve against the manifests provided
Brock Pytlik <bpytlik@sun.com>
parents: 1859
diff changeset
  1932
                api_obj.plan_uninstall(pkg_list, False, **kwargs)
650a8de627ae 15777 pkgdep resolve should provide an option to only resolve against the manifests provided
Brock Pytlik <bpytlik@sun.com>
parents: 1859
diff changeset
  1933
                self._api_finish(api_obj)
650a8de627ae 15777 pkgdep resolve should provide an option to only resolve against the manifests provided
Brock Pytlik <bpytlik@sun.com>
parents: 1859
diff changeset
  1934
650a8de627ae 15777 pkgdep resolve should provide an option to only resolve against the manifests provided
Brock Pytlik <bpytlik@sun.com>
parents: 1859
diff changeset
  1935
        def _api_image_update(self, api_obj, **kwargs):
2089
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2085
diff changeset
  1936
                self.debug("planning update")
2092
0ef66bf272d3 16852 pkg should look at its image for certs if active image lacks certs
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2089
diff changeset
  1937
                api_obj.plan_update_all(**kwargs)
1886
650a8de627ae 15777 pkgdep resolve should provide an option to only resolve against the manifests provided
Brock Pytlik <bpytlik@sun.com>
parents: 1859
diff changeset
  1938
                self._api_finish(api_obj)
650a8de627ae 15777 pkgdep resolve should provide an option to only resolve against the manifests provided
Brock Pytlik <bpytlik@sun.com>
parents: 1859
diff changeset
  1939
650a8de627ae 15777 pkgdep resolve should provide an option to only resolve against the manifests provided
Brock Pytlik <bpytlik@sun.com>
parents: 1859
diff changeset
  1940
        def _api_finish(self, api_obj):
650a8de627ae 15777 pkgdep resolve should provide an option to only resolve against the manifests provided
Brock Pytlik <bpytlik@sun.com>
parents: 1859
diff changeset
  1941
                api_obj.prepare()
650a8de627ae 15777 pkgdep resolve should provide an option to only resolve against the manifests provided
Brock Pytlik <bpytlik@sun.com>
parents: 1859
diff changeset
  1942
                api_obj.execute_plan()
650a8de627ae 15777 pkgdep resolve should provide an option to only resolve against the manifests provided
Brock Pytlik <bpytlik@sun.com>
parents: 1859
diff changeset
  1943
                api_obj.reset()
650a8de627ae 15777 pkgdep resolve should provide an option to only resolve against the manifests provided
Brock Pytlik <bpytlik@sun.com>
parents: 1859
diff changeset
  1944
1895
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1945
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1946
class ManyDepotTestCase(CliTestCase):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1947
1895
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1948
        def __init__(self, methodName="runTest"):
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1949
                super(ManyDepotTestCase, self).__init__(methodName)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1950
                self.dcs = {}
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1951
1895
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1952
        def setUp(self, publishers, debug_features=EmptyI, start_depots=False):
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1953
                CliTestCase.setUp(self)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1954
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1955
                self.debug("setup: %s" % self.id())
1895
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1956
                self.debug("creating %d repo(s)" % len(publishers))
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1957
                self.debug("publishers: %s" % publishers)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1958
                self.debug("debug_features: %s" % list(debug_features))
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1959
                self.dcs = {}
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1960
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1961
                for n, pub in enumerate(publishers):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1962
                        i = n + 1
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1963
                        testdir = os.path.join(self.test_root)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1964
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1965
                        try:
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1966
                                os.makedirs(testdir, 0755)
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1967
                        except OSError, e:
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1968
                                if e.errno != errno.EEXIST:
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1969
                                        raise e
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1970
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1971
                        depot_logfile = os.path.join(testdir,
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1972
                            "depot_logfile%d" % i)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1973
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1974
                        props = { "publisher": { "prefix": pub } }
1895
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1975
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1976
                        # We pick an arbitrary base port.  This could be more
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1977
                        # automated in the future.
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  1978
                        repodir = os.path.join(testdir, "repo_contents%d" % i)
1895
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1979
                        self.dcs[i] = self.prep_depot(12000 + i, repodir,
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1980
                            depot_logfile, debug_features=debug_features,
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  1981
                            properties=props, start=start_depots)
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1982
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1983
        def check_traceback(self, logpath):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1984
                """ Scan logpath looking for tracebacks.
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1985
                    Raise a DepotTracebackException if one is seen.
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1986
                """
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1987
                self.debug("check for depot tracebacks in %s" % logpath)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1988
                logfile = open(logpath, "r")
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1989
                output = logfile.read()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1990
                for line in output.splitlines():
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1991
                        if line.find("Traceback") > -1:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1992
                                raise DepotTracebackException(logpath, output)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1993
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1994
        def restart_depots(self):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1995
                self.debug("restarting %d depot(s)" % len(self.dcs))
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1996
                for i in sorted(self.dcs.keys()):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1997
                        dc = self.dcs[i]
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1998
                        self.debug("stopping depot at url: %s" % dc.get_depot_url())
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  1999
                        dc.stop()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2000
                        self.debug("starting depot at url: %s" % dc.get_depot_url())
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2001
                        dc.start()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2002
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2003
        def killall_sighandler(self, signum, frame):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2004
                print >> sys.stderr, \
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2005
                    "Ctrl-C: I'm killing depots, please wait.\n"
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2006
                print self
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2007
                self.signalled = True
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2008
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2009
        def killalldepots(self):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2010
                self.signalled = False
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2011
                self.debug("killalldepots: %s" % self.id())
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2012
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2013
                oldhdlr = signal.signal(signal.SIGINT, self.killall_sighandler)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2014
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2015
                try:
1895
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  2016
                        check_dc = []
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2017
                        for i in sorted(self.dcs.keys()):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2018
                                dc = self.dcs[i]
1895
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  2019
                                if not dc.started:
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  2020
                                        continue
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  2021
                                check_dc.append(dc)
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  2022
                                path = dc.get_repodir()
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2023
                                self.debug("stopping depot at url: %s, %s" % \
1895
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  2024
                                    (dc.get_depot_url(), path))
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2025
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2026
                                status = 0
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2027
                                try:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2028
                                        status = dc.kill()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2029
                                except Exception:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2030
                                        pass
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2031
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2032
                                if status:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2033
                                        self.debug("depot: %s" % status)
1895
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  2034
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  2035
                        for dc in check_dc:
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2036
                                try:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2037
                                        self.check_traceback(dc.get_logpath())
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2038
                                except Exception:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2039
                                        pass
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2040
                finally:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2041
                        signal.signal(signal.SIGINT, oldhdlr)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2042
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2043
                self.dcs = {}
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2044
                if self.signalled:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2045
                        raise KeyboardInterrupt("Ctrl-C while killing depots.")
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2046
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2047
        def tearDown(self):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2048
                self.debug("ManyDepotTestCase.tearDown: %s" % self.id())
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2049
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2050
                self.killalldepots()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2051
                CliTestCase.tearDown(self)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2052
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2053
        def run(self, result=None):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2054
                if result is None:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2055
                        result = self.defaultTestResult()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2056
                CliTestCase.run(self, result)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2057
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2058
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2059
class SingleDepotTestCase(ManyDepotTestCase):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2060
1895
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  2061
        def setUp(self, debug_features=EmptyI, publisher="test",
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  2062
            start_depot=False):
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2063
                ManyDepotTestCase.setUp(self, [publisher],
1895
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  2064
                    debug_features=debug_features, start_depots=start_depot)
2092
0ef66bf272d3 16852 pkg should look at its image for certs if active image lacks certs
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2089
diff changeset
  2065
                self.backup_img_path = None
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2066
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2067
        def __get_dc(self):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2068
                if self.dcs:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2069
                        return self.dcs[1]
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2070
                else:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2071
                        return None
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2072
1895
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  2073
        @property
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  2074
        def durl(self):
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  2075
                return self.dc.get_depot_url()
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  2076
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  2077
        @property
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  2078
        def rurl(self):
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  2079
                return self.dc.get_repo_url()
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  2080
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2081
        # dc is a readonly property which is an alias for self.dcs[1],
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2082
        # for convenience of writing test cases.
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2083
        dc = property(fget=__get_dc)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2084
2092
0ef66bf272d3 16852 pkg should look at its image for certs if active image lacks certs
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2089
diff changeset
  2085
        def create_sub_image(self, repourl, prefix="test", variants=EmptyDict):
0ef66bf272d3 16852 pkg should look at its image for certs if active image lacks certs
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2089
diff changeset
  2086
                if not self.backup_img_path:
0ef66bf272d3 16852 pkg should look at its image for certs if active image lacks certs
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2089
diff changeset
  2087
                        self.backup_img_path = self.img_path
0ef66bf272d3 16852 pkg should look at its image for certs if active image lacks certs
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2089
diff changeset
  2088
                self.image_set(os.path.join(self.img_path, "sub"))
0ef66bf272d3 16852 pkg should look at its image for certs if active image lacks certs
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2089
diff changeset
  2089
                self.image_create(repourl, prefix, variants, destroy=False)
0ef66bf272d3 16852 pkg should look at its image for certs if active image lacks certs
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2089
diff changeset
  2090
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2091
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2092
class SingleDepotTestCaseCorruptImage(SingleDepotTestCase):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2093
        """ A class which allows manipulation of the image directory that
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2094
        SingleDepotTestCase creates. Specifically, it supports removing one
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2095
        or more of the files or subdirectories inside an image (publisher,
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2096
        cfg_cache, etc...) in a controlled way.
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2097
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2098
        To add a new directory or file to be corrupted, it will be necessary
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2099
        to update corrupt_image_create to recognize a new option in config
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2100
        and perform the appropriate action (removing the directory or file
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2101
        for example).
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2102
        """
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2103
1895
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  2104
        def setUp(self, debug_features=EmptyI, publisher="test",
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  2105
            start_depot=False):
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2106
                SingleDepotTestCase.setUp(self, debug_features=debug_features,
1895
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1890
diff changeset
  2107
                    publisher=publisher, start_depot=start_depot)
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2108
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2109
        def tearDown(self):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2110
                self.__uncorrupt_img_path()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2111
                SingleDepotTestCase.tearDown(self)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2112
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2113
        def __uncorrupt_img_path(self):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2114
                """ Function which restores the img_path back to the original
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2115
                level. """
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2116
                if self.backup_img_path:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2117
                        self.img_path = self.backup_img_path
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2118
2092
0ef66bf272d3 16852 pkg should look at its image for certs if active image lacks certs
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2089
diff changeset
  2119
        def corrupt_image_create(self, repourl, config, subdirs, prefix="test",
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2120
            destroy = True):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2121
                """ Creates two levels of directories under the original image
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2122
                directory. In the first level (called bad), it builds a "corrupt
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2123
                image" which means it builds subdirectories the subdirectories
2158
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
  2124
                specified by subdirs (essentially determining whether a user
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2125
                image or a full image will be built). It populates these
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2126
                subdirectories with a partial image directory stucture as
2158
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
  2127
                specified by config. As another subdirectory of bad, it
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2128
                creates a subdirectory called final which represents the
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2129
                directory the command was actually run from (which is why
2092
0ef66bf272d3 16852 pkg should look at its image for certs if active image lacks certs
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2089
diff changeset
  2130
                img_path is set to that location). Existing image destruction
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2131
                was made optional to allow testing of two images installed next
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2132
                to each other (a user and full image created in the same
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2133
                directory for example). """
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2134
                if not self.backup_img_path:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2135
                        self.backup_img_path = self.img_path
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2136
                self.img_path = os.path.join(self.img_path, "bad")
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2137
                assert self.img_path and self.img_path != "/"
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2138
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2139
                if destroy:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2140
                        self.image_destroy()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2141
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2142
                for s in subdirs:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2143
                        if s == "var/pkg":
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2144
                                cmdline = "pkg image-create -F -p %s=%s %s" % \
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2145
                                    (prefix, repourl, self.img_path)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2146
                        elif s == ".org.opensolaris,pkg":
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2147
                                cmdline = "pkg image-create -U -p %s=%s %s" % \
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2148
                                    (prefix, repourl, self.img_path)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2149
                        else:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2150
                                raise RuntimeError("Got unknown subdir option:"
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2151
                                    "%s\n" % s)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2152
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2153
                        self.debugcmd(cmdline)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2154
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2155
                        # Run the command to actually create a good image
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  2156
                        p = subprocess.Popen(cmdline, shell=True,
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  2157
                                             stdout=subprocess.PIPE,
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  2158
                                             stderr=subprocess.STDOUT)
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2159
                        output = p.stdout.read()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2160
                        retcode = p.wait()
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2161
                        self.debugresult(retcode, 0, output)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2162
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2163
                        if retcode == 99:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2164
                                raise TracebackException(cmdline, output)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2165
                        if retcode != 0:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2166
                                raise UnexpectedExitCodeException(cmdline, 0,
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2167
                                    retcode, output)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2168
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2169
                        tmpDir = os.path.join(self.img_path, s)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2170
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2171
                        # This is where the actual corruption of the
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2172
                        # image takes place. A normal image was created
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2173
                        # above and this goes in and removes critical
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2174
                        # directories and files.
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2175
                        if "publisher_absent" in config or \
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2176
                           "publisher_empty" in config:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2177
                                shutil.rmtree(os.path.join(tmpDir, "publisher"))
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2178
                        if "known_absent" in config or \
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2179
                           "known_empty" in config:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2180
                                shutil.rmtree(os.path.join(tmpDir, "state",
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2181
                                    "known"))
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2182
                        if "known_empty" in config:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2183
                                os.mkdir(os.path.join(tmpDir, "state", "known"))
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2184
                        if "publisher_empty" in config:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2185
                                os.mkdir(os.path.join(tmpDir, "publisher"))
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2186
                        if "cfg_cache_absent" in config:
2144
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2097
diff changeset
  2187
                                os.remove(os.path.join(tmpDir, "pkg5.image"))
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2188
                        if "index_absent" in config:
2144
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2097
diff changeset
  2189
                                shutil.rmtree(os.path.join(tmpDir, "cache",
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2097
diff changeset
  2190
                                    "index"))
2092
0ef66bf272d3 16852 pkg should look at its image for certs if active image lacks certs
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2089
diff changeset
  2191
                shutil.copy("%s/usr/bin/pkg" % g_proto_area,
0ef66bf272d3 16852 pkg should look at its image for certs if active image lacks certs
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2089
diff changeset
  2192
                    os.path.join(self.img_path, "pkg"))
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2193
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2194
                # Make find root start at final. (See the doc string for
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2195
                # more explanation.)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2196
                cmd_path = os.path.join(self.img_path, "final")
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2197
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2198
                os.mkdir(cmd_path)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2199
                return cmd_path
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2200
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2201
def eval_assert_raises(ex_type, eval_ex_func, func, *args):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2202
        try:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2203
                func(*args)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2204
        except ex_type, e:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2205
                print str(e)
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2206
                if not eval_ex_func(e):
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2207
                        raise
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2208
        else:
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1516
diff changeset
  2209
                raise RuntimeError("Function did not raise exception.")