From 2daaa5ddcba99f553409f1019dbaf2fe34a26618 Mon Sep 17 00:00:00 2001 From: George Vlahavas Date: Wed, 8 Sep 2021 21:45:08 +0300 Subject: [PATCH] Update some tests --- kea_testing.groovy | 146 +++++++++++++++-------------------------------------- 1 file changed, 41 insertions(+), 105 deletions(-) diff --git a/kea_testing.groovy b/kea_testing.groovy index e253a68..27d6548 100644 --- a/kea_testing.groovy +++ b/kea_testing.groovy @@ -10,78 +10,17 @@ pipeline { agent any environment { - // Keep as is the following two lines - PRIVATE_REGISTRY = "https://registry.curex-project.eu:443/curex-local/" - ARTIFACTORY_URL = "registry.curex-project.eu:443/curex-local/" - - HOST_IP = "116.203.166.220" - DEPLOYMENT_HOST = "${HOST_IP}:2376" - DEPLOYMENT_HOST_CREDENTIALS = "vm2-creds" - - // KEA specific - APP_NAME = "KEA" - APP_ENV = "production" - APP_DEBUG = "true" - APP_URL = "http://${HOST_IP}" - - KIBANA_PORT = "5611" - GRAFANA_PORT = "3001" - - LOG_CHANNEL = "stack" - - DB_CONNECTION = "pgsql" - DB_HOST = "timescaledb" - DB_PORT = "5432" - DB_DATABASE = "kea" - DB_USERNAME = "postgres" - DB_PASSWORD = "postgres" - - BROADCAST_DRIVER = "log" - CACHE_DRIVER = "file" - QUEUE_CONNECTION = "sync" - SESSION_DRIVER = "file" - SESSION_LIFETIME = "120" - - JWT_TTL = "1440" - - ELASTICSEARCH_HOST = "elasticsearch" - ELASTICSEARCH_PORT = "9200" - ELASTICSEARCH_SCHEME = "http" - MQTT_HOST = "mosquitto" - MQTT_PORT = "1883" - MQTT_DEBUG = "false" - MQTT_QOS = "0" - MQTT_RETAIN = "0" - - MLTD_HOST = "mltd" - MLTD_PORT = "5000" - OD_HOST = "od" - OD_PORT = "9091" + APP_URL = "https://kea.curex-project.eu" + KEYCLOAK_URL = "https://keycloak-curex.gnubila.fr/auth/realms/Integration/protocol/openid-connect/token" + USER = credentials('keycloak-test-user') + PASSWORD = credentials('keycloak-test-password') + CLIENT_ID = "KEA" + } stages { - - stage('Checkout the source code') { - steps { - checkout scm - } - } - - stage('Deploy Docker containers in DEV server') { - steps { - script { - docker.withServer("$DEPLOYMENT_HOST", "$DEPLOYMENT_HOST_CREDENTIALS") { - docker.withRegistry("$PRIVATE_REGISTRY" , 'artifactory') { - echo 'Deploying the specified Docker containers in DEV server' - sh 'sh deploy.sh' - } - } - } - } - } - stage('Run tests') { steps { script { @@ -91,53 +30,65 @@ pipeline { /* Here do your tests */ sleep 90 try { + // Get Keycloak auth token + String token = sh(label: "get_keycloak_token", script: "curl -s -X POST $KEYCLOAK_URL -H 'Content-Type: application/x-www-form-urlencoded' -d 'username=$USER' -d 'password=$PASSWORD' -d 'grant_type=password' -d 'client_id=$CLIENT_ID' | sed 's/.*access_token\":\"//g' | sed 's/\".*//g'", returnStdout: true) + String testName = "KEA_F001" - String url = "$APP_URL:13880" - String responseCode = sh(label: testName, script: "curl -m 10 -sLI -w '%{http_code}' $url -o /dev/null", returnStdout: true) + String url = "$APP_URL" + String responseCode = sh(label: testName, script: "curl -m 10 -sLI -w '%{http_code}' -H 'Authorization: Bearer $token' -H 'Accept: application/json, text/plain, */*' $url -o /dev/null", returnStdout: true) if (responseCode != '200') { error("$testName: Returned status code = $responseCode when calling $url") } + testName = "KEA_F002" - url = "$APP_URL:13880/components/od" - responseCode = sh(label: testName, script: "curl -m 10 -sLI -w '%{http_code}' $url -o /dev/null", returnStdout: true) + url = "$APP_URL/components/od" + responseCode = sh(label: testName, script: "curl -m 10 -sLI -w '%{http_code}' -H 'Authorization: Bearer $token' -H 'Accept: application/json, text/plain, */*' $url -o /dev/null", returnStdout: true) if (responseCode != '200') { error("$testName: Returned status code = $responseCode when calling $url") } + testName = "KEA_F003" - url = "$APP_URL:13880/components/mltd" - responseCode = sh(label: testName, script: "curl -m 10 -sLI -w '%{http_code}' $url -o /dev/null", returnStdout: true) + url = "$APP_URL/components/mltd" + responseCode = sh(label: testName, script: "curl -m 10 -sLI -w '%{http_code}' -H 'Authorization: Bearer $token' -H 'Accept: application/json, text/plain, */*' $url -o /dev/null", returnStdout: true) + if (responseCode != '200') { + error("$testName: Returned status code = $responseCode when calling $url") + } + + testName = "KEA_F004" + url = "$APP_URL/api/config" + responseCode = sh(label: testName, script: "curl -m 10 -sLI -w '%{http_code}' -H 'Authorization: Bearer $token' -H 'Accept: application/json, text/plain, */*' $url -o /dev/null", returnStdout: true) if (responseCode != '200') { error("$testName: Returned status code = $responseCode when calling $url") } + + testName = "KEA_F005" + url = "$APP_URL/api/capec" + responseCode = sh(label: testName, script: "curl -m 10 -sLI -w '%{http_code}' -H 'Authorization: Bearer $token' -H 'Accept: application/json, text/plain, */*' $url -o /dev/null", returnStdout: true) + if (responseCode != '200') { + error("$testName: Returned status code = $responseCode when calling $url") + } + testName = "KEA_F006" - url = "$APP_URL:3001" - responseCode = sh(label: testName, script: "curl -m 10 -sLI -w '%{http_code}' $url -o /dev/null", returnStdout: true) + url = "https://kea-grafana.vlahavas.com" + responseCode = sh(label: testName, script: "curl -m 10 -sLI -w '%{http_code}' -H 'Authorization: Bearer $token' -H 'Accept: application/json, text/plain, */*' $url -o /dev/null", returnStdout: true) if (responseCode != '200') { error("$testName: Returned status code = $responseCode when calling $url") } + testName = "KEA_F007" - url = "$APP_URL:5611" - responseCode = sh(label: testName, script: "curl -m 10 -sLI -w '%{http_code}' $url -o /dev/null", returnStdout: true) + url = "https://kea-kibana.vlahavas.com/app/kibana" + responseCode = sh(label: testName, script: "curl -m 10 -sLI -w '%{http_code}' -H 'Authorization: Bearer $token' -H 'Accept: application/json, text/plain, */*' $url -o /dev/null", returnStdout: true) if (responseCode != '200') { error("$testName: Returned status code = $responseCode when calling $url") } + testName = "KEA_F008" - url = "$APP_URL:13880/components/ceptd" - responseCode = sh(label: testName, script: "curl -m 10 -sLI -w '%{http_code}' $url -o /dev/null", returnStdout: true) + url = "$APP_URL/components/ceptd" + responseCode = sh(label: testName, script: "curl -m 10 -sLI -w '%{http_code}' -H 'Authorization: Bearer $token' -H 'Accept: application/json, text/plain, */*' $url -o /dev/null", returnStdout: true) if (responseCode != '200') { error("$testName: Returned status code = $responseCode when calling $url") } - testName = "KEA_F004" - url = "mqtt://${HOST_IP}:1883/test" - responseCode = sh(label: testName, script: "sleep 2 ; curl -d 1 $url & OUT=`curl -m 4 -s $url` ; echo $OUT", returnStdout: true) - if (responseCode != 'test1') { - error("$testName: Returned status code = $responseCode when running MQTT test on $url") - } - testName = "KEA_F005" - responseCode = sh(label: testName, script: "docker exec -ti kea_timescaledb psql -l -U postgres | grep -q kea ; echo \$?", returnStdout: true) - if (responseCode != '0') { - error("$testName: Returned status code = $responseCode when looking for presense of kea DB") - } + } catch (ignored) { currentBuild.result = 'FAILURE' echo "KEA Deployment Tests failed" @@ -146,21 +97,6 @@ pipeline { } } - - stage('Stop and remove the Docker containers in DEV server') { - steps { - script { - docker.withServer("$DEPLOYMENT_HOST", "$DEPLOYMENT_HOST_CREDENTIALS") { - docker.withRegistry("$PRIVATE_REGISTRY" , 'artifactory') { - - //echo 'Stop and remove the specified Docker containers from the DEV server' - sh 'sh delete.sh' - - } - } - } - } - } } } -- 2.2.2