+////////////////////////////////////////////////////////////////////////////////////////
+// Helper Functions
+////////////////////////////////////////////////////////////////////////////////////////
+void run_robot_systest(String tagName,
+ String testName,
+ String osmHostname,
+ String prometheusHostname,
+ Integer prometheusPort=null,
+ String ociRegistryUrl,
+ String envfile=null,
+ String portmappingfile=null,
+ String kubeconfig=null,
+ String clouds=null,
+ String hostfile=null,
+ String jujuPassword=null,
+ String osmRSAfile=null,
+ String passThreshold='0.0',
+ String unstableThreshold='0.0') {
+ tempdir = sh(returnStdout: true, script: 'mktemp -d').trim()
+ String environmentFile = ''
+ if (envfile) {
+ environmentFile = envfile
+ } else {
+ sh(script: "touch ${tempdir}/env")
+ environmentFile = "${tempdir}/env"
+ }
+ PROMETHEUS_PORT_VAR = ''
+ if (prometheusPort != null) {
+ PROMETHEUS_PORT_VAR = "--env PROMETHEUS_PORT=${prometheusPort}"
+ }
+ hostfilemount = ''
+ if (hostfile) {
+ hostfilemount = "-v ${hostfile}:/etc/hosts"
+ }
+
+ JUJU_PASSWORD_VAR = ''
+ if (jujuPassword != null) {
+ JUJU_PASSWORD_VAR = "--env JUJU_PASSWORD=${jujuPassword}"
+ }
+
+ try {
+ withCredentials([usernamePassword(credentialsId: 'gitlab-oci-test',
+ passwordVariable: 'OCI_REGISTRY_PSW', usernameVariable: 'OCI_REGISTRY_USR')]) {
+ sh("""docker run --env OSM_HOSTNAME=${osmHostname} --env PROMETHEUS_HOSTNAME=${prometheusHostname} \
+ ${PROMETHEUS_PORT_VAR} ${JUJU_PASSWORD_VAR} --env-file ${environmentFile} \
+ --env OCI_REGISTRY_URL=${ociRegistryUrl} --env OCI_REGISTRY_USER=${OCI_REGISTRY_USR} \
+ --env OCI_REGISTRY_PASSWORD=${OCI_REGISTRY_PSW} \
+ -v ${clouds}:/etc/openstack/clouds.yaml -v ${osmRSAfile}:/root/osm_id_rsa \
+ -v ${kubeconfig}:/root/.kube/config -v ${tempdir}:/robot-systest/reports \
+ -v ${portmappingfile}:/root/port-mapping.yaml ${hostfilemount} opensourcemano/tests:${tagName} \
+ -c -t ${testName}""")
+ }
+ } finally {
+ sh("cp ${tempdir}/*.xml .")
+ sh("cp ${tempdir}/*.html .")
+ outputDirectory = sh(returnStdout: true, script: 'pwd').trim()
+ println("Present Directory is : ${outputDirectory}")
+ step([
+ $class : 'RobotPublisher',
+ outputPath : "${outputDirectory}",
+ outputFileName : '*.xml',
+ disableArchiveOutput : false,
+ reportFileName : 'report.html',
+ logFileName : 'log.html',
+ passThreshold : passThreshold,
+ unstableThreshold: unstableThreshold,
+ otherFiles : '*.png',
+ ])
+ }
+}
+
+void archive_logs(Map remote) {
+
+ sshCommand remote: remote, command: '''mkdir -p logs/dags'''
+ if (useCharmedInstaller) {
+ sshCommand remote: remote, command: '''
+ 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 $pod --timestamps=true 2>&1 > logs/$logfile.log
+ done
+ '''
+ } else {
+ sshCommand remote: remote, command: '''
+ for deployment in `kubectl -n osm get deployments | grep -v operator | grep -v NAME| awk '{print $1}'`; do
+ echo "Extracting log for $deployment"
+ kubectl -n osm logs deployments/$deployment --timestamps=true --all-containers 2>&1 \
+ > logs/$deployment.log
+ done
+ '''
+ sshCommand remote: remote, command: '''
+ for statefulset in `kubectl -n osm get statefulsets | grep -v operator | grep -v NAME| awk '{print $1}'`; do
+ echo "Extracting log for $statefulset"
+ kubectl -n osm logs statefulsets/$statefulset --timestamps=true --all-containers 2>&1 \
+ > 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
+ archiveArtifacts artifacts: 'logs/*.log, logs/dags/*.log'