-
Notifications
You must be signed in to change notification settings - Fork 2
/
validate.sh
executable file
·135 lines (117 loc) · 5.5 KB
/
validate.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
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
#!/bin/bash
# This is the script that is used to validate that the examples are runnable with xOpera orchestrator.
# We validate (= parse) the xOpera examples with xOpera TOSCA parser (opera-tosca-parser PyPI package)
# This script is used within the CI/CD, but you can also run it manually with: ./validate.sh opera-tosca-parser
# get opera executable
opera_tosca_parser_executable="$1"
[[ -z "$opera_tosca_parser_executable" ]] && echo "Missing path to opera-tosca-parser (the first argument)." && exit 1
# initialize variables for testing
tests_run=0
successful=0
failed=0
# function for validating and checking the exit codes of the tested examples
validate_example() {
# set function arguments
example_base_path="$1"
service_template_file_name="$2"
inputs_file_name="$3"
# move into folder with example
cd "$example_base_path" || true
if [ "$inputs_file_name" == "" ]; then
validate=$($opera_tosca_parser_executable parse "${service_template_file_name}" 2>&1)
exit_code="$?"
else
validate=$($opera_tosca_parser_executable parse -i "${inputs_file_name}" "${service_template_file_name}" 2>&1)
exit_code="$?"
fi
# move back
cd - >/dev/null || true
tests_run=$((tests_run + 1))
if [ "$exit_code" -eq 0 ]; then
successful=$((successful + 1))
printf "%-80s OK\n" "$example_base_path"
else
failed=$((failed + 1))
printf "%-80s ERROR\n" "$example_base_path"
echo "$validate"
fi
return 0
}
# start testing
printf "Validating xOpera examples ...\n"
# test an example from tosca/artifacts
validate_example "tosca/artifacts" "service.yaml" ""
# test an example from tosca/attribute-mapping
validate_example "tosca/attribute-mapping" "service.yaml" ""
# test an example from tosca/capability-attributes-properties
validate_example "tosca/capability-attributes-properties" "service.yaml" ""
# test an example from tosca/intrinsic-functions
validate_example "tosca/intrinsic-functions" "service.yaml" ""
# test an example from tosca/outputs
validate_example "tosca/outputs" "service.yaml" ""
# test an example from tosca/policy-triggers
validate_example "tosca/policy-triggers" "service.yaml" ""
# test an example from tosca/relationship-outputs
validate_example "tosca/relationship-outputs" "service.yaml" ""
# test an example from misc/compare-templates
validate_example "misc/compare-templates" "service1.yaml" "inputs1.yaml"
# test an example from misc/concurrency
validate_example "misc/concurrency" "service.yaml" ""
# test an example from misc/hello-world
validate_example "misc/hello-world" "service.yaml" ""
# test an example from misc/nginx-openstack
validate_example "misc/nginx-openstack" "service.yaml" "inputs.yaml"
# test an example from misc/scaling
validate_example "misc/scaling" "service.yaml" ""
# test an example from misc/server-client
validate_example "misc/server-client" "service.yaml" ""
# test an example from csars/small
validate_example "csars/small" "service.yaml" "inputs.json"
# test a compressed CSAR example from csars/small
cd csars/small || true
mkdir -p compressed
cp inputs.json compressed/inputs.json
zip -qFSr compressed/small.csar service.yaml playbooks files
cd ../..
validate_example "csars/small/compressed" "small.csar" "inputs.json"
rm -rf csars/small/compressed
# test an example from csars/misc-tosca-types
validate_example "csars/misc-tosca-types" "service.yaml" "inputs.yaml"
# test a compressed CSAR example from csars/misc-tosca-types
cd csars/misc-tosca-types || true
mkdir -p compressed
cp inputs.yaml compressed/inputs.yaml
zip -qFSr compressed/misc-tosca-types.csar service.yaml modules TOSCA-Metadata
cd ../..
validate_example "csars/misc-tosca-types/compressed" "misc-tosca-types.csar" "inputs.yaml"
rm -rf csars/misc-tosca-types/compressed
# test an example from cloud/aws/s3-bucket
validate_example "cloud/aws/s3-bucket" "service.yaml" "inputs.yaml"
# test an example from cloud/aws/thumbnail-generator
validate_example "cloud/aws/thumbnail-generator" "service.yaml" "inputs.yaml"
# test an example from cloud/aws/thumbnail-generator-with-api-gateway
validate_example "cloud/aws/thumbnail-generator-with-api-gateway" "service.yaml" "inputs.yaml"
# test an example from cloud/aws/thumbnail-generator-with-vm
validate_example "cloud/aws/thumbnail-generator-with-vm" "service.yaml" "inputs.yaml"
# test an example from cloud/azure/thumbnail-generator
validate_example "cloud/azure/thumbnail-generator" "service.yaml" "inputs.yaml"
# test an example from cloud/gcp/thumbnail-generator
validate_example "cloud/gcp/thumbnail-generator" "service.yaml" "inputs.yaml"
# test an example from cloud/openfaas/thumbnail-generator
validate_example "cloud/openfaas/thumbnail-generator/openfaas-setup" "service.yaml" "inputs.yaml"
validate_example "cloud/openfaas/thumbnail-generator/image-resize" "service.yaml" "inputs.yaml"
# test an example from cloud/platform-connection/aws-azure-connection
validate_example "cloud/platform-connection/aws-azure-connection/aws-azure" "service.yaml" "inputs.yaml"
validate_example "cloud/platform-connection/aws-azure-connection/azure-aws" "service.yaml" "inputs.yaml"
# test an example from kubernetes/docker
validate_example "kubernetes/docker" "service.yaml" "inputs.yaml"
# test an example from kubernetes/rancher
validate_example "kubernetes/rancher" "service.yaml" "inputs.yaml"
# finish testing
printf "\nTesting finished: %d tests runned, %d successful, %d failures\n" "$tests_run" "$successful" "$failed"
# decide the final exit code
if [ "$failed" -ne 0 ]; then
exit 1
else
exit 0
fi