diff options
author | Victor Morales <victor.morales@intel.com> | 2017-08-06 11:23:15 -0500 |
---|---|---|
committer | Victor Morales <victor.morales@intel.com> | 2017-08-06 11:26:02 -0500 |
commit | 158c18c732e97119880e6a8bddf85ed0ea5d41af (patch) | |
tree | 2ec5fc28dcf6932a3d50ddb038c8916572ac466c /bootstrap/vagrant-onap | |
parent | 3529c70a5bff5139f6d483a86ddfca407374022f (diff) |
Add AAI Unit Tests
This change includes the addition of Unit Tests for A&AI component
and the required refactor process in their functions
Change-Id: Ib3b1109e7e80d5ef51e682445b7ecbf600bf3e62
Signed-off-by: Victor Morales <victor.morales@intel.com>
Diffstat (limited to 'bootstrap/vagrant-onap')
-rw-r--r-- | bootstrap/vagrant-onap/Vagrantfile | 4 | ||||
-rwxr-xr-x | bootstrap/vagrant-onap/lib/aai | 29 | ||||
-rwxr-xr-x | bootstrap/vagrant-onap/lib/asserts | 33 | ||||
-rwxr-xr-x | bootstrap/vagrant-onap/lib/functions | 4 | ||||
-rw-r--r-- | bootstrap/vagrant-onap/tests/test_aai | 123 | ||||
-rw-r--r-- | bootstrap/vagrant-onap/tox.ini | 4 |
6 files changed, 177 insertions, 20 deletions
diff --git a/bootstrap/vagrant-onap/Vagrantfile b/bootstrap/vagrant-onap/Vagrantfile index f89c2dc47..bdf1d611c 100644 --- a/bootstrap/vagrant-onap/Vagrantfile +++ b/bootstrap/vagrant-onap/Vagrantfile @@ -354,10 +354,10 @@ Vagrant.configure("2") do |config| testing.vm.network :private_network, ip: '192.168.50.3' testing.vm.synced_folder './tests', '/var/onap_tests/', create: true testing.vm.provider "virtualbox" do |v| - v.customize ["modifyvm", :id, "--memory", 2 * 1024] + v.customize ["modifyvm", :id, "--memory", 4 * 1024] end testing.vm.provider "libvirt" do |v| - v.memory = 2 * 1024 + v.memory = 4 * 1024 v.nested = true end testing.vm.provider "openstack" do |v| diff --git a/bootstrap/vagrant-onap/lib/aai b/bootstrap/vagrant-onap/lib/aai index 336a446aa..df903fd7b 100755 --- a/bootstrap/vagrant-onap/lib/aai +++ b/bootstrap/vagrant-onap/lib/aai @@ -7,7 +7,7 @@ source /var/onap/asserts hbase_version=1.2.3 src_folder=$git_src_folder/aai -aai_repos=("aai-common" "aai-config" "aai-data" "aai-service" "data-router" "logging-service" "model-loader" "resources" "rest-client" "router-core" "search-data-service" "sparky-be" "sparky-fe" "test-config" "traversal") +aai_repos=("aai-common" "aai-config" "aai-data" "aai-service" "data-router" "logging-service" "model-loader" "resources" "rest-client" "router-core" "search-data-service" "test-config" "traversal" "sparky-fe" "sparky-be") # install_hadoop() - Function that installs Hadoop function install_hadoop { @@ -22,6 +22,11 @@ function install_hadoop { mkdir -p $dest_folder unzip /tmp/${filename}.zip -d $dest_folder pushd $dest_folder/${filename} + # Change commitlog_directory and data_file_directories values (https://stackoverflow.com/a/26856246/1707651) + sed -i "s|db/cassandra/data|/tmp/data|g" conf/cassandra/cassandra.yaml + sed -i "s|db/cassandra/commitlog|/tmp/commitlog|g" conf/cassandra/cassandra.yaml + + install_java ./bin/titan.sh start popd fi @@ -52,7 +57,7 @@ function clone_all_aai_repos { function compile_aai_repos { local repos=("aai-common" "resources" "logging-service" "traversal") if [[ "$compile_repo" == "True" ]]; then - repos=aai_repos + repos=("${aai_repos[@]}") fi for dirc in ${repos[@]}; do @@ -74,6 +79,7 @@ function setup_titan { # Addthe schema to the local isntance pushd $src_folder + install_java java -DAJSC_HOME=$src_folder/resources/aai-resources -DBUNDLECONFIG_DIR="bundleconfig-local" -cp aai-common/aai-core/target/aai-core-1.1.0-SNAPSHOT.jar:resources/aai-resources/target/aai-resources.jar:resources/aai-resources/target/userjars/* org.openecomp.aai.dbgen.GenTester popd } @@ -88,8 +94,8 @@ function start_aai_microservices { done } -# pull_hbase_image() - Pull HBase container image from a Docker Registry Hub -function pull_hbase_image { +# _pull_hbase_image() - Pull HBase container image from a Docker Registry Hub +function _pull_hbase_image { docker_openecomp_login docker pull $nexus_docker_repo/aaidocker/aai-hbase-${hbase_version} } @@ -97,13 +103,12 @@ function pull_hbase_image { # install_hbase() - Install HBase Service function install_hbase { docker rm -f hbase - pull_hbase_image + _pull_hbase_image docker run -d --net=host --name="hbase" $nexus_docker_repo/aaidocker/aai-hbase-${hbase_version} } # install_ajsc() - Install ASJC Java service container function install_ajsc_aai { - local src_folder=/opt/aai/aai-service cat <<EOL > /etc/ajsc-aai.conf AAI_REPO_PATH=r/aai AAI_CHEF_ENV=simpledemo @@ -112,14 +117,11 @@ docker_gitbranch=master EOL docker rm -f aai-service if [[ "$build_image" == "True" ]]; then - clone_repo aai/aai-service $src_folder - build_docker_image $src_folder/ajsc-aai + build_docker_image $src_folder/aai-service/ajsc-aai else pull_openecomp_image ajsc-aai fi - asserts_image openecomp/ajsc-aai - docker run --env-file /etc/ajsc-aai.conf --name=aai-service --net=host -v /etc/ssl/certs/ca-certificates.crt:/etc/ssl/certs/ca-certificates.crt -it -d $nexus_docker_repo/openecomp/ajsc-aai:$docker_version } @@ -151,12 +153,11 @@ EOL pull_openecomp_image model-loader ARGS+="--name=model-loader-service -it -d --env-file /etc/model-loader.conf $nexus_docker_repo/openecomp/model-loader:$docker_version" fi - asserts_image openecomp/model-loader docker run ${ARGS} } -# wait_for_sdc() - Function that determines if SDC is up and running -function wait_for_sdc { +# _wait_for_sdc() - Function that determines if SDC is up and running +function _wait_for_sdc { if [[ -s "/opt/config/sdc_ip_addr.txt" ]]; then SDC_IP_ADDR=$(cat /opt/config/sdc_ip_addr.txt) else @@ -190,6 +191,6 @@ function init_aai { sleep 180 install_ajsc_aai - wait_for_sdc + _wait_for_sdc install_model_loader } diff --git a/bootstrap/vagrant-onap/lib/asserts b/bootstrap/vagrant-onap/lib/asserts index d02cb5da8..02c269b4c 100755 --- a/bootstrap/vagrant-onap/lib/asserts +++ b/bootstrap/vagrant-onap/lib/asserts @@ -4,11 +4,44 @@ set -o xtrace source /var/onap/commons +# asserts_process() - Function that verifies if a specific process is running +function asserts_process { + local process=$1 + local error_msg=${2:-"There is no $process running process"} + + if [[ "ps -ef | grep $process" == "" ]]; then + raise_error $error_msg + fi +} + +# asserts_java_process() - Function that verifies if a specific java process is running +function asserts_java_process { + local process=$1 + local error_msg=${2:-"There is no $process java running process"} + + install_java + if [[ "jps | grep $process" == "" ]]; then + raise_error $error_msg + fi +} + +# asserts_image_running() - Function that verifies if a specific image is running +function asserts_image_running { + local image=$1 + local error_msg=${2:-"There is no process with $image image running"} + + asserts_image $image + if [[ "$(docker ps -q --filter=ancestor=$image 2> /dev/null)" == "" ]]; then + raise_error $error_msg + fi +} + # asserts_image() - Function that verifies if a specific image was created function asserts_image { local image=$1 local error_msg=${2:-"There is no $image image"} + install_docker if [[ "$(docker images -q $image 2> /dev/null)" == "" ]]; then raise_error $error_msg fi diff --git a/bootstrap/vagrant-onap/lib/functions b/bootstrap/vagrant-onap/lib/functions index 7e6ff2e98..eeced5a34 100755 --- a/bootstrap/vagrant-onap/lib/functions +++ b/bootstrap/vagrant-onap/lib/functions @@ -129,7 +129,9 @@ function install_python { # _install_pip() - Install Python Package Manager function _install_pip { install_python - curl -sL https://bootstrap.pypa.io/get-pip.py | python + if [ ! -f /usr/local/bin/pip ]; then + curl -sL https://bootstrap.pypa.io/get-pip.py | python + fi } # install_python_package() - Install a python module diff --git a/bootstrap/vagrant-onap/tests/test_aai b/bootstrap/vagrant-onap/tests/test_aai new file mode 100644 index 000000000..b0f8888f3 --- /dev/null +++ b/bootstrap/vagrant-onap/tests/test_aai @@ -0,0 +1,123 @@ +#!/bin/bash + +source /var/onap_tests/_test_base +source /var/onap/aai + +covered_functions=( +"install_hadoop" "install_haproxy" "clone_all_aai_repos" "compile_aai_repos" "setup_titan" "start_aai_microservices" "install_hbase" "install_ajsc_aai" "install_model_loader" +) + +# TODO(electrocucaracha): Remove/Modify functions that doesn't support proxy settings +if [ -z $http_proxy ] & [ -z $https_proxy ]; then + covered_functions=(${covered_functions[@]} "install_hbase") +fi + +# test_install_hadoop() - Verify that Hadoop is downloaded and started properly +function test_install_hadoop { + install_hadoop + + asserts_file_exist /opt/hadoop/current/titan-1.0.0-hadoop1/bin/titan.sh + asserts_java_process Elasticsearch + asserts_java_process GremlinServer + asserts_java_process CassandraDaemon +} + +# test_install_haproxy() - Verify that HAProxy is installed properly +function test_install_haproxy { + install_haproxy + + asserts_installed_package haproxy + asserts_process haproxy +} + +# test_clone_all_aai_repos() - Verify that all the AAI Repos are cloned +function test_clone_all_aai_repos { + clone_all_aai_repos + + asserts_file_exist $src_folder/aai-common/pom.xml + asserts_file_exist $src_folder/aai-config/cookbooks/aai-resources/runlist-aai-resources.json + asserts_file_exist $src_folder/aai-data/environments/solo.json + asserts_file_exist $src_folder/aai-service/pom.xml + asserts_file_exist $src_folder/data-router/pom.xml + asserts_file_exist $src_folder/logging-service/pom.xml + asserts_file_exist $src_folder/model-loader/pom.xml + asserts_file_exist $src_folder/resources/pom.xml + asserts_file_exist $src_folder/rest-client/pom.xml + asserts_file_exist $src_folder/router-core/pom.xml + asserts_file_exist $src_folder/search-data-service/pom.xml + asserts_file_exist $src_folder/sparky-be/pom.xml + asserts_file_exist $src_folder/sparky-fe/pom.xml + asserts_file_exist $src_folder/test-config/docker-compose-app.yml + asserts_file_exist $src_folder/traversal/pom.xml +} + +# test_compile_aai_repos() - Verify that all the AAI Repositories complile properly +function test_compile_aai_repos { + clone_all_aai_repos + export compile_repo="True" + compile_aai_repos + + asserts_file_exist $src_folder/aai-common/aai-annotations/target/aai-annotations-1.1.0-SNAPSHOT.jar + asserts_file_exist $src_folder/aai-common/aai-auth/target/aai-auth-1.1.0-SNAPSHOT.jar + asserts_file_exist $src_folder/aai-common/aai-core/target/aai-core-1.1.0-SNAPSHOT.jar + asserts_file_exist $src_folder/aai-common/aai-schema/target/aai-schema-1.1.0-SNAPSHOT.jar + + asserts_file_exist $src_folder/aai-service/aai-schema/target/aai-schema-1.1.0-SNAPSHOT.jar + asserts_file_exist $src_folder/aai-service/ajsc-aai/target/aai.jar + asserts_file_exist $src_folder/aai-service/annotations/target/annotations-1.1.0-SNAPSHOT.jar + + asserts_file_exist $src_folder/data-router/target/data-router-1.1.0-SNAPSHOT.jar + + asserts_file_exist $src_folder/logging-service/common-logging/target/common-logging-1.1.0-SNAPSHOT.jar + asserts_file_exist $src_folder/logging-service/eelf-logging/target/eelf-logging-1.1.0-SNAPSHOT.jar + asserts_file_exist $src_folder/logging-service/logging-api/target/logging-api-1.1.0-SNAPSHOT.jar + + asserts_file_exist $src_folder/model-loader/target/model-loader-1.1.0-SNAPSHOT.jar + asserts_file_exist $src_folder/resources/aai-resources/target/aai-resources.jar + asserts_file_exist $src_folder/rest-client/target/rest-client-1.1.0-SNAPSHOT.jar + asserts_file_exist $src_folder/router-core/target/router-core-1.1.0-SNAPSHOT.jar + asserts_file_exist $src_folder/search-data-service/target/search-data-service-1.1.0-SNAPSHOT.jar + asserts_file_exist $src_folder/sparky-be/target/sparky-be-1.0-SNAPSHOT.jar + asserts_file_exist $src_folder/sparky-fe/target/sparky-fe-1.0.0-SNAPSHOT.war + asserts_file_exist $src_folder/traversal/aai-traversal/target/traversal.jar +} + +# test_setup_titan() - Verify that Titan Cassandra DB is up and running +function test_setup_titan { + setup_titan +} + +# test_start_aai_microservices() - Verify that AAI Resources and Traversal images works +function test_start_aai_microservices { + clone_all_aai_repos + start_aai_microservices +} + +# test_install_hbase() - Verify that AAI HBase service is up and running properly +function test_install_hbase { + install_hbase + + asserts_image_running aai-hbase-${hbase_version} +} + +# test_install_ajsc_aai() - Verify that AJSC AAI service is up and running properly +function test_install_ajsc_aai { + clone_all_aai_repos + install_ajsc_aai + + asserts_image_running openecomp/ajsc-aai +} + +# test_install_model_loader() - Verify that Model AAI service is up and running properly +function test_install_model_loader { + clone_all_aai_repos + install_model_loader + + asserts_image openecomp/model-loader +} + +if [ "$1" != '*' ]; then + unset covered_functions + covered_functions=$1 +fi +main "${covered_functions[@]}" diff --git a/bootstrap/vagrant-onap/tox.ini b/bootstrap/vagrant-onap/tox.ini index 3a2743d51..02fccf58d 100644 --- a/bootstrap/vagrant-onap/tox.ini +++ b/bootstrap/vagrant-onap/tox.ini @@ -16,9 +16,7 @@ deps = {env:BASHATE_INSTALL_PATH:bashate==0.5.1} whitelist_externals = bash commands = bash -c "find {toxinidir}/{tests,lib,tools} \ - -not \( -type f -name *.template -prune \) \ - -not \( -type f -name *.pem -prune \) \ - -not \( -type f -name *.cfg -prune \) \ + -not \( -type d -path *files* -prune \) \ -type f \ # E005 file does not begin with #! or have a .sh prefix # E006 check for lines longer than 79 columns |