Bug 1903: Better SSH check 31/12131/1 v10.1.1-rc1
authorbeierlm <mark.beierl@canonical.com>
Thu, 10 Mar 2022 11:14:38 +0000 (06:14 -0500)
committerbeierlm <mark.beierl@canonical.com>
Thu, 26 May 2022 15:51:59 +0000 (11:51 -0400)
Changes the ssh port ready check from a simple 'is the port open?' to
a full ssh login check to ensure that sshd is actually running on the
target server.

Adds timeout to ssh check

Fixes bug 1903

Change-Id: I8c3f0d8e1ac450726bc3336c00e7fbdf405fe067
Signed-off-by: beierlm <mark.beierl@canonical.com>
jenkins/ci-pipelines/ci_stage_3.groovy

index 14736e9..801ddbb 100644 (file)
@@ -396,10 +396,16 @@ node("${params.NODE}") {
                     println("Waiting for VM at ${IP_ADDRESS} to be reachable")
 
                     alive = false
-                    while (! alive) {
-                        output=sh(returnStdout: true, script: "sleep 1 ; nc -zv ${IP_ADDRESS} 22 2>&1 || true").trim()
-                        println("output is [$output]")
-                        alive = output.contains("succeeded")
+                    timeout(time: 1, unit: 'MINUTES') {
+                        while (!alive) {
+                            output = sh(
+                                returnStatus: true,
+                                script: "ssh -T -i ${SSH_KEY} " +
+                                    "-o StrictHostKeyChecking=no " +
+                                    "-o UserKnownHostsFile=/dev/null " +
+                                    "-o ConnectTimeout=5 ubuntu@${IP_ADDRESS} 'echo Alive'")
+                            alive = (output == 0)
+                        }
                     }
                     println("VM is ready and accepting ssh connections")
                 } // stage("Spawn Remote VM")