Sylvain Desbureaux | 16bdf24 | 2020-12-07 10:28:24 +0100 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # Copyright 2019 Samsung Electronics Co., Ltd. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | # |
| 18 | # Gather information on ONAP cluster required by security tests. |
| 19 | # Copy results to Robot pod. |
| 20 | # |
| 21 | |
| 22 | |
| 23 | TMPDIR='/tmp' |
| 24 | TMPTPL='onap_security' |
| 25 | CSV2JSON='import csv; import json; import sys; print(json.dumps({i[0]: i[1] for i in csv.reader(sys.stdin)}))' |
| 26 | FILTER="$(tr -d [:space:] <<TEMPLATE |
| 27 | {{range .items}} |
| 28 | {{range.spec.ports}} |
| 29 | {{if .nodePort}} |
| 30 | {{.nodePort}}{{','}}{{.name}}{{'\n'}} |
| 31 | {{end}} |
| 32 | {{end}} |
| 33 | {{end}} |
| 34 | TEMPLATE)" |
| 35 | |
| 36 | |
| 37 | setup () { |
| 38 | export NODEPORTS_FILE="$(mktemp -p ${TMPDIR} ${TMPTPL}XXX)" |
| 39 | } |
| 40 | |
| 41 | create_actual_nodeport_json () { |
| 42 | kubectl get svc -n $NAMESPACE -o go-template="$FILTER" | python3 -c "$CSV2JSON" > "$NODEPORTS_FILE" |
| 43 | } |
| 44 | |
| 45 | copy_actual_nodeport_json_to_robot () { |
| 46 | kubectl cp "$1" "$2/$3:$4" |
| 47 | } |
| 48 | |
| 49 | cleanup () { |
| 50 | rm "$NODEPORTS_FILE" |
| 51 | } |
| 52 | |
| 53 | |
| 54 | setup |
| 55 | create_actual_nodeport_json |
| 56 | copy_actual_nodeport_json_to_robot "$NODEPORTS_FILE" "$NAMESPACE" "$POD" "$TMPDIR" |
| 57 | cleanup |