Skip to content

Commit

Permalink
Merge pull request #355 from cloudify-cosmo/fix-encode-user-data
Browse files Browse the repository at this point in the history
Fix encode user data
  • Loading branch information
AdarShaked authored May 24, 2020
2 parents fe5210d + a79bc0a commit b6e7a36
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 50 deletions.
2 changes: 2 additions & 0 deletions .circleci/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
'openstack_region': False,
'base_image_id': False,
'base_flavor_id': False,
'openstack_user_domain_name': False,
'openstack_project_domain_name': False,
}

prepare_test(secrets=SECRETS_TO_CREATE)
Expand Down
32 changes: 0 additions & 32 deletions openstack_plugin/tests/test_utils.py

This file was deleted.

19 changes: 4 additions & 15 deletions openstack_plugin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import copy
import logging
import base64
import binascii
import inspect
import re

Expand All @@ -34,7 +33,7 @@
from cloudify.constants import NODE_INSTANCE, RELATIONSHIP_INSTANCE

# Py2/3 compatibility
from openstack_sdk._compat import text_type, PY2
from openstack_sdk._compat import text_type


# Local imports
Expand Down Expand Up @@ -213,17 +212,6 @@ def resolve_ctx(_ctx):
return _ctx


def is_userdata_encoded(userdata_string):
try:
if PY2:
base64.decodestring(userdata_string)
else:
base64.decodebytes(userdata_string.encode('utf-8'))
except binascii.Error:
return False
return True


def handle_userdata(existing_userdata):
"""
This method will be responsible for handle user data provided by the
Expand All @@ -247,7 +235,7 @@ def handle_userdata(existing_userdata):

if not existing_userdata:
existing_userdata = ''
elif is_userdata_encoded(existing_userdata):
elif not ctx.node.properties['encode_user_data']:
return existing_userdata

if install_agent_userdata and os_family == 'windows':
Expand Down Expand Up @@ -290,7 +278,8 @@ def handle_userdata(existing_userdata):
final_userdata = compute.create_multi_mimetype_userdata(
[existing_userdata, install_agent_userdata])

final_userdata = base64.b64encode(final_userdata)
final_userdata = base64.b64encode(final_userdata.encode('utf-8')).decode(
'ascii')
return final_userdata


Expand Down
12 changes: 10 additions & 2 deletions plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ plugins:

openstack:
executor: central_deployment_agent
source: https://github.com/cloudify-cosmo/cloudify-openstack-plugin/archive/3.2.14.zip
source: https://github.com/cloudify-cosmo/cloudify-openstack-plugin/archive/3.2.15.zip
package_name: cloudify-openstack-plugin
package_version: '3.2.14'
package_version: '3.2.15'

dsl_definitions:

Expand Down Expand Up @@ -391,6 +391,7 @@ data_types:
Must be Base64 encoded. Restricted to 65535 bytes.
required: false
type: string

metadata:
description: >
Metadata key and value pairs.
Expand Down Expand Up @@ -1047,6 +1048,13 @@ node_types:
type: cloudify.types.openstack.Server
description: A dictionary that may contain these keys https://developer.openstack.org/api-ref/compute/?expanded=create-server-detail
required: true
encode_user_data:
required: false
type: boolean
default: true
description: >
A boolean describing if the plugin will encode the user_data given in resource_config.
if the user data is bae64 encoded and this flag is false, the user_data that accepted will be sent as the server user_data.
use_password:
type: boolean
default: false
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

setup(
name='cloudify-openstack-plugin',
version='3.2.14',
version='3.2.15',
author='Cloudify',
author_email='[email protected]',
license='LICENSE',
Expand Down

0 comments on commit b6e7a36

Please sign in to comment.