Add checking of status of local http server used to serve deb packages 22/11922/3
authorgarciadeblas <gerardo.garciadeblas@telefonica.com>
Fri, 22 Apr 2022 10:05:15 +0000 (12:05 +0200)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Tue, 24 May 2022 08:36:57 +0000 (10:36 +0200)
Change-Id: Ic624afeee0ec5011e21c10bd0eb110ec78888e1c
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
jenkins/ci-pipelines/ci_helper.groovy
jenkins/ci-pipelines/ci_stage_3.groovy

index c920f46..0b41169 100644 (file)
@@ -69,7 +69,24 @@ def lxc_file_push(container_name,file,destination) {
 def start_http_server(repo_dir,server_name,port) {
     sh "docker run -dit --name ${server_name} -p ${port}:80 -v ${repo_dir}:/usr/local/apache2/htdocs/ httpd:2.4"
     def http_server_ip = sh(returnStdout:true,  script: "docker inspect --format '{{ .NetworkSettings.IPAddress }}' ${server_name}").trim()
-    return "http://${http_server_ip}/"
+    return "http://${http_server_ip}:${port}/"
+}
+
+def check_status_http_server(ip, port) {
+    alive = false
+    timeout(time: 1, unit: 'MINUTES') {
+        while (!alive) {
+            output = sh(
+                returnStatus: true,
+                script: "wget http://${ip}:${port}/release/dists/unstable/Release")
+            alive = (output == 0)
+            if (!alive) {
+                sleep(time: 5, unit: 'SECONDS')
+            }
+        }
+    }
+    println('HTTP server is ready and accepting http connections')
+    return
 }
 
 def lxc_get_file(container_name,file,destination) {
index 44117ad..14736e9 100644 (file)
@@ -294,10 +294,13 @@ node("${params.NODE}") {
                 http_server_name = "${container_name}-apache"
 
                 pwd = sh(returnStdout:true,  script: 'pwd').trim()
-                repo_port = sh(script: 'echo $(python -c \'import socket; s=socket.socket(); s.bind(("", 0)); print(s.getsockname()[1]); s.close()\');', returnStdout: true).trim()
-                repo_base_url = ci_helper.start_http_server(pwd,http_server_name,repo_port)
-                NODE_IP_ADDRESS=sh(returnStdout: true, script:
+                repo_port = sh(script: 'echo $(python -c \'import socket; s=socket.socket(); s.bind(("", 0));' +
+                               'print(s.getsockname()[1]); s.close()\');',
+                               returnStdout: true).trim()
+                internal_docker_http_server_url = ci_helper.start_http_server(pwd, http_server_name, repo_port)
+                NODE_IP_ADDRESS = sh(returnStdout: true, script:
                     "echo ${SSH_CONNECTION} | awk '{print \$3}'").trim()
+                ci_helper.check_status_http_server(NODE_IP_ADDRESS, repo_port)
             }
 
             // Unpack devops package into temporary location so that we use it from upstream if it was part of a patch