def test_ok_proxy(self):
     cfg = '''
         api_key: "00000000-0000-0000-0000-000000000000"
         https_proxy: "http://10.10.1.10:1080"
     '''
     y = yaml.load(textwrap.dedent(cfg))
     periodic.validate_agent_config(y)
 def test_missing_required_key(self):
     cfg = '''
     '''
     y = yaml.load(textwrap.dedent(cfg))
     with self.assertRaises(periodic.ValidationError) as cm:
         periodic.validate_agent_config(y)
     print cm.exception.message
 def test_bad_api_key(self):
     cfg = '''
         api_key: "not a uuidv4"
     '''
     y = yaml.load(textwrap.dedent(cfg))
     with self.assertRaises(periodic.ValidationError) as cm:
         periodic.validate_agent_config(y)
     print cm.exception.message
 def test_bad_endpoint(self):
     cfg = '''
         api_key: "00000000-0000-0000-0000-000000000000"
         endpoint: "not a hostname"
     '''
     y = yaml.load(textwrap.dedent(cfg))
     with self.assertRaises(periodic.ValidationError) as cm:
         periodic.validate_agent_config(y)
     print cm.exception.message
 def test_unknown_key(self):
     cfg = '''
         api_key: "00000000-0000-0000-0000-000000000000"
         something: "whatever"
     '''
     y = yaml.load(textwrap.dedent(cfg))
     with self.assertRaises(periodic.ValidationError) as cm:
         periodic.validate_agent_config(y)
     print cm.exception.message
 def test_spelling(self):
     cfg = '''
         api_key: "00000000-0000-0000-0000-000000000000"
         ednpoint: "a.carbon.endpoint"
     '''
     y = yaml.load(textwrap.dedent(cfg))
     with self.assertRaises(periodic.ValidationError) as cm:
         periodic.validate_agent_config(y)
     print cm.exception.message
 def test_hostname_method(self):
     cfg = '''
         api_key: "00000000-0000-0000-0000-000000000000"
         hostname_method: "fqdn"
     '''
     y = yaml.load(textwrap.dedent(cfg))
     periodic.validate_agent_config(y)
     diamond = periodic.gen_diamond_config(y)
     lines = diamond.split('\n')
     self.assertIn('hostname_method = fqdn', lines)
 def test_custom_prefix(self):
     cfg = '''
         api_key: "00000000-0000-0000-0000-000000000000"
         custom_prefix: "no_2_hg_agent"
     '''
     y = yaml.load(textwrap.dedent(cfg))
     periodic.validate_agent_config(y)
     diamond = periodic.gen_diamond_config(y)
     lines = diamond.split('\n')
     self.assertIn(
         'path_prefix = no_2_hg_agent',
         lines)
 def test_gen(self):
     cfg = '''
         api_key: "00000000-0000-0000-0000-000000000000"
     '''
     y = yaml.load(textwrap.dedent(cfg))
     periodic.validate_agent_config(y)
     diamond = periodic.gen_diamond_config(y)
     lines = diamond.split('\n')
     self.assertIn('host = localhost', lines)
     self.assertIn(
         'path_prefix = hg_agent',
         lines)
def main():
    args = get_args()
    periodic.init_log('hg-agent-diamond-config', args.debug)

    try:
        data = periodic.load_file(args.config)
        agent_config = yaml.load(data)
        periodic.validate_agent_config(agent_config)
        new_diamond = periodic.gen_diamond_config(agent_config)
        with open(args.diamond_config, 'w') as f:
            f.write(new_diamond)
    except periodic.LoadFileError as e:
        logging.error('config loading %s: %s', args.config, e)
    except periodic.ValidationError as e:
        logging.error('config in %s: %s', args.config, e)
    except (OSError, IOError) as e:
        logging.error('writing %s: %s', args.diamond_config, e)
    except Exception:
        logging.exception('unhandled exception')
Пример #11
0
def main():
    args = get_args()
    periodic.init_log('hg-agent-config', args.debug)

    try:
        agent_config = {
            'api_key': args.api_key,
        }
        if args.endpoint_url:
            agent_config['endpoint_url'] = args.endpoint_url
        if args.heartbeat_url:
            agent_config['heartbeat_url'] = args.heartbeat_url

        periodic.validate_agent_config(agent_config)
        data = yaml.dump(agent_config, default_flow_style=False)
        with open(args.config, 'w') as f:
            f.write(data)
    except periodic.ValidationError as e:
        logging.error('generating %s: %s', args.config, e)
    except (OSError, IOError) as e:
        logging.error('writing %s: %s', args.config, e)
    except Exception:
        logging.exception('unhandled exception')
 def test_ok(self):
     cfg = '''
         api_key: "00000000-0000-0000-0000-000000000000"
     '''
     y = yaml.load(textwrap.dedent(cfg))
     periodic.validate_agent_config(y)
 def test_barestring(self):
     y = yaml.load('bare string')
     with self.assertRaises(periodic.ValidationError) as cm:
         periodic.validate_agent_config(y)
     print cm.exception.message