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 test_debug(self, capsys): writer = output.NagiosOutputWriter() msg = 'test message' writer.debug(msg) (out, err) = capsys.readouterr() assert out == '' assert err == '' msg = 'test arg %s' args = ('1st', ) writer.debug(msg, *args) (out, err) = capsys.readouterr() assert out == '' assert err == '' msg = 'test args %d %s' args = (1, 'two') writer.debug(msg, *args) (out, err) = capsys.readouterr() assert out == '' assert err == '' msg = 'test kwargs %(num)d %(string)s' kwargs = dict(num=1, string='two') writer.debug(msg, kwargs) (out, err) = capsys.readouterr() assert out == '' assert err == ''
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 test_no_server_result_check(self, capsys): writer = output.NagiosOutputWriter() output.error_occurred = False writer.close() (out, err) = capsys.readouterr() assert out == 'BARMAN OK - No server configured\n' assert err == '' assert not output.error_occurred
def test_single_result_check(self, capsys): writer = output.NagiosOutputWriter() output.error_occurred = False # one server with no error writer.result_check('a', 'test', True, None) writer.close() (out, err) = capsys.readouterr() assert out == 'BARMAN OK - Ready to serve the Espresso backup ' \ 'for a\n' assert err == '' assert not output.error_occurred
def test_single_result_check_error(self, capsys): writer = output.NagiosOutputWriter() output.error_occurred = False # one server with one error writer.result_check('a', 'test', False, None) writer.close() (out, err) = capsys.readouterr() assert out == 'BARMAN CRITICAL - server a has issues * ' \ 'a FAILED: test\na.test: FAILED\n' assert err == '' assert output.error_occurred assert output.error_exit_code == 2
def test_result_check_error(self, capsys): writer = output.NagiosOutputWriter() output.error_occurred = False # three server with one error writer.result_check('a', 'test', True, None) writer.result_check('b', 'test', False, None) writer.result_check('c', 'test', True, None) writer.close() (out, err) = capsys.readouterr() assert out == 'BARMAN CRITICAL - 1 server out of 3 have issues * ' \ 'b FAILED: test\nb.test: FAILED\n' assert err == '' assert output.error_occurred assert output.error_exit_code == 2
def test_result_check_all_ignore(self, capsys): writer = output.NagiosOutputWriter() output.error_occurred = False # three server with no error writer.active = False writer.result_check('a', 'test', False, None) writer.result_check('b', 'test', False, None) writer.result_check('c', 'test', False, None) writer.close() (out, err) = capsys.readouterr() assert out == 'BARMAN OK - No server configured ' \ '* IGNORING: a * IGNORING: b * IGNORING: c\n' assert err == '' assert not output.error_occurred
def test_result_check_multiple_ignore(self, capsys): writer = output.NagiosOutputWriter() output.error_occurred = False # three server with no error writer.result_check('a', 'test', True, None) writer.result_check('b', 'test', True, None) writer.active = False writer.result_check('c', 'test', False, None) writer.close() (out, err) = capsys.readouterr() assert out == 'BARMAN OK - Ready to serve the Espresso backup ' \ 'for 2 servers * a * b * IGNORING: c\n' assert err == '' assert not output.error_occurred