Add ExampleService by default to single-node POD

Change-Id: Ic2397aca2e732cc513e8c2165549c2225f2f27cd
(cherry picked from commit 8a7b8b62323eb72aadb1da816d0df29fce55ed8d)
diff --git a/cord-post-deploy-playbook.yml b/cord-post-deploy-playbook.yml
index c1c2395..f1261eb 100644
--- a/cord-post-deploy-playbook.yml
+++ b/cord-post-deploy-playbook.yml
@@ -8,9 +8,9 @@
   - include_vars: vars/cord.yml
   - include_vars: vars/example_keystone.yml
 
-- name: Run post-deploy test
+- name: Run post-deploy tests
   hosts: head
   become: no
   roles:
-    - post-deploy-tests
-
+    - test-vsg
+    - test-exampleservice
diff --git a/roles/test-exampleservice/tasks/main.yml b/roles/test-exampleservice/tasks/main.yml
new file mode 100644
index 0000000..2ae3813
--- /dev/null
+++ b/roles/test-exampleservice/tasks/main.yml
@@ -0,0 +1,53 @@
+---
+# test-examplservice/tasks/main.yml
+#
+# Run tests to check that the single-node deployment has worked
+
+- name: Onboard ExampleService and instantiate a VM
+  command: ansible xos-1 -u ubuntu -m shell \
+    -a "cd ~/service-profile/cord-pod; make exampleservice"
+
+- name: Pause 60 seconds (work around bug in synchronizer)
+  pause: seconds=60
+
+- name: Re-run 'make vtn' (work around bug in synchronizer)
+  command: ansible xos-1 -u ubuntu -m shell \
+    -a "cd ~/service-profile/cord-pod; make vtn"
+
+- name: Wait for ExampleService VM to come up
+  shell: bash -c "source ~/admin-openrc.sh; nova list --all-tenants|grep 'exampleservice.*ACTIVE' > /dev/null"
+  register: result
+  until: result | success
+  retries: 10
+  delay: 60
+
+- name: Get ID of VM
+  shell: bash -c "source ~/admin-openrc.sh; nova list --all-tenants|grep mysite_exampleservice|cut -d '|' -f 2"
+  register: nova_id
+
+- name: Get mgmt IP of VM
+  shell: bash -c "source ~/admin-openrc.sh; nova interface-list {{ nova_id.stdout }}|grep -o -m 1 172.27.[[:digit:]]*.[[:digit:]]*"
+  register: mgmt_ip
+
+- name: Get public IP of VM
+  shell: bash -c "source ~/admin-openrc.sh; nova interface-list {{ nova_id.stdout }}|grep -o -m 1 10.168.[[:digit:]]*.[[:digit:]]*"
+  register: public_ip
+
+- name: Wait for Apache to come up inside VM
+  shell: ssh -o ProxyCommand="ssh -W %h:%p ubuntu@nova-compute-1" ubuntu@{{ mgmt_ip.stdout }} "ls /var/run/apache2/apache2.pid" > /dev/null
+  register: result
+  until: result | success
+  retries: 20
+  delay: 60
+
+- name: Install curl in testclient
+  command: ansible nova-compute-1 -u ubuntu -m shell \
+    -s -a "lxc-attach -n testclient -- apt-get -y install curl"
+
+- name: Test connectivity to ExampleService from test client
+  command: ansible nova-compute-1 -u ubuntu -m shell \
+    -s -a "lxc-attach -n testclient -- curl -s http://{{ public_ip.stdout }}"
+  register: curltest
+
+- name: Output from curl test
+  debug: var=curltest.stdout_lines
diff --git a/roles/post-deploy-tests/tasks/main.yml b/roles/test-vsg/tasks/main.yml
similarity index 97%
rename from roles/post-deploy-tests/tasks/main.yml
rename to roles/test-vsg/tasks/main.yml
index 32b8b63..14ed325 100644
--- a/roles/post-deploy-tests/tasks/main.yml
+++ b/roles/test-vsg/tasks/main.yml
@@ -1,5 +1,5 @@
 ---
-# post-deploy-tasks/tasks/main.yml
+# test-vsg/tasks/main.yml
 #
 # Run tests to check that the single-node deployment has worked
 
