-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasks
executable file
·275 lines (243 loc) · 8.47 KB
/
tasks
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#!/usr/bin/env bash
set -Eeo pipefail
###########################
# Local Config Parameters #
###########################
export AWS_DEFAULT_REGION=eu-west-2
export AWS_REGION=eu-west-2
IMAGE_REPO_NAME=deductions/prm-deductions-automatic-trigger-e2e
export NHS_SERVICE=prm-deductions-automatic-trigger-e2e
AWS_HELPERS_VERSION=0.2.19
echo "AWS helper scripts version: $AWS_HELPERS_VERSION"
# Do not change the file name as the aws helper scripts depend on it
AWS_HELPERS_FILE="utils/$AWS_HELPERS_VERSION/aws-helpers"
mkdir -p "utils/$AWS_HELPERS_VERSION"
if [[ ! -f $AWS_HELPERS_FILE ]];then
wget --quiet -O $AWS_HELPERS_FILE https://github.com/nhsconnect/prm-deductions-support-infra/releases/download/${AWS_HELPERS_VERSION}/aws-helpers
fi
chmod +x $AWS_HELPERS_FILE
source $AWS_HELPERS_FILE
####################################
# Instance (Environment) Variables #
####################################
function check_env {
if [[ -z "${NHS_ENVIRONMENT}" ]]; then
echo "Must set NHS_ENVIRONMENT"
exit 17
fi
}
function check_environment_id {
if [[ -z "${ENVIRONMENT_ID}" ]]; then
echo "Must set ENVIRONMENT_ID"
exit 14
fi
}
function set_image_tag() {
export IMAGE_TAG=$(git rev-parse HEAD | cut -c 1-8)
}
function configure_local_envs {
export NHS_ENVIRONMENT=local
}
function configure_mesh_access {
mesh_mailbox_id="/repo/dev/user-input/external/mesh-mailbox-id"
echo "${mesh_mailbox_id}"
mesh_client_cert="/repo/${NHS_ENVIRONMENT}/user-input/external/mesh-mailbox-client-cert"
echo "${mesh_client_cert}"
mesh_client_key="/repo/${NHS_ENVIRONMENT}/user-input/external/mesh-mailbox-client-key"
export MESH_MAILBOX_ID=$(dojo -c Dojofile-infra "aws ssm get-parameter --with-decryption --region ${AWS_DEFAULT_REGION} --name ${mesh_mailbox_id} | jq -r .Parameter.Value")
export MESH_CLIENT_CERT=$(dojo -c Dojofile-infra "aws ssm get-parameter --with-decryption --region ${AWS_DEFAULT_REGION} --name ${mesh_client_cert} | jq -r .Parameter.Value")
export MESH_CLIENT_KEY=$(dojo -c Dojofile-infra "aws ssm get-parameter --with-decryption --region ${AWS_DEFAULT_REGION} --name ${mesh_client_key} | jq -r .Parameter.Value")
}
function get_suspension_service_cluster_name {
cluster_ssm_param_name="/repo/${NHS_ENVIRONMENT}/output/suspension-service/suspension-service-ecs-cluster-name"
export SUSPENSION_SERVICE_CLUSTER_NAME=$(dojo -c Dojofile-infra "aws ssm get-parameter --with-decryption --region ${AWS_DEFAULT_REGION} --name ${cluster_ssm_param_name} | jq -r .Parameter.Value")
echo $SUSPENSION_SERVICE_CLUSTER_NAME
}
function get_running_task_count {
echo $(aws ecs describe-clusters \
--cluster "$1" \
--region "$AWS_REGION" \
| jq -r '.clusters[0].runningTasksCount')
}
function check_suspension_service {
if [[ "$NHS_ENVIRONMENT" != "test" ]]; then
echo "We're not checking suspension-service for dev env"
return 0
fi
POLLING_ATTEMPTS_LEFT=6
CLUSTER_NAME=$(get_suspension_service_cluster_name)
while [ "$POLLING_ATTEMPTS_LEFT" -gt "0" ]; do
TASKS_COUNT=$(get_running_task_count ${CLUSTER_NAME})
echo "Number of running tasks found: $TASKS_COUNT"
if [[ "$TASKS_COUNT" -eq "0" || "$TASKS_COUNT" == "null" ]]; then
let POLLING_ATTEMPTS_LEFT--
echo "No running task found. Making another attempt. Attempts left: $POLLING_ATTEMPTS_LEFT"
sleep 180 #3 mins
else
echo "Found $TASKS_COUNT running tasks in $CLUSTER_NAME"
return 0
fi
done
echo "Can't find a running task in $CLUSTER_NAME"
exit 1
}
function set_required_role_arn_from_assumed_role() {
export REQUIRED_ROLE_ARN=$(dojo -c Dojofile-infra "aws sts get-caller-identity | jq -r .Arn")
}
source gocd/gocd_api_client.sh
source gocd/trigger_functions.sh
###########
## TASKS ##
###########
command="$1"
case "${command}" in
_test_continuity_e2e)
gradle test --tests "uk.nhs.prm.e2etests.test.ContinuityE2ETest"
;;
test_continuity_e2e)
check_env
assume_environment_role $NHS_ENVIRONMENT
check_suspension_service
dojo "./tasks _test_continuity_e2e"
;;
_test_repo_e2e)
gradle test --tests "uk.nhs.prm.e2etests.test.RepositoryE2ETest"
;;
test_repo_e2e)
check_env
assume_environment_role $NHS_ENVIRONMENT
dojo "./tasks _test_repo_e2e"
;;
test_repo_e2e_shell)
check_env
assume_environment_role $NHS_ENVIRONMENT
dojo
;;
_livetest_inject)
gradle test --tests InjectChangeOfGPMessageTest
;;
livetest_inject)
check_env
assume_environment_role $NHS_ENVIRONMENT
dojo "./tasks _livetest_inject"
;;
_livetest_day1_test)
gradle test --tests ChangeOfGPMessageReceivedTest
;;
livetest_day1_test)
check_env
assume_environment_role $NHS_ENVIRONMENT
dojo "./tasks _livetest_day1_test"
;;
_livetest_day2_test)
gradle test --tests ValidateMOFUpdatedTest
;;
livetest_day2_test)
check_env
assume_environment_role $NHS_ENVIRONMENT
dojo "./tasks _livetest_day2_test"
;;
_live_synthetic_check_suspended)
gradle test --tests ValidateSyntheticPatientIsSuspendedTest
;;
live_synthetic_check_suspended)
check_env
assume_environment_role $NHS_ENVIRONMENT
dojo "./tasks _live_synthetic_check_suspended"
;;
_live_synthetic_transfer_in_ehr)
gradle test --tests ValidateSyntheticEhrTransferInToRepoUsingMofTest
;;
live_synthetic_transfer_in_ehr)
check_env
assume_environment_role $NHS_ENVIRONMENT
dojo "./tasks _live_synthetic_transfer_in_ehr"
;;
_test_perf_unit)
gradle test --tests *.performance.*.*Test
;;
test_perf_unit)
dojo "./tasks _test_perf_unit"
;;
_test_performance)
gradle test --tests *.PerformanceTest
;;
test_performance_local) # using local user auth
check_env
assume_environment_role $NHS_ENVIRONMENT
dojo "./tasks _test_performance"
;;
test_performance) # in pipeline
check_env
assume_environment_role $NHS_ENVIRONMENT
set_required_role_arn_from_assumed_role
echo "set REQUIRED_ROLE_ARN to $REQUIRED_ROLE_ARN for long-running test process"
echo "NB: clearing temporary auth session credentials to allow native AWS auth access to re-assume role after expiry"
_clear_aws_env_credentials
dojo "./tasks _test_performance"
;;
_test_repo_in_performance)
gradle test --tests *.RepoInPerformanceTest
;;
test_repo_in_performance)
check_env
assume_environment_role $NHS_ENVIRONMENT
set_required_role_arn_from_assumed_role
echo "set REQUIRED_ROLE_ARN to $REQUIRED_ROLE_ARN for long-running test process"
echo "NB: clearing temporary auth session credentials to allow native AWS auth access to re-assume role after expiry"
_clear_aws_env_credentials
dojo "./tasks _test_repo_in_performance"
;;
_test_repo_out_performance)
gradle test --tests *.RepositoryPerformanceTest
;;
test_repo_out_performance)
check_env
assume_environment_role $NHS_ENVIRONMENT
set_required_role_arn_from_assumed_role
echo "set REQUIRED_ROLE_ARN to $REQUIRED_ROLE_ARN for long-running test process"
echo "NB: clearing temporary auth session credentials to allow native AWS auth access to re-assume role after expiry"
_clear_aws_env_credentials
dojo "./tasks _test_repo_out_performance"
;;
_test_technical)
gradle test --tests *ChangeOfGPMessageReceivedTest
;;
test_technical)
;;
_ehr_tool)
export MESSAGES_DIR=tools/large-ehr-inspector/samples
export TEMPLATE_MESSAGE_ID=9e6f8d45-913a-4c67-89f3-10d131fc332c
export TARGET_MESSAGE_ID=be6f8d45-913a-4c67-89f3-10d131fc332c
gradle ehrTool
;;
_check_env_deployed_before)
check_environment_id
check_environment_is_deployed
;;
check_env_deployed_before)
dojo -c Dojofile-infra "./tasks _check_env_deployed_before"
;;
_check_env_still_deployed_after)
check_environment_id
check_environment_is_still_deployed_after
;;
check_env_still_deployed_after)
dojo -c Dojofile-infra "./tasks _check_env_still_deployed_after"
;;
_trigger_gocd_job)
check_environment_id
trigger_downstream_stages
;;
trigger_gocd_job)
dojo -c Dojofile-infra "./tasks _trigger_gocd_job"
;;
test_gocd_trigger_functions)
dojo -c Dojofile-infra './gocd/test_trigger_functions.sh'
;;
*)
echo "Invalid command: '${command}'"
exit 1
;;
esac
set +e