blob: fe7c87cc9a0f0f465605fc17122ce78c6c17a8e9 [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 Felkl663ee822018-07-26 15:23:32 +020011 * DELETE_STACK Option to delete Heat Stack
Richard Felkl14258e22018-06-28 12:42:34 +020012 */
13
14
15common = new com.mirantis.mk.Common()
16salt = new com.mirantis.mk.Salt()
17test = new com.mirantis.mk.Test()
18python = new com.mirantis.mk.Python()
19
20pepperEnv = "pepperEnv"
21
22def setupPepperVirtualenv(path, url, creds) {
23 requirements = ['salt-pepper>=0.5.2,<0.5.4']
24 python.setupVirtualenv(path, 'python2', requirements, null, true, true)
25 rcFile = "${path}/pepperrc"
26 rc = """\
27[main]
28SALTAPI_EAUTH=pam
29SALTAPI_URL=${url}
30SALTAPI_USER=${creds.username}
31SALTAPI_PASS=${creds.password}
32"""
33 writeFile file: rcFile, text: rc
34 return rcFile
35}
36
37def runJobOnJenkins(jenkinsUrl, userName, password, jobName, parameters){
Richard Felkl055abae2018-07-26 14:41:15 +020038 def status = "null"
Richard Felkl14258e22018-06-28 12:42:34 +020039 def jenkinsDownCmd = "curl -OL ${jenkinsUrl}/jnlpJars/jenkins-cli.jar --output ./jenkins-cli.jar"
Richard Felkl055abae2018-07-26 14:41:15 +020040 def runJobFromSaltMasterCmd = "java -jar jenkins-cli.jar -s ${jenkinsUrl} -noKeyAuth -auth ${userName}:${password} build ${jobName} ${parameters} -w"
41 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 +020042 salt.cmdRun(pepperEnv, "I@salt:master", jenkinsDownCmd)
43 salt.cmdRun(pepperEnv, "I@salt:master", runJobFromSaltMasterCmd)
Richard Felkl055abae2018-07-26 14:41:15 +020044 while (status == "null" || status.contains("parse error")){
45 status = salt.cmdRun(pepperEnv, "I@salt:master", waitJobFromSaltMasterCmd, false)
46 status = status.get("return")[0].values()[0].trim()
47 println("The job ${jobName} result is $status")
48 if(status == "FAILURE"){
49 throw new Exception("The job ${jobName} result is FAILURE.")
50 }
51 sleep(10)
52 }
Richard Felkl14258e22018-06-28 12:42:34 +020053}
54
55timeout(time: 12, unit: 'HOURS') {
56 node("python") {
57 try {
58 def mcpEnvJob
59 def saltReturn
60 def saltCreds = [:]
Richard Felkl57eace42018-07-19 19:11:41 +020061 def mcpEnvJobIP
Richard Felkl14258e22018-06-28 12:42:34 +020062
Richard Felkl663ee822018-07-26 15:23:32 +020063 stage('Trigger deploy job') {
64 if(ENVIRONMENT_IP == ""){
Richard Felkl57eace42018-07-19 19:11:41 +020065 mcpEnvJob = build(job: "create-mcp-env", parameters: [
66 [$class: 'StringParameterValue', name: 'OS_AZ', value: 'mcp-mk'],
67 [$class: 'StringParameterValue', name: 'OS_PROJECT_NAME', value: 'mcp-mk'],
68 [$class: 'StringParameterValue', name: 'STACK_NAME', value: 'jenkins-drivetrain-test-' + currentBuild.number],
69 [$class: 'StringParameterValue', name: 'STACK_INSTALL', value: 'core,cicd'],
70 [$class: 'BooleanParameterValue', name: 'STACK_FULL', value: false],
71 [$class: 'BooleanParameterValue', name: 'RUN_TESTS', value: false],
72 [$class: 'TextParameterValue', name: 'COOKIECUTTER_TEMPLATE_CONTEXT', value: COOKIECUTTER_TEMPLATE_CONTEXT]
73 ])
Richard Felkl663ee822018-07-26 15:23:32 +020074 def mcpEnvJobDesc = mcpEnvJob.getDescription().tokenize(" ")
75 mcpEnvJobIP = mcpEnvJobDesc[2]
76 }else{
77 mcpEnvJobIP = ENVIRONMENT_IP
Richard Felkl57eace42018-07-19 19:11:41 +020078 }
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
Richard Felkl558b51d2018-07-30 11:50:51 +020094 salt.cmdRun(pepperEnv, "I@salt:master", 'cd /srv/salt/reclass && echo -e ".gitignore\\nclasses/service/\\nnodes/_generated/" >> .gitignore')
95 salt.cmdRun(pepperEnv, "I@salt:master", "cd /srv/salt/reclass && git reset --hard")
96 salt.cmdRun(pepperEnv, "I@salt:master", "cd /srv/salt/reclass/classes/system && git reset --hard && git clean -fd")
97
Richard Felklca5ceb42018-07-31 09:20:12 +020098 //TODO: Temporary fix. Remove the line below after 2a3757a (reclass-system) is in stable tag.
99 salt.cmdRun(pepperEnv, "cid*", "mkdir /etc/aptly", false)
100
Richard Felkl14258e22018-06-28 12:42:34 +0200101 stage('Run CVP before upgrade') {
Richard Felkl158c6292018-07-25 15:25:17 +0200102 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 Felklca5ceb42018-07-31 09:20:12 +0200103 //TODO: Enable functional tests after they become implemented.
Richard Felkl662cac52018-07-19 19:02:03 +0200104 //runJobOnJenkins(jenkinsUrl, "admin", stackCicdPassword, "cvp-dt-func", "-p SETTINGS=${FUNC_TEST_SETTINGS}")
Richard Felkl14258e22018-06-28 12:42:34 +0200105 }
106
107 stage('Run Upgrade on DriveTrain') {
Richard Felkl662cac52018-07-19 19:02:03 +0200108 runJobOnJenkins(jenkinsUrl, "admin", stackCicdPassword, "upgrade-mcp-release", "-p MCP_VERSION=${TARGET_MCP_VERSION}")
Richard Felkl14258e22018-06-28 12:42:34 +0200109 }
110
111 stage('Run CVP after upgrade') {
Richard Felkl158c6292018-07-25 15:25:17 +0200112 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 Felklca5ceb42018-07-31 09:20:12 +0200113 //TODO: Enable functional tests after they become implemented.
Richard Felkl662cac52018-07-19 19:02:03 +0200114 //runJobOnJenkins(jenkinsUrl, "admin", stackCicdPassword, "cvp-dt-func", "-p SETTINGS=${FUNC_TEST_SETTINGS}")
Richard Felkl14258e22018-06-28 12:42:34 +0200115 }
116
Richard Felkl14258e22018-06-28 12:42:34 +0200117 } catch (Throwable e) {
118 currentBuild.result = 'FAILURE'
119 throw e
Richard Felklba460822018-07-30 12:42:16 +0200120 } finally{
121 if(DELETE_STACK.toBoolean() && ENVIRONMENT_IP == ""){
122 mcpEnvJob = build(job: "delete-heat-stack-for-mcp-env", parameters: [
123 [$class: 'StringParameterValue', name: 'OS_PROJECT_NAME', value: 'mcp-mk'],
124 [$class: 'StringParameterValue', name: 'STACK_NAME', value: 'jenkins-drivetrain-test-' + currentBuild.number],
125 ])
126 }
Richard Felkl14258e22018-06-28 12:42:34 +0200127 }
128 }
129}