Skip to content

Commit

Permalink
Merge pull request #342 from cloudify-cosmo/CYBL-1009
Browse files Browse the repository at this point in the history
support already encoded stuff
  • Loading branch information
EarthmanT authored Mar 24, 2020
2 parents 7ebae8f + 4deb10b commit aa01aab
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
3.2.12:
- Support previously base64 encoded userdata.
3.2.11:
- Keystone V3 validation to refer to docs URL in case of missing configuration.
- Add public_ip property when using server_connected_to_floating_ip and if use_public_ip is set True.
Expand Down
32 changes: 32 additions & 0 deletions openstack_plugin/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# #######
# Copyright (c) 2019 Cloudify Platform Ltd. All rights reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import base64

# Local imports
from openstack_plugin.tests.base import OpenStackTestBase
from openstack_plugin.utils import is_userdata_encoded


class UtilsTestCase(OpenStackTestBase):

def setUp(self):
super(UtilsTestCase, self).setUp()

def test_base64_encoding(self):
encoded_string = base64.b64encode('foo')
not_encoded_string = 'foo'
self.assertTrue(is_userdata_encoded(encoded_string))
self.assertFalse(is_userdata_encoded(not_encoded_string))
11 changes: 11 additions & 0 deletions openstack_plugin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import copy
import logging
import base64
import binascii
import inspect
import re

Expand Down Expand Up @@ -209,6 +210,14 @@ def resolve_ctx(_ctx):
return _ctx


def is_userdata_encoded(userdata_string):
try:
base64.decodestring(userdata_string)
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 @@ -232,6 +241,8 @@ def handle_userdata(existing_userdata):

if not existing_userdata:
existing_userdata = ''
elif is_userdata_encoded(existing_userdata):
return existing_userdata

if install_agent_userdata and os_family == 'windows':

Expand Down
4 changes: 2 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.11.zip
source: https://github.com/cloudify-cosmo/cloudify-openstack-plugin/archive/3.2.12.zip
package_name: cloudify-openstack-plugin
package_version: '3.2.11'
package_version: '3.2.12'

dsl_definitions:

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.11',
version='3.2.12',
author='Cloudify',
author_email='[email protected]',
license='LICENSE',
Expand Down

0 comments on commit aa01aab

Please sign in to comment.