Add AAI Unit Tests 63/6763/1
authorVictor Morales <victor.morales@intel.com>
Sun, 6 Aug 2017 16:23:15 +0000 (11:23 -0500)
committerVictor Morales <victor.morales@intel.com>
Sun, 6 Aug 2017 16:26:02 +0000 (11:26 -0500)
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>
bootstrap/vagrant-onap/Vagrantfile
bootstrap/vagrant-onap/lib/aai
bootstrap/vagrant-onap/lib/asserts
bootstrap/vagrant-onap/lib/functions
bootstrap/vagrant-onap/tests/test_aai [new file with mode: 0644]
bootstrap/vagrant-onap/tox.ini

index f89c2dc..bdf1d61 100644 (file)
@@ -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|
index 336a446..df903fd 100755 (executable)
@@ -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
 }
index d02cb5d..02c269b 100755 (executable)
@@ -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
index 7e6ff2e..eeced5a 100755 (executable)
@@ -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 (file)
index 0000000..b0f8888
--- /dev/null
@@ -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[@]}"
index 3a2743d..02fccf5 100644 (file)
@@ -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