From 8e1a1ffdfbf59e01688fd2e6e007ab72d49263ed Mon Sep 17 00:00:00 2001
From: Steven Hardy <shardy@redhat.com>
Date: Fri, 21 Feb 2014 14:45:48 +0000
Subject: [PATCH] Set stack_user_domain config correctly

The recently merged patch which creates a domain for heat
fails to correctly set the domain ID in heat.conf, so move the
setting of the config option to immediately after we create the
domain.  Also add the missing DEFAULT section identifier in the
iniset, and use OS_TOKEN instead of OS_SERVICE token, because
the stack.sh comment says this is exported for the openstackclient
workaround.

Change-Id: I912f774f1215d68cbcfe44229b371f318d92966a
Closes-Bug: #1283075
---
 lib/heat | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/lib/heat b/lib/heat
index efb01ef3b8..af10fa6f1d 100644
--- a/lib/heat
+++ b/lib/heat
@@ -110,15 +110,6 @@ function configure_heat() {
     iniset $HEAT_CONF ec2authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/v2.0
     iniset $HEAT_CONF ec2authtoken keystone_ec2_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/v2.0/ec2tokens
 
-    # stack user domain
-    # Note we have to pass token/endpoint here because the current endpoint and
-    # version negotiation in OSC means just --os-identity-api-version=3 won't work
-    KS_ENDPOINT_V3="$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/v3"
-    D_ID=$(openstack --os-token $OS_SERVICE_TOKEN --os-url=$KS_ENDPOINT_V3 \
-        --os-identity-api-version=3 domain show heat \
-        | grep ' id ' | get_field 2)
-    iniset $HEAT_CONF stack_user_domain ${D_ID}
-
     # paste_deploy
     [[ "$HEAT_STANDALONE" = "True" ]] && iniset $HEAT_CONF paste_deploy flavor standalone
 
@@ -211,9 +202,11 @@ function create_heat_accounts() {
     # Note we have to pass token/endpoint here because the current endpoint and
     # version negotiation in OSC means just --os-identity-api-version=3 won't work
     KS_ENDPOINT_V3="$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/v3"
-    openstack --os-token $OS_SERVICE_TOKEN --os-url=$KS_ENDPOINT_V3 \
+    D_ID=$(openstack --os-token $OS_TOKEN --os-url=$KS_ENDPOINT_V3 \
         --os-identity-api-version=3 domain create heat \
-        --description "Owns users and projects created by heat"
+        --description "Owns users and projects created by heat" \
+        | grep ' id ' | get_field 2)
+    iniset $HEAT_CONF DEFAULT stack_user_domain ${D_ID}
 }
 
 # Restore xtrace