diff options
author | Takashi Kajinami <tkajinam@redhat.com> | 2021-09-04 23:03:17 +0900 |
---|---|---|
committer | Hervé Beraud <herveberaud.pro@gmail.com> | 2021-10-18 11:54:15 +0000 |
commit | 3e81ba70a617c450b4d7d71a95d323c7af035405 (patch) | |
tree | 467d8768f8d37bc6ac73b58ce039a2f295ba617d | |
parent | ceb83ed73a0bf2f8aa08228c80a01453f5e64371 (diff) | |
download | oslo-utils-3e81ba70a617c450b4d7d71a95d323c7af035405.tar.gz |
QemuImgInfo: Fix inconsistent value format of encrypted
The qemu-img info command shows the encrpyed field in different formats
according to the output format. When the default human format is used
the field can be 'yes' or None while when json format is used the same
field can be True or False.
This change ensures the corresponding attribute has the consistent
format regardless of the output format used.
Closes-Bug: #1942682
Change-Id: I949f07582a708114fdfba76f1a05aa3a3e5c4f40
(cherry picked from commit 2922a3491a5987aa80f0612df44bd60ed22a0225)
-rw-r--r-- | oslo_utils/imageutils.py | 2 | ||||
-rw-r--r-- | oslo_utils/tests/test_imageutils.py | 5 | ||||
-rw-r--r-- | releasenotes/notes/bug-1942682-ea95d54b2587b32f.yaml | 6 |
3 files changed, 11 insertions, 2 deletions
diff --git a/oslo_utils/imageutils.py b/oslo_utils/imageutils.py index 65292dc..d764a7f 100644 --- a/oslo_utils/imageutils.py +++ b/oslo_utils/imageutils.py @@ -63,7 +63,7 @@ class QemuImgInfo(object): self.cluster_size = details.get('cluster-size') self.disk_size = details.get('actual-size') self.snapshots = details.get('snapshots', []) - self.encrypted = details.get('encrypted') + self.encrypted = 'yes' if details.get('encrypted') else None self.format_specific = details.get('format-specific') else: if cmd_output is not None: diff --git a/oslo_utils/tests/test_imageutils.py b/oslo_utils/tests/test_imageutils.py index 63e0ee9..6b25226 100644 --- a/oslo_utils/tests/test_imageutils.py +++ b/oslo_utils/tests/test_imageutils.py @@ -238,7 +238,8 @@ class ImageUtilsJSONTestCase(test_base.BaseTestCase): "cluster-size": 65536, "format": "qcow2", "actual-size": 13168640, - "format-specific": {"data": {"foo": "bar"}} + "format-specific": {"data": {"foo": "bar"}}, + "encrypted": true }''' image_info = imageutils.QemuImgInfo(img_output, format='json') mock_deprecate.assert_not_called() @@ -248,6 +249,7 @@ class ImageUtilsJSONTestCase(test_base.BaseTestCase): self.assertEqual('qcow2', image_info.file_format) self.assertEqual(13168640, image_info.disk_size) self.assertEqual("bar", image_info.format_specific["data"]["foo"]) + self.assertEqual('yes', image_info.encrypted) @mock.patch("debtcollector.deprecate") def test_qemu_img_info_blank(self, mock_deprecate): @@ -260,3 +262,4 @@ class ImageUtilsJSONTestCase(test_base.BaseTestCase): self.assertIsNone(image_info.file_format) self.assertIsNone(image_info.disk_size) self.assertIsNone(image_info.format_specific) + self.assertIsNone(image_info.encrypted) diff --git a/releasenotes/notes/bug-1942682-ea95d54b2587b32f.yaml b/releasenotes/notes/bug-1942682-ea95d54b2587b32f.yaml new file mode 100644 index 0000000..b21d6b0 --- /dev/null +++ b/releasenotes/notes/bug-1942682-ea95d54b2587b32f.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + `bug #1942682 <https://bugs.launchpad.net/oslo.utils/+bug/1942682>`_: + Fix inconsistent value of `QemuImgInfo.encrypted`. Now the attribute is + always `'yes'` or `None` regardless of the format(`human` or `json`) used. |