From 8a0c9450a19892d4254e2b69d04f3b84007b700b Mon Sep 17 00:00:00 2001 From: Nate Potter Date: Wed, 2 Aug 2017 15:17:41 -0700 Subject: Add warnings and options to run.sh Adds a warning to run.sh informing the user that the contents of their /opt folder will be deleted by the test. Also adds option parsing, -y for skipping the prompt, -s for test suite selection, -c for test case selection, as well as -h for displaying help for the program. Change-Id: I888350d31839bd6db91a497a04ae3308af5329e9 Issue-Id: INT-97 Signed-off-by: Nate Potter --- bootstrap/vagrant-onap/CONTRIBUTING.md | 8 +- bootstrap/vagrant-onap/Vagrantfile | 30 +++---- bootstrap/vagrant-onap/postinstall.sh | 17 ---- bootstrap/vagrant-onap/tools/run.sh | 91 +++++++++++++++++++--- bootstrap/vagrant-onap/unit_testing.sh | 15 ---- .../vagrant-onap/vagrant_utils/postinstall.sh | 17 ++++ .../vagrant-onap/vagrant_utils/unit_testing.sh | 10 +++ 7 files changed, 128 insertions(+), 60 deletions(-) delete mode 100755 bootstrap/vagrant-onap/postinstall.sh delete mode 100755 bootstrap/vagrant-onap/unit_testing.sh create mode 100755 bootstrap/vagrant-onap/vagrant_utils/postinstall.sh create mode 100755 bootstrap/vagrant-onap/vagrant_utils/unit_testing.sh (limited to 'bootstrap/vagrant-onap') diff --git a/bootstrap/vagrant-onap/CONTRIBUTING.md b/bootstrap/vagrant-onap/CONTRIBUTING.md index 6f2897ce3..3e42510fe 100644 --- a/bootstrap/vagrant-onap/CONTRIBUTING.md +++ b/bootstrap/vagrant-onap/CONTRIBUTING.md @@ -15,7 +15,7 @@ implementation of the _functions_ created on **_lib_** folder. In order to execute the Unit Tests defined for this project, you must run the following command: - $ ./tools/run.sh testing [test_suite] [function] + $ ./tools/run.sh -s [test_suite] -c [function] testing or using PowerShell @@ -25,6 +25,6 @@ or using PowerShell Examples -------- - $ ./tools/run.sh testing # Executes all the Unit Tests - $ ./tools/run.sh testing functions # Executes all the Unit Tests of Functions Test Suite - $ ./tools/run.sh testing functions install_maven # Executes the install_maven Unit Test of Functions Test Suite + $ ./tools/run.sh -y testing # Executes all the Unit Tests unattended mode + $ ./tools/run.sh -s functions testing # Executes all the Unit Tests of Functions Test Suite + $ ./tools/run.sh -s functions -c install_maven testing # Executes the install_maven Unit Test of Functions Test Suite diff --git a/bootstrap/vagrant-onap/Vagrantfile b/bootstrap/vagrant-onap/Vagrantfile index 0e8e1da1c..3ee305c39 100644 --- a/bootstrap/vagrant-onap/Vagrantfile +++ b/bootstrap/vagrant-onap/Vagrantfile @@ -152,7 +152,7 @@ Vagrant.configure("2") do |config| v.flavor = 'm1.xlarge' end all_in_one.vm.provision 'shell' do |s| - s.path = 'postinstall.sh' + s.path = 'vagrant_utils/postinstall.sh' s.args = ['mr', 'sdc', 'aai', 'mso', 'robot', 'vid', 'sdnc', 'portal', 'dcae', 'policy', 'appc', 'vfc'] s.env = conf end @@ -175,7 +175,7 @@ Vagrant.configure("2") do |config| v.flavor = 'm1.small' end dns.vm.provision 'shell' do |s| - s.path = 'postinstall.sh' + s.path = 'vagrant_utils/postinstall.sh' s.env = conf end end @@ -187,7 +187,7 @@ Vagrant.configure("2") do |config| v.server_name = 'message-router' end mr.vm.provision 'shell' do |s| - s.path = 'postinstall.sh' + s.path = 'vagrant_utils/postinstall.sh' s.args = ['mr'] s.env = conf end @@ -209,7 +209,7 @@ Vagrant.configure("2") do |config| v.server_name = 'sdc' end sdc.vm.provision 'shell' do |s| - s.path = 'postinstall.sh' + s.path = 'vagrant_utils/postinstall.sh' s.args = ['sdc'] s.env = conf end @@ -222,7 +222,7 @@ Vagrant.configure("2") do |config| v.server_name = 'aai' end aai.vm.provision 'shell' do |s| - s.path = 'postinstall.sh' + s.path = 'vagrant_utils/postinstall.sh' s.args = ['aai'] s.env = conf end @@ -235,7 +235,7 @@ Vagrant.configure("2") do |config| v.server_name = 'mso' end mso.vm.provision 'shell' do |s| - s.path = 'postinstall.sh' + s.path = 'vagrant_utils/postinstall.sh' s.args = ['mso'] s.env = conf end @@ -248,7 +248,7 @@ Vagrant.configure("2") do |config| v.server_name = 'robot' end robot.vm.provision 'shell' do |s| - s.path = 'postinstall.sh' + s.path = 'vagrant_utils/postinstall.sh' s.args = ['robot'] s.env = conf end @@ -261,7 +261,7 @@ Vagrant.configure("2") do |config| v.server_name = 'vid' end vid.vm.provision 'shell' do |s| - s.path = 'postinstall.sh' + s.path = 'vagrant_utils/postinstall.sh' s.args = ['vid'] s.env = conf end @@ -274,7 +274,7 @@ Vagrant.configure("2") do |config| v.server_name = 'sdnc' end sdnc.vm.provision 'shell' do |s| - s.path = 'postinstall.sh' + s.path = 'vagrant_utils/postinstall.sh' s.args = ['sdnc'] s.env = conf end @@ -287,7 +287,7 @@ Vagrant.configure("2") do |config| v.server_name = 'portal' end portal.vm.provision 'shell' do |s| - s.path = 'postinstall.sh' + s.path = 'vagrant_utils/postinstall.sh' s.args = ['portal'] s.env = conf end @@ -300,7 +300,7 @@ Vagrant.configure("2") do |config| v.server_name = 'dcae' end dcae.vm.provision 'shell' do |s| - s.path = 'postinstall.sh' + s.path = 'vagrant_utils/postinstall.sh' s.args = ['dcae'] s.env = conf end @@ -313,7 +313,7 @@ Vagrant.configure("2") do |config| v.server_name = 'policy' end policy.vm.provision 'shell' do |s| - s.path = 'postinstall.sh' + s.path = 'vagrant_utils/postinstall.sh' s.args = ['policy'] s.env = conf end @@ -326,7 +326,7 @@ Vagrant.configure("2") do |config| v.server_name = 'appc' end appc.vm.provision 'shell' do |s| - s.path = 'postinstall.sh' + s.path = 'vagrant_utils/postinstall.sh' s.args = ['appc'] s.env = conf end @@ -339,7 +339,7 @@ Vagrant.configure("2") do |config| v.server_name = 'vfc' end vfc.vm.provision 'shell' do |s| - s.path = 'postinstall.sh' + s.path = 'vagrant_utils/postinstall.sh' s.args = ['vfc'] s.env = conf end @@ -366,7 +366,7 @@ Vagrant.configure("2") do |config| v.flavor = 'm1.small' end testing.vm.provision 'shell' do |s| - s.path = 'unit_testing.sh' + s.path = 'vagrant_utils/unit_testing.sh' s.args = [test_suite, test_case] s.env = conf end diff --git a/bootstrap/vagrant-onap/postinstall.sh b/bootstrap/vagrant-onap/postinstall.sh deleted file mode 100755 index f5a7ac684..000000000 --- a/bootstrap/vagrant-onap/postinstall.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -set -o xtrace - -source /var/onap/functions - -export_env_vars -create_configuration_files -install_dev_tools -install_java -configure_bind - -for serv in $@; do - source /var/onap/${serv} - configure_service ${serv}_serv.sh - init_${serv} -done diff --git a/bootstrap/vagrant-onap/tools/run.sh b/bootstrap/vagrant-onap/tools/run.sh index b9a4a4311..aeb9d8c49 100755 --- a/bootstrap/vagrant-onap/tools/run.sh +++ b/bootstrap/vagrant-onap/tools/run.sh @@ -1,20 +1,93 @@ #!/bin/bash -case $1 in +usage () +{ +cat < + Test suite to use in testing mode. + -c + Test case to use in testing mode. +Commands: + all_in_one Deploy in all-in-one mode. + dns|mr|sdc|aai|mso|robot|vid|sdnc|portal|dcae|policy|appc Deploy chosen service. + testing Deploy in testing mode. +EOF +} + +run=false +test_suite="*" +test_case="*" + +COMMAND=${@: -1} + +while getopts "yhs:c:" OPTION; do + case "$OPTION" in + y) + run=true + ;; + s) + if [ "$COMMAND" != "testing" ] ; then + echo "Test suite should only be specified in testing mode." + echo "./run.sh -h for usage." + exit 0 + fi + test_suite=$OPTARG + ;; + c) + if [ "$COMMAND" != "testing" ] ; then + echo "Test case should only be specified in testing mode." + echo "./run.sh -h for usage." + exit 0 + fi + test_case=$OPTARG + ;; + h) + usage + exit 0 + ;; + esac +done + +case $COMMAND in "all_in_one" ) - export DEPLOY_MODE='all-in-one' ;; + export DEPLOY_MODE='all-in-one' + ;; "dns" | "mr" | "sdc" | "aai" | "mso" | "robot" | "vid" | "sdnc" | "portal" | "dcae" | "policy" | "appc" ) - export DEPLOY_MODE='individual' ;; + export DEPLOY_MODE='individual' + ;; "testing" ) export DEPLOY_MODE='testing' - export TEST_SUITE=${2:-*} - export TEST_CASE=${3:-*} + if [ "$run" == false ] ; then + while true ; do + echo "Warning: This test script will delete the contents of ../opt/ and ~/.m2." + read -p "Would you like to continue? [y]es/[n]o: " yn + case $yn in + [Yy]*) + break + ;; + [Nn]*) + echo "Exiting." + exit 0 + ;; + esac + done + fi + export TEST_SUITE=$test_suite + export TEST_CASE=$test_case rm -rf ../opt/ - rm -rf ~/.m2/;; + rm -rf ~/.m2/ + ;; * ) - echo $"Usage: $0 {all_in_one|dns|mr|sdc|aai|mso|robot|vid|sdnc|portal|dcae|policy|appc|testing}" + usage exit 1 esac -vagrant destroy -f $1 -vagrant up $1 + +vagrant destroy -f $COMMAND +vagrant up $COMMAND diff --git a/bootstrap/vagrant-onap/unit_testing.sh b/bootstrap/vagrant-onap/unit_testing.sh deleted file mode 100755 index 360d28bc7..000000000 --- a/bootstrap/vagrant-onap/unit_testing.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -set -o xtrace - -rm -rf /opt/ -rm -rf /root/.m2/ - -set -o errexit - -TEST_SUITE=${1:-*} -TEST_CASE=${2:-*} - -for file in $( ls /var/onap_tests/test_$TEST_SUITE); do - bash ${file} $TEST_CASE -done diff --git a/bootstrap/vagrant-onap/vagrant_utils/postinstall.sh b/bootstrap/vagrant-onap/vagrant_utils/postinstall.sh new file mode 100755 index 000000000..f5a7ac684 --- /dev/null +++ b/bootstrap/vagrant-onap/vagrant_utils/postinstall.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +set -o xtrace + +source /var/onap/functions + +export_env_vars +create_configuration_files +install_dev_tools +install_java +configure_bind + +for serv in $@; do + source /var/onap/${serv} + configure_service ${serv}_serv.sh + init_${serv} +done diff --git a/bootstrap/vagrant-onap/vagrant_utils/unit_testing.sh b/bootstrap/vagrant-onap/vagrant_utils/unit_testing.sh new file mode 100755 index 000000000..a378ad0cd --- /dev/null +++ b/bootstrap/vagrant-onap/vagrant_utils/unit_testing.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +set -o errexit + +TEST_SUITE=${1:-*} +TEST_CASE=${2:-*} + +for file in $( ls /var/onap_tests/test_$TEST_SUITE); do + bash ${file} $TEST_CASE +done -- cgit 1.2.3-korg