X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FNBI.git;a=blobdiff_plain;f=osm_nbi%2Ftests%2Fclear-all.sh;h=23a87ac765cfc0544e5a7695e1b5e8be62988044;hp=5a9a9c69b45a09a3721446b318bd392f9ec0fe77;hb=7cbd03c5c21202fff473ae943e75dd49a18f2516;hpb=b69fb3ca37645088483959976edbfc7fda66df8d diff --git a/osm_nbi/tests/clear-all.sh b/osm_nbi/tests/clear-all.sh index 5a9a9c6..23a87ac 100755 --- a/osm_nbi/tests/clear-all.sh +++ b/osm_nbi/tests/clear-all.sh @@ -1,15 +1,31 @@ #! /bin/bash + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + # author: Alfonso Tierno # Script that uses the test NBI URL to clean database. See usage function usage(){ echo -e "usage: $0 [OPTIONS]" - echo -e "TEST NBI API is used to clean database content, except user admin. Useful for testing." + echo -e "TEST NBI API is used to clean database content, except admin users,projects and roles. Useful for testing." echo -e "NOTE: database is cleaned but not the content of other modules as RO or VCA that must be cleaned manually." echo -e " OPTIONS" echo -e " -h --help: show this help" echo -e " -f --force: Do not ask for confirmation" + echo -e " --completely: It cleans also admin user/project and roles. It only works for internal" \ + "authentication. NBI will need to be restarted to init database" echo -e " --clean-RO: clean RO content. RO client (openmano) must be installed and configured" echo -e " --clean-VCA: clean VCA content. juju must be installed and configured" echo -e " ENV variable 'OSMNBI_URL' is used for the URL of the NBI server. If missing, it uses" \ @@ -38,6 +54,7 @@ do shift ( [ "$option" == -h ] || [ "$option" == --help ] ) && usage && exit ( [ "$option" == -f ] || [ "$option" == --force ] ) && OSMNBI_CLEAN_FORCE=yes && continue + [ "$option" == --completely ] && OSMNBI_COMPLETELY=yes && continue [ "$option" == --clean-RO ] && OSMNBI_CLEAN_RO=yes && continue [ "$option" == --clean-VCA ] && OSMNBI_CLEAN_VCA=yes && continue echo "Unknown option '$option'. Type $0 --help" 2>&1 && exit 1 @@ -64,23 +81,59 @@ then done fi -for item in vim_accounts vims sdns nsrs vnfrs nslcmops nsds vnfds projects +for item in vim_accounts wim_accounts sdns nsrs vnfrs nslcmops nsds vnfds pdus nsts nsis nsilcmops # vims do curl --insecure ${OSMNBI_URL}/test/db-clear/${item} - echo " ${item}" done -# delete all users except admin -curl --insecure ${OSMNBI_URL}/test/db-clear/users?username.ne=admin +curl --insecure ${OSMNBI_URL}/test/fs-clear +if [ -n "$OSMNBI_COMPLETELY" ] ; then + # delete all users. It will only works for internal backend + curl --insecure ${OSMNBI_URL}/test/db-clear/users + curl --insecure ${OSMNBI_URL}/test/db-clear/projects + curl --insecure ${OSMNBI_URL}/test/db-clear/roles +fi + + [[ -z "$OSM_USER" ]] && OSM_USER=admin + [[ -z "$OSM_PASSWORD" ]] && OSM_PASSWORD=admin + [[ -z "$OSM_PROJECT" ]] && OSM_PROJECT=admin + + TOKEN=`curl --insecure -H "Content-Type: application/yaml" -H "Accept: application/yaml" \ + --data "{username: '$OSM_USER', password: '$OSM_PASSWORD', project_id: '$OSM_PROJECT'}" \ + ${OSMNBI_URL}/admin/v1/tokens 2>/dev/null | awk '($1=="_id:"){print $2}'`; + echo "TOKEN='$TOKEN'" + + echo "delete users, prujects,roles. Ignore response errors due that own user,project cannot be deleted" + for topic in users projects roles + do + elements=`curl --insecure ${OSMNBI_URL}/admin/v1/$topic -H "Authorization: Bearer $TOKEN" \ + -H "Accept: application/yaml" 2>/dev/null | awk '($1=="_id:"){print $2};($2=="_id:"){print $3}'`; + for element in $elements + do + # not needed to check if own user, project, etc; because OSM will deny deletion + echo deleting $topic _id=$element + curl --insecure ${OSMNBI_URL}/admin/v1/$topic/$element -H "Authorization: Bearer $TOKEN" \ + -H "Accept: application/yaml" -X DELETE 2>/dev/null + done + done + if [ -n "$OSMNBI_CLEAN_RO" ] then for dc in `openmano datacenter-list | awk '{print $1}'` ; do openmano datacenter-detach $dc ; done for dc in `openmano datacenter-list --all | awk '{print $1}'` ; do openmano datacenter-delete -f $dc ; done for dc in `openmano sdn-controller-list | awk '{print $1}'` ; do openmano sdn-controller-delete -f $dc ; done + for dc in `openmano wim-list | awk '{print $1}'` ; do openmano wim-detach $dc ; done + for dc in `openmano wim-list --all | awk '{print $1}'` ; do openmano wim-delete -f $dc ; done fi if [ -n "$OSMNBI_CLEAN_VCA" ] then - juju destroy-model -y default - juju add-model default + for juju_model in `juju models | grep lxd | grep -v controller | grep -v default | awk '{print$1}'` + do + echo + echo juju destroy-model $juju_model + juju destroy-model -y $juju_model + done + # juju destroy-model -y default + # juju add-model default fi