Fix Python 3 bytes vs strings differences
Writing files was done fairly naively with our Python 2 code - this change introduces explicit ASCII encoding when writing files. Change-Id: I93c9fa4ba2fd8af9c9bf9424adaec602dbdca5f0
This commit is contained in:
parent
fa5336ca36
commit
e2f56ec634
@ -193,7 +193,7 @@ def write_hostnames(save_path, hostnames_ips):
|
||||
indent=4,
|
||||
separators=(',', ': '),
|
||||
sort_keys=True
|
||||
)
|
||||
).encode('ascii')
|
||||
)
|
||||
|
||||
|
||||
@ -212,7 +212,7 @@ def _load_from_json(filename, preferred_path=None, raise_if_missing=True):
|
||||
dictionary = False
|
||||
if target_file is not False:
|
||||
with open(target_file, 'rb') as f_handle:
|
||||
dictionary = json.loads(f_handle.read())
|
||||
dictionary = json.loads(f_handle.read().decode('ascii'))
|
||||
|
||||
return dictionary, target_file
|
||||
|
||||
@ -264,7 +264,7 @@ def save_inventory(inventory_json, save_path):
|
||||
else:
|
||||
inventory_file = os.path.join(save_path, INVENTORY_FILENAME)
|
||||
with open(inventory_file, 'wb') as f:
|
||||
f.write(inventory_json)
|
||||
f.write(inventory_json.encode('ascii'))
|
||||
logger.info("Inventory written")
|
||||
|
||||
|
||||
|
@ -570,7 +570,7 @@ class TestConfigCheckBase(unittest.TestCase):
|
||||
self.config_changed = True
|
||||
# Save new user_config_file
|
||||
with open(USER_CONFIG_FILE, 'wb') as f:
|
||||
f.write(yaml.dump(self.user_defined_config))
|
||||
f.write(yaml.dump(self.user_defined_config).encode('ascii'))
|
||||
|
||||
def restore_config(self):
|
||||
# get back our initial user config file
|
||||
|
Loading…
Reference in New Issue
Block a user