def test_config(self): fp = StringIO(TEST_CONFIG.format(**os.environ)) c = Config(fp) main = c.get_server('main') expected = dict(config=c) expected.update(TEST_CONFIG_MAIN) assert main.__dict__ == expected web = c.get_server('web') expected = dict(config=c) expected.update(TEST_CONFIG_WEB) assert web.__dict__ == expected
def test_config(self): """ Test for a basic configuration object construction """ fp = StringIO(TEST_CONFIG.format(**os.environ)) c = Config(fp) main = c.get_server('main') # create the expected dictionary expected = build_config_dictionary({ 'config': main.config, 'compression': 'gzip', 'last_backup_maximum_age': timedelta(1), 'last_backup_minimum_size': 1048576, 'last_wal_maximum_age': timedelta(hours=1), 'retention_policy': 'redundancy 3', 'reuse_backup': 'link', 'description': 'Main PostgreSQL Database', 'ssh_command': 'ssh -c arcfour -p 22 [email protected]', 'wal_retention_policy': 'base', 'custom_compression_filter': 'bzip2 -c -9', 'wals_directory': 'wals', 'custom_decompression_filter': 'bzip2 -c -d' }) assert main.__dict__ == expected web = c.get_server('web') # create the expected dictionary expected = build_config_dictionary({ 'config': web.config, 'backup_directory': '/some/barman/home/web', 'basebackups_directory': '/some/barman/home/web/base', 'compression': None, 'conninfo': 'host=web01 user=postgres port=5432', 'description': 'Web applications database', 'incoming_wals_directory': '/some/barman/home/web/incoming', 'name': 'web', 'reuse_backup': None, 'retention_policy': 'redundancy 2', 'wals_directory': '/some/barman/home/web/wals', 'wal_retention_policy': 'base', 'last_backup_maximum_age': timedelta(1), 'last_backup_minimum_size': 1048576, 'last_wal_maximum_age': timedelta(hours=1), 'ssh_command': 'ssh -I ~/.ssh/web01_rsa -c arcfour ' '-p 22 postgres@web01', 'streaming_conninfo': 'host=web01 user=postgres port=5432', 'streaming_wals_directory': '/some/barman/home/web/streaming', 'errors_directory': '/some/barman/home/web/errors', }) assert web.__dict__ == expected
def test_config(self): """ Test for a basic configuration object construction """ fp = StringIO(TEST_CONFIG.format(**os.environ)) c = Config(fp) main = c.get_server('main') # create the expected dictionary expected = build_config_dictionary({ 'config': main.config, 'compression': 'gzip', 'last_backup_maximum_age': timedelta(1), 'retention_policy': 'redundancy 3', 'reuse_backup': 'link', 'description': 'Main PostgreSQL Database', 'ssh_command': 'ssh -c arcfour -p 22 [email protected]', 'wal_retention_policy': 'base', 'custom_compression_filter': 'bzip2 -c -9', 'wals_directory': 'wals', 'custom_decompression_filter': 'bzip2 -c -d', 'backup_method': 'rsync' }) assert main.__dict__ == expected web = c.get_server('web') # create the expected dictionary expected = build_config_dictionary({ 'config': web.config, 'backup_directory': '/some/barman/home/web', 'basebackups_directory': '/some/barman/home/web/base', 'compression': None, 'conninfo': 'host=web01 user=postgres port=5432', 'description': 'Web applications database', 'incoming_wals_directory': '/some/barman/home/web/incoming', 'name': 'web', 'reuse_backup': None, 'retention_policy': 'redundancy 2', 'wals_directory': '/some/barman/home/web/wals', 'wal_retention_policy': 'base', 'last_backup_maximum_age': timedelta(1), 'ssh_command': 'ssh -I ~/.ssh/web01_rsa -c arcfour ' '-p 22 postgres@web01', 'streaming_conninfo': 'host=web01 user=postgres port=5432', 'streaming_wals_directory': '/some/barman/home/web/streaming', 'errors_directory': '/some/barman/home/web/errors', }) assert web.__dict__ == expected
def test_quotes(self): fp = StringIO(MINIMAL_CONFIG.format(**os.environ)) c = Config(fp) main = c.get_server('main') self.assertEqual(main.description, ' Text with quotes ') self.assertEqual(main.ssh_command, 'ssh -c "arcfour" -p 22 postgres@pg01')
def test_interpolation(self): fp = StringIO(MINIMAL_CONFIG.format(**os.environ)) c = Config(fp) main = c.get_server('main') expected = dict(config=c) expected.update(MINIMAL_CONFIG_MAIN) assert main.__dict__ == expected
def main(): parser = argparse.ArgumentParser(description="Barman plugin for NRPE.") parser.add_argument("-s", "--server", dest="server", help="server to check") parser.add_argument('-w', '--warning', type=int, dest="warning", metavar="W", help="warning threshold.") parser.add_argument('-c', '--critical', type=int, dest="critical", metavar="C", help="critical threshold.") parser.add_argument( '-u' '--user', dest='user', metavar='U', help="user needed to run this script. If the " "current user is not this one, the script will try " + "to rerun itself using sudo.") subparsers = parser.add_subparsers() for key, value in ACTIONS.items(): (action, help) = value subparser = subparsers.add_parser(key, help=help) subparser.set_defaults(action=action) parser.error = unknown args = parser.parse_args() user = pwd.getpwuid(os.getuid())[0] if args.user and user != args.user: import subprocess retval = subprocess.call(["/usr/bin/sudo", "-u", args.user] + sys.argv) raise SystemExit(retval) from barman.config import Config from barman.server import Server config = Config() config.load_configuration_files_directory() server = Server(config.get_server(args.server)) try: args.action(server, args) except KeyError: unknown("The action %s does not exist." % args.action)
def test_interpolation(self): self.maxDiff = None fp = StringIO(MINIMAL_CONFIG.format(**os.environ)) c = Config(fp) main = c.get_server('main') expected = dict(config=c) expected.update(MINIMAL_CONFIG_MAIN) self.assertEqual(main.__dict__, expected)
def test_interpolation(self): self.maxDiff = None fp = StringIO(MINIMAL_CONFIG.format(**os.environ)) c = Config(fp) main = c.get_server('main') expected = dict(config=c) expected.update(MINIMAL_CONFIG_MAIN) self.assertEqual(main.__dict__,expected)
def test_interpolation(self): self.maxDiff = None fp = StringIO(MINIMAL_CONFIG.format(**os.environ)) c = Config(fp) main = c.get_server('main') self.assertEqual(main.__dict__, dict(MINIMAL_CONFIG_MAIN.items() + [('config',c)]))
def test_quotes(self): """ Test quotes management during configuration parsing """ fp = StringIO(MINIMAL_CONFIG) c = Config(fp) main = c.get_server('main') assert main.description == ' Text with quotes ' assert main.ssh_command == 'ssh -c "arcfour" ' \ '-p 22 [email protected]'
def test_quotes(self): """ Test quotes management during configuration parsing """ fp = StringIO(MINIMAL_CONFIG.format(**os.environ)) c = Config(fp) main = c.get_server('main') assert main.description == ' Text with quotes ' assert main.ssh_command == 'ssh -c "arcfour" ' \ '-p 22 [email protected]'
def test_interpolation(self): """ Basic interpolation test """ fp = StringIO(MINIMAL_CONFIG) c = Config(fp) main = c.get_server('main') # create the expected dictionary expected = build_config_dictionary({'config': main.config}) assert main.__dict__ == expected
def test_interpolation(self): """ Basic interpolation test """ fp = StringIO(MINIMAL_CONFIG.format(**os.environ)) c = Config(fp) main = c.get_server('main') # create the expected dictionary expected = build_config_dictionary({'config': main.config}) assert main.__dict__ == expected
def main(): parser = argparse.ArgumentParser(description="Barman plugin for NRPE.") parser.add_argument("-s", "--server", dest="server", help="server to check") parser.add_argument('-w', '--warning', type=int, dest="warning", metavar="W", help="warning threshold.") parser.add_argument('-c', '--critical', type=int, dest="critical", metavar="C", help="critical threshold.") parser.add_argument('-u' '--user', dest='user', metavar='U', help="user needed to run this script. If the " "current user is not this one, the script will try " + "to rerun itself using sudo.") subparsers = parser.add_subparsers() for key, value in ACTIONS.items(): (action, help) = value subparser = subparsers.add_parser(key, help=help) subparser.set_defaults(action=action) parser.error = unknown args = parser.parse_args() user = pwd.getpwuid(os.getuid())[0] if args.user and user != args.user: import subprocess retval = subprocess.call(["/usr/bin/sudo", "-u", args.user] + sys.argv) raise SystemExit(retval) from barman.config import Config from barman.server import Server config = Config() config.load_configuration_files_directory() server = Server(config.get_server(args.server)) try: args.action(server, args) except KeyError: unknown("The action %s does not exist." % args.action)
def test_quotes(self): fp = StringIO(MINIMAL_CONFIG.format(**os.environ)) c = Config(fp) main = c.get_server('main') assert main.description == ' Text with quotes ' assert main.ssh_command == 'ssh -c "arcfour" -p 22 postgres@pg01'