From 61323654ebc0a8c8bd64cc4adfef8fd695d311bf Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Fri, 1 Aug 2025 14:32:19 +0100 Subject: [PATCH] tests: Use binary mode to open files A recent change to the CONTRIBUTING.rst file introduced unicode characters, which requests does not handle correctly when the file is open in text mode. requests 3.0 is removing support for opening files in text mode so we kill two birds with one stone here by switching to opening the file in binary mode. We also remove the unicode character (I tested the fix separately), correct the project name in the document, and use the raise from syntax to get better error handling in these cases. Change-Id: I47d65383233e23ec5edf1e6735c39c66eeafb804 Signed-off-by: Stephen Finucane --- CONTRIBUTING.rst | 4 ++-- openstack/image/v2/_proxy.py | 6 ++++-- openstack/tests/functional/image/v2/test_image.py | 5 ++++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 047e59e65..1c61eb426 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -13,11 +13,11 @@ Developer Certificate of Origin .. index:: single: license; agreement -In order to contribute to the Tacker-Horizon project, you need to adhere +In order to contribute to the openstacksdk project, you need to adhere to the `Developer Certificate of Origin`_. OpenStack utilizes the Developer Certificate of Origin (DCO) as a lightweight means to confirm that you are entitled to contribute the code you submit. This ensures that you are -providing your contributions under the project’s license and that you have +providing your contributions under the project's license and that you have the right to do so. Please read `DeveloperWorkflow`_ before sending your first patch for review. diff --git a/openstack/image/v2/_proxy.py b/openstack/image/v2/_proxy.py index 988ef1f86..004d09f0f 100644 --- a/openstack/image/v2/_proxy.py +++ b/openstack/image/v2/_proxy.py @@ -632,7 +632,9 @@ class Proxy(proxy.Proxy): self.log.debug("Image creation failed", exc_info=True) raise except Exception as e: - raise exceptions.SDKException(f"Image creation failed: {str(e)}") + raise exceptions.SDKException( + f"Image creation failed: {str(e)}" + ) from e def _make_v2_image_params(self, meta, properties): ret: dict = {} @@ -820,7 +822,7 @@ class Proxy(proxy.Proxy): raise exceptions.SDKException( f"Image creation failed: {e.message}", extra_data=glance_task, - ) + ) from e finally: # Clean up after ourselves. The object we created is not # needed after the import is done. diff --git a/openstack/tests/functional/image/v2/test_image.py b/openstack/tests/functional/image/v2/test_image.py index 7eafe828c..a5b694c66 100644 --- a/openstack/tests/functional/image/v2/test_image.py +++ b/openstack/tests/functional/image/v2/test_image.py @@ -22,6 +22,9 @@ class TestImage(base.BaseImageTest): def setUp(self): super().setUp() + with open('CONTRIBUTING.rst', 'rb') as fh: + data = fh.read() + # there's a limit on name length self.image = self.operator_cloud.image.create_image( name=TEST_IMAGE_NAME, @@ -30,7 +33,7 @@ class TestImage(base.BaseImageTest): properties={ 'description': 'This is not an image', }, - data=open('CONTRIBUTING.rst'), + data=data, ) self.assertIsInstance(self.image, _image.Image) self.assertEqual(TEST_IMAGE_NAME, self.image.name)