IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 24, 2019, 1:19:12 PM (7 years ago)
Author:
fairlamb
Message:

Backups write out a tiny log saying when it was last run

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ipp-259_genericise_backups/tools/backups/backup_test.py

    r40962 r40966  
    354354        config['TAR'] = \
    355355        { 'sources' : f"{source}"
    356         , 'additional_args' : "-C / -cf"
     356        , 'additional_args' : "-cf"
    357357        , 'target_filename' : 'cool_tar.tar'
    358358        , 'prefix_date' : 'False'
     
    366366
    367367        expected_tar1 = os.path.join(tmpdir, 'bck1', 'cool_tar.tar')
     368        print(expected_tar1)
    368369        assert not os.path.exists(expected_tar1)
    369370        backy._run_tar()
     
    382383        config['TAR'] = \
    383384        { 'sources' : f"{source1}, {source2}"
    384         , 'additional_args' : "-C / -cf"
     385        , 'additional_args' : "-cf"
    385386        , 'target_filename' : 'cool_tar.tar'
    386387        , 'prefix_date' : 'True'
     
    596597
    597598
    598 
    599599@pytest.mark.skip(reason="Requires a fake database to be setup")
    600600class TestMysqlBackup(object):
     
    656656        with pytest.raises(errs.SubprocessError):
    657657            backy._run_mysqldump()
     658
     659
     660# class TestRunningAll(object):
     661
     662#     def test_running_copy_tar_and_rsyc(self):
     663        config = make_default_config(tmpdir, ['bck1', 'bck2'])
     664
     665
     666class TestSimpleLogWriting(object):
     667
     668    def test_log_writing_success(self, tmpdir):
     669        config = make_default_config(tmpdir, ['bck1', 'bck2'])
     670        schema = ConfigSchema(None)
     671        schema.add_section(bckup.DEFAULT_SCHEMA_SECTION)
     672
     673        backy = Backup(config, schema)
     674
     675        expected_log1 = os.path.join(tmpdir, 'bck1', 'latest_run.log')
     676        expected_log2 = os.path.join(tmpdir, 'bck2', 'latest_run.log')
     677        assert not os.path.exists(expected_log1)
     678        assert not os.path.exists(expected_log2)
     679        backy.run_backup_processes()
     680        assert os.path.exists(expected_log1)
     681        assert os.path.exists(expected_log2)
     682
     683        # Read file
     684        with open(expected_log1, "r") as logf:
     685            lines = logf.readlines()
     686            assert len(lines) == 2
     687            assert "Run started at: " in lines[0]
     688            assert "Last successful backup completed at :" in lines[1]
     689
     690        with open(expected_log2, "r") as logf:
     691            lines = logf.readlines()
     692            assert len(lines) == 2
     693            assert "Run started at: " in lines[0]
     694            assert "Last successful backup completed at :" in lines[1]
     695
     696    def test_log_writes_only_attempted_if_failure_encountered(self, tmpdir):
     697
     698        config = make_default_config(tmpdir, ['bck1', 'bck2'])
     699        source = os.path.join(tmpdir, "and_specific_file.jpeg")
     700        config['COPY'] = \
     701        { 'sources' : f"{source}"
     702        , 'additional_args' : '-r'
     703        }
     704        schema = ConfigSchema(None)
     705        schema.add_section(bckup.DEFAULT_SCHEMA_SECTION)
     706        schema.add_section(bckup.COPY_SCHEMA_SECTION)
     707
     708        backy = Backup(config, schema)
     709
     710        expected_log1 = os.path.join(tmpdir, 'bck1', 'latest_run.log')
     711        expected_log2 = os.path.join(tmpdir, 'bck2', 'latest_run.log')
     712        assert not os.path.exists(expected_log1)
     713        assert not os.path.exists(expected_log2)
     714        # fails due to missing source file in copy
     715        with pytest.raises(errs.ValidationError):
     716            backy.run_backup_processes()
     717
     718        assert os.path.exists(expected_log1)
     719        assert os.path.exists(expected_log2)
     720
     721        with open(expected_log1, "r") as logf:
     722            lines = logf.readlines()
     723            assert len(lines) == 1
     724            assert "Run started at: " in lines[0]
     725
     726        with open(expected_log2, "r") as logf:
     727            lines = logf.readlines()
     728            assert len(lines) == 1
     729            assert "Run started at: " in lines[0]
Note: See TracChangeset for help on using the changeset viewer.