def check(args): """ Check if the server configuration is working. This command returns success if every checks pass, or failure if any of these fails """ if args.nagios: output.set_output_writer(output.NagiosOutputWriter()) servers = get_server_list(args) for name in sorted(servers): server = servers[name] # Validate the returned server if not manage_server_command( server, name, skip_inactive=False, skip_disabled=False, disabled_is_error=False): continue # If the server has been manually disabled if not server.config.active: name += " (inactive)" # If server has configuration errors elif server.config.disabled: name += " (WARNING: disabled)" output.init('check', name, server.config.active) server.check() output.close_and_exit()
def list_server(minimal=False): """ List available servers, with useful information """ # Get every server, both inactive and temporarily disabled servers = get_server_list() for name in sorted(servers): server = servers[name] # Exception: manage_server_command is not invoked here # Normally you would call manage_server_command to check if the # server is None and to report inactive and disabled servers, but here # we want all servers and the server cannot be None output.init('list_server', name, minimal=minimal) description = server.config.description # If the server has been manually disabled if not server.config.active: description += " (inactive)" # If server has configuration errors elif server.config.disabled: description += " (WARNING: disabled)" # If server is a passive node if server.passive_node: description += ' (Passive)' output.result('list_server', name, description) output.close_and_exit()
def show_server(args): """ Show all configuration parameters for the specified servers """ servers = get_server_list(args) for name in sorted(servers): server = servers[name] # Skip the server (apply general rule) if not manage_server_command(server, name, skip_inactive=False, skip_disabled=False, disabled_is_error=False): continue # If the server has been manually disabled if not server.config.active: name += " (inactive)" # If server has configuration errors elif server.config.disabled: name += " (WARNING: disabled)" output.init('show_server', name) with closing(server): server.show() output.close_and_exit()
def check(args): """ Check if the server configuration is working. This command returns success if every checks pass, or failure if any of these fails """ if args.nagios: output.set_output_writer(output.NagiosOutputWriter()) servers = get_server_list(args) for name in sorted(servers): server = servers[name] # Validate the returned server if not manage_server_command(server, name, skip_inactive=False, skip_disabled=False, disabled_is_error=False): continue # If the server has been manually disabled if not server.config.active: name += " (inactive)" # If server has configuration errors elif server.config.disabled: name += " (WARNING: disabled)" output.init('check', name, server.config.active) with closing(server): server.check() output.close_and_exit()
def check(args): """ Check if the server configuration is working. This command returns success if every checks pass, or failure if any of these fails """ if args.nagios: output.set_output_writer(output.NagiosOutputWriter()) servers = get_server_list(args) for name in sorted(servers): server = servers[name] # Validate the returned server if not manage_server_command( server, name, skip_inactive=False, skip_disabled=False, disabled_is_error=False, ): continue output.init("check", name, server.config.active, server.config.disabled) with closing(server): server.check() output.close_and_exit()
def keep(args): """ Tag the specified backup so that it will never be deleted """ if not any((args.release, args.status, args.target)): output.error( "one of the arguments -r/--release -s/--status --target is required" ) output.close_and_exit() server = get_server(args) backup_info = parse_backup_id(server, args) backup_manager = server.backup_manager if args.status: output.init("status", server.config.name) target = backup_manager.get_keep_target(backup_info.backup_id) if target: output.result("status", server.config.name, "keep_status", "Keep", target) else: output.result("status", server.config.name, "keep_status", "Keep", "nokeep") elif args.release: backup_manager.release_keep(backup_info.backup_id) else: if backup_info.status != BackupInfo.DONE: msg = ("Cannot add keep to backup %s because it has status %s. " "Only backups with status DONE can be kept.") % ( backup_info.backup_id, backup_info.status) output.error(msg) output.close_and_exit() backup_manager.keep_backup(backup_info.backup_id, args.target)
def list_backup(self, server_name): output.init('list_backup', server_name) server = self.servers[server_name] server.list_backups() server.close() results = output._writer.close() return results
def list_server(minimal=False): """ List available servers, with useful information """ servers = get_server_list() for name in sorted(servers): server = servers[name] output.init('list_server', name, minimal=minimal) output.result('list_server', name, server.config.description) output.close_and_exit()
def test_init(self): # preparation writer = self._mock_writer() args = ('1', 'two') kwargs = dict(three=3, four=5) output.init('command', *args, **kwargs) output.init('another_command') # writer test writer.init_command.assert_called_once_with(*args, **kwargs) writer.init_another_command.assert_called_once_with()
def test_init(self): # preparation writer = self._mock_writer() args = ("1", "two") kwargs = dict(three=3, four=5) output.init("command", *args, **kwargs) output.init("another_command") # writer test writer.init_command.assert_called_once_with(*args, **kwargs) writer.init_another_command.assert_called_once_with()
def show_server(args): """ Show all configuration parameters for the specified servers """ servers = get_server_list(args) for name in sorted(servers): server = servers[name] if server is None: output.error("Unknown server '%s'" % name) continue output.init('show_server', name) server.show() output.close_and_exit()
def status(args): """ Shows live information and status of the PostgreSQL server """ servers = get_server_list(args) for name in sorted(servers): server = servers[name] if server is None: output.error("Unknown server '%s'" % name) continue output.init('status', name) server.status() output.close_and_exit()
def list_backup(args): """ List available backups for the given server (supports 'all') """ servers = get_server_list(args) for name in sorted(servers): server = servers[name] output.init('list_backup', name, minimal=args.minimal) if server is None: output.error("Unknown server '%s'" % name) continue server.list_backups() output.close_and_exit()
def status(args): """ Shows live information and status of the PostgreSQL server """ servers = get_server_list(args, skip_inactive=True) for name in sorted(servers): server = servers[name] # Skip the server (apply general rule) if not manage_server_command(server, name): continue output.init('status', name) server.status() output.close_and_exit()
def list_backup(args): """ List available backups for the given server (supports 'all') """ servers = get_server_list(args, skip_inactive=True) for name in sorted(servers): server = servers[name] # Skip the server (apply general rule) if not manage_server_command(server, name): continue output.init('list_backup', name, minimal=args.minimal) server.list_backups() output.close_and_exit()
def show_server(args): """ Show all configuration parameters for the specified servers """ servers = get_server_list(args, skip_inactive=True) for name in sorted(servers): server = servers[name] # Skip the server (apply general rule) if not manage_server_command(server, name): continue output.init('show_server', name) server.show() output.close_and_exit()
def show_server(args): """ Show all configuration parameters for the specified servers """ servers = get_server_list(args, skip_inactive=True) for name in sorted(servers): server = servers[name] # Skip the server (apply general rule) if not manage_server_command(server, name): continue output.init('show_server', name) with closing(server): server.show() output.close_and_exit()
def replication_status(args): """ Shows live information and status of any streaming client """ servers = get_server_list(args, skip_inactive=True) for name in sorted(servers): server = servers[name] # Skip the server (apply general rule) if not manage_server_command(server, name): continue with closing(server): output.init('replication_status', name, minimal=args.minimal) server.replication_status(args.target) output.close_and_exit()
def status(args): """ Shows live information and status of the PostgreSQL server """ servers = get_server_list(args, skip_inactive=True) for name in sorted(servers): server = servers[name] # Skip the server (apply general rule) if not manage_server_command(server, name): continue output.init('status', name) with closing(server): server.status() output.close_and_exit()
def list_backup(args): """ List available backups for the given server (supports 'all') """ servers = get_server_list(args, skip_inactive=True) for name in sorted(servers): server = servers[name] # Skip the server (apply general rule) if not manage_server_command(server, name): continue output.init('list_backup', name, minimal=args.minimal) with closing(server): server.list_backups() output.close_and_exit()
def check(args): """ Check if the server configuration is working. This command returns success if every checks pass, or failure if any of these fails """ if args.nagios: output.set_output_writer(output.NagiosOutputWriter()) servers = get_server_list(args) for name in sorted(servers): server = servers[name] if server is None: output.error("Unknown server '%s'" % name) continue output.init('check', name) server.check() output.close_and_exit()
def test_init_bad_command(self, exit_mock, caplog): # preparation writer = self._mock_writer() del writer.init_bad_command output.init('bad_command') # logging test for record in caplog.records(): assert record.levelname == 'ERROR' assert 'bad_command' in caplog.text() assert 'Traceback' in caplog.text() # writer test writer.error_occurred.assert_called_once_with() assert writer.exception.call_count == 1 # exit with error assert exit_mock.called assert exit_mock.call_count == 1 assert exit_mock.call_args[0] != 0
def test_init_bad_command(self, exit_mock, caplog): # preparation writer = self._mock_writer() del writer.init_bad_command output.init('bad_command') # logging test for record in caplog.records: assert record.levelname == 'ERROR' assert 'bad_command' in caplog.text assert 'Traceback' in caplog.text # writer test writer.error_occurred.assert_called_once_with() assert writer.exception.call_count == 1 # exit with error assert exit_mock.called assert exit_mock.call_count == 1 assert exit_mock.call_args[0] != 0
def check(args): """ Check if the server configuration is working. This command returns success if every checks pass, or failure if any of these fails """ if args.nagios: output.set_output_writer(output.NagiosOutputWriter()) servers = get_server_list(args, skip_disabled=True) for name in sorted(servers): server = servers[name] if server is None: output.error("Unknown server '%s'" % name) continue # If the server is disabled add '(disabled)' next to the name if not server.config.active: name += ' (disabled)' output.init('check', name) server.check() output.close_and_exit()
def check(self, server_name, check_strategy=CheckOutputStrategy()): output.init('check', server_name) server = self.servers[server_name] server.check_archive(check_strategy) if not server.passive_node: server.check_postgres(check_strategy) server.check_directories(check_strategy) server.check_retention_policy_settings(check_strategy) server.check_backup_validity(check_strategy) server.backup_manager.check(check_strategy) server.check_configuration(check_strategy) for archiver in server.archivers: archiver.check(check_strategy) server.check_archiver_errors(check_strategy) server.close() results = output._writer.close() return results
def show_server(args): """ Show all configuration parameters for the specified servers """ servers = get_server_list(args) for name in sorted(servers): server = servers[name] # Skip the server (apply general rule) if not manage_server_command( server, name, skip_inactive=False, skip_disabled=False, disabled_is_error=False): continue # If the server has been manually disabled if not server.config.active: name += " (inactive)" # If server has configuration errors elif server.config.disabled: name += " (WARNING: disabled)" output.init('show_server', name) with closing(server): server.show() output.close_and_exit()
def list_server(minimal=False): """ List available servers, with useful information """ # Get every server, both inactive and temporarily disabled servers = get_server_list() for name in sorted(servers): server = servers[name] # Exception: manage_server_command is not invoked here # Normally you would call manage_server_command to check if the # server is None and to report inactive and disabled servers, but here # we want all servers and the server cannot be None output.init('list_server', name, minimal=minimal) description = server.config.description # If the server has been manually disabled if not server.config.active: description += " (inactive)" # If server has configuration errors elif server.config.disabled: description += " (WARNING: disabled)" output.result('list_server', name, description) output.close_and_exit()