5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
24 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
29 # Check on RTI status for bug IDs passed.
31 # How we obtain the bug IDs will vary per SCM.
32 # - For Teamware, we want to check the active list comments.
33 # - For Mercurial, we can check the incoming changegroup (via the
34 # pretxnchangegroup hook) and abort if necessary
36 # This module is implemented as a generic checking module given a list of
37 # bug IDs. It can then be wrapped or hooked into whatever SCM with an
38 # SCM-specific hook to parse and pass the requisite bug IDs
42 from onbld
.Checks
.DbLookups
import Rti
, RtiException
, RtiNotFound
, RtiOffSwan
44 opensolarisGateRe
= re
.compile(r
'.*osol[0-9]+-sust$')
45 patchGateRe
= re
.compile(r
'.*-patch.*')
46 testGateRe
= re
.compile(r
'.*-(stc2|test)$')
48 def rti(bugids
, gatePath
=None, consolidation
=None,
50 """Return True iff each of the specified bugids has an approved RTI.
53 bugids: list of seven-digit bug ids
55 Keyword arguments, used to limit the scope of the RTI search:
56 gatePath: fully qualified path to gate
57 consolidation: name of the consolidation
60 rtiType
= "MarketingRelease"
61 gateType
= "MarketingRelease"
63 # Check to see if we were given a gate to lookup with
67 # The gate name should be the last component of the gate path,
68 # no matter how it's accessed.
70 # We make a special case for "closed," and check to see if it
71 # appears to be the "usr/closed" portion of a nested repository.
72 # In that case, we really want the parent repository name.
74 gatePath
= gatePath
.rstrip(os
.path
.sep
).split(os
.path
.sep
)
75 gateName
= gatePath
[-1]
77 if gatePath
[-2:] == ['usr', 'closed']:
78 gateName
= gatePath
[-3]
82 # Is this an OpenSolaris gate?
83 if opensolarisGateRe
.search(gateName
):
84 rtiType
= "OpenSolaris"
85 gateType
= "OpenSolaris"
87 # Is this a patch gate?
88 if patchGateRe
.search(gateName
):
92 # Is this a test gate?
93 if testGateRe
.search(gateName
):
99 # Query RTI if there's a gate
100 # Check the RTIs, caching them in the 'rtis' dictionary
101 # We do our error checking/handling here
105 # If we don't already have an Rti object for this cr cached,
106 # then go create/query it
107 if cr
not in rtis
.keys() + badRtis
:
109 rtis
[cr
] = Rti(cr
, gateName
, consolidation
)
110 except RtiOffSwan
, e
:
111 output
.write("%s\n" % e
)
113 except RtiException
, e
:
114 output
.write("%s\n" % e
)
120 # If we've reached this point, then the Rti query succeeded,
121 # and we didn't get an error back from webrti. There is still
122 # some sanity checking to be done, however
123 rtiNumber
= crRti
.rtiNumber()
124 rtiType
= crRti
.rtiType()
126 # check to make sure the RTI type matches the gate type
127 if not gateType
in rtiType
:
128 message
= "Error: for bug " + cr
129 for each
in rtiNumber
:
130 message
+= " the RTI " + each
+ " is of "
131 message
+= rtiType
[rtiNumber
.index(each
)] + " type "
132 message
+= "but the parent gate " + gateName
+ " is a "
133 message
+= gateType
+ " gate.\n" + "A " + gateType
134 message
+= " RTI must be submitted to putback bug " + cr
+ " to "
135 message
+= gateName
+ ". \n"
137 output
.write( message
)
141 if not crRti
.accepted():
142 for each
in rtiNumber
:
143 message
= "Error: RTI " + each
+ " for CR " + cr
+ " is not in "
144 message
+= "the accepted state.\n"
145 output
.write(message
)