Skip to content

Commit 606d588

Browse files
committed
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. libguestfs/libguestfs@0ee02e0 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
1 parent 3f2868c commit 606d588

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

nova/tests/unit/virt/disk/vfs/fakeguestfs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def read_file(self, path):
109109
"mode": 0o700
110110
}
111111

112-
return self.files[path]["content"]
112+
return bytes(self.files[path]["content"].encode())
113113

114114
def write(self, path, content):
115115
if path not in self.files:

nova/virt/disk/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -615,8 +615,8 @@ def _set_passwd(username, admin_passwd, passwd_data, shadow_data):
615615
616616
:param username: the username
617617
:param admin_passwd: the admin password
618-
:param passwd_data: path to the passwd file
619-
:param shadow_data: path to the shadow password file
618+
:param passwd_data: Data from the passwd file decoded as a string
619+
:param shadow_data: Data from the shadow file decoded as a string
620620
:returns: nothing
621621
:raises: exception.NovaException(), IOError()
622622

nova/virt/disk/vfs/guestfs.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,14 @@ def replace_file(self, path, content):
306306
def read_file(self, path):
307307
LOG.debug("Read file path=%s", path)
308308
path = self._canonicalize_path(path)
309-
return self.handle.read_file(path)
309+
data = self.handle.read_file(path)
310+
# NOTE(lyarwood): libguestfs v1.41.1 (0ee02e0117527) switched the
311+
# return type of read_file from string to bytes and as such we need to
312+
# handle both here, decoding and returning a string if bytes is
313+
# provided. https://bugzilla.redhat.com/show_bug.cgi?id=1661871
314+
if isinstance(data, bytes):
315+
return data.decode()
316+
return data
310317

311318
def has_file(self, path):
312319
LOG.debug("Has file path=%s", path)

0 commit comments

Comments
 (0)