|
| 1 | +importos |
| 2 | +importunittest |
| 3 | +from .helpers.ptrack_helpersimportProbackupTest,ProbackupException |
| 4 | + |
| 5 | + |
| 6 | +module_name='time_stamp' |
| 7 | + |
| 8 | +classCheckTimeStamp(ProbackupTest,unittest.TestCase): |
| 9 | + |
| 10 | +deftest_start_time_format(self): |
| 11 | +"""Test backup ID changing after start-time editing in backup.control. |
| 12 | + We should convert local time in UTC format""" |
| 13 | +# Create simple node |
| 14 | +fname=self.id().split('.')[3] |
| 15 | +node=self.make_simple_node(base_dir="{0}/{1}/node".format(module_name,fname), |
| 16 | +initdb_params=['--data-checksums'], |
| 17 | +pg_options={'wal_level':'replica'} |
| 18 | + ) |
| 19 | +backup_dir=os.path.join(self.tmp_path,module_name,fname,'backup') |
| 20 | +self.init_pb(backup_dir) |
| 21 | +self.add_instance(backup_dir,'node',node) |
| 22 | +self.set_archiving(backup_dir,'node',node) |
| 23 | +node.start() |
| 24 | + |
| 25 | +backup_id=self.backup_node(backup_dir,'node',node,options=['--stream','-j 2']) |
| 26 | +show_backup=self.show_pb(backup_dir,'node') |
| 27 | + |
| 28 | +i=0 |
| 29 | +whilei<2: |
| 30 | +withopen(os.path.join(backup_dir,"backups","node",backup_id,"backup.control"),"r+")asf: |
| 31 | +output="" |
| 32 | +forlineinf: |
| 33 | +ifline.startswith('start-time')isTrue: |
| 34 | +ifi==0: |
| 35 | +output=output+str(line[:-5])+'+00\''+'\n' |
| 36 | +else: |
| 37 | +output=output+str(line[:-5])+'\''+'\n' |
| 38 | +else: |
| 39 | +output=output+str(line) |
| 40 | +f.close() |
| 41 | + |
| 42 | +withopen(os.path.join(backup_dir,"backups","node",backup_id,"backup.control"),"w")asfw: |
| 43 | +fw.write(output) |
| 44 | +fw.flush() |
| 45 | +show_backup=show_backup+self.show_pb(backup_dir,'node') |
| 46 | +i+=1 |
| 47 | + |
| 48 | +self.assertTrue(show_backup[1]['id']==show_backup[2]['id'],"ERROR: Localtime format using instead of UTC") |
| 49 | + |
| 50 | +node.stop() |
| 51 | +# Clean after yourself |
| 52 | +self.del_test_dir(module_name,fname) |