blueprint show -S fails for templates without *.blueprint-template.sh #106

Closed
ekoyle opened this Issue Dec 19, 2011 · 0 comments

Comments

Projects
None yet
2 participants

ekoyle commented Dec 19, 2011

I'm running the blueprint package from packages.devstructure.com (I have version 3.4.0-1py2.6).

I created a couple of templates and was unable to run blueprint show -S:

root@fwser-pri:~/deleteme# blueprint show -S firewalls
Traceback (most recent call last):
  File "/usr/bin/blueprint-show", line 58, in <module>
    filename = getattr(b, options.generate)(options.relaxed).dumpf()
  File "/usr/lib/python2.6/dist-packages/blueprint/__init__.py", line 476, in sh
    return frontend.sh.sh(self, relaxed, server, secret)
  File "/usr/lib/python2.6/dist-packages/blueprint/frontend/sh.py", line 186, in sh
    service=service)
  File "/usr/lib/python2.6/dist-packages/blueprint/__init__.py", line 504, in walk
    walk.walk(self, **kwargs)
  File "/usr/lib/python2.6/dist-packages/blueprint/walk.py", line 27, in walk
    walk_files(b, **kwargs)
  File "/usr/lib/python2.6/dist-packages/blueprint/walk.py", line 96, in walk_files
    callable(pathname, f)
  File "/usr/lib/python2.6/dist-packages/blueprint/frontend/sh.py", line 101, in file
    (f['data'].rstrip(),),
KeyError: 'data'
root@fwser-pri:~/deleteme# 

It looks like the 'data' key is only populated for a file with *.blueprint-template.mustache temlpate when the corresponding *.blueprint-template.sh file exists.

One fix would to be to only reference the value if it exists (will work for existing templates):

--- blueprint/frontend/sh.py.orig      2011-12-19 09:37:15.000000000 -0700
+++ blueprint/frontend/sh.py   2011-12-19 09:55:02.000000000 -0700
@@ -98,7 +98,7 @@
                                ('do',),
                                ('\t. "$F"',),
                                ('done',),
-                               (f['data'].rstrip(),),
+                               ('' if not f.has_key('data') else f['data'].rstrip(),),
                                (command(*commands,
                                         escape_stdin=True,
                                         stdin=f['template'],

Another option would be to always populate it for templates (existing templates would need to be recreated, but probably not a big deal since they don't work anyway):

--- /usr/lib/python2.6/dist-packages/blueprint/backend/files.py.orig    2011-12-19 10:00:50.000000000 -0700
+++ /usr/lib/python2.6/dist-packages/blueprint/backend/files.py 2011-12-19 10:02:11.000000000 -0700
@@ -764,6 +764,8 @@
                     if template:
                         if data:
                             kwargs['data'] = data.decode('utf_8')
+                        else:
+                            kwargs['data'] = ''
                         kwargs['template'] = template.decode('utf_8')
                     else:
                         kwargs['content'] = content.decode('utf_8')

rcrowley closed this in 3abaf7f Dec 20, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment