blob: 4b3c23ff827dcee6f5d5dfa2d6231a22411ed6d3 [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}: "
Vladimir Khlyunevc6db3412024-10-18 20:28:02 +040062 sh "ssh ${ssh_params} root@${seed_ext_ip} bash /root/bm_mcc_mosk/seed/do_deploy_mcc_mgmt.sh"
63 sh "ssh ${ssh_params} root@${seed_ext_ip} bash /root/bm_mcc_mosk/seed/do_deploy_child.sh"
Vladimir Khlyuneve03b04f2024-04-26 02:57:02 +040064 // 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"){
Vladimir Khlyunevc6db3412024-10-18 20:28:02 +040087 sh "ssh ${ssh_params} root@${seed_ext_ip} '/bin/bash /root/bm_mcc_mosk/seed/get_child_kubeconfig.sh'"
Vladimir Khlyuneve03b04f2024-04-26 02:57:02 +040088 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}'"
Vladimir Khlyunev3f27ff72024-11-01 14:42:24 +0400105 get_dns_external_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='{.status.loadBalancer.ingress[0].ip}'"
Vladimir Khlyuneve03b04f2024-04-26 02:57:02 +0400106 ingress_ip = sh(returnStdout: true, script: get_ingress_ip_cmd).trim()
107 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"
108 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"
109 sleep 120
110 dns_internal_ip = sh(returnStdout: true, script: get_dns_internal_ip_cmd).trim()
111 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\""
112 sh "ssh ${ssh_params} root@${seed_ext_ip} /usr/bin/python3 /root/bm_mcc_mosk/utils/update_kube_dns_conf.py ${dns_internal_ip}"
113 sh "ssh ${ssh_params} root@${seed_ext_ip} /root/kaas-bootstrap/bin/kubectl --kubeconfig /root/child.kubeconfig apply -f coredns.patched.conf"
Vladimir Khlyunev3f27ff72024-11-01 14:42:24 +0400114 dns_external_ip = sh(returnStdout: true, script: get_dns_external_ip_cmd).trim()
115 sh "ssh ${ssh_params} root@${seed_ext_ip} bash /root/bm_mcc_mosk/seed/setup_dnsmasq.sh ${dns_external_ip}"
116 sh "ssh ${ssh_params} root@${seed_ext_ip} bash /root/bm_mcc_mosk/seed/get_openstack_credentials.sh"
Vladimir Khlyuneve03b04f2024-04-26 02:57:02 +0400117 } // stage DNS
Pavel Glazov8f561592024-06-05 14:02:08 +0400118
119 stage("Get openstack credentials") {
120 kubectl_openstack_external_cmd = "ssh ${ssh_params} root@${seed_ext_ip} /root/kaas-bootstrap/bin/kubectl --kubeconfig /root/child.kubeconfig -n openstack-external "
121 cmd = "${kubectl_openstack_external_cmd} get secrets openstack-identity-credentials -o jsonpath='{.data.clouds\\\\.yaml}' | base64 -d"
122 openstack_credentials = sh(returnStdout: true, script: "${cmd}")
123 println openstack_credentials
124 writeFile(file: "openstack_credentials.yaml", text: openstack_credentials, encoding: "UTF-8")
125 } //stage get credentials
Pavel Glazov040d1c62024-10-09 20:13:07 +0400126 if (env.RUN_TESTS_AFTER_DEPLOY == "true") {
127 stage("Run tempest job"){
128 def deploy = build job: 'mosk-tempest',
129 parameters: [
130 string(name: 'NODE_LABEL', value: NODE_LABEL),
131 string(name: 'MAINTENANCE_TEAM_SSH_ID', value: MAINTENANCE_TEAM_SSH_ID),
132 string(name: 'TCP_QA_REFS', value: env.TCP_QA_REFS),
133 string(name: 'SEED_EXT_IP', value: seed_ext_ip)
134 ],
135 wait: false,
136 propagate: false
Pavel Glazov8f561592024-06-05 14:02:08 +0400137 }
Pavel Glazov8f561592024-06-05 14:02:08 +0400138 }
Vladimir Khlyuneve03b04f2024-04-26 02:57:02 +0400139 } //withCredentials
140 } //sshagent
141 } //node
142 } //timestamps
143} //timeout