forked from OSGP/open-smart-grid-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runTestsAtRemoteServer.sh
executable file
·110 lines (91 loc) · 4.64 KB
/
runTestsAtRemoteServer.sh
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
#!/bin/bash
# SPDX-FileCopyrightText: Contributors to the GXF project
#
# SPDX-License-Identifier: Apache-2.0
set -e
if [ "$#" -eq 0 ]
then
echo "Usage: $0 <server> <project> <user> [<ssh key file>] [<additional java parameters>] [<additional cucumber options>]"
echo ""
exit 1
fi
if [ "$#" -ne 7 ]; then
echo "Illegal number of parameters"
exit -1
fi
SERVER=$1
FOLDER=$2
PROJECT=$3
USER=$4
SSH_KEY_FILE=$5
ADDITIONAL_PARAMETERS=$6
ADDITIONAL_CUCUMBER_OPTIONS=$7
# If a space is found in the identity file then create a shortcut as the -i parameter for ssh can't handle spaces.
[[ $SSH_KEY_FILE != "" ]] && [[ $SSH_KEY_FILE =~ " " ]] && echo "Creating link ${HOME}/.ssh/${5/ /} => ${HOME}/.ssh/${5} ..." && ln -sf "${HOME}/.ssh/${5}" "${HOME}/.ssh/${5/ /}"
# Now determine if a -i parameter should be generated
[ "${SSH_KEY_FILE}"!="" ] && SSH_KEY_FILE="-oIdentityFile=\"${HOME}/.ssh/${5/ /}\"" && echo "SSH_KEY_FILE=[${SSH_KEY_FILE}]"
echo "Going to run the cucumber project ${PROJECT} on ${SERVER} ..."
echo "- Create directory structure ..."
CMD="ssh -oStrictHostKeyChecking=no ${SSH_KEY_FILE} ${USER}@${SERVER} \"\"sudo mkdir -p /data/software/${PROJECT}/target/output\"\""
echo " [${CMD}]"
${CMD}
CMD="ssh -oStrictHostKeyChecking=no ${SSH_KEY_FILE} ${USER}@${SERVER} \"\"sudo mkdir -p /data/software/certificates\"\""
echo " [${CMD}]"
${CMD}
CMD="ssh -oStrictHostKeyChecking=no ${SSH_KEY_FILE} ${USER}@${SERVER} \"\"sudo chown -R ${USER}:${USER} /data/software\"\""
echo " [${CMD}]"
${CMD}
echo "- Copy over necessary files to ${SERVER} ..."
CMD="scp -oStrictHostKeyChecking=no ${SSH_KEY_FILE} ${FOLDER}/certificates/* ${USER}@${SERVER}:/data/software/certificates"
echo " [${CMD}]"
${CMD}
echo "- Copy over cucumber project ${PROJECT} to ${SERVER} ..."
CMD="scp -oStrictHostKeyChecking=no ${SSH_KEY_FILE} ${FOLDER}/${PROJECT}/target/cucumber-*test-jar-with-dependencies.jar ${USER}@${SERVER}:/data/software/${PROJECT}"
echo " [${CMD}]"
${CMD}
echo "- Executing cucumber project ${PROJECT} remote on ${SERVER} ..."
CMD="sudo java -javaagent:/usr/share/tomcat/lib/jacocoagent.jar=destfile=target/code-coverage/jacoco-it.exec ${ADDITIONAL_PARAMETERS}\
-Dcucumber.execution.strict=true\
-Dcucumber.filter.tags=\"not @Skip ${ADDITIONAL_CUCUMBER_OPTIONS}\"\
-DskipITs=false\
-Dtimeout=30\
-DskipITCoverage=false\
-DrunHeadless=true\
-jar cucumber-*-test-jar-with-dependencies.jar -report target/output"
echo " [${CMD}]"
CMD="ssh -oStrictHostKeyChecking=no -oTCPKeepAlive=yes -oServerAliveInterval=50 ${SSH_KEY_FILE} ${USER}@${SERVER} \"\"cd /data/software/${PROJECT} && ${CMD}\"\""
${CMD}
echo "- Take ownership over /data/software/${PROJECT}/* directory ..."
CMD="sudo chown -R ${USER}:${USER} /data/software/${PROJECT}/*"
echo " [${CMD}]"
CMD="ssh -oStrictHostKeyChecking=no -oTCPKeepAlive=yes -oServerAliveInterval=50 ${SSH_KEY_FILE} ${USER}@${SERVER} \"\"cd /data/software/${PROJECT} && ${CMD}\"\""
${CMD}
echo '- Create zip file from files from server ...'
CMD="sudo tar zhcvf /tmp/${SERVER}-${PROJECT}.tgz /etc/osgp /etc/httpd/conf.d /usr/share/tomcat/conf /var/log/tomcat /var/log/osgp /var/lib/pgsql/9.6/data/pg_log --warning=no-file-changed || true"
echo " [${CMD}]"
CMD="ssh -oStrictHostKeyChecking=no ${SSH_KEY_FILE} ${USER}@${SERVER} \"\"cd /data/software/${PROJECT} && ${CMD}\"\""
${CMD}
echo '- Take ownership over /tmp/${SERVER}-${PROJECT}.tgz ...'
CMD="sudo chown $USER:$USER /tmp/${SERVER}-${PROJECT}.tgz"
echo " [${CMD}]"
CMD="ssh -oStrictHostKeyChecking=no ${SSH_KEY_FILE} ${USER}@${SERVER} \"\"cd /data/software/${PROJECT} && ${CMD}\"\""
${CMD}
echo "- Collecting test output from cucumber project ${PROJECT} on ${SERVER} ..."
mkdir -p ${PROJECT}/target
CMD="scp -oStrictHostKeyChecking=no ${SSH_KEY_FILE} -r ${USER}@${SERVER}:/data/software/${PROJECT}/target/* ${PROJECT}/target"
echo " [${CMD}]"
${CMD}
echo "- Collecting code-coverage output from cucumber project ${PROJECT} on ${SERVER} ..."
mkdir -p ${PROJECT}/code-coverage
CMD="scp -oStrictHostKeyChecking=no ${SSH_KEY_FILE} -r ${USER}@${SERVER}:/data/software/${PROJECT}/target/code-coverage/* ${PROJECT}/code-coverage"
echo " [${CMD}]"
${CMD}
echo "- Collecting server files from ${SERVER} ..."
CMD="scp -oStrictHostKeyChecking=no ${SSH_KEY_FILE} -r ${USER}@${SERVER}:/tmp/${SERVER}-${PROJECT}.tgz ${PROJECT}/target"
echo " [${CMD}]"
${CMD}
#echo "- Clean logging for next tests on ${SERVER} ..."
#CMD="ssh -oStrictHostKeyChecking=no ${SSH_KEY_FILE} ${USER}@${SERVER} \"\"sudo truncate -s 0 /var/log/tomcat/catalina.out && sudo find /var/log/osgp/logs/ -name 'osgp*.log' -exec truncate -s 0 {} \; && sudo find /var/log/osp/logs/ -name 'web*.log' -exec truncate -s0 {} \; \"\""
#echo " [${CMD}]"
#${CMD}
echo "Done."