Skip to content
Permalink
Newer
Older
100644 162 lines (146 sloc) 5.06 KB
1
#!/bin/bash
2
Sep 28, 2018
3
#
4
# Contains common functions usable for midPoint system tests
5
#
6
7
# do not use from outside (ugly signature)
8
function generic_wait_for_log () {
Sep 28, 2018
9
CONTAINER_NAME=$1
10
MESSAGE="$2"
11
WAITING_FOR="$3"
12
FAILURE="$4"
13
ADDITIONAL_CONTAINER_NAME=$5
14
ATTEMPT=0
15
MAX_ATTEMPTS=20
16
DELAY=10
17
18
until [[ $ATTEMPT = $MAX_ATTEMPTS ]]; do
19
ATTEMPT=$((ATTEMPT+1))
20
echo "Waiting $DELAY seconds for $WAITING_FOR (attempt $ATTEMPT) ..."
21
sleep $DELAY
22
docker ps
23
( docker logs $CONTAINER_NAME 2>&1 | grep "$MESSAGE" ) && return 0
24
done
25
26
echo "$FAILURE" in $(( $MAX_ATTEMPTS * $DELAY )) seconds in $CONTAINER_NAME
27
echo "========== Container log =========="
28
docker logs $CONTAINER_NAME 2>&1
29
echo "========== End of the container log =========="
30
if [ -n "ADDITIONAL_CONTAINER_NAME" ]; then
31
echo "========== Container log ($ADDITIONAL_CONTAINER_NAME) =========="
32
docker logs $ADDITIONAL_CONTAINER_NAME 2>&1
33
echo "========== End of the container log ($DATABASE_CONTAINER_NAME) =========="
34
fi
35
return 1
36
}
Sep 28, 2018
37
38
function wait_for_log_message () {
39
generic_wait_for_log $1 "$2" "log message" "log message has not appeared"
40
}
41
42
# Waits until midPoint starts
43
function wait_for_midpoint_start () {
44
generic_wait_for_log $1 "INFO (com.evolveum.midpoint.web.boot.MidPointSpringApplication): Started MidPointSpringApplication in" "midPoint to start" "midPoint did not start" $2
45
}
46
Sep 28, 2018
47
# Checks the health of midPoint server
48
function check_health () {
49
echo Checking health...
50
(set -o pipefail ; curl -k -f https://localhost:8443/midpoint/actuator/health | tr -d '[:space:]' | grep -q "\"status\":\"UP\"")
51
status=$?
52
if [ $status -ne 0 ]; then
53
echo Error: $status
54
docker ps
55
return 1
56
else
57
echo OK
58
return 0
59
fi
60
}
61
62
# Retrieves XML object and checks if the name matches
63
function get_and_check_object () {
64
TYPE=$1
65
OID=$2
66
NAME=$3
67
TMPFILE=$(mktemp /tmp/get.XXXXXX)
68
echo tmp file is $TMPFILE
69
curl -k --user administrator:5ecr3t -H "Content-Type: application/xml" -X GET "https://localhost:8443/midpoint/ws/rest/$TYPE/$OID" >$TMPFILE || (rm $TMPFILE ; return 1)
70
if (grep -q "<name>$NAME</name>" <$TMPFILE); then
71
echo "Object $TYPE/$OID '$NAME' is OK"
72
rm $TMPFILE
73
return 0
74
else
75
echo "Object $TYPE/$OID '$NAME' was not found or not retrieved correctly:"
76
cat $TMPFILE
77
rm $TMPFILE
78
return 1
79
fi
80
}
81
82
# Adds object from a given file
83
# TODO Returns the OID in OID variable
84
# it can be found in the following HTTP reader returned: Location: "https://localhost:8443/midpoint/ws/rest/users/85e62669-d36b-41ce-b4f1-1ffdd9f66262"
85
function add_object () {
86
local TYPE=$1
87
local FILE=$2
Sep 28, 2018
88
echo "Adding to $TYPE from $FILE..."
89
curl -k --user administrator:5ecr3t -H "Content-Type: application/xml" -X POST "https://localhost:8443/midpoint/ws/rest/$TYPE" -d @$FILE || return 1
90
#TODO check the returned XML
91
return 0
92
}
93
94
# Tries to find an object with a given name
95
# Results of the search are in the $SEARCH_RESULT_FILE
96
# TODO check if the result is valid (i.e. not an error) - return 1 if invalid, otherwise return 0 ("no objects" is considered OK here)
97
function search_objects_by_name () {
98
TYPE=$1
99
NAME="$2"
Sep 28, 2018
100
TMPFILE=$(mktemp /tmp/search.XXXXXX)
101
102
curl -k --user administrator:5ecr3t -H "Content-Type: application/xml" -X POST "https://localhost:8443/midpoint/ws/rest/$TYPE/search" -d @- << EOF >$TMPFILE || (rm $TMPFILE ; return 1)
103
<q:query xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3">
104
<q:filter>
105
<q:equal>
106
<q:path>name</q:path>
107
<q:value>$NAME</q:value>
108
</q:equal>
109
</q:filter>
110
</q:query>
111
EOF
112
SEARCH_RESULT_FILE=$TMPFILE
113
# TODO check validity of the file
114
return 0
115
}
116
117
# Searches for object with a given name and verifies it was found
118
function search_and_check_object () {
119
local TYPE=$1
120
local NAME="$2"
121
search_objects_by_name $TYPE "$NAME" || return 1
Sep 28, 2018
122
if (grep -q "<name>$NAME</name>" <$SEARCH_RESULT_FILE); then
123
echo "Object $TYPE/'$NAME' is OK"
124
rm $SEARCH_RESULT_FILE
125
return 0
126
else
127
echo "Object $TYPE/'$NAME' was not found or not retrieved correctly:"
128
cat $SEARCH_RESULT_FILE
129
rm $SEARCH_RESULT_FILE
130
return 1
131
fi
132
}
133
134
# Tests a resource
135
function test_resource () {
136
local OID=$1
137
local TMPFILE=$(mktemp /tmp/test.resource.XXXXXX)
138
139
curl -k --user administrator:5ecr3t -H "Content-Type: application/xml" -X POST "https://localhost:8443/midpoint/ws/rest/resources/$OID/test" >$TMPFILE || (rm $TMPFILE ; return 1)
140
if [[ $(xmllint --xpath "/*/*[local-name()='status']/text()" $TMPFILE) == "success" ]]; then
141
echo "Resource $OID test succeeded"
142
rm $TMPFILE
143
return 0
144
else
145
echo "Resource $OID test failed"
146
cat $TMPFILE
147
rm $TMPFILE
148
return 1
149
fi
150
}
152
function assert_task_success () {
153
local OID=$1
154
# TODO
155
return 0
156
}
157
158
function wait_for_task_completion () {
159
local OID=$1
160
sleep 60 # TODO
161
return 0
You can’t perform that action at this time.