Add functional tests and examples for merge
authorClint Byrum <clint@fewbar.com>
Thu, 19 Sep 2013 01:08:08 +0000 (18:08 -0700)
committerClint Byrum <clint@fewbar.com>
Thu, 19 Sep 2013 20:02:03 +0000 (13:02 -0700)
merge.py is undocumented and untested, which is undesirable, as it does
not seem to be going away any time soon.

Change-Id: I7e4870e58a32c567e5947b9a48893b8210ad4d65

.gitignore
Makefile
README.md
examples/lib.yaml [new file with mode: 0644]
examples/source.yaml [new file with mode: 0644]
examples/source_lib_result.yaml [new file with mode: 0644]
test_merge.bash [new file with mode: 0644]

index bc15ad2..769ab22 100644 (file)
@@ -39,3 +39,5 @@ nosetests.xml
 
 *~
 *.swp
+
+doc/_build
index ad93ff0..534cd0f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -6,3 +6,6 @@ notcompute.yaml: $(NOTCOMPUTE)
 overcloud.yaml: overcloud-source.yaml nova-compute-instance.yaml
        python merge.py $< > $@.tmp
        mv $@.tmp $@
+
+test:
+       @bash test_merge.bash
index 2013552..97cc384 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,4 +1,10 @@
 templates
 =========
 
-Generic templates to describe multi-host infrastructure, consumable by OpenStack Heat, Crowbar, others.
\ No newline at end of file
+Generic templates to describe multi-host infrastructure, consumable by OpenStack Heat, Crowbar, others.
+
+
+merge.py
+========
+
+The Makefile contains several targets for generated templates, see its contents for all of them. To run functional tests for merge.py, run 'make test'.
diff --git a/examples/lib.yaml b/examples/lib.yaml
new file mode 100644 (file)
index 0000000..e527d83
--- /dev/null
@@ -0,0 +1,11 @@
+Parameters:
+  ImportantValue:
+  Default: a_default
+  Type: String
+Resources:
+  GenericB:
+    Type: OS::Nova::Server
+    Properties:
+      image: {Ref: BImage}
+    Metadata:
+      my_meta: {Ref: ImportantValue}
diff --git a/examples/source.yaml b/examples/source.yaml
new file mode 100644 (file)
index 0000000..89707a7
--- /dev/null
@@ -0,0 +1,15 @@
+Parameters:
+  SourceImage:
+  Type: String
+  Default: my_image
+Resources:
+  A:
+    Type: OS::Nova::Server
+    Properties:
+      image: {Ref: SourceImage}
+  B:
+    Type: FileInclude
+    Path: examples/lib.yaml
+    SubKey: Resources.GenericB
+    Parameters:
+      ImportantValue: {'Fn::Join': [ '', ['one', 'two', 'three']]}
diff --git a/examples/source_lib_result.yaml b/examples/source_lib_result.yaml
new file mode 100644 (file)
index 0000000..a165cab
--- /dev/null
@@ -0,0 +1,24 @@
+Description: examples/source.yaml
+HeatTemplateFormatVersion: '2012-12-12'
+Parameters:
+  AImage: null
+  Default: my_image
+  Type: String
+Resources:
+  A:
+    Properties:
+      image:
+        Ref: AImage
+    Type: OS::Nova::Server
+  B:
+    Metadata:
+      my_meta:
+        Fn::Join:
+        - ''
+        - - one
+          - two
+          - three
+    Properties:
+      image:
+        Ref: BImage
+    Type: OS::Nova::Server
diff --git a/test_merge.bash b/test_merge.bash
new file mode 100644 (file)
index 0000000..35390aa
--- /dev/null
@@ -0,0 +1,24 @@
+#!/bin/bash
+set -ue
+result=""
+cleanup() {
+    if [ -n "$result" ] ; then
+        rm -f $result
+    fi
+}
+trap cleanup EXIT
+result=$(mktemp /tmp/test_merge.XXXXXX)
+fail=0
+python merge.py examples/source.yaml > $result
+if ! cmp $result examples/source_lib_result.yaml ; then
+    diff -u $result examples/source_lib_result.yaml
+    echo
+    echo FAIL - merge of source.yaml result does not match expected output
+    echo
+    fail=1
+else
+    echo
+    echo PASS - merge of source.yaml result matches expected output
+    echo
+fi
+exit $fail