Chore: Add gerrit maven verify GHA workflow
[sdnc/oam.git] / csit / scripts / sdnr / sdnr-teardown.sh
1 #!/bin/bash
2 #
3 # Copyright 2016-2017 Huawei Technologies 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 # Modifications copyright (c) 2018 AT&T Intellectual Property
18 # Modifications copyright (C) 2022 highstreet technologies GmbH Intellectual Property
19 #
20
21 if [[ -z $WORKSPACE ]]; then
22         CUR_PATH="`dirname \"$0\"`"              # relative path
23         CUR_PATH="`( cd \"$CUR_PATH\" && pwd )`"  # absolutized and normalized
24         if [ -z "$CUR_PATH" ] ; then
25                 echo "Permission error!"
26                 exit 1
27         fi
28
29         # define location of workpsace based on where the current script is
30         WORKSPACE=$(cd $CUR_PATH/../../ && pwd)
31 fi
32
33 if [[ -z $SCRIPTS ]]; then
34         SCRIPTS=$(cd $WORKSPACE/scripts && pwd)
35 fi
36
37 source ${SCRIPTS}/sdnr/sdnrEnv_Common.sh
38 env_file="--env-file ${SCRIPTS}/sdnr/docker-compose/.env"
39
40 function sdnr_teardown() {
41         running_containers=$(docker ps -a --format "{{.Names}}")
42         if [ -z "$running_containers" ]
43         then
44                 echo "No containers to get logs from!"
45         else
46                 echo "Getting logs from containers!"
47                 running_containers_array=($(echo "$running_containers" | tr ' ' '\n'))
48                 mkdir -p ${WORKSPACE}/archives/getallinfo
49                 for i in "${running_containers_array[@]}"
50                 do
51                         echo "Getting logs from container $i"
52                         docker logs $i >> ${WORKSPACE}/archives/getallinfo/$i.log 2>&1
53                 done
54         docker cp sdnr:/opt/opendaylight/data/log/karaf.log ${WORKSPACE}/archives/getallinfo/sdnr_karaf.log
55         docker cp sdnr:/opt/opendaylight/data/log/installCerts.log ${WORKSPACE}/archives/getallinfo/sdnr_installCerts.log
56         docker cp sdnr:/opt/opendaylight/etc/custom.properties ${WORKSPACE}/archives/getallinfo/sdnr_custom_properties.log
57         fi
58         echo "Starting teardown!"
59         # removes sdnrdb, sdnr AND all of the rest of the containers (--remove-orphans)
60         docker rm -f $(docker ps -aq -f name=ntsim*)
61         docker rm -f $(docker ps -aq -f name=nts-*)
62         docker rm -f $(docker ps -aq -f name=NTS_Manager*)
63         docker rm -f $(docker ps -aq -f name=NTS-Manager*)
64         docker-compose $env_file -f ${WORKSPACE}/scripts/sdnr/docker-compose/docker-compose-single-sdnr.yaml down --remove-orphans
65         docker network rm integration
66 }