From 797feda87a3019b4694421c2a2a3d0c70913832a Mon Sep 17 00:00:00 2001
From: Clark Boylan <clark.boylan@gmail.com>
Date: Wed, 22 Apr 2015 13:52:54 -0700
Subject: [PATCH] Allow blank lines in node{} with apply test

The apply test does some really simple string manipulation to generate
puppet manifests based on our site.pp on the fly. Unfortunately the old
code assumed there would be no blank lines within a node{} definition.
This assumption is breaking as we work to decouple the
openstack_project::server contents from within openstack_project
manifests and move that into site.pp.

This is a relatively simple fix where we csplit nodes based on the
previous /^}$/ which ends the last node{} definition instead of
splitting on blank lines. Added some comments to make what the parsing
does a bit more clear.

Change-Id: I2cc7317ed90423d6f923c4303a76e091a0bc2ebb
---
 tools/apply-test.sh | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/tools/apply-test.sh b/tools/apply-test.sh
index d0d83843a6..4d41a7e672 100755
--- a/tools/apply-test.sh
+++ b/tools/apply-test.sh
@@ -59,10 +59,17 @@ if [[ ! -d applytest ]] ; then
     mkdir applytest
 fi
 
-csplit -sf applytest/puppetapplytest manifests/site.pp '/^$/' {*}
-sed -i -e 's/^[^][:space:]$]/#&/g' applytest/puppetapplytest*
-sed -i -e 's@hiera(.\([^.]*\).,\([^)]*\))@\2@' applytest/puppetapplytest*
-mv applytest/*00 applytest/head  # These are the top-level variables defined in site.pp
+# First split the variables at the beginning of the file
+csplit -sf applytest/prep manifests/site.pp '/^$/' {0}
+# Then split the class defs.
+csplit -sf applytest/puppetapplytest applytest/prep01 '/^}$/' {*}
+# Remove } header left by csplit
+sed -i -e '/^\}$/d' applytest/puppetapplytest*
+# Comment out anything that doesn't begin with a space.
+# This gives us the node {} internal contents.
+sed -i -e 's/^[^][:space:]$]/#&/g' applytest/prep00 applytest/puppetapplytest*
+sed -i -e 's@hiera(.\([^.]*\).,\([^)]*\))@\2@' applytest/prep00 applytest/puppetapplytest*
+mv applytest/prep00 applytest/head  # These are the top-level variables defined in site.pp
 
 if [[ `lsb_release -i -s` == 'CentOS' ]]; then
     if [[ `lsb_release -r -s` =~ '6' ]]; then