Try to read compiled template as StringIO

The fact that PyYAML was the last renderer in the render pipe initially,
masked the fact that template renderers return StringIO instances and
not strings. This commit makes sure that we try reading from the
StringIO first and then fallback to just trying to base64 encode the
userdata value as returned by compile_template().
This commit is contained in:
Erik Johnson 2017-03-31 12:11:47 -05:00
parent 79cc253bbf
commit 04f02df5fe
4 changed files with 34 additions and 4 deletions

View File

@ -905,7 +905,15 @@ def request_instance(call=None, kwargs=None): # pylint: disable=unused-argument
input_data=userdata,
)
os_kwargs['custom_data'] = base64.b64encode(userdata)
try:
# template renderers like "jinja" should return a StringIO
os_kwargs['custom_data'] = \
''.join(base64.b64encode(userdata).readlines())
except AttributeError:
try:
os_kwargs['custom_data'] = base64.b64encode(userdata)
except Exception as exc:
log.exception('Failed to encode userdata: %s')
iface_data = create_interface(kwargs=vm_)
vm_['iface_id'] = iface_data['id']

View File

@ -1715,7 +1715,15 @@ def request_instance(vm_=None, call=None):
input_data=userdata,
)
params[spot_prefix + 'UserData'] = base64.b64encode(userdata)
try:
# template renderers like "jinja" should return a StringIO
params[spot_prefix + 'UserData'] = \
''.join(base64.b64encode(userdata).readlines())
except AttributeError:
try:
params[spot_prefix + 'UserData'] = base64.b64encode(userdata)
except Exception as exc:
log.exception('Failed to encode userdata: %s')
vm_size = config.get_cloud_config_value(
'size', vm_, __opts__, search_global=False

View File

@ -675,7 +675,14 @@ def request_instance(vm_=None, call=None):
input_data=userdata,
)
kwargs['userdata'] = userdata
try:
# template renderers like "jinja" should return a StringIO
kwargs['userdata'] = ''.join(base64.b64encode(userdata).readlines())
except AttributeError:
try:
kwargs['userdata'] = base64.b64encode(userdata)
except Exception as exc:
log.exception('Failed to encode userdata: %s')
kwargs['config_drive'] = config.get_cloud_config_value(
'config_drive', vm_, __opts__, search_global=False

View File

@ -556,7 +556,14 @@ def request_instance(vm_=None, call=None):
input_data=userdata,
)
kwargs['ex_userdata'] = userdata
try:
# template renderers like "jinja" should return a StringIO
kwargs['ex_userdata'] = ''.join(base64.b64encode(userdata).readlines())
except AttributeError:
try:
kwargs['ex_userdata'] = base64.b64encode(userdata)
except Exception as exc:
log.exception('Failed to encode userdata: %s')
config_drive = config.get_cloud_config_value(
'config_drive', vm_, __opts__, default=None, search_global=False