blob: bf51329431fdfe195b8d1e7357398c841db60b82 [file] [log] [blame]
Sylvain Desbureaux16bdf242020-12-07 10:28:24 +01001#!/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
23TMPDIR='/tmp'
24TMPTPL='onap_security'
25CSV2JSON='import csv; import json; import sys; print(json.dumps({i[0]: i[1] for i in csv.reader(sys.stdin)}))'
26FILTER="$(tr -d [:space:] <<TEMPLATE
27{{range .items}}
guillaume.lambert7bf306e2021-09-08 12:03:22 +020028 {{range.spec.ports}}
29 {{if .nodePort}}
30 {{.nodePort}}{{','}}{{.name}}{{'\n'}}
31 {{end}}
32 {{end}}
Sylvain Desbureaux16bdf242020-12-07 10:28:24 +010033{{end}}
34TEMPLATE)"
35
36
37setup () {
guillaume.lambert7bf306e2021-09-08 12:03:22 +020038 export NODEPORTS_FILE="$(mktemp -p ${TMPDIR} ${TMPTPL}XXX)"
Sylvain Desbureaux16bdf242020-12-07 10:28:24 +010039}
40
41create_actual_nodeport_json () {
guillaume.lambert7bf306e2021-09-08 12:03:22 +020042 kubectl get svc -n $NAMESPACE -o go-template="$FILTER" | python3 -c "$CSV2JSON" > "$NODEPORTS_FILE"
Sylvain Desbureaux16bdf242020-12-07 10:28:24 +010043}
44
45copy_actual_nodeport_json_to_robot () {
guillaume.lambert7bf306e2021-09-08 12:03:22 +020046 kubectl cp "$1" "$2/$3:$4"
Sylvain Desbureaux16bdf242020-12-07 10:28:24 +010047}
48
49cleanup () {
guillaume.lambert7bf306e2021-09-08 12:03:22 +020050 rm "$NODEPORTS_FILE"
Sylvain Desbureaux16bdf242020-12-07 10:28:24 +010051}
52
53
54setup
55create_actual_nodeport_json
56copy_actual_nodeport_json_to_robot "$NODEPORTS_FILE" "$NAMESPACE" "$POD" "$TMPDIR"
57cleanup