summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLee Yarwood <lyarwood@redhat.com>2021-04-23 12:14:42 +0100
committerLee Yarwood <lyarwood@redhat.com>2021-04-25 21:34:34 +0100
commit637402eec7f3f7f552bfc30d16c5960e3a651395 (patch)
tree12a5aef42e2ab0e77448507f6ecceb9213be3bd2
parent4fd78fb70f689c49d5aeaaf1b196f6181947674d (diff)
downloadnova-637402eec7f3f7f552bfc30d16c5960e3a651395.tar.gz
guestfs: With libguestfs >= v1.41.1 decode returned bytes to string
libguestfs >= v1.41.1 and commit 0ee02e0117527 changed the return type of read_file from string to bytes. https://github.com/libguestfs/libguestfs/commit/0ee02e0117527b86a31b2a88a14994ce7f15571f As we don't check the version of libguestfs installed this change handles both the original behaviour where a string is returned and the newer behaviour by decoding any returned bytes to a string. Closes-Bug: #1882421 Change-Id: I1c12b2903c1e5bf3a88394493456ad33233f3cd8 (cherry picked from commit 606d588e3eca1d88ad26b4c2cfa3f2e1d5ed553e) (cherry picked from commit e98935f705a931e3ae666820387a419be1622b64) (cherry picked from commit 210abc09b857880aa7665fb540f46cb53662a600)
-rw-r--r--nova/tests/unit/virt/disk/vfs/fakeguestfs.py2
-rw-r--r--nova/virt/disk/api.py4
-rw-r--r--nova/virt/disk/vfs/guestfs.py9
3 files changed, 11 insertions, 4 deletions
diff --git a/nova/tests/unit/virt/disk/vfs/fakeguestfs.py b/nova/tests/unit/virt/disk/vfs/fakeguestfs.py
index 96c97edf79..168400e956 100644
--- a/nova/tests/unit/virt/disk/vfs/fakeguestfs.py
+++ b/nova/tests/unit/virt/disk/vfs/fakeguestfs.py
@@ -109,7 +109,7 @@ class GuestFS(object):
"mode": 0o700
}
- return self.files[path]["content"]
+ return bytes(self.files[path]["content"].encode())
def write(self, path, content):
if path not in self.files:
diff --git a/nova/virt/disk/api.py b/nova/virt/disk/api.py
index c79ae77371..83d3f13ed2 100644
--- a/nova/virt/disk/api.py
+++ b/nova/virt/disk/api.py
@@ -615,8 +615,8 @@ def _set_passwd(username, admin_passwd, passwd_data, shadow_data):
:param username: the username
:param admin_passwd: the admin password
- :param passwd_data: path to the passwd file
- :param shadow_data: path to the shadow password file
+ :param passwd_data: Data from the passwd file decoded as a string
+ :param shadow_data: Data from the shadow file decoded as a string
:returns: nothing
:raises: exception.NovaException(), IOError()
diff --git a/nova/virt/disk/vfs/guestfs.py b/nova/virt/disk/vfs/guestfs.py
index db260d9a4a..ce5f48794a 100644
--- a/nova/virt/disk/vfs/guestfs.py
+++ b/nova/virt/disk/vfs/guestfs.py
@@ -308,7 +308,14 @@ class VFSGuestFS(vfs.VFS):
def read_file(self, path):
LOG.debug("Read file path=%s", path)
path = self._canonicalize_path(path)
- return self.handle.read_file(path)
+ data = self.handle.read_file(path)
+ # NOTE(lyarwood): libguestfs v1.41.1 (0ee02e0117527) switched the
+ # return type of read_file from string to bytes and as such we need to
+ # handle both here, decoding and returning a string if bytes is
+ # provided. https://bugzilla.redhat.com/show_bug.cgi?id=1661871
+ if isinstance(data, bytes):
+ return data.decode()
+ return data
def has_file(self, path):
LOG.debug("Has file path=%s", path)