Implement test_install_policy UT

It was missed the Unit test that verifies the installation of policy
services.  This commit creates that method and also refactors some
policy code

Change-Id: I58f3f416efc096fc6199fd831bb63293b95157d2
Signed-off-by: Victor Morales <victor.morales@intel.com>
Issue-Id: INT-23
diff --git a/bootstrap/vagrant-onap/lib/functions b/bootstrap/vagrant-onap/lib/functions
index 9b903d9..90af2bc 100755
--- a/bootstrap/vagrant-onap/lib/functions
+++ b/bootstrap/vagrant-onap/lib/functions
@@ -6,15 +6,12 @@
 source /var/onap/_composed_functions
 source /var/onap/_onap_functions
 
+export MTU=$(/sbin/ifconfig | grep MTU | sed 's/.*MTU://' | sed 's/ .*//' |sort -n | head -1)
+export IP_ADDRESS=$(ifconfig eth0 | grep "inet addr" | tr -s ' ' | cut -d' ' -f3 | cut -d':' -f2)
+
 mvn_conf_file=/root/.m2/settings.xml
 git_src_folder=/opt
 
-# export_env_vars() - Export environment variables
-function export_env_vars {
-    export MTU=$(/sbin/ifconfig | grep MTU | sed 's/.*MTU://' | sed 's/ .*//' |sort -n | head -1)
-    export IP_ADDRESS=$(ifconfig eth0 | grep "inet addr" | tr -s ' ' | cut -d' ' -f3 | cut -d':' -f2)
-}
-
 # configure_dns() - DNS/GW IP address configuration
 function configure_dns {
     echo "nameserver 10.0.0.1" >> /etc/resolvconf/resolv.conf.d/head
@@ -51,7 +48,7 @@
     local repo=$1
     local dest_folder=${2:-$git_src_folder/$repo}
     if [ ! -d $dest_folder ]; then
-        _git_timed clone -b $gerrit_branch --single-branch ${repo_url}${repo} $dest_folder
+        _git_timed clone ${repo_url}${repo} $dest_folder
     else
         pushd $dest_folder
         _git_timed pull
diff --git a/bootstrap/vagrant-onap/lib/policy b/bootstrap/vagrant-onap/lib/policy
index f4dc5fb..c117c41 100755
--- a/bootstrap/vagrant-onap/lib/policy
+++ b/bootstrap/vagrant-onap/lib/policy
@@ -9,39 +9,45 @@
 
 # clone_all_policy_repos() - Function that clones Policy source repo.
 function clone_all_policy_repos {
-    for dirc in ${aai_repos[@]}; do
+    for dirc in ${policy_repos[@]}; do
         clone_repo policy/$dirc $src_folder/$dirc
     done
 }
 
-# # compile_all_policy_repos() - Function that compiles Policy source repo.
+# compile_all_policy_repos() - Function that compiles Policy source repo.
 function compile_all_policy_repos {
     for dirc in ${aai_repos[@]}; do
         compile_src $src_folder/$dirc
     done
 }
 
-# install_policy() - Function that clones and installs the Policy services from source code
-function install_policy {
+# _build_policy_images() - Function that build Policy docker images from source code
+function _build_policy_images {
+    compile_src $src_folder/docker
+    pushd $src_folder/docker
+    install_maven
+    mvn prepare-package
+    cp -r target/policy-pe/* policy-pe/
+    cp -r target/policy-drools/* policy-drools
+    install_docker
+    bash docker_verify.sh
+    popd
+}
+
+# get_policy_images() - Function that retrieves Policy docker images
+function get_policy_images {
     if [[ "$build_image" == "True" ]]; then
-        compile_src $src_folder/docker
-        install_docker
-        pushd $src_folder/docker
-        install_maven
-        mvn prepare-package
-        cp -r target/policy-pe/* policy-pe/
-        cp -r target/policy-drools/* policy-drools
-        bash docker_verify.sh
-        for image in os nexus db base drools pe; do
-            asserts_image onap/policy/policy-$image
-        done
-        popd
+        _build_policy_images
     else
         pull_onap_image policy/policy-db onap/policy/policy-db:latest
         pull_onap_image policy/policy-pe onap/policy/policy-pe:latest
         pull_onap_image policy/policy-drools onap/policy/policy-drools:latest
         pull_onap_image policy/policy-nexus onap/policy/policy-nexus:latest
     fi
+}
+
+# install_policy() - Function that clones and installs the Policy services from source code
+function install_policy {
     pushd $src_folder/docker
     chmod +x config/drools/drools-tweaks.sh
     echo $IP_ADDRESS > config/pe/ip_addr.txt
@@ -57,5 +63,6 @@
         compile_all_policy_repos
     fi
 
+    get_policy_images
     install_policy
 }
diff --git a/bootstrap/vagrant-onap/tests/test_policy b/bootstrap/vagrant-onap/tests/test_policy
index 0fa338d..f5490a4 100644
--- a/bootstrap/vagrant-onap/tests/test_policy
+++ b/bootstrap/vagrant-onap/tests/test_policy
@@ -6,11 +6,10 @@
 covered_functions=(
 "clone_all_policy_repos"
 "compile_all_policy_repos"
-"init_policy"
+"get_policy_images"
+"install_policy"
 )
 
-src_folder=/opt/policy
-
 # test_clone_all_policy_repos() - Verify cloning of Policy source code
 function test_clone_all_policy_repos {
     clone_all_policy_repos
@@ -28,17 +27,29 @@
     asserts_file_exist $src_folder/drools-applications/controlloop/common/actors/actor.test/target/actor.test-1.1.0-SNAPSHOT.jar
 }
 
-# test_init_policy() - Verify Policy images are created or cloned
-function test_init_policy {
-    init_policy
+# test_get_policy_images() - Verify that Policy Docker images are retrieved properly
+function test_get_policy_images {
+    clone_all_policy_repos
+    get_policy_images
 
     for image in os nexus db base drools pe; do
         asserts_image onap/policy/policy-$image
     done
 }
 
+# test_install_policy() - Verify that Policy services are started properly
+function test_install_policy {
+    clone_all_policy_repos
+    get_policy_images
+    install_policy
+
+    for image in pe drools db nexus; do
+        asserts_image_running onap/policy/policy-$image
+    done
+}
+
 if [ "$1" != '*' ]; then
     unset covered_functions
     covered_functions=$1
 fi
-main "${covered_functions[@]}"
\ No newline at end of file
+main "${covered_functions[@]}"
diff --git a/bootstrap/vagrant-onap/vagrant_utils/postinstall.sh b/bootstrap/vagrant-onap/vagrant_utils/postinstall.sh
index f5a7ac6..b0e64ad 100755
--- a/bootstrap/vagrant-onap/vagrant_utils/postinstall.sh
+++ b/bootstrap/vagrant-onap/vagrant_utils/postinstall.sh
@@ -4,7 +4,6 @@
 
 source /var/onap/functions
 
-export_env_vars
 create_configuration_files
 install_dev_tools
 install_java