From 2d3cdcb7c9113d9b84660da8e2c0b8b8c9d94f99 Mon Sep 17 00:00:00 2001 From: Jason Dunsmore Date: Thu, 3 Jul 2014 13:51:04 -0500 Subject: [PATCH] Base64-encode personality file contents in AS client The Autoscale API expects the personality file contents to be base64-encoded. Transparently base64-encode the file contents similarly to how python-novaclient does it. --- pyrax/autoscale.py | 6 ++++++ tests/unit/test_autoscale.py | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pyrax/autoscale.py b/pyrax/autoscale.py index af3b1c45..4b66ca06 100644 --- a/pyrax/autoscale.py +++ b/pyrax/autoscale.py @@ -17,6 +17,8 @@ # License for the specific language governing permissions and limitations # under the License. +import base64 + import pyrax from pyrax.client import BaseClient from pyrax.cloudloadbalancers import CloudLoadBalancer @@ -766,6 +768,10 @@ def _create_body(self, name, cooldown, min_entities, max_entities, metadata = {} if personality is None: personality = [] + else: + for file in personality: + if 'contents' in file: + file['contents'] = base64.b64encode(file['contents']) if scaling_policies is None: scaling_policies = [] group_config = self._create_group_config_body(name, cooldown, diff --git a/tests/unit/test_autoscale.py b/tests/unit/test_autoscale.py index 2512c6eb..90cf77e2 100644 --- a/tests/unit/test_autoscale.py +++ b/tests/unit/test_autoscale.py @@ -1094,7 +1094,7 @@ def test_mgr_create_body(self): flavor = utils.random_unicode() disk_config = None metadata = None - personality = None + personality = [{'path': '/tmp/testing', 'contents': 'testtest'}] scaling_policies = None networks = utils.random_unicode() lb = fakes.FakeLoadBalancer() @@ -1119,7 +1119,8 @@ def test_mgr_create_body(self): "imageRef": image, "metadata": {}, "name": server_name, - "personality": [], + "personality": [{'path': '/tmp/testing', + 'contents': 'dGVzdHRlc3Q='}], "networks": networks, "key_name": key_name} },