add some utility scripts and update the playbook to verify API connectitivy and image download
Change-Id: I007a2aef68f5c60a4c809cd711aff4d18d87efb9
diff --git a/roles/compute-node/files/delete-fabric-config b/roles/compute-node/files/delete-fabric-config
new file mode 100755
index 0000000..4ddce2d
--- /dev/null
+++ b/roles/compute-node/files/delete-fabric-config
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+CFG=${1:-"config-tibit.json"}
+
+curl -v -XDELETE -H Content-Type: application/json http://karaf:karaf@onos-fabric:8181/onos/v1/network/configuration
diff --git a/roles/compute-node/files/delete-node-prov-state b/roles/compute-node/files/delete-node-prov-state
new file mode 100755
index 0000000..ced8baa
--- /dev/null
+++ b/roles/compute-node/files/delete-node-prov-state
@@ -0,0 +1,9 @@
+#!/bin/bash
+
+LIST=$(curl -sS http://$(docker-ip provisioner):4243/provision/ | jq . | grep "node-" | awk '{print $2}' | sed -e 's/"//g')
+
+for i in $LIST; do
+ echo "DELETE PROV RECORD '$i'"
+ curl -sS -XDELETE http://$(docker-ip provisioner):4243/provision/$i
+done
+
diff --git a/roles/compute-node/files/docker-ip b/roles/compute-node/files/docker-ip
new file mode 100755
index 0000000..4e678bb
--- /dev/null
+++ b/roles/compute-node/files/docker-ip
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+test $# -ne 1 && echo "must specify the name of a container" && exit 1
+
+IP=$(docker inspect --format '{{.NetworkSettings.IPAddress}}' $1)
+
+if [ "$IP x" == " x" ]; then
+ IP=$(docker inspect --format '{{.NetworkSettings.Networks.maas_default.IPAddress}}' $1)
+fi
+
+/bin/echo -ne $IP
diff --git a/roles/compute-node/files/fabric-pingall b/roles/compute-node/files/fabric-pingall
new file mode 100755
index 0000000..d6de75c
--- /dev/null
+++ b/roles/compute-node/files/fabric-pingall
@@ -0,0 +1,40 @@
+#!/bin/bash
+
+NODES="10.2.1.1 10.2.1.2 10.2.2.1 10.2.2.2 10.2.1.254 10.2.2.254"
+
+test -z $1 || NODES="$*"
+
+USE_LIST="br-int fabric"
+for u in $USE_LIST; do
+ ifconfig $u > /dev/null 2>&1
+ if [ $? -eq 0 ]; then
+ USE_IFACE=$u
+ break
+ fi
+done
+
+LIST="-$USE_IFACE $NODES - 8.8.8.8"
+IFACE=
+ILABEL="none"
+FROM="none"
+if [ ! -z $USE_IFACE ]; then
+ FROM=$(ifconfig $USE_IFACE | grep "inet addr" | head -1 | awk '{print $2}' | cut -d: -f2)
+fi
+
+echo "from $(hostname) ($FROM):"
+for ip in $LIST; do
+ case $ip in
+ -*)
+ if [ "$ip" == "-" ]; then
+ IFACE=
+ ILABEL="none"
+ else
+ ILABEL="$(echo $ip | sed -e 's/^-//g')"
+ IFACE="-I $ILABEL"
+ fi
+ ;;
+ *)
+ printf " %-20s%s\n" "$ip ($ILABEL)" $(ping $IFACE -c 1 $ip 2>&1 | grep "^rtt min/avg/max/mdev" | sed -e 's/.*= \([.0-9]*\).*/\1/')
+ ;;
+ esac
+done
diff --git a/roles/compute-node/files/get-fabric-config b/roles/compute-node/files/get-fabric-config
new file mode 100755
index 0000000..3622bc7
--- /dev/null
+++ b/roles/compute-node/files/get-fabric-config
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+curl -sS -H Content-Type: application/json http://karaf:karaf@onos-fabric:8181/onos/v1/network/configuration
diff --git a/roles/compute-node/files/get-node-prov-state b/roles/compute-node/files/get-node-prov-state
new file mode 100755
index 0000000..5aa8b29
--- /dev/null
+++ b/roles/compute-node/files/get-node-prov-state
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+curl -sS http://$(docker-ip provisioner):4243/provision/ | jq '[.[] | { "id": .request.Info.id, "message": .message, "status": .status, "name": .request.Info.name}]'
diff --git a/roles/compute-node/files/post-fabric-config b/roles/compute-node/files/post-fabric-config
new file mode 100755
index 0000000..636de56
--- /dev/null
+++ b/roles/compute-node/files/post-fabric-config
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+CFG=${1:-"config-tibit.json"}
+
+curl -v -XPOST -H Content-Type: application/json http://karaf:karaf@onos-fabric:8181/onos/v1/network/configuration -d @$CFG
diff --git a/roles/compute-node/files/remove-xos-components b/roles/compute-node/files/remove-xos-components
new file mode 100755
index 0000000..d696dda
--- /dev/null
+++ b/roles/compute-node/files/remove-xos-components
@@ -0,0 +1,48 @@
+#!/bin/bash
+
+J=$(which juju)
+
+if [ ! -z $J ]; then
+ juju remove-machine --force 12
+ juju remove-machine --force 11
+ juju remove-machine --force 10
+
+ RETRY=30
+ while [ $RETRY -gt 0 -a $(juju status --format=tabular | grep "^10\|^11\|^12" | wc -l) -ne 0 ]; do
+ echo -n "."
+ RETRY=$(expr $RETRY - 1)
+ sleep 2
+ done
+ echo
+fi
+
+UVT=$(which uvt-kvm)
+test -z $UVT || uvt-kvm list | xargs uvt-kvm destroy
+
+sudo apt-get remove --purge -y $(dpkg --get-selections | grep "nagioas\|juju\|nova\|neutron" | awk '{print $1}') &&sudo apt-get autoremove -y && sudo rm -rf /etc/juju /etc/neutron /home/ubuntu/.juju && sudo find / -name "*juju*" -exec rm -r \{\} \;
+
+OVS=$(which ovs-vsctl)
+
+if [ ! -z $OVS ]; then
+ sudo ovs-vsctl del-br br-int
+fi
+
+sudo ifdown fabric
+sleep 3
+sudo ifup eth0
+sleep 3
+
+IP=$(ifconfig fabric | grep "inet addr" | awk '{print $2}' | cut -d: -f2)
+
+case $(echo "$IP" | cut -d. -f3) in
+ 1)
+ TO=$(echo "$IP" | awk -F. '{printf("%s.%s.2.0/24", $1, $2)}')
+ GW=$(echo "$IP" | awk -F. '{printf("%s.%s.%s.254", $1, $2, $3)}')
+ ;;
+ 2)
+ TO=$(echo "$IP" | awk -F. '{printf("%s.%s.1.0/24", $1, $2)}')
+ GW=$(echo "$IP" | awk -F. '{printf("%s.%s.%s.254", $1, $2, $3)}')
+ ;;
+esac
+
+sudo route add -net $TO gw $GW
diff --git a/roles/compute-node/tasks/main.yml b/roles/compute-node/tasks/main.yml
index e50cc4e..76f0f85 100644
--- a/roles/compute-node/tasks/main.yml
+++ b/roles/compute-node/tasks/main.yml
@@ -91,6 +91,23 @@
group=root
mode=0600
+- name: Ensure Utility Scripts
+ become: yes
+ copy:
+ src=files/{{ item }}
+ dest=/usr/local/bin/{{ item }}
+ owner=root
+ group=root
+ mode=0755
+ with_items:
+ - delete-fabric-config
+ - delete-node-prov-state
+ - docker-ip
+ - fabric-pingall
+ - get-fabric-config
+ - get-node-prov-state
+ - remove-xos-components
+
- name: Verify Mellanox 40Gb NIC
shell: /usr/bin/lspci | grep "Ethernet controller" | grep -c ConnectX-3 || true
register: mlx_nic_present
diff --git a/roles/maas/tasks/main.yml b/roles/maas/tasks/main.yml
index 9ef263f..c5c4642 100644
--- a/roles/maas/tasks/main.yml
+++ b/roles/maas/tasks/main.yml
@@ -401,3 +401,11 @@
with_items:
- automation-compose.yml
- harvest-compose.yml
+
+- name: Wait For Image Download
+ shell: maas login cord http://localhost/MAAS/api/1.0/ "{{apikey.stdout}}" > /dev/null 2>&1 && maas cord boot-resources read | jq 'map(select(.type != "Synced"))' && maas logout cord > /dev/null 2>&1
+ register: images_synced
+ until: images_synced.stdout == "[]"
+ retries: 5
+ delay: 60
+ failed_when: images_synced.stdout != "[]"