Fixed open tempfile.NamedTemporaryFile as text in Python3

Python3 opens tempfile by default as binary[1] and not as ascii,
and nvmetcli writes json output as ascii.

This issue was overlooked with Python2, since binary and ascii
variables are less distiguished there.

[1] https://docs.python.org/3/library/tempfile.html
[2] https://bugs.python.org/issue29245

Change-Id: Ia1f280ab64f0dc90824d4cb9ed20a8537af32ef6
Closes-Bug: 1855855
This commit is contained in:
Lenny Verkhovsky 2019-12-10 11:42:52 +02:00
parent 40c3e4b34c
commit 195e12b1c1
1 changed files with 1 additions and 1 deletions

View File

@ -83,7 +83,7 @@ class NVMET(nvmeof.NVMeOF):
def _restore(self, nvmf_subsystems):
# Dump updated JSON dict to append new subsystem
with tempfile.NamedTemporaryFile() as tmp_fd:
with tempfile.NamedTemporaryFile(mode='w') as tmp_fd:
tmp_fd.write(json.dumps(nvmf_subsystems))
tmp_fd.flush()
try: