From 743002cc269ac1e91d8df2eee5f4fdad3d14c365 Mon Sep 17 00:00:00 2001 From: Gorka Eguileor Date: Tue, 12 Jul 2022 16:31:43 +0200 Subject: [PATCH] RBD: Fix disconnect_volume for encrypted volumes After change Ie373ab050dcc0a35c749d9a53b6cf5ca060bcb58 closing bugs connector was broken for encrypted volumes: <== disconnect_volume: exception (0ms) AttributeError("'RBDVolumeIOWrapper' object has no attribute 'startswith'") trace_logging_wrapper /usr/lib/python3.9/site-packages/os_brick/utils.py:162 This hapens because "_device_path_from_symlink" doesn't take into account of the file handle, and we were missing a unit test for this case. Closes-Bug: #1981455 Change-Id: Ib001e2b4d1347754c2b46730bc10d86e8cdab7ad (cherry picked from commit dde8f102b714e2e4001a3fe82f975cd9978ac1c5) --- os_brick/tests/test_utils.py | 6 ++++++ os_brick/utils.py | 3 ++- .../notes/rbd-disconnect-failure-9efa6932df40271b.yaml | 6 ++++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/rbd-disconnect-failure-9efa6932df40271b.yaml diff --git a/os_brick/tests/test_utils.py b/os_brick/tests/test_utils.py index 3b1aa442b..e087c4593 100644 --- a/os_brick/tests/test_utils.py +++ b/os_brick/tests/test_utils.py @@ -388,6 +388,12 @@ class ConnectionPropertiesDecoratorsTestCase(base.TestCase): res = utils._device_path_from_symlink(symlink) self.assertEqual('/dev/md/alias', res) + def test__device_path_from_symlink_file_handle(self): + """Get device name for a file handle (eg: RBD).""" + handle = io.StringIO() + res = utils._device_path_from_symlink(handle) + self.assertEqual(handle, res) + @ddt.data(({}, {'type': 'block', 'path': '/dev/sda'}), ({'encrypted': False}, {'type': 'block', 'path': '/dev/sda'}), ({'encrypted': False}, {'type': 'block', 'path': b'/dev/sda'}), diff --git a/os_brick/utils.py b/os_brick/utils.py index c0fd69503..f8031c2cc 100644 --- a/os_brick/utils.py +++ b/os_brick/utils.py @@ -257,7 +257,8 @@ def _device_path_from_symlink(symlink): This is the reverse operation of the one performed by the _symlink_name_from_device_path method. """ - if symlink and symlink.startswith(CUSTOM_LINK_PREFIX): + if (symlink and isinstance(symlink, str) + and symlink.startswith(CUSTOM_LINK_PREFIX)): ending = symlink[len(CUSTOM_LINK_PREFIX):] return ending.replace('+', '/') return symlink diff --git a/releasenotes/notes/rbd-disconnect-failure-9efa6932df40271b.yaml b/releasenotes/notes/rbd-disconnect-failure-9efa6932df40271b.yaml new file mode 100644 index 000000000..80133d81a --- /dev/null +++ b/releasenotes/notes/rbd-disconnect-failure-9efa6932df40271b.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + RBD connector `bug #1981455 + `_: Fixed AttributeError + error on disconnect for RBD encrypted volumes not using host attachments.