blob: 0dddf3ddce74ccb79d0a5fd516f955b2692f4bf7 [file] [log] [blame]
Vladimir Khlyuneve03b04f2024-04-26 02:57:02 +04001@Library('tcp-qa')_
2
3import groovy.xml.XmlUtil
4
5common = new com.mirantis.mk.Common()
6shared = new com.mirantis.system_qa.SharedPipeline()
7
8NODE_LABEL = "sre-team-infra"
Vladimir Khlyunevb90702f2024-05-06 17:00:05 +04009// ENV_NAME = "bm-mcc-mosk"
Vladimir Khlyuneve03b04f2024-04-26 02:57:02 +040010MAINTENANCE_TEAM_SSH_ID = 'maintenance-team-ssh'
11IPMI_CREDS = 'lab_engineer' // base bm lab
12def seed_ext_ip = '172.16.180.2'
13def kubectl_openstack_cmd = ''
14ssh_params = "-o ConnectTimeout=20 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
15
Pavel Glazov8f561592024-06-05 14:02:08 +040016timeout(time: 9, unit: 'HOURS') {
Vladimir Khlyuneve03b04f2024-04-26 02:57:02 +040017 timestamps {
18 node ("${NODE_LABEL}") {
19 checkout scm
20 shared.update_working_dir()
21 withCredentials(
22 [[$class : 'UsernamePasswordMultiBinding',
23 credentialsId : env.OS_CREDENTIALS,
24 passwordVariable: 'OS_PASSWORD',
25 usernameVariable: 'OS_USERNAME'
26 ]]) {
27 env.OS_IDENTITY_API_VERSION = 3
28 stage("Pre-cleanup: erase BM labs") {
29 // TODO: wipe all bm labs, including MCP1
30 println "Remove heat stack '${ENV_NAME}'"
31 shared.run_cmd("""\
32 openstack stack delete -y ${ENV_NAME} || true
33 timeout 20m /bin/bash -c "while openstack stack show ${ENV_NAME} -f value -c stack_status; do sleep 10; done"
34 """)
35 withCredentials([
36 [$class : 'UsernamePasswordMultiBinding',
37 credentialsId : "${IPMI_CREDS}",
38 passwordVariable: 'IPMI_PASS',
39 usernameVariable: 'IPMI_USER']
40 ]) {
41 env.IPMI_PASS = IPMI_PASS
42 env.IPMI_USER = IPMI_USER
43 shared.reboot_hardware_nodes("${IPMI_CREDS}")
44 } //withCredentials IPMI
45 } //stage
46 stage("Boot seed node's heat stack"){
47 println "Create stack '${ENV_NAME}'"
48 shared.run_cmd("pushd bm_mcc_mosk && openstack stack create --wait -t mcc_seed_2401.yaml --parameter env_name=${ENV_NAME} ${ENV_NAME}")
49 seed_ext_ip = shared.run_cmd_stdout("openstack stack output show ${ENV_NAME} seed_ext_ip -f value -c output_value").trim().split().last()
50 println "SEED IP: '${seed_ext_ip}'"
51 } //stage
52 } //withCredentials OS cloud
53 sshagent(credentials: ['maintenance-team-ssh']) {
54 withCredentials(
55 [[$class: 'SSHUserPrivateKeyBinding',
56 keyFileVariable: "MAINTENANCE_TEAM_SSH_KEY",
57 credentialsId: MAINTENANCE_TEAM_SSH_ID,
58 usernameVariable: "MAINTENANCE_TEAM_SSH_USERNAME"]]) {
59 stage("Bootstrap MCC+child"){
60 sh "scp ${ssh_params} ${MAINTENANCE_TEAM_SSH_KEY} root@${seed_ext_ip}:/root/.ssh/id_rsa "
61 sh "scp -r ${ssh_params} bm_mcc_mosk root@${seed_ext_ip}: "
62 sh "ssh ${ssh_params} root@${seed_ext_ip} bash do_deploy_mcc_mgmt.sh"
63 sh "ssh ${ssh_params} root@${seed_ext_ip} bash do_deploy_child.sh"
64 // TODO: unhardcode cluster names
65 check_child_cmd = "ssh ${ssh_params} root@${seed_ext_ip} /root/kaas-bootstrap/bin/kubectl --kubeconfig /root/kubeconfig -n mosk get cluster mosk -o jsonpath='{.status.providerStatus.ready}' 2>/dev/null || echo 'ssh error, ignoring'"
66 check_kcc_cmd = "ssh ${ssh_params} root@${seed_ext_ip} /root/kaas-bootstrap/bin/kubectl --kubeconfig /root/kubeconfig -n mosk get kcc mosk-ceph -o jsonpath='{.status.shortClusterInfo.state}' 2>/dev/null || echo 'ssh error, ignoring'"
67 child_ready = false
68 kcc_ready = false
69 println "Waiting child cluster to become ready..."
70 while(!child_ready){
71 sleep 60
72 status = sh(returnStdout: true, script: "${check_child_cmd}").trim()
73 if (status == "true"){
74 child_ready = true
75 } //if
76 } //while
77 println "Waiting child Ceph cluster to become ready..."
78 while(!kcc_ready){
79 sleep 60
80 status = sh(returnStdout: true, script: "${check_kcc_cmd}").trim()
81 if (status == "Ready"){
82 kcc_ready = true
83 } //if
84 } //while
85 } //stage MCC
86 stage("Prepare and deploy MOSK"){
87 sh "ssh ${ssh_params} root@${seed_ext_ip} '/bin/bash /root/get_child_kubeconfig.sh'"
88 sh "ssh ${ssh_params} root@${seed_ext_ip} '/bin/bash /root/bm_mcc_mosk/utils/tsl_gen.sh'"
89 kubectl_openstack_cmd = "ssh ${ssh_params} root@${seed_ext_ip} /root/kaas-bootstrap/bin/kubectl --kubeconfig /root/child.kubeconfig -n openstack "
90 sh "${kubectl_openstack_cmd} apply -f /root/bm_mcc_mosk/child/kaas_workloads/osdpl-ssl-secrets.yaml"
91 sh "${kubectl_openstack_cmd} apply -f /root/bm_mcc_mosk/child/kaas_workloads/osdpl.yaml"
92 mosk_check_cmd = "${kubectl_openstack_cmd} get osdplst osh-dev -o jsonpath='{.status.osdpl.state}'"
93 mosk_ready = false
94 while(!mosk_ready){
95 sleep 60
96 status = sh(returnStdout: true, script: "${mosk_check_cmd}").trim()
97 if (status == "APPLIED"){
98 mosk_ready = true
99 } //if
100 } //while
101 } //stage MOSK
102 stage("Configure DNS server") {
103 get_ingress_ip_cmd = "${kubectl_openstack_cmd} get service ingress -o jsonpath='{.status.loadBalancer.ingress[0].ip}'"
104 get_dns_internal_ip_cmd = "ssh ${ssh_params} root@${seed_ext_ip} /root/kaas-bootstrap/bin/kubectl --kubeconfig /root/child.kubeconfig -n coredns get service coredns-coredns -o jsonpath='{.spec.clusterIP}'"
105 ingress_ip = sh(returnStdout: true, script: get_ingress_ip_cmd).trim()
106 sh "ssh ${ssh_params} root@${seed_ext_ip} sed -i 's/!!!EXT_DNS_IP/${ingress_ip}/g' /root/bm_mcc_mosk/child/kaas_workloads/coredns.yaml"
107 sh "ssh ${ssh_params} root@${seed_ext_ip} /root/kaas-bootstrap/bin/kubectl --kubeconfig /root/child.kubeconfig apply -f /root/bm_mcc_mosk/child/kaas_workloads/coredns.yaml"
108 sleep 120
109 dns_internal_ip = sh(returnStdout: true, script: get_dns_internal_ip_cmd).trim()
110 sh "ssh ${ssh_params} root@${seed_ext_ip} \"/root/kaas-bootstrap/bin/kubectl --kubeconfig /root/child.kubeconfig -n kube-system get configmap coredns -oyaml > coredns.conf\""
111 sh "ssh ${ssh_params} root@${seed_ext_ip} /usr/bin/python3 /root/bm_mcc_mosk/utils/update_kube_dns_conf.py ${dns_internal_ip}"
112 sh "ssh ${ssh_params} root@${seed_ext_ip} /root/kaas-bootstrap/bin/kubectl --kubeconfig /root/child.kubeconfig apply -f coredns.patched.conf"
113
114 } // stage DNS
Pavel Glazov8f561592024-06-05 14:02:08 +0400115
116 stage("Get openstack credentials") {
117 kubectl_openstack_external_cmd = "ssh ${ssh_params} root@${seed_ext_ip} /root/kaas-bootstrap/bin/kubectl --kubeconfig /root/child.kubeconfig -n openstack-external "
118 cmd = "${kubectl_openstack_external_cmd} get secrets openstack-identity-credentials -o jsonpath='{.data.clouds\\\\.yaml}' | base64 -d"
119 openstack_credentials = sh(returnStdout: true, script: "${cmd}")
120 println openstack_credentials
121 writeFile(file: "openstack_credentials.yaml", text: openstack_credentials, encoding: "UTF-8")
122 } //stage get credentials
123
124 stage("Tempest configuration and run") {
125 kubectl_openstack_cmd = "ssh ${ssh_params} root@${seed_ext_ip} /root/kaas-bootstrap/bin/kubectl --kubeconfig /root/child.kubeconfig -n openstack "
126 sh "${kubectl_openstack_cmd} patch osdpl osh-dev --type merge -p '{\\\"spec\\\":{\\\"features\\\":{\\\"services\\\":[\\\"tempest\\\"]}}}'"
127 tempest_pod_name_cmd = "ssh ${ssh_params} root@${seed_ext_ip} '/root/kaas-bootstrap/bin/kubectl --kubeconfig /root/child.kubeconfig -n openstack get pods -o custom-columns=POD:.metadata.name --no-headers | grep openstack-tempest-run-tests'"
128 tempest_pod_name = ''
129 while(tempest_pod_name==''){
130 try{
131 tempest_pod_name = sh(returnStdout: true, script: "${tempest_pod_name_cmd}").trim()
132 } catch(Exception e) {
133 println("Wait tempest pod start (Exception: ${e}")}
134 sleep 30
135 }
136 tempest_check_cmd = "ssh ${ssh_params} root@${seed_ext_ip} '/root/kaas-bootstrap/bin/kubectl --kubeconfig /root/child.kubeconfig -n openstack get -o jsonpath=\'{.status.phase}\' pod/${tempest_pod_name}'"
137 status = ""
138 while (status != "Succeeded"){ //Completed
139 status = sh(returnStdout: true, script: "${tempest_check_cmd}").trim()
140 println("Tempest pod status is ${status}")
141 sleep 60
142 }
143 } //stage tempest
144 stage("Archive artifacts"){
145 sh "${kubectl_openstack_cmd} apply -f /root/bm_mcc_mosk/child/kaas_workloads/tempest-pvc-storage.yaml"
146 sleep 60
147 ssh_cmd = "ssh ${ssh_params} root@${seed_ext_ip} "
148 sh "${ssh_cmd} '/root/kaas-bootstrap/bin/kubectl --kubeconfig /root/child.kubeconfig -n openstack cp tempest-test-results-pod:var/lib/tempest/data/ /root/tempest_log/'"
149 sh "scp -r -v ${ssh_params} root@${seed_ext_ip}:/root/tempest_log ."
150 sh "tar -czvf tempest_log/tempest_full.tar.gz tempest_log/tempest.log"
151 archiveArtifacts artifacts: "openstack_credentials.yaml, tempest_log/*/tempest.log, tempest_log/tempest_full.tar.gz"
152 sh "${kubectl_openstack_cmd} delete pod tempest-test-results-pod"
153 sh "${kubectl_openstack_cmd} patch osdpl osh-dev --type merge -p '{\\\"spec\\\":{\\\"features\\\":{\\\"services\\\":[]}}}'"
154 }
Vladimir Khlyuneve03b04f2024-04-26 02:57:02 +0400155 } //withCredentials
156 } //sshagent
157 } //node
158 } //timestamps
159} //timeout