slapos.grid.promise: prevent json file corruption while updating data

history and statistics files are sometimes corrupted because of invalid json

We do 2 things to improve this:
 1. we use json.load to read the previous file (this will detect if the file is corrupted)
 2. we use json.dump to write the entire file at once in a temporary file and then we move this file to be atomic.

Probably this will consume more resources.

See merge request !728
1 job for master in 0 seconds
Status Job ID Name Coverage
  External
failed SlapOS.Eggs.UnitTest-Master.Python3

00:39:16