xref: /onnv-gate/usr/src/tools/onbld/Checks/Rti.py (revision 9920:9a117fecafb3)
17078Smjnelson#! /usr/bin/python
27078Smjnelson#
37078Smjnelson# CDDL HEADER START
47078Smjnelson#
57078Smjnelson# The contents of this file are subject to the terms of the
67078Smjnelson# Common Development and Distribution License (the "License").
77078Smjnelson# You may not use this file except in compliance with the License.
87078Smjnelson#
97078Smjnelson# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107078Smjnelson# or http://www.opensolaris.org/os/licensing.
117078Smjnelson# See the License for the specific language governing permissions
127078Smjnelson# and limitations under the License.
137078Smjnelson#
147078Smjnelson# When distributing Covered Code, include this CDDL HEADER in each
157078Smjnelson# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167078Smjnelson# If applicable, add the following below this CDDL HEADER, with the
177078Smjnelson# fields enclosed by brackets "[]" replaced with your own identifying
187078Smjnelson# information: Portions Copyright [yyyy] [name of copyright owner]
197078Smjnelson#
207078Smjnelson# CDDL HEADER END
217078Smjnelson#
227078Smjnelson
237078Smjnelson#
24*8674SPeter.Dennis@Sun.COM# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
257078Smjnelson# Use is subject to license terms.
267078Smjnelson#
277078Smjnelson
287078Smjnelson#
297078Smjnelson# Check on RTI status for bug IDs passed.
307078Smjnelson#
317078Smjnelson# How we obtain the bug IDs will vary per SCM.
327078Smjnelson# 	- For Teamware, we want to check the active list comments.
337078Smjnelson#	- For Mercurial, we can check the incoming changegroup (via the
347078Smjnelson#	  pretxnchangegroup hook) and abort if necessary
357078Smjnelson#
367078Smjnelson# This module is implemented as a generic checking module given a list of
377078Smjnelson# bug IDs.  It can then be wrapped or hooked into whatever SCM with an
387078Smjnelson# SCM-specific hook to parse and pass the requisite bug IDs
397078Smjnelson#
407078Smjnelson
417078Smjnelsonimport re, os, sys
427078Smjnelsonfrom onbld.Checks.DbLookups import Rti, RtiException, RtiNotFound, RtiOffSwan
437078Smjnelson
44*8674SPeter.Dennis@Sun.COMopensolarisGateRe = re.compile(r'.*osol[0-9]+-sust$')
457078SmjnelsonpatchGateRe = re.compile(r'.*-patch.*')
467078SmjnelsontestGateRe = re.compile(r'.*-(stc2|test)$')
477078Smjnelson
487078Smjnelsondef rti(bugids, gatePath=None, consolidation=None,
497078Smjnelson	output=sys.stderr):
507078Smjnelson	"""Return True iff each of the specified bugids has an approved RTI.
517078Smjnelson
527078Smjnelson	Required argument:
537078Smjnelson	bugids:	list of seven-digit bug ids
547078Smjnelson
557078Smjnelson	Keyword arguments, used to limit the scope of the RTI search:
567078Smjnelson	gatePath: fully qualified path to gate
577078Smjnelson	consolidation: name of the consolidation
587078Smjnelson	"""
597078Smjnelson
607078Smjnelson	rtiType = "MarketingRelease"
617078Smjnelson	gateType = "MarketingRelease"
627078Smjnelson
637078Smjnelson	# Check to see if we were given a gate to lookup with
647078Smjnelson	if gatePath != None:
657298SMark.J.Nelson@Sun.COM
667298SMark.J.Nelson@Sun.COM		#
677298SMark.J.Nelson@Sun.COM		# The gate name should be the last component of the gate path,
687298SMark.J.Nelson@Sun.COM		# no matter how it's accessed.
697298SMark.J.Nelson@Sun.COM		#
707298SMark.J.Nelson@Sun.COM		# We make a special case for "closed," and check to see if it
717298SMark.J.Nelson@Sun.COM		# appears to be the "usr/closed" portion of a nested repository.
727298SMark.J.Nelson@Sun.COM		# In that case, we really want the parent repository name.
737298SMark.J.Nelson@Sun.COM		#
747298SMark.J.Nelson@Sun.COM		gatePath = gatePath.rstrip(os.path.sep).split(os.path.sep)
757298SMark.J.Nelson@Sun.COM		gateName = gatePath[-1]
767298SMark.J.Nelson@Sun.COM		try:
777298SMark.J.Nelson@Sun.COM			if gatePath[-2:] == ['usr', 'closed']:
787298SMark.J.Nelson@Sun.COM				gateName = gatePath[-3]
797298SMark.J.Nelson@Sun.COM		except IndexError:
807298SMark.J.Nelson@Sun.COM			pass
817078Smjnelson
82*8674SPeter.Dennis@Sun.COM		# Is this an OpenSolaris gate?
83*8674SPeter.Dennis@Sun.COM		if opensolarisGateRe.search(gateName):
84*8674SPeter.Dennis@Sun.COM			rtiType = "OpenSolaris"
85*8674SPeter.Dennis@Sun.COM			gateType = "OpenSolaris"
86*8674SPeter.Dennis@Sun.COM
877078Smjnelson		# Is this a patch gate?
887298SMark.J.Nelson@Sun.COM		if patchGateRe.search(gateName):
897078Smjnelson			rtiType = "Patch"
907078Smjnelson			gateType = "Patch"
917078Smjnelson
927078Smjnelson		# Is this a test gate?
937298SMark.J.Nelson@Sun.COM		if testGateRe.search(gateName):
947078Smjnelson			rtiType = "RTI"
957078Smjnelson			gateType = "RTI"
967078Smjnelson	else:
977078Smjnelson		gateName = None
987078Smjnelson
997078Smjnelson	# Query RTI if there's a gate
1007078Smjnelson	# Check the RTIs, caching them in the 'rtis' dictionary
1017078Smjnelson	# We do our error checking/handling here
1027078Smjnelson	rtis = {}
1037078Smjnelson	badRtis = []
1047078Smjnelson	for cr in bugids:
1057078Smjnelson		# If we don't already have an Rti object for this cr cached,
1067078Smjnelson		# then go create/query it
1077078Smjnelson		if cr not in rtis.keys() + badRtis:
1087078Smjnelson			try:
1097078Smjnelson				rtis[cr] = Rti(cr, gateName, consolidation)
1107078Smjnelson			except RtiOffSwan, e:
1117078Smjnelson				output.write("%s\n" % e)
1127078Smjnelson				return False
1137078Smjnelson			except RtiException, e:
1147078Smjnelson				output.write("%s\n" % e)
1157078Smjnelson				badRtis.append(cr)
1167078Smjnelson				continue
1177078Smjnelson
1187078Smjnelson		crRti = rtis[cr]
1197078Smjnelson
1207078Smjnelson		# If we've reached this point, then the Rti query succeeded,
1217078Smjnelson		# and we didn't get an error back from webrti.  There is still
1227078Smjnelson		# some sanity checking to be done, however
1237078Smjnelson		rtiNumber = crRti.rtiNumber()
1247078Smjnelson		rtiType = crRti.rtiType()
1257078Smjnelson
1267078Smjnelson		# check to make sure the RTI type matches the gate type
1277764SJohn.Sonnenschein@Sun.COM		if not gateType in rtiType:
1287764SJohn.Sonnenschein@Sun.COM			message = "Error: for bug " + cr
1297764SJohn.Sonnenschein@Sun.COM			for each in rtiNumber:
1307765SJohn.Sonnenschein@Sun.COM				message += " the RTI " +  each + "  is of "
1317764SJohn.Sonnenschein@Sun.COM				message += rtiType[rtiNumber.index(each)] + " type "
1327764SJohn.Sonnenschein@Sun.COM			message += "but the parent gate " + gateName + " is a "
1337764SJohn.Sonnenschein@Sun.COM			message += gateType + " gate.\n" + "A " + gateType
1347764SJohn.Sonnenschein@Sun.COM			message += " RTI must be submitted to putback bug " + cr + " to "
1357764SJohn.Sonnenschein@Sun.COM			message += gateName  + ". \n"
1367764SJohn.Sonnenschein@Sun.COM
1377764SJohn.Sonnenschein@Sun.COM			output.write( message )
1387078Smjnelson			badRtis.append(cr)
1397078Smjnelson			continue
1407078Smjnelson
1417078Smjnelson		if not crRti.accepted():
1427764SJohn.Sonnenschein@Sun.COM			for each in rtiNumber:
1437764SJohn.Sonnenschein@Sun.COM				message = "Error: RTI " + each + " for CR " + cr + " is not in "
1447778SJohn.Sonnenschein@Sun.COM				message += "the accepted state.\n"
1457778SJohn.Sonnenschein@Sun.COM				output.write(message)
1467078Smjnelson			badRtis.append(cr)
1477078Smjnelson			continue
1487078Smjnelson
1497078Smjnelson	if len(badRtis) > 0:
1507078Smjnelson		return False
1517078Smjnelson
1527078Smjnelson	return True
1537078Smjnelson
154