Merge "Poll resource tracker for ironic cpus as well as count"
diff --git a/lib/ironic b/lib/ironic
index 571202d..3f7ae21 100644
--- a/lib/ironic
+++ b/lib/ironic
@@ -496,18 +496,20 @@
 }
 
 function wait_for_nova_resources {
-    # After nodes have been enrolled, we need to wait for n-cpu's periodic
-    # task populate the resource tracker with available nodes.  Wait for 2
-    # minutes before timing out.
-    local expected_count=$1
-    echo_summary "Waiting 2 minutes for Nova resource tracker to pick up $expected_count Ironic nodes"
+    # After nodes have been enrolled, we need to wait for both ironic and
+    # nova's periodic tasks to populate the resource tracker with available
+    # nodes and resources. Wait up to 2 minutes for a given resource before
+    # timing out.
+    local resource=$1
+    local expected_count=$2
+    echo_summary "Waiting 2 minutes for Nova resource tracker to pick up $resource >= $expected_count"
     for i in $(seq 1 120); do
-        if [ $(nova hypervisor-stats | grep " count " | get_field 2) -ge $expected_count ]; then
+        if [ $(nova hypervisor-stats | grep " $resource " | get_field 2) -ge $expected_count ]; then
             return 0
         fi
         sleep 1
     done
-    die $LINENO "Nova hypervisor-stats did not register at least $expected_count nodes"
+    die $LINENO "Timed out waiting for Nova hypervisor-stats $resource >= $expected_count"
 }
 
 function enroll_nodes {
@@ -546,6 +548,7 @@
     fi
 
     local total_nodes=0
+    local total_cpus=0
     while read hardware_info; do
         if ! is_ironic_hardware; then
             local mac_address=$hardware_info
@@ -575,6 +578,7 @@
         ironic port-create --address $mac_address --node_uuid $node_id
 
         total_nodes=$((total_nodes+1))
+        total_cpus=$((total_cpus+$ironic_node_cpu))
     done < $ironic_hwinfo_file
 
     # create the nova flavor
@@ -587,7 +591,8 @@
     nova flavor-key baremetal set "cpu_arch"="x86_64"
 
     if [ "$VIRT_DRIVER" == "ironic" ]; then
-        wait_for_nova_resources $total_nodes
+        wait_for_nova_resources "count" $total_nodes
+        wait_for_nova_resources "vcpus" $total_cpus
     fi
 }