Commit 0c96eda1 authored by aregimbe's avatar aregimbe

CI: add state handling

parent 8ca1c829
......@@ -25,6 +25,7 @@ import glob
import re
import unittest
import sys
import json
trace = False
......@@ -204,6 +205,31 @@ site:"+site+", stamp:"+stamp+", name:"+name+", project:"+project+".")
build_url += "buildid=" + buildid
return build_url
def GetBuildStatus(self, buildid = "" ):
"""
This function returns the status of a build id as a pair 'state' + 'errors'
"""
if ( buildid == "" ):
buildid = self.buildid
if ( buildid == "" ):
print( "Not enougth argument given to build Status")
return
full_url = self.url + "/api/v1/buildSummary.php?buildid=" + buildid
response = urllib.request.urlopen(full_url).read().decode()
full_status = json.loads(response)
state = "success"
if full_status["configure"]["nerrors"] or full_status["build"]["nerrors"] \
or full_status["test"]["nerrors"] or full_status["test"]["nfailed"]:
state = 'failed'
errors = ""
if full_status["configure"]["nerrors"]:
errors = "Errors occur during configure"
elif full_status["build"]["nerrors"]:
errors = "Errors occur during build"
elif full_status["test"]["nerrors"] or full_status["test"]["nfailed"]:
errors = "Errors occur during tests"
return ( state , errors)
"""
TODO :
documentation, header, test if it is possible.
......@@ -228,12 +254,13 @@ if __name__ == "__main__":
handler.GetBuildId()
# handler.buildid="1"
cdash_url = handler.GetBuildUrl()
( state , error ) = handler.GetBuildUrl()
if trace:
print ( "cdash_url is: " + cdash_url )
gitlab_url = "https://gitlab.orfeo-toolbox.org/api/v4/projects/"
gitlab_url += sys.argv[2] + "/statuses/" + sys.argv[1]
params = urllib.parse.urlencode({'name':'cdash:' + handler.site , 'state': 'success' ,\
'target_url' : cdash_url})
params = urllib.parse.urlencode({'name':'cdash:' + handler.site , 'state': state ,\
'target_url' : cdash_url , 'description' : error })
gitlab_request = urllib.request.Request(gitlab_url)
gitlab_request.add_header('PRIVATE-TOKEN' , sys.argv[4] )
res = urllib.request.urlopen(gitlab_request, data=params.encode('ascii'))
......
......@@ -48,5 +48,26 @@ class TestHandler(unittest.TestCase):
self.assertTrue( \
"https://cdash.orfeo-toolbox.org/buildSummary.php?buildid=1" == url)
def test_GetBuildStatus (self):
handler = cdash_handler.Handler()
# We need to test error in configure, build, test, and no error
# test buildid 720
(status , error) = handler.GetBuildStatus("720")
self.assertTrue( status == "failed")
self.assertTrue( error == "Errors occur during tests")
# configure buildid 352
(status , error) = handler.GetBuildStatus("352")
self.assertTrue( status == "failed")
self.assertTrue( error == "Errors occur during configure")
# build buildid 358
(status , error) = handler.GetBuildStatus("358")
self.assertTrue( status == "failed")
self.assertTrue( error == "Errors occur during build")
# passing buildid 373
(status , error) = handler.GetBuildStatus("373")
self.assertTrue( status == "success")
self.assertTrue( error == "")
if __name__ == '__main__':
unittest.main()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment