CDash:Dart2AndCDashSubmission: Difference between revisions

From KitwarePublic
Jump to navigationJump to search
Line 102: Line 102:
   
   
  if not done:
  if not done:
   print "Problem submiting data"
   print "Problem summiting data"


== TriggerSiteDart2AndCDash.cgi ==
== TriggerSiteDart2AndCDash.cgi ==

Revision as of 15:16, 24 March 2008

If you are moving from Dart2 to CDash you may want to submit to both in parallel for a while before switching to solely CDash.

The following shows how to setup CTest to use a trigger script, which in turns does a submit to both Dart2 and CDash. The Dart2 submission uses XML-RPC, the CDash submission uses HTTP.

We configure CTest to use a trigger script:

SET (DROP_METHOD "http")
SET (DROP_SITE "mysite.org")
SET (DROP_LOCATION "/cgi-bin/HTTPUploadDartFile.cgi")
SET (TRIGGER_SITE "http://${DROP_SITE}/cgi-bin/TriggerSiteDart2AndCDash.cgi")

HTTPUploadDartFile.cgi

#!/usr/bin/env python
#
# Script that will upload files to specified directory on the server, where
# triggering script will find it.
#
# Installation:
#    Place this script in your cgi-bin area.
#    Change the variable "incoming_directory" to match your
#        installation.
###

import cgi
import re
import sys
import os
import string

print "Content-type: text/html"
print

done = 0

incoming_directory = '/srv/dart2/incoming'

form = cgi.FieldStorage()

# Debug
#try:
#  tmpfile = open("/tmp/http_upload_log_file.log", "w")
#  tmpfile.write(`form`)
#  tmpfile.close()
#except Exception: pass

FileData = ""
FileName = ""

# process form
if type(form.value) == type("foo"):
 if os.environ.has_key("QUERY_STRING"):
   dt = cgi.parse_qs(os.environ["QUERY_STRING"])
   if dt.has_key("FileName"):
     FileName = dt["FileName"][0]
   FileData = form.value
elif form.has_key("FileName"):
 FileName = form["FileName"].value
 if form.has_key("FileData"):
    FileData = "form"

# verify file specified
if not FileData or not FileName:
  print "Please send file. "
  print "FileName has to contain file name"
  print "FileData has to contain file content"
  print form
  sys.exit(0)

print "Received file: " + FileName

# check if valid file name
filename = re.sub("[/\\|:%%]", "_", FileName)
if re.match(".+___.+___[0-9]{8}-[0-9]{4}-(Experimental|Nightly|Continuous)___XML___(Update|Configure|Build|Test|Coverage|Purify).xml", filename):
  print "Correct file name"
else:
  print "Can only upload files with format:"
  print "<site>___<BuildType>___<TAG>-<TestType>___XML___<File>.xml"
  sys.exit(0)

# get the file data
file_lines = ""
if FileData == "form":
  fileitem = form["FileData"]
  if fileitem.file:
    file_lines = fileitem.file.read()
  else:
    print "Not a file"
else:
  file_lines = FileData

# write to a file on disk
if file_lines:
  file = open(incoming_directory + "/" + filename, "w")
  if not file:
    print "Cannot create file: %s/%s" % ( incoming_directory, filename )
    sys.exit(0)
  file.write(file_lines)
  file.close()
  print "Thank you for the file"
  done = 1

if not done:
  print "Problem summiting data"

TriggerSiteDart2AndCDash.cgi

#!/usr/bin/env python
#
# Script that will resubmit incoming testing results to
# Dart2 (via XMLRPC) and CDash (via HTTP).
#
# This scripts intended use is to allow the transition from
# Dart2 to CDash, but allowing both to be run in parallel.
#
###

import cgi
import cgitb; cgitb.enable(display=0, logdir="/tmp")

import sys
import os
import xmlrpclib
import put

def Trigger(dart2Url, cdashUrl, projectName, dropLocation):
	print "Content-Type: text/html"
	print

	form = cgi.FieldStorage()
	xmlfile = ""
	if form.has_key("xmlfile"):
		xmlfile = form["xmlfile"].value

	if not xmlfile:
		print "No submission file"
		sys.exit(1)

	ipfile = dropLocation + xmlfile

	try:
		dart2Server = xmlrpclib.ServerProxy(dart2Url + projectName + "/Command/")

		try:
			fp = open(ipfile)
			content = fp.read()
			bin = xmlrpclib.Binary(content)
			print "Server responded: [%s]" % dart2Server.Submit.put(bin)
			fp.close()
		except Exception, v:
			print "ERROR", v
			print "Unexpected error:", sys.exc_info()
	except:
		print "Problem submitting XML-RPC for the file: %s" % xmlfile

	try:
		cdashServer = cdashUrl + "CDash/submit.php?project=" + projectName

		f = open(ipfile, 'rb')
		put.putfile(f, cdashServer)
		f.close()
	except:
		print "Problem submitting HTTP for the file: %s" % xmlfile

	os.unlink(ipfile)


if __name__ == "__main__":
	# Ensure all paths have a trailing slash
	# Dart2 URL, CDash URL, project, incoming directory
	Trigger("http://localhost:8081/", "http://localhost/", "MyProject", "/srv/dart2/incoming/")

Put