From 39822599734e3aa3995e25e3c2ca09acc5d1aff9 Mon Sep 17 00:00:00 2001 From: Emilien Macchi Date: Tue, 12 Mar 2019 10:34:04 -0400 Subject: [PATCH] Make _upload_file to work with Python 3 Open the content from the file in Swift as bytes and in read mode, otherwise Python 3 fails to open it as it comes as a string by default. Closes-Bug: #1819665 Change-Id: I0da24d3508174190b431b660e67365f242ef04d8 --- tripleoclient/tests/v1/test_overcloud_plan.py | 2 +- tripleoclient/tests/workflows/test_plan_management.py | 4 ++-- tripleoclient/workflows/plan_management.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tripleoclient/tests/v1/test_overcloud_plan.py b/tripleoclient/tests/v1/test_overcloud_plan.py index 947f342cb..da5bd9b1a 100644 --- a/tripleoclient/tests/v1/test_overcloud_plan.py +++ b/tripleoclient/tests/v1/test_overcloud_plan.py @@ -337,7 +337,7 @@ class TestOvercloudCreatePlan(utils.TestCommand): }) mock_open_context.assert_has_calls( - [mock.call('the_plan_environment.yaml')]) + [mock.call('the_plan_environment.yaml', 'rb')]) self.tripleoclient.object_store.put_object.assert_called_once_with( 'overcast', 'plan-environment.yaml', mock_open_context()) diff --git a/tripleoclient/tests/workflows/test_plan_management.py b/tripleoclient/tests/workflows/test_plan_management.py index 1ac43c985..1df01bb59 100644 --- a/tripleoclient/tests/workflows/test_plan_management.py +++ b/tripleoclient/tests/workflows/test_plan_management.py @@ -155,7 +155,7 @@ class TestPlanCreationWorkflows(utils.TestCommand): 'validate_stack': False}) mock_open_context.assert_has_calls( - [mock.call('the-plan-environment.yaml')]) + [mock.call('the-plan-environment.yaml', 'rb')]) self.tripleoclient.object_store.put_object.assert_called_once_with( 'test-overcloud', 'plan-environment.yaml', mock_open_context()) @@ -190,7 +190,7 @@ class TestPlanCreationWorkflows(utils.TestCommand): 'validate_stack': False}) mock_open_context.assert_has_calls( - [mock.call('the-network-data.yaml')]) + [mock.call('the-network-data.yaml', 'rb')]) self.tripleoclient.object_store.put_object.assert_called_once_with( 'test-overcloud', 'network_data.yaml', mock_open_context()) diff --git a/tripleoclient/workflows/plan_management.py b/tripleoclient/workflows/plan_management.py index f3057193f..0a33e581f 100644 --- a/tripleoclient/workflows/plan_management.py +++ b/tripleoclient/workflows/plan_management.py @@ -277,7 +277,7 @@ def _list_plan_files(swift_client, container): def _upload_file(swift_client, container, filename, local_filename): - with open(local_filename) as file_content: + with open(local_filename, 'rb') as file_content: swift_client.put_object(container, filename, file_content)