From ceaa38b3299d56adc1e65e7128bb67cb7364acd1 Mon Sep 17 00:00:00 2001
From: Dean Troyer <dtroyer@gmail.com>
Date: Wed, 12 Dec 2012 17:09:57 -0600
Subject: [PATCH] Fix tempest flavors and DEFAULT_INSTANCE_TYPE

The flavor selection was broken if DEFAULT_INSTANCE_TYPE is defined
but not yet created, for example when it is created in local.sh.
This also has the side effect of setting flavor_ref_alt to the first
flavor where it was unset in the previous code.

Change-Id: I1fa48b3f90af45144c92298b6b07a4f7ee3b499f
---
 lib/tempest | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/lib/tempest b/lib/tempest
index b408b113a5..fa637c12fb 100644
--- a/lib/tempest
+++ b/lib/tempest
@@ -134,12 +134,14 @@ function configure_tempest() {
     flavor_lines=`nova flavor-list`
     IFS=$'\r\n'
     flavors=""
-    for line in $flavor_lines; do
-        if [ -z $DEFAULT_INSTANCE_TYPE ]; then
-            flavors="$flavors `echo $line | grep -v "^\(|\s*ID\|+--\)" | cut -d' ' -f2`"
-        else
-            flavors="$flavors `echo $line | grep -v "^\(|\s*ID\|+--\)" | grep "$DEFAULT_INSTANCE_TYPE" | cut -d' ' -f2`"
+    if [[ -n "$DEFAULT_INSTANCE_TYPE" ]]; then
+        for line in $flavor_lines; do
+            f=$(echo $line | awk "/ $DEFAULT_INSTANCE_TYPE / { print \$2 }")
+            flavors="$flavors $f"
+        done
     fi
+    for line in $flavor_lines; do
+        flavors="$flavors `echo $line | grep -v "^\(|\s*ID\|+--\)" | cut -d' ' -f2`"
     done
 
     IFS=" "