def main(): """Runs the essnapshot tool.""" parser = OptionParser() parser.add_option("-c", "--config", dest="configfile", help="Path to configuration file. " "See example and documentation at " "https://github.com/gricertg/essnapshot", metavar="FILE") options = parser.parse_args()[0] if options.configfile is None: parser.error('No configuration file given.') config = open_configfile(options.configfile) # if the optional es_connections parameter is given, use it # otherwise we set None to use the default config esconfig = config['es_connections'] if 'es_connections' in config else None esclient = es.initialize_es_client(esconfig) es.connection_check(esclient) es.ensure_snapshot_repo( esclient, config['repository_name'], config['repository']) wait_for_running_snapshots(esclient, config['repository_name']) es.create_snapshot(esclient, config['repository_name'], snapshot_name()) wait_for_running_snapshots delete_eligible_snapshots = find_delete_eligible_snapshots( es.get_snapshots(esclient, config['repository_name']), config['retention_time']) if len(delete_eligible_snapshots) > 0: es.delete_snapshots(esclient, config['repository_name'], delete_eligible_snapshots)
def es_service(docker_ip, docker_services): """Ensure that ES services is up and responsive.""" docker_services.wait_until_responsive(timeout=90.0, pause=1.0, check=lambda: is_responsive()) return open_configfile('tests/configs/integration.yaml')
def test_open_configfile_missing_required_param(): with pytest.raises(ValueError): assert open_configfile('tests/configs/missing_param.yaml')
def test_open_configfile_no_valid_yaml(): with pytest.raises(SystemExit) as e: open_configfile('tests/configs/no.yaml') assert e.type == SystemExit assert e.value.code == 3
def test_open_configfile_not_found(): with pytest.raises(SystemExit) as e: open_configfile('tests/configs/missing.yaml') assert e.type == SystemExit assert e.value.code == 2
def test_open_configfile_success(): assert isinstance(open_configfile('tests/configs/success.yaml'), dict)