read/write binary w/msgpack

This commit is contained in:
David Boucha 2014-02-07 15:57:18 -07:00
parent 12fff24fbe
commit 16ef0c43f0

View File

@ -108,7 +108,7 @@ class MasterPillarUtil(object):
continue
path = os.path.join(mdir, minion_id, 'mine.p')
if os.path.isfile(path):
with salt.utils.fopen(path) as fp_:
with salt.utils.fopen(path, 'rb') as fp_:
mdata = self.serial.loads(fp_.read())
if isinstance(mdata, dict):
mine_data[minion_id] = mdata
@ -132,7 +132,7 @@ class MasterPillarUtil(object):
continue
path = os.path.join(mdir, minion_id, 'data.p')
if os.path.isfile(path):
with salt.utils.fopen(path) as fp_:
with salt.utils.fopen(path, 'rb') as fp_:
mdata = self.serial.loads(fp_.read())
if mdata.get('grains', False):
grains[minion_id] = mdata['grains']
@ -363,21 +363,21 @@ class MasterPillarUtil(object):
# Not saving pillar or grains, so just delete the cache file
os.remove(os.path.join(data_file))
elif clear_pillar and minion_grains:
with salt.utils.fopen(data_file, 'w+') as fp_:
with salt.utils.fopen(data_file, 'w+b') as fp_:
fp_.write(self.serial.dumps({'grains': minion_grains}))
elif clear_grains and minion_pillar:
with salt.utils.fopen(data_file, 'w+') as fp_:
with salt.utils.fopen(data_file, 'w+b') as fp_:
fp_.write(self.serial.dumps({'pillar': minion_pillar}))
if clear_mine:
# Delete the whole mine file
os.remove(os.path.join(mine_file))
elif clear_mine_func is not None:
# Delete a specific function from the mine file
with salt.utils.fopen(mine_file) as fp_:
with salt.utils.fopen(mine_file, 'rb') as fp_:
mine_data = self.serial.loads(fp_.read())
if isinstance(mine_data, dict):
if mine_data.pop(clear_mine_func, False):
with salt.utils.fopen(mine_file, 'w+') as fp_:
with salt.utils.fopen(mine_file, 'w+b') as fp_:
fp_.write(self.serial.dumps(mine_data))
except (OSError, IOError):
return True