kea_testing.groovy 5.65 KB
   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
/**
* Jenkinsfile to deploy multiple Docker containers based on docker-compose into a DEV server and run any test.
* This pipeline will run the Docker containers, execute the tests and then stop and remove the containers from the DEV
* server automatically.
**/


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"
}

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 {
echo '*************'
echo '*** TESTS ***'
echo '*************'
/* Here do your tests */
sleep 90
try {
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)
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)
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)
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)
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)
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)
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"
}
}
}
}


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'
}
}
}
}
}
}
}