Add option in Jenkins stage3 to test old SA
[osm/devops.git] / jenkins / ci-pipelines / ci_stage_3.groovy
index f7e77c6..bc08891 100644 (file)
@@ -31,7 +31,8 @@ properties([
         string(defaultValue: 'artifactory-osm', description: '', name: 'ARTIFACTORY_SERVER'),
         string(defaultValue: 'osm-stage_4', description: '', name: 'DOWNSTREAM_STAGE_NAME'),
         string(defaultValue: 'testing-daily', description: '', name: 'DOCKER_TAG'),
-        string(defaultValue: 'ubuntu20.04', description: '', name: 'OPENSTACK_BASE_IMAGE'),
+        string(defaultValue: 'ubuntu22.04', description: '', name: 'OPENSTACK_BASE_IMAGE'),
+        booleanParam(defaultValue: false, description: '', name: 'TRY_OLD_SERVICE_ASSURANCE'),
         booleanParam(defaultValue: false, description: '', name: 'SAVE_CONTAINER_ON_FAIL'),
         booleanParam(defaultValue: false, description: '', name: 'SAVE_CONTAINER_ON_PASS'),
         booleanParam(defaultValue: true, description: '', name: 'SAVE_ARTIFACTS_ON_SMOKE_SUCCESS'),
@@ -124,13 +125,13 @@ void run_robot_systest(String tagName,
 
 void archive_logs(Map remote) {
 
-    sshCommand remote: remote, command: '''mkdir -p logs'''
+    sshCommand remote: remote, command: '''mkdir -p logs/dags'''
     if (useCharmedInstaller) {
         sshCommand remote: remote, command: '''
-            for container in `kubectl get pods -n osm | grep -v operator | grep -v NAME| awk '{print $1}'`; do
-                logfile=`echo $container | cut -d- -f1`
+            for pod in `kubectl get pods -n osm | grep -v operator | grep -v NAME| awk '{print $1}'`; do
+                logfile=`echo $pod | cut -d- -f1`
                 echo "Extracting log for $logfile"
-                kubectl logs -n osm $container --timestamps=true 2>&1 > logs/$logfile.log
+                kubectl logs -n osm $pod --timestamps=true 2>&1 > logs/$logfile.log
             done
         '''
     } else {
@@ -148,12 +149,17 @@ void archive_logs(Map remote) {
                 > logs/$statefulset.log
             done
         '''
+        sshCommand remote: remote, command: '''
+            schedulerPod="$(kubectl get pods -n osm | grep airflow-scheduler| awk '{print $1; exit}')"; \
+            echo "Extracting logs from Airflow DAGs from pod ${schedulerPod}"; \
+            kubectl cp -n osm ${schedulerPod}:/opt/airflow/logs/scheduler/latest/dags logs/dags -c scheduler
+        '''
     }
 
     sh 'rm -rf logs'
     sshCommand remote: remote, command: '''ls -al logs'''
     sshGet remote: remote, from: 'logs', into: '.', override: true
-    sh 'cp logs/* .'
+    sh 'cp logs/*.log logs/dags/*.log .'
     archiveArtifacts artifacts: '*.log'
 }
 
@@ -216,7 +222,9 @@ node("${params.NODE}") {
 ///////////////////////////////////////////////////////////////////////////////////////
         stage('Copy Artifacts') {
             // cleanup any previous repo
-            sh 'rm -rf repo'
+            sh "tree -fD repo || exit 0"
+            sh 'rm -rvf repo'
+            sh "tree -fD repo && lsof repo || exit 0"
             dir('repo') {
                 packageList = []
                 dir("${RELEASE}") {
@@ -256,7 +264,7 @@ node("${params.NODE}") {
 
                     parallelSteps = [:]
                     list = ['RO', 'osmclient', 'IM', 'devops', 'MON', 'N2VC', 'NBI',
-                            'common', 'LCM', 'POL', 'NG-UI', 'PLA', 'tests']
+                            'common', 'LCM', 'POL', 'NG-UI', 'NG-SA', 'PLA', 'tests']
                     if (upstreamComponent.length() > 0) {
                         println("Skipping upstream fetch of ${upstreamComponent}")
                         list.remove(upstreamComponent)
@@ -324,6 +332,8 @@ node("${params.NODE}") {
                 ci_helper.check_status_http_server(NODE_IP_ADDRESS, repo_port)
             }
 
+            sh "tree -fD repo"
+
             // Unpack devops package into temporary location so that we use it from upstream if it was part of a patch
             osm_devops_dpkg = sh(returnStdout: true, script: 'find ./repo/release/pool/ -name osm-devops*.deb').trim()
             devopstempdir = sh(returnStdout: true, script: 'mktemp -d').trim()
@@ -433,6 +443,30 @@ node("${params.NODE}") {
                         }
                     }
                     println('VM is ready and accepting ssh connections')
+
+                    //////////////////////////////////////////////////////////////////////////////////////////////
+                    println('Applying sshd config workaround for Ubuntu 22.04 and old jsch client in Jenkins...')
+
+                    sh( returnStatus: true,
+                        script: "ssh -T -i ${SSH_KEY} " +
+                            "-o StrictHostKeyChecking=no " +
+                            "-o UserKnownHostsFile=/dev/null " +
+                            "ubuntu@${IP_ADDRESS} " +
+                            "'echo HostKeyAlgorithms +ssh-rsa | sudo tee -a /etc/ssh/sshd_config'")
+                    sh( returnStatus: true,
+                        script: "ssh -T -i ${SSH_KEY} " +
+                            "-o StrictHostKeyChecking=no " +
+                            "-o UserKnownHostsFile=/dev/null " +
+                            "ubuntu@${IP_ADDRESS} " +
+                            "'echo PubkeyAcceptedKeyTypes +ssh-rsa | sudo tee -a /etc/ssh/sshd_config'")
+                    sh( returnStatus: true,
+                        script: "ssh -T -i ${SSH_KEY} " +
+                            "-o StrictHostKeyChecking=no " +
+                            "-o UserKnownHostsFile=/dev/null " +
+                            "ubuntu@${IP_ADDRESS} " +
+                            "'sudo systemctl restart sshd'")
+                    //////////////////////////////////////////////////////////////////////////////////////////////
+
                 } // stage("Spawn Remote VM")
 
 ///////////////////////////////////////////////////////////////////////////////////////
@@ -452,8 +486,8 @@ node("${params.NODE}") {
                     // Ensure the VM is ready
                     sshCommand remote: remote, command: 'cloud-init status --wait'
                     // Force time sync to avoid clock drift and invalid certificates
-                    sshCommand remote: remote, command: 'sudo apt-get update'
-                    sshCommand remote: remote, command: 'sudo apt-get install -y chrony'
+                    sshCommand remote: remote, command: 'sudo apt-get -y update'
+                    sshCommand remote: remote, command: 'sudo apt-get -y install chrony'
                     sshCommand remote: remote, command: 'sudo service chrony stop'
                     sshCommand remote: remote, command: 'sudo chronyd -vq'
                     sshCommand remote: remote, command: 'sudo service chrony start'
@@ -497,7 +531,7 @@ node("${params.NODE}") {
                     ]
 
                     sshCommand remote: remote, command: '''
-                        wget https://osm-download.etsi.org/ftp/osm-11.0-eleven/install_osm.sh
+                        wget https://osm-download.etsi.org/ftp/osm-13.0-thirteen/install_osm.sh
                         chmod +x ./install_osm.sh
                         sed -i '1 i\\export PATH=/snap/bin:\$PATH' ~/.bashrc
                     '''
@@ -532,6 +566,10 @@ node("${params.NODE}") {
                         osmHostname = "nbi.${IP_ADDRESS}.nip.io:443"
                     } else {
                         // Run -k8s installer here specifying internal docker registry and docker proxy
+                        osm_installation_options = ""
+                        if (params.TRY_OLD_SERVICE_ASSURANCE) {
+                            osm_installation_options = "--old-sa"
+                        }
                         withCredentials([gitlabCredentialsMap]) {
                             sshCommand remote: remote, command: """
                                 ./install_osm.sh -y \
@@ -540,7 +578,8 @@ node("${params.NODE}") {
                                     ${release} -r unstable \
                                     -d ${USERNAME}:${PASSWORD}@${INTERNAL_DOCKER_REGISTRY} \
                                     -p ${INTERNAL_DOCKER_PROXY} \
-                                    -t ${containerName}
+                                    -t ${containerName} \
+                                    ${osm_installation_options}
                             """
                         }
                         prometheusHostname = IP_ADDRESS
@@ -633,7 +672,8 @@ EOF"""
 
                                 parallelSteps[module] = {
                                     dir("$module") {
-                                        sh("""docker tag opensourcemano/${moduleName}:${moduleTag} \
+                                        sh("docker pull ${INTERNAL_DOCKER_REGISTRY}opensourcemano/${moduleName}:${moduleTag}")
+                                        sh("""docker tag ${INTERNAL_DOCKER_REGISTRY}opensourcemano/${moduleName}:${moduleTag} \
                                            opensourcemano/${moduleName}:${dockerTag}""")
                                         sh "docker push opensourcemano/${moduleName}:${dockerTag}"
                                     }
@@ -685,6 +725,7 @@ EOF"""
                                 'osm-pol',
                                 'osm-ro',
                                 'osm-prometheus',
+                                'osm-update-db-operator',
                                 'osm-vca-integrator',
                             ]
                             for (charm in charms) {
@@ -699,12 +740,26 @@ EOF"""
                                 withCredentials([string(credentialsId: 'Charmstore', variable: 'CHARMCRAFT_AUTH')]) {
                                     sh "charmcraft status $charm --format json > ${charm}.json"
                                     isCharm = sh(returnStdout: true, script: "grep architecture ${charm}.json | wc -l").trim() as int
+                                    resourceArgument = ""
                                     if (isCharm) {
-                                        jqScriptEdge = "cat ${charm}.json | jq -r '.[] | select(.track==\"$channel\") | .mappings[] | select(.base.architecture==\"amd64\" and .base.channel==\"20.04\") | .releases[] | select(.channel==\"latest/edge/merged\")| .version'|head -1"
-                                        jqScriptBeta = "cat ${charm}.json | jq -r '.[] | select(.track==\"$channel\") | .mappings[] | select(.base.architecture==\"amd64\" and .base.channel==\"20.04\") | .releases[] | select(.channel==\"latest/beta\")| .version'|head -1"
+                                        jqScriptEdge = "cat ${charm}.json | jq -r '.[] | select(.track==\"$channel\") | .mappings[] | select(.base.architecture==\"amd64\" and .base.channel==\"20.04\") | .releases[] | select(.channel==\"$channel/edge/merged\")| .version'|head -1"
+                                        jqScriptBeta = "cat ${charm}.json | jq -r '.[] | select(.track==\"$channel\") | .mappings[] | select(.base.architecture==\"amd64\" and .base.channel==\"20.04\") | .releases[] | select(.channel==\"$channel/beta\")| .version'|head -1"
+                                        index=0
+                                        while (index < 5) {
+                                            resourceNameScript = "cat ${charm}.json | jq -r '.[] | select(.track==\"$channel\") | .mappings[] | select(.base.architecture==\"amd64\" and .base.channel==\"20.04\") | .releases[] | select(.channel==\"$channel/edge/merged\")| .resources[$index].name'|head -1"
+                                            resourceRevsScript = "cat ${charm}.json | jq -r '.[] | select(.track==\"$channel\") | .mappings[] | select(.base.architecture==\"amd64\" and .base.channel==\"20.04\") | .releases[] | select(.channel==\"$channel/edge/merged\")| .resources[$index].revision'|head -1"
+                                            resourceName = sh(returnStdout: true, script: resourceNameScript).trim()
+                                            resourceRevs = sh(returnStdout: true, script: resourceRevsScript).trim()
+                                            if (resourceName != "null") {
+                                                resourceArgument += " --resource ${resourceName}:${resourceRevs}"
+                                            } else {
+                                                break
+                                            }
+                                            index ++
+                                        }
                                     } else {
-                                        jqScriptEdge = "cat ${charm}.json | jq -r '.[] | select(.track==\"$channel\") | .mappings[].releases[] | select(.channel==\"latest/edge/merged\")| .version'|head -1"
-                                        jqScriptBeta = "cat ${charm}.json | jq -r '.[] | select(.track==\"$channel\") | .mappings[].releases[] | select(.channel==\"latest/beta\")| .version'|head -1"
+                                        jqScriptEdge = "cat ${charm}.json | jq -r '.[] | select(.track==\"$channel\") | .mappings[].releases[] | select(.channel==\"$channel/edge/merged\")| .version'|head -1"
+                                        jqScriptBeta = "cat ${charm}.json | jq -r '.[] | select(.track==\"$channel\") | .mappings[].releases[] | select(.channel==\"$channel/beta\")| .version'|head -1"
                                     }
                                     // edge/merged is used in place of /edge as 10.1.0 LTS uses latest/edge
                                     edge_rev = sh(returnStdout: true, script: jqScriptEdge).trim()
@@ -712,12 +767,12 @@ EOF"""
                                     try { edge_rev = edge_rev as int } catch (NumberFormatException nfe) {edge_rev = 0}
                                     try { beta_rev = beta_rev as int } catch (NumberFormatException nfe) {beta_rev = 0}
 
-                                    print "Edge: $edge_rev, Beta: $beta_rev"
+                                    print "Edge: $edge_rev, Beta: $beta_rev $resourceArgument"
 
                                     if (edge_rev > beta_rev) {
                                         print "Promoting $edge_rev to beta in place of $beta_rev"
                                         beta_track = channel + 'beta'
-                                        sh "charmcraft release ${charm} --revision=${edge_rev} --channel=${channel}/beta"
+                                        sh "charmcraft release ${charm} --revision=${edge_rev}  ${resourceArgument} --channel=${channel}/beta"
                                     }
 
                                 }
@@ -728,7 +783,10 @@ EOF"""
             } // if (params.SAVE_ARTIFACTS_OVERRIDE || stage_archive)
         } // dir(OSM_DEVOPS)
     } finally {
-       stage('Archive Container Logs') {
+        // stage('Debug') {
+        //     sleep 900
+        // }
+        stage('Archive Container Logs') {
             if ( ARCHIVE_LOGS_FLAG ) {
                 try {
                     // Archive logs