blob: 559968bd1cd3d487510fdaff43cc37ca42c5c40a [file] [log] [blame]
Richard Felkl14258e22018-06-28 12:42:34 +02001/**
2 *
3 * Test Drivetrain pipeline
4 *
5 * Expected parameters:
6 * COOKIECUTTER_TEMPLATE_CONTEXT Template context for CookieCutter
7 * SOURCE_MCP_VERSION MCP version to start with
8 * TARGET_MCP_VERSION MCP version to upgrade to
9 * FUNC_TEST_SETTINGS Settings for functional tests
Richard Felkl57eace42018-07-19 19:11:41 +020010 * ENVIRONMENT_IP IP of already deployed environment
Richard Felkl14258e22018-06-28 12:42:34 +020011 */
12
13
14common = new com.mirantis.mk.Common()
15salt = new com.mirantis.mk.Salt()
16test = new com.mirantis.mk.Test()
17python = new com.mirantis.mk.Python()
18
19pepperEnv = "pepperEnv"
20
21def setupPepperVirtualenv(path, url, creds) {
22 requirements = ['salt-pepper>=0.5.2,<0.5.4']
23 python.setupVirtualenv(path, 'python2', requirements, null, true, true)
24 rcFile = "${path}/pepperrc"
25 rc = """\
26[main]
27SALTAPI_EAUTH=pam
28SALTAPI_URL=${url}
29SALTAPI_USER=${creds.username}
30SALTAPI_PASS=${creds.password}
31"""
32 writeFile file: rcFile, text: rc
33 return rcFile
34}
35
36def runJobOnJenkins(jenkinsUrl, userName, password, jobName, parameters){
Richard Felkl055abae2018-07-26 14:41:15 +020037 def status = "null"
Richard Felkl14258e22018-06-28 12:42:34 +020038 def jenkinsDownCmd = "curl -OL ${jenkinsUrl}/jnlpJars/jenkins-cli.jar --output ./jenkins-cli.jar"
Richard Felkl055abae2018-07-26 14:41:15 +020039 def runJobFromSaltMasterCmd = "java -jar jenkins-cli.jar -s ${jenkinsUrl} -noKeyAuth -auth ${userName}:${password} build ${jobName} ${parameters} -w"
40 def waitJobFromSaltMasterCmd = "curl -s -X GET '${jenkinsUrl}/job/${jobName}/lastBuild/api/json?tree=result' --user ${userName}:${password} | jq -r '.result'"
Richard Felkl14258e22018-06-28 12:42:34 +020041 salt.cmdRun(pepperEnv, "I@salt:master", jenkinsDownCmd)
42 salt.cmdRun(pepperEnv, "I@salt:master", runJobFromSaltMasterCmd)
Richard Felkl055abae2018-07-26 14:41:15 +020043 while (status == "null" || status.contains("parse error")){
44 status = salt.cmdRun(pepperEnv, "I@salt:master", waitJobFromSaltMasterCmd, false)
45 status = status.get("return")[0].values()[0].trim()
46 println("The job ${jobName} result is $status")
47 if(status == "FAILURE"){
48 throw new Exception("The job ${jobName} result is FAILURE.")
49 }
50 sleep(10)
51 }
Richard Felkl14258e22018-06-28 12:42:34 +020052}
53
54timeout(time: 12, unit: 'HOURS') {
55 node("python") {
56 try {
57 def mcpEnvJob
58 def saltReturn
59 def saltCreds = [:]
Richard Felkl57eace42018-07-19 19:11:41 +020060 def mcpEnvJobIP
Richard Felkl14258e22018-06-28 12:42:34 +020061
Richard Felkl57eace42018-07-19 19:11:41 +020062 if(ENVIRONMENT_IP == ""){
63 stage('Trigger deploy job') {
64 mcpEnvJob = build(job: "create-mcp-env", parameters: [
65 [$class: 'StringParameterValue', name: 'OS_AZ', value: 'mcp-mk'],
66 [$class: 'StringParameterValue', name: 'OS_PROJECT_NAME', value: 'mcp-mk'],
67 [$class: 'StringParameterValue', name: 'STACK_NAME', value: 'jenkins-drivetrain-test-' + currentBuild.number],
68 [$class: 'StringParameterValue', name: 'STACK_INSTALL', value: 'core,cicd'],
69 [$class: 'BooleanParameterValue', name: 'STACK_FULL', value: false],
70 [$class: 'BooleanParameterValue', name: 'RUN_TESTS', value: false],
71 [$class: 'TextParameterValue', name: 'COOKIECUTTER_TEMPLATE_CONTEXT', value: COOKIECUTTER_TEMPLATE_CONTEXT]
72 ])
73 }
74
75 def mcpEnvJobDesc = mcpEnvJob.getDescription().tokenize(" ")
76 mcpEnvJobIP = mcpEnvJobDesc[2]
77 }else{
78 mcpEnvJobIP = ENVIRONMENT_IP
Richard Felkl14258e22018-06-28 12:42:34 +020079 }
80
Richard Felkl14258e22018-06-28 12:42:34 +020081 def saltMasterUrl = "http://${mcpEnvJobIP}:6969"
82 def script = "println(com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials(com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials.class,jenkins.model.Jenkins.instance).findAll {cred -> cred.id == 'salt'}[0].password)"
83 def saltPasswd = sh(returnStdout: true, script: "curl -d \"script=${script}\" --user admin:r00tme http://${mcpEnvJobIP}:8081/scriptText")
84 saltPasswd = saltPasswd.trim()
85 saltCreds.put("username", "salt")
86 saltCreds.put("password", saltPasswd)
87 setupPepperVirtualenv(pepperEnv, saltMasterUrl, saltCreds)
88 saltReturn = salt.getPillar(pepperEnv, 'I@jenkins:client and not I@salt:master', '_param:openldap_admin_password')
89 def stackCicdPassword = saltReturn.get("return")[0].values()[0]
90 saltReturn = salt.getPillar(pepperEnv, 'I@jenkins:client and not I@salt:master', 'jenkins:client:master:host')
91 def stackCicdAddr = saltReturn.get("return")[0].values()[0]
92 def jenkinsUrl = "http://${stackCicdAddr}:8081"
93
94 stage('Run CVP before upgrade') {
Richard Felkl158c6292018-07-25 15:25:17 +020095 runJobOnJenkins(jenkinsUrl, "admin", stackCicdPassword, "cvp-sanity", "-p TESTS_SET=cvp-sanity-checks/cvp_checks/tests/test_drivetrain.py -p TESTS_SETTINGS='drivetrain_version=\"${SOURCE_MCP_VERSION}\"'")
Richard Felkl662cac52018-07-19 19:02:03 +020096 //runJobOnJenkins(jenkinsUrl, "admin", stackCicdPassword, "cvp-dt-func", "-p SETTINGS=${FUNC_TEST_SETTINGS}")
Richard Felkl14258e22018-06-28 12:42:34 +020097 }
98
99 stage('Run Upgrade on DriveTrain') {
Richard Felkl662cac52018-07-19 19:02:03 +0200100 runJobOnJenkins(jenkinsUrl, "admin", stackCicdPassword, "upgrade-mcp-release", "-p MCP_VERSION=${TARGET_MCP_VERSION}")
Richard Felkl14258e22018-06-28 12:42:34 +0200101 }
102
103 stage('Run CVP after upgrade') {
Richard Felkl158c6292018-07-25 15:25:17 +0200104 runJobOnJenkins(jenkinsUrl, "admin", stackCicdPassword, "cvp-sanity", "-p TESTS_SET=cvp-sanity-checks/cvp_checks/tests/test_drivetrain.py -p TESTS_SETTINGS='drivetrain_version=\"${TARGET_MCP_VERSION}\"'")
Richard Felkl662cac52018-07-19 19:02:03 +0200105 //runJobOnJenkins(jenkinsUrl, "admin", stackCicdPassword, "cvp-dt-func", "-p SETTINGS=${FUNC_TEST_SETTINGS}")
Richard Felkl14258e22018-06-28 12:42:34 +0200106 }
107
108 } catch (Throwable e) {
109 currentBuild.result = 'FAILURE'
110 throw e
111 }
112 }
113}