blob: 89d3efab3f08591c96d6b38b82fccd8da089a458 [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){
37 def jenkinsDownCmd = "curl -OL ${jenkinsUrl}/jnlpJars/jenkins-cli.jar --output ./jenkins-cli.jar"
38 def runJobFromSaltMasterCmd = "java -jar jenkins-cli.jar -s ${jenkinsUrl} -noKeyAuth -auth admin:${password} build ${jobName} ${parameters} -s | grep -E 'SUCCESS|UNSTABLE'"
39 salt.cmdRun(pepperEnv, "I@salt:master", jenkinsDownCmd)
40 salt.cmdRun(pepperEnv, "I@salt:master", runJobFromSaltMasterCmd)
41}
42
43timeout(time: 12, unit: 'HOURS') {
44 node("python") {
45 try {
46 def mcpEnvJob
47 def saltReturn
48 def saltCreds = [:]
Richard Felkl57eace42018-07-19 19:11:41 +020049 def mcpEnvJobIP
Richard Felkl14258e22018-06-28 12:42:34 +020050
Richard Felkl57eace42018-07-19 19:11:41 +020051 if(ENVIRONMENT_IP == ""){
52 stage('Trigger deploy job') {
53 mcpEnvJob = build(job: "create-mcp-env", parameters: [
54 [$class: 'StringParameterValue', name: 'OS_AZ', value: 'mcp-mk'],
55 [$class: 'StringParameterValue', name: 'OS_PROJECT_NAME', value: 'mcp-mk'],
56 [$class: 'StringParameterValue', name: 'STACK_NAME', value: 'jenkins-drivetrain-test-' + currentBuild.number],
57 [$class: 'StringParameterValue', name: 'STACK_INSTALL', value: 'core,cicd'],
58 [$class: 'BooleanParameterValue', name: 'STACK_FULL', value: false],
59 [$class: 'BooleanParameterValue', name: 'RUN_TESTS', value: false],
60 [$class: 'TextParameterValue', name: 'COOKIECUTTER_TEMPLATE_CONTEXT', value: COOKIECUTTER_TEMPLATE_CONTEXT]
61 ])
62 }
63
64 def mcpEnvJobDesc = mcpEnvJob.getDescription().tokenize(" ")
65 mcpEnvJobIP = mcpEnvJobDesc[2]
66 }else{
67 mcpEnvJobIP = ENVIRONMENT_IP
Richard Felkl14258e22018-06-28 12:42:34 +020068 }
69
Richard Felkl14258e22018-06-28 12:42:34 +020070 def saltMasterUrl = "http://${mcpEnvJobIP}:6969"
71 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)"
72 def saltPasswd = sh(returnStdout: true, script: "curl -d \"script=${script}\" --user admin:r00tme http://${mcpEnvJobIP}:8081/scriptText")
73 saltPasswd = saltPasswd.trim()
74 saltCreds.put("username", "salt")
75 saltCreds.put("password", saltPasswd)
76 setupPepperVirtualenv(pepperEnv, saltMasterUrl, saltCreds)
77 saltReturn = salt.getPillar(pepperEnv, 'I@jenkins:client and not I@salt:master', '_param:openldap_admin_password')
78 def stackCicdPassword = saltReturn.get("return")[0].values()[0]
79 saltReturn = salt.getPillar(pepperEnv, 'I@jenkins:client and not I@salt:master', 'jenkins:client:master:host')
80 def stackCicdAddr = saltReturn.get("return")[0].values()[0]
81 def jenkinsUrl = "http://${stackCicdAddr}:8081"
82
83 stage('Run CVP before upgrade') {
Richard Felkl0f3e0aa2018-07-24 09:45:06 +020084 runJobOnJenkins(jenkinsUrl, "admin", stackCicdPassword, "cvp-sanity", "-p TESTS_SET=test_drivetrain.py -p TESTS_SETTINGS='drivetrain_version=\"${SOURCE_MCP_VERSION}\"'")
Richard Felkl662cac52018-07-19 19:02:03 +020085 //runJobOnJenkins(jenkinsUrl, "admin", stackCicdPassword, "cvp-dt-func", "-p SETTINGS=${FUNC_TEST_SETTINGS}")
Richard Felkl14258e22018-06-28 12:42:34 +020086 }
87
88 stage('Run Upgrade on DriveTrain') {
Richard Felkl662cac52018-07-19 19:02:03 +020089 runJobOnJenkins(jenkinsUrl, "admin", stackCicdPassword, "upgrade-mcp-release", "-p MCP_VERSION=${TARGET_MCP_VERSION}")
Richard Felkl14258e22018-06-28 12:42:34 +020090 }
91
92 stage('Run CVP after upgrade') {
Richard Felkl0f3e0aa2018-07-24 09:45:06 +020093 runJobOnJenkins(jenkinsUrl, "admin", stackCicdPassword, "cvp-sanity", "-p TESTS_SET=test_drivetrain.py -p TESTS_SETTINGS='drivetrain_version=\"${TARGET_MCP_VERSION}\"'")
Richard Felkl662cac52018-07-19 19:02:03 +020094 //runJobOnJenkins(jenkinsUrl, "admin", stackCicdPassword, "cvp-dt-func", "-p SETTINGS=${FUNC_TEST_SETTINGS}")
Richard Felkl14258e22018-06-28 12:42:34 +020095 }
96
97 } catch (Throwable e) {
98 currentBuild.result = 'FAILURE'
99 throw e
100 }
101 }
102}