Richard Felkl | 14258e2 | 2018-06-28 12:42:34 +0200 | [diff] [blame] | 1 | /** |
| 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 Felkl | 57eace4 | 2018-07-19 19:11:41 +0200 | [diff] [blame] | 10 | * ENVIRONMENT_IP IP of already deployed environment |
Richard Felkl | 14258e2 | 2018-06-28 12:42:34 +0200 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | |
| 14 | common = new com.mirantis.mk.Common() |
| 15 | salt = new com.mirantis.mk.Salt() |
| 16 | test = new com.mirantis.mk.Test() |
| 17 | python = new com.mirantis.mk.Python() |
| 18 | |
| 19 | pepperEnv = "pepperEnv" |
| 20 | |
| 21 | def 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] |
| 27 | SALTAPI_EAUTH=pam |
| 28 | SALTAPI_URL=${url} |
| 29 | SALTAPI_USER=${creds.username} |
| 30 | SALTAPI_PASS=${creds.password} |
| 31 | """ |
| 32 | writeFile file: rcFile, text: rc |
| 33 | return rcFile |
| 34 | } |
| 35 | |
| 36 | def runJobOnJenkins(jenkinsUrl, userName, password, jobName, parameters){ |
Richard Felkl | 055abae | 2018-07-26 14:41:15 +0200 | [diff] [blame^] | 37 | def status = "null" |
Richard Felkl | 14258e2 | 2018-06-28 12:42:34 +0200 | [diff] [blame] | 38 | def jenkinsDownCmd = "curl -OL ${jenkinsUrl}/jnlpJars/jenkins-cli.jar --output ./jenkins-cli.jar" |
Richard Felkl | 055abae | 2018-07-26 14:41:15 +0200 | [diff] [blame^] | 39 | 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 Felkl | 14258e2 | 2018-06-28 12:42:34 +0200 | [diff] [blame] | 41 | salt.cmdRun(pepperEnv, "I@salt:master", jenkinsDownCmd) |
| 42 | salt.cmdRun(pepperEnv, "I@salt:master", runJobFromSaltMasterCmd) |
Richard Felkl | 055abae | 2018-07-26 14:41:15 +0200 | [diff] [blame^] | 43 | 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 Felkl | 14258e2 | 2018-06-28 12:42:34 +0200 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | timeout(time: 12, unit: 'HOURS') { |
| 55 | node("python") { |
| 56 | try { |
| 57 | def mcpEnvJob |
| 58 | def saltReturn |
| 59 | def saltCreds = [:] |
Richard Felkl | 57eace4 | 2018-07-19 19:11:41 +0200 | [diff] [blame] | 60 | def mcpEnvJobIP |
Richard Felkl | 14258e2 | 2018-06-28 12:42:34 +0200 | [diff] [blame] | 61 | |
Richard Felkl | 57eace4 | 2018-07-19 19:11:41 +0200 | [diff] [blame] | 62 | 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 Felkl | 14258e2 | 2018-06-28 12:42:34 +0200 | [diff] [blame] | 79 | } |
| 80 | |
Richard Felkl | 14258e2 | 2018-06-28 12:42:34 +0200 | [diff] [blame] | 81 | 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 Felkl | 158c629 | 2018-07-25 15:25:17 +0200 | [diff] [blame] | 95 | 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 Felkl | 662cac5 | 2018-07-19 19:02:03 +0200 | [diff] [blame] | 96 | //runJobOnJenkins(jenkinsUrl, "admin", stackCicdPassword, "cvp-dt-func", "-p SETTINGS=${FUNC_TEST_SETTINGS}") |
Richard Felkl | 14258e2 | 2018-06-28 12:42:34 +0200 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | stage('Run Upgrade on DriveTrain') { |
Richard Felkl | 662cac5 | 2018-07-19 19:02:03 +0200 | [diff] [blame] | 100 | runJobOnJenkins(jenkinsUrl, "admin", stackCicdPassword, "upgrade-mcp-release", "-p MCP_VERSION=${TARGET_MCP_VERSION}") |
Richard Felkl | 14258e2 | 2018-06-28 12:42:34 +0200 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | stage('Run CVP after upgrade') { |
Richard Felkl | 158c629 | 2018-07-25 15:25:17 +0200 | [diff] [blame] | 104 | 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 Felkl | 662cac5 | 2018-07-19 19:02:03 +0200 | [diff] [blame] | 105 | //runJobOnJenkins(jenkinsUrl, "admin", stackCicdPassword, "cvp-dt-func", "-p SETTINGS=${FUNC_TEST_SETTINGS}") |
Richard Felkl | 14258e2 | 2018-06-28 12:42:34 +0200 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | } catch (Throwable e) { |
| 109 | currentBuild.result = 'FAILURE' |
| 110 | throw e |
| 111 | } |
| 112 | } |
| 113 | } |