diff --git a/scripts/single-node-pod.sh b/scripts/single-node-pod.sh
index 6726467..023d0a8 100755
--- a/scripts/single-node-pod.sh
+++ b/scripts/single-node-pod.sh
@@ -66,62 +66,10 @@
     ansible-playbook -i $INVENTORY cord-single-playbook.yml --extra-vars="$extra_vars"
 }
 
-function setup_xos() {
-
-    if [[ $EXAMPLESERVICE -eq 1 ]]
-    then
-      ssh ubuntu@xos "cd service-profile/cord-pod; make exampleservice"
-
-      echo "(Temp workaround for bug in Synchronizer) Pause 60 seconds"
-      sleep 60
-      ssh ubuntu@xos "cd service-profile/cord-pod; make vtn"
-    fi
-
-}
-
 function run_e2e_test () {
     ansible-playbook -i $INVENTORY cord-post-deploy-playbook.yml
 }
 
-function run_exampleservice_test () {
-    source ~/admin-openrc.sh
-
-    echo "*** Wait for exampleservice VM to come up."
-    echo "!!! NOTE that currently the VM will only be created after you login"
-    echo "!!! to XOS and manually create an ExampleService tenant."
-    i=0
-    until nova list --all-tenants|grep exampleservice.*ACTIVE > /dev/null
-    do
-      sleep 60
-	    (( i += 1 ))
-	    echo "Waited $i minutes"
-    done
-
-    # get mgmt IP address
-    ID=$( nova list --all-tenants|grep mysite_exampleservice|awk '{print $2}' )
-    MGMTIP=$( nova interface-list $ID|grep 172.27|awk '{print $8}' )
-    PUBLICIP=$( nova interface-list $ID|grep 10.168|awk '{print $8}' )
-
-    echo ""
-    echo "*** ssh into exampleservice VM, wait for Apache come up"
-    i=0
-    until ssh -o ProxyCommand="ssh -W %h:%p ubuntu@nova-compute" ubuntu@$MGMTIP "ls /var/run/apache2/apache2.pid"
-    do
-      sleep 60
-      (( i += 1 ))
-      echo "Waited $i minutes"
-    done
-
-
-    echo ""
-    echo "*** Install curl in test client"
-    ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- apt-get -y install curl"
-
-    echo ""
-    echo "*** Test connectivity to ExampleService from test client"
-    ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- curl -s http://$PUBLICIP"
-}
-
 function run_diagnostics() {
     echo "*** COLLECTING DIAGNOSTIC INFO - check ~/diag-* on the head node"
     ansible-playbook -i $INVENTORY cord-diag-playbook.yml
@@ -129,25 +77,25 @@
 
 # Parse options
 RUN_TEST=0
-EXAMPLESERVICE=0
 SETUP_BRANCH="master"
 SETUP_REPO_URL="https://github.com/opencord/platform-install"
 INVENTORY="inventory/single-localhost"
 DIAGNOSTICS=1
+CLEANUP=0
 
 while getopts "b:dehi:p:r:ts:" opt; do
   case ${opt} in
     b ) XOS_BRANCH=$OPTARG
       ;;
-    d ) DIAGNOSTICS=0
+    c ) CLEANUP=1
       ;;
-    e ) EXAMPLESERVICE=1
+    d ) DIAGNOSTICS=0
       ;;
     h ) echo "Usage:"
       echo "    $0                install OpenStack and prep XOS and ONOS VMs [default]"
       echo "    $0 -b <branch>    checkout <branch> of the xos git repo"
+      echo "    $0 -c             cleanup from previous test"
       echo "    $0 -d             don't run diagnostic collector"
-      echo "    $0 -e             add exampleservice to XOS"
       echo "    $0 -h             display this help message"
       echo "    $0 -i <inv_file>  specify an inventory file (default is inventory/single-localhost)"
       echo "    $0 -p <git_url>   use <git_url> to obtain the platform-install git repo"
@@ -173,7 +121,7 @@
 done
 
 # What to do
-if [[ $RUN_TEST -eq 1 ]]
+if [[ $CLEANUP -eq 1 ]]
 then
   cleanup_from_previous_test
 fi
@@ -186,12 +134,6 @@
 if [[ $RUN_TEST -eq 1 ]]
 then
   run_e2e_test
-
-  if [[ $EXAMPLESERVICE -eq 1 ]]
-  then
-    setup_xos
-    run_exampleservice_test
-  fi
 fi
 
 if [[ $DIAGNOSTICS -eq 1 ]]