IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 41059


Ignore:
Timestamp:
Nov 5, 2019, 9:17:31 AM (7 years ago)
Author:
fairlamb
Message:

Added rsync to jira/conf schema and tests to boot

Location:
branches/ipp-350_add_to_jira_conf_backups
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/ipp-350_add_to_jira_conf_backups/backup.py

    r40973 r41059  
    8383
    8484        self.read_config_and_schema(config, schema)
    85         # self.read_copy_config_section(config, schema)
    86         # self.read_tar_config_section(config, schema)
    87         # self.read_rsync_config_section(config, schema)
    88         # self.read_mysqldump_config_section(config, schema)
    8985
    9086    def read_config_and_schema(self, config: ConfigParser, schema: ConfigSchema):
     
    206202        self.target_backup_paths_ok(raise_error=True)
    207203        backup_paths = self.default_dict['backup_paths']
    208         for bp in backup_paths:
    209             # if not path.exists(bp):
    210             #     raise errs.ValidationError(f"ValidationError: target path does not exist: {bp}")
    211 
    212             for s in self.rsync_dict['sources']:
    213                 if not path.exists(s):
     204
     205        sources = self.rsync_dict['sources']
     206        for i in range(0, len(sources)):
     207            s = sources[i]
     208            if not path.exists(s):
    214209                    raise errs.ValidationError(f"ValidationError: target path does not exist: {s}")
     210
     211            for bp in backup_paths:
    215212                try:
    216213                    args = [s, bp]
     214
    217215                    if 'additional_args' in self.rsync_dict.keys():
    218216                        args = args + self.rsync_dict['additional_args']
    219217                    sub_utils.local_rsync_wrapper(args)
     218
    220219                except errs.SubprocessError as e:
    221220                    raise errs.SubprocessError( f"Error: rsync\n"
  • branches/ipp-350_add_to_jira_conf_backups/confluence_backup.py

    r40967 r41059  
    3232        , ConfigSchemaLine('target_filename', True,  str)
    3333        , ConfigSchemaLine('prefix_date',     True,  bool)
     34        ])
     35    , ConfigSchemaSection('RSYNC',
     36        [ ConfigSchemaLine('sources', True, list,
     37            cfg_help.SpecialSchemaProcessing.commma_separated)
     38        , ConfigSchemaLine('additional_args', False, list,
     39            cfg_help.SpecialSchemaProcessing.space_separated)
    3440        ])
    3541    , ConfigSchemaSection('MYSQLDUMP',
  • branches/ipp-350_add_to_jira_conf_backups/confluence_backup_test.py

    r40967 r41059  
    3434        , 'target_filename' : 'confluence.tar.gz'
    3535        , 'prefix_date' : 'True'
     36        }
     37    config['RSYNC'] = \
     38        { 'sources' : (f"{os.path.join(tmpdir, 'rsync_source_dir1')},"
     39                       f"{os.path.join(tmpdir, 'rsync_source_dir2')}")
     40        , 'additional_args' : '-a --delete-after'
    3641        }
    3742    config['MYSQLDUMP'] = \
     
    8287    assert os.path.exists(confluence_attachment_2_filepath)
    8388
     89    # Create a few folders to be rsync'd
     90    rsync_source_dir1 = os.path.join(tmpdir, "rsync_source_dir1")
     91    rsync_source_dir2 = os.path.join(tmpdir, "rsync_source_dir2")
     92    file_in_rsync_dir1 = os.path.join(rsync_source_dir1, "some_file_to_rsync")
     93    file_in_rsync_dir2 = os.path.join(rsync_source_dir2, "some_other_file_to_rsync")
     94    os.makedirs(rsync_source_dir1)
     95    os.makedirs(rsync_source_dir2)
     96    Path(file_in_rsync_dir1).touch()
     97    Path(file_in_rsync_dir2).touch()
     98    assert os.path.exists(file_in_rsync_dir1)
     99    assert os.path.exists(file_in_rsync_dir2)
     100
    84101
    85102class TestArguments(object):
     
    287304        assert os.path.exists(expected_confluence_bak1_tar)
    288305        assert os.path.exists(expected_confluence_bak2_tar)
     306
     307
     308class TestRsyncOfFiles(object):
     309
     310    def test_confluence_rsync(self, tmpdir):
     311        """This should be similar to the regular Backup version"""
     312        create_items_for_full_confluence_backup_test(tmpdir)
     313        config = make_config(tmpdir)
     314
     315        cb = ConfluenceBackup(config_file=config)
     316
     317        # Expected resulting rsync directories
     318        expected_confluence_host_rsync1 = os.path.join(tmpdir, "host_backup_path", "rsync_source_dir1")
     319        expected_confluence_bak1_rsync1 = os.path.join(tmpdir, "backup_1_path",    "rsync_source_dir1")
     320        expected_confluence_bak2_rsync1 = os.path.join(tmpdir, "backup_2_path",    "rsync_source_dir1")
     321        expected_confluence_host_rsync2 = os.path.join(tmpdir, "host_backup_path", "rsync_source_dir2")
     322        expected_confluence_bak1_rsync2 = os.path.join(tmpdir, "backup_1_path",    "rsync_source_dir2")
     323        expected_confluence_bak2_rsync2 = os.path.join(tmpdir, "backup_2_path",    "rsync_source_dir2")
     324        assert not os.path.exists(expected_confluence_host_rsync1)
     325        assert not os.path.exists(expected_confluence_bak1_rsync1)
     326        assert not os.path.exists(expected_confluence_bak2_rsync1)
     327        assert not os.path.exists(expected_confluence_host_rsync2)
     328        assert not os.path.exists(expected_confluence_bak1_rsync2)
     329        assert not os.path.exists(expected_confluence_bak2_rsync2)
     330        # Expected resulting rsync files
     331        expected_file_host_dir1 = os.path.join( expected_confluence_host_rsync1, "some_file_to_rsync")
     332        expected_file_bak1_dir1 = os.path.join( expected_confluence_bak1_rsync1, "some_file_to_rsync")
     333        expected_file_bak2_dir1 = os.path.join( expected_confluence_bak2_rsync1, "some_file_to_rsync")
     334        expected_file_host_dir2 = os.path.join( expected_confluence_host_rsync2, "some_other_file_to_rsync")
     335        expected_file_bak1_dir2 = os.path.join( expected_confluence_bak1_rsync2, "some_other_file_to_rsync")
     336        expected_file_bak2_dir2 = os.path.join( expected_confluence_bak2_rsync2, "some_other_file_to_rsync")
     337        assert not os.path.exists(expected_file_host_dir1)
     338        assert not os.path.exists(expected_file_bak1_dir1)
     339        assert not os.path.exists(expected_file_bak2_dir1)
     340        assert not os.path.exists(expected_file_host_dir2)
     341        assert not os.path.exists(expected_file_bak1_dir2)
     342        assert not os.path.exists(expected_file_bak2_dir2)
     343
     344        rsync_result = cb._run_rsync()
     345        assert rsync_result == 0
     346
     347        # All files Rsync'd
     348        assert os.path.exists(expected_confluence_host_rsync1)
     349        assert os.path.exists(expected_confluence_bak1_rsync1)
     350        assert os.path.exists(expected_confluence_bak2_rsync1)
     351        assert os.path.exists(expected_confluence_host_rsync2)
     352        assert os.path.exists(expected_confluence_bak1_rsync2)
     353        assert os.path.exists(expected_confluence_bak2_rsync2)
     354        assert os.path.exists(expected_file_host_dir1)
     355        assert os.path.exists(expected_file_bak1_dir1)
     356        assert os.path.exists(expected_file_bak2_dir1)
     357        assert os.path.exists(expected_file_host_dir2)
     358        assert os.path.exists(expected_file_bak1_dir2)
     359        assert os.path.exists(expected_file_bak2_dir2)
  • branches/ipp-350_add_to_jira_conf_backups/jira_backup.py

    r40967 r41059  
    3232        , ConfigSchemaLine('target_filename', True,  str)
    3333        , ConfigSchemaLine('prefix_date',     True,  bool)
     34        ])
     35    , ConfigSchemaSection('RSYNC',
     36        [ ConfigSchemaLine('sources', True, list,
     37            cfg_help.SpecialSchemaProcessing.commma_separated)
     38        , ConfigSchemaLine('additional_args', False, list,
     39            cfg_help.SpecialSchemaProcessing.space_separated)
    3440        ])
    3541    , ConfigSchemaSection('MYSQLDUMP',
  • branches/ipp-350_add_to_jira_conf_backups/jira_backup_test.py

    r40967 r41059  
    3333        , 'target_filename' : 'jira.tar.gz'
    3434        , 'prefix_date' : 'True'
     35        }
     36    config['RSYNC'] = \
     37        { 'sources' : (f"{os.path.join(tmpdir, 'rsync_source_dir1')},"
     38                       f"{os.path.join(tmpdir, 'rsync_source_dir2')}")
     39        , 'additional_args' : '-a --delete-after'
    3540        }
    3641    config['MYSQLDUMP'] = \
     
    8186    assert os.path.exists(jira_attachment_2_filepath)
    8287
     88    # Create a few folders to be rsync'd
     89    rsync_source_dir1 = os.path.join(tmpdir, "rsync_source_dir1")
     90    rsync_source_dir2 = os.path.join(tmpdir, "rsync_source_dir2")
     91    file_in_rsync_dir1 = os.path.join(rsync_source_dir1, "some_file_to_rsync")
     92    file_in_rsync_dir2 = os.path.join(rsync_source_dir2, "some_other_file_to_rsync")
     93    os.makedirs(rsync_source_dir1)
     94    os.makedirs(rsync_source_dir2)
     95    Path(file_in_rsync_dir1).touch()
     96    Path(file_in_rsync_dir2).touch()
     97    assert os.path.exists(file_in_rsync_dir1)
     98    assert os.path.exists(file_in_rsync_dir2)
     99
    83100
    84101class TestArguments(object):
     
    288305        assert os.path.exists(expected_jira_bak1_tar)
    289306        assert os.path.exists(expected_jira_bak2_tar)
     307
     308
     309class TestRsyncOfFiles(object):
     310
     311    def test_jira_rsync(self, tmpdir):
     312        """This should be similar to the regular Backup version"""
     313        create_items_for_full_jira_backup_test(tmpdir)
     314        config = make_config(tmpdir)
     315
     316        jb = JiraBackup(config_file=config)
     317
     318        # Expected resulting rsync directories
     319        expected_jira_host_rsync1 = os.path.join(tmpdir, "host_backup_path", "rsync_source_dir1")
     320        expected_jira_bak1_rsync1 = os.path.join(tmpdir, "backup_1_path",    "rsync_source_dir1")
     321        expected_jira_bak2_rsync1 = os.path.join(tmpdir, "backup_2_path",    "rsync_source_dir1")
     322        expected_jira_host_rsync2 = os.path.join(tmpdir, "host_backup_path", "rsync_source_dir2")
     323        expected_jira_bak1_rsync2 = os.path.join(tmpdir, "backup_1_path",    "rsync_source_dir2")
     324        expected_jira_bak2_rsync2 = os.path.join(tmpdir, "backup_2_path",    "rsync_source_dir2")
     325        assert not os.path.exists(expected_jira_host_rsync1)
     326        assert not os.path.exists(expected_jira_bak1_rsync1)
     327        assert not os.path.exists(expected_jira_bak2_rsync1)
     328        assert not os.path.exists(expected_jira_host_rsync2)
     329        assert not os.path.exists(expected_jira_bak1_rsync2)
     330        assert not os.path.exists(expected_jira_bak2_rsync2)
     331        # Expected resulting rsync files
     332        expected_file_host_dir1 = os.path.join( expected_jira_host_rsync1, "some_file_to_rsync")
     333        expected_file_bak1_dir1 = os.path.join( expected_jira_bak1_rsync1, "some_file_to_rsync")
     334        expected_file_bak2_dir1 = os.path.join( expected_jira_bak2_rsync1, "some_file_to_rsync")
     335        expected_file_host_dir2 = os.path.join( expected_jira_host_rsync2, "some_other_file_to_rsync")
     336        expected_file_bak1_dir2 = os.path.join( expected_jira_bak1_rsync2, "some_other_file_to_rsync")
     337        expected_file_bak2_dir2 = os.path.join( expected_jira_bak2_rsync2, "some_other_file_to_rsync")
     338        assert not os.path.exists(expected_file_host_dir1)
     339        assert not os.path.exists(expected_file_bak1_dir1)
     340        assert not os.path.exists(expected_file_bak2_dir1)
     341        assert not os.path.exists(expected_file_host_dir2)
     342        assert not os.path.exists(expected_file_bak1_dir2)
     343        assert not os.path.exists(expected_file_bak2_dir2)
     344
     345        rsync_result = jb._run_rsync()
     346        assert rsync_result == 0
     347
     348        # All files Rsync'd
     349        assert os.path.exists(expected_jira_host_rsync1)
     350        assert os.path.exists(expected_jira_bak1_rsync1)
     351        assert os.path.exists(expected_jira_bak2_rsync1)
     352        assert os.path.exists(expected_jira_host_rsync2)
     353        assert os.path.exists(expected_jira_bak1_rsync2)
     354        assert os.path.exists(expected_jira_bak2_rsync2)
     355        assert os.path.exists(expected_file_host_dir1)
     356        assert os.path.exists(expected_file_bak1_dir1)
     357        assert os.path.exists(expected_file_bak2_dir1)
     358        assert os.path.exists(expected_file_host_dir2)
     359        assert os.path.exists(expected_file_bak1_dir2)
     360        assert os.path.exists(expected_file_bak2_dir2)
  • branches/ipp-350_add_to_jira_conf_backups/testing/confluence_test.config

    r40967 r41059  
    1717prefix_date = True
    1818
     19[RSYNC]
     20sources = /opt/atlassian, /var/atlassian
     21additional_args = -a --delete-after
     22
    1923[MYSQLDUMP]
    2024user = dumper
  • branches/ipp-350_add_to_jira_conf_backups/testing/jira_test.config

    r40967 r41059  
    1616prefix_date = True
    1717
     18[RSYNC]
     19sources = /opt/atlassian, /var/atlassian
     20additional_args = -a --delete-after
     21
    1822[MYSQLDUMP]
    1923user = dumper
Note: See TracChangeset for help on using the changeset viewer.