Skip to content

Commit b6e7a36

Browse files
authored
Merge pull request #355 from cloudify-cosmo/fix-encode-user-data
Fix encode user data
2 parents fe5210d + a79bc0a commit b6e7a36

File tree

5 files changed

+17
-50
lines changed

5 files changed

+17
-50
lines changed

.circleci/test_examples.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
'openstack_region': False,
3232
'base_image_id': False,
3333
'base_flavor_id': False,
34+
'openstack_user_domain_name': False,
35+
'openstack_project_domain_name': False,
3436
}
3537

3638
prepare_test(secrets=SECRETS_TO_CREATE)

openstack_plugin/tests/test_utils.py

Lines changed: 0 additions & 32 deletions
This file was deleted.

openstack_plugin/utils.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import copy
1919
import logging
2020
import base64
21-
import binascii
2221
import inspect
2322
import re
2423

@@ -34,7 +33,7 @@
3433
from cloudify.constants import NODE_INSTANCE, RELATIONSHIP_INSTANCE
3534

3635
# Py2/3 compatibility
37-
from openstack_sdk._compat import text_type, PY2
36+
from openstack_sdk._compat import text_type
3837

3938

4039
# Local imports
@@ -213,17 +212,6 @@ def resolve_ctx(_ctx):
213212
return _ctx
214213

215214

216-
def is_userdata_encoded(userdata_string):
217-
try:
218-
if PY2:
219-
base64.decodestring(userdata_string)
220-
else:
221-
base64.decodebytes(userdata_string.encode('utf-8'))
222-
except binascii.Error:
223-
return False
224-
return True
225-
226-
227215
def handle_userdata(existing_userdata):
228216
"""
229217
This method will be responsible for handle user data provided by the
@@ -247,7 +235,7 @@ def handle_userdata(existing_userdata):
247235

248236
if not existing_userdata:
249237
existing_userdata = ''
250-
elif is_userdata_encoded(existing_userdata):
238+
elif not ctx.node.properties['encode_user_data']:
251239
return existing_userdata
252240

253241
if install_agent_userdata and os_family == 'windows':
@@ -290,7 +278,8 @@ def handle_userdata(existing_userdata):
290278
final_userdata = compute.create_multi_mimetype_userdata(
291279
[existing_userdata, install_agent_userdata])
292280

293-
final_userdata = base64.b64encode(final_userdata)
281+
final_userdata = base64.b64encode(final_userdata.encode('utf-8')).decode(
282+
'ascii')
294283
return final_userdata
295284

296285

plugin.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ plugins:
22

33
openstack:
44
executor: central_deployment_agent
5-
source: https://github.com/cloudify-cosmo/cloudify-openstack-plugin/archive/3.2.14.zip
5+
source: https://github.com/cloudify-cosmo/cloudify-openstack-plugin/archive/3.2.15.zip
66
package_name: cloudify-openstack-plugin
7-
package_version: '3.2.14'
7+
package_version: '3.2.15'
88

99
dsl_definitions:
1010

@@ -391,6 +391,7 @@ data_types:
391391
Must be Base64 encoded. Restricted to 65535 bytes.
392392
required: false
393393
type: string
394+
394395
metadata:
395396
description: >
396397
Metadata key and value pairs.
@@ -1047,6 +1048,13 @@ node_types:
10471048
type: cloudify.types.openstack.Server
10481049
description: A dictionary that may contain these keys https://developer.openstack.org/api-ref/compute/?expanded=create-server-detail
10491050
required: true
1051+
encode_user_data:
1052+
required: false
1053+
type: boolean
1054+
default: true
1055+
description: >
1056+
A boolean describing if the plugin will encode the user_data given in resource_config.
1057+
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.
10501058
use_password:
10511059
type: boolean
10521060
default: false

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
setup(
2222
name='cloudify-openstack-plugin',
23-
version='3.2.14',
23+
version='3.2.15',
2424
author='Cloudify',
2525
author_email='[email protected]',
2626
license='LICENSE',

0 commit comments

Comments
 (0)