示例#1
0
    def test_backup_option_parser(self):
        """
        Test of the BackupOption class alone.

        Builds the class using 'concurrent_backup', then using
        'exclusive_backup' as values.
        Then tests for ValueError conditions
        """
        # Builds using the two allowed values
        assert set([BackupOptions.CONCURRENT_BACKUP]) == \
            BackupOptions(BackupOptions.CONCURRENT_BACKUP, "", "")
        assert set([BackupOptions.EXCLUSIVE_BACKUP]) == \
            BackupOptions(BackupOptions.EXCLUSIVE_BACKUP, "", "")
        # build using a not allowed value
        with pytest.raises(ValueError):
            BackupOptions("test_string", "", "")
        # conflicting values error
        with pytest.raises(ValueError):
            conflict = "%s, %s" % (BackupOptions.EXCLUSIVE_BACKUP,
                                   BackupOptions.CONCURRENT_BACKUP)
            BackupOptions(conflict, "", "")
示例#2
0
    def test_recovery_option_parser(self):
        """
        Test of the RecoveryOptions class.

        Builds the class using '', then using
        'get-wal' as values.
        Tests for ValueError conditions
        """
        # Builds using the two allowed values
        assert set([]) == \
            RecoveryOptions('', '', '')
        assert set([RecoveryOptions.GET_WAL]) == \
            RecoveryOptions(RecoveryOptions.GET_WAL, '', '')
        # build using a not allowed value
        with pytest.raises(ValueError):
            BackupOptions("test_string", "", "")
def build_config_dictionary(config_keys=None):
    """
    Utility method, generate a dict useful for config comparison

    It has a 'basic' format and every key could be overwritten the
    config_keys parameter.

    :param dict[str,str|None]|None config_keys: using this dictionary
        it is possible to override or add new values to the base dictionary.
    :return dict: a dictionary representing a barman configuration
    """
    # Basic dictionary
    base_config = {
        'active': True,
        'archiver': True,
        'archiver_batch_size': 0,
        'config': None,
        'backup_directory': '/some/barman/home/main',
        'backup_options': BackupOptions("", "", ""),
        'bandwidth_limit': None,
        'barman_home': '/some/barman/home',
        'basebackups_directory': '/some/barman/home/main/base',
        'barman_lock_directory': '/some/barman/home',
        'compression': None,
        'conninfo': 'host=pg01.nowhere user=postgres port=5432',
        'backup_method': 'rsync',
        'check_timeout': 30,
        'custom_compression_filter': None,
        'custom_decompression_filter': None,
        'description': ' Text with quotes ',
        'immediate_checkpoint': False,
        'incoming_wals_directory': '/some/barman/home/main/incoming',
        'max_incoming_wals_queue': None,
        'minimum_redundancy': '0',
        'name': 'main',
        'network_compression': False,
        'post_backup_script': None,
        'pre_backup_script': None,
        'post_recovery_script': None,
        'pre_recovery_script': None,
        'post_recovery_retry_script': None,
        'pre_recovery_retry_script': None,
        'slot_name': None,
        'streaming_archiver_name': 'barman_receive_wal',
        'streaming_archiver_batch_size': 0,
        'post_backup_retry_script': None,
        'streaming_backup_name': 'barman_streaming_backup',
        'pre_backup_retry_script': None,
        'recovery_options': set(),
        'retention_policy': None,
        'retention_policy_mode': 'auto',
        'reuse_backup': None,
        'ssh_command': 'ssh -c "arcfour" -p 22 [email protected]',
        'primary_ssh_command': None,
        'tablespace_bandwidth_limit': None,
        'wal_retention_policy': 'main',
        'wals_directory': '/some/barman/home/main/wals',
        'basebackup_retry_sleep': 30,
        'basebackup_retry_times': 0,
        'post_archive_script': None,
        'streaming_conninfo': 'host=pg01.nowhere user=postgres port=5432',
        'pre_archive_script': None,
        'post_archive_retry_script': None,
        'pre_archive_retry_script': None,
        'post_delete_script': None,
        'pre_delete_script': None,
        'post_delete_retry_script': None,
        'pre_delete_retry_script': None,
        'post_wal_delete_script': None,
        'pre_wal_delete_script': None,
        'post_wal_delete_retry_script': None,
        'pre_wal_delete_retry_script': None,
        'last_backup_maximum_age': None,
        'disabled': False,
        'msg_list': [],
        'path_prefix': None,
        'streaming_archiver': False,
        'streaming_wals_directory': '/some/barman/home/main/streaming',
        'errors_directory': '/some/barman/home/main/errors',
        'parallel_jobs': 1,
    }
    # Check for overriding keys
    if config_keys is not None:
        base_config.update(config_keys)
    return base_config
示例#4
0
def build_config_dictionary(config_keys=None):
    """
    Utility method, generate a dict useful for config comparison

    It has a 'basic' format and every key could be overwritten the
    config_keys parameter.

    :param dict[str,str|None]|None config_keys: using this dictionary
        it is possible to override or add new values to the base dictionary.
    :return dict: a dictionary representing a barman configuration
    """
    # Basic dictionary
    base_config = {
        "active": True,
        "archiver": True,
        "archiver_batch_size": 0,
        "config": None,
        "backup_directory": "/some/barman/home/main",
        "backup_options": BackupOptions("", "", ""),
        "bandwidth_limit": None,
        "barman_home": "/some/barman/home",
        "basebackups_directory": "/some/barman/home/main/base",
        "barman_lock_directory": "/some/barman/home",
        "compression": None,
        "conninfo": "host=pg01.nowhere user=postgres port=5432",
        "backup_method": "rsync",
        "check_timeout": 30,
        "custom_compression_filter": None,
        "custom_decompression_filter": None,
        "description": " Text with quotes ",
        "immediate_checkpoint": False,
        "incoming_wals_directory": "/some/barman/home/main/incoming",
        "max_incoming_wals_queue": None,
        "minimum_redundancy": "0",
        "name": "main",
        "network_compression": False,
        "post_backup_script": None,
        "pre_backup_script": None,
        "post_recovery_script": None,
        "pre_recovery_script": None,
        "post_recovery_retry_script": None,
        "pre_recovery_retry_script": None,
        "slot_name": None,
        "streaming_archiver_name": "barman_receive_wal",
        "streaming_archiver_batch_size": 0,
        "post_backup_retry_script": None,
        "streaming_backup_name": "barman_streaming_backup",
        "pre_backup_retry_script": None,
        "recovery_options": set(),
        "retention_policy": None,
        "retention_policy_mode": "auto",
        "reuse_backup": None,
        "ssh_command": 'ssh -c "arcfour" -p 22 [email protected]',
        "primary_ssh_command": None,
        "tablespace_bandwidth_limit": None,
        "wal_retention_policy": "main",
        "wals_directory": "/some/barman/home/main/wals",
        "basebackup_retry_sleep": 30,
        "basebackup_retry_times": 0,
        "post_archive_script": None,
        "streaming_conninfo": "host=pg01.nowhere user=postgres port=5432",
        "pre_archive_script": None,
        "post_archive_retry_script": None,
        "pre_archive_retry_script": None,
        "post_delete_script": None,
        "pre_delete_script": None,
        "post_delete_retry_script": None,
        "pre_delete_retry_script": None,
        "post_wal_delete_script": None,
        "pre_wal_delete_script": None,
        "post_wal_delete_retry_script": None,
        "pre_wal_delete_retry_script": None,
        "last_backup_maximum_age": None,
        "disabled": False,
        "msg_list": [],
        "path_prefix": None,
        "streaming_archiver": False,
        "streaming_wals_directory": "/some/barman/home/main/streaming",
        "errors_directory": "/some/barman/home/main/errors",
        "parallel_jobs": 1,
        "create_slot": "manual",
        "forward_config_path": False,
    }
    # Check for overriding keys
    if config_keys is not None:
        base_config.update(config_keys)
    return base_config