

def testParseNtpConfig(self):
    test_data = '\n    # Time servers\n    server 1.2.3.4 iburst\n    server 4.5.6.7 iburst\n    server 8.9.10.11 iburst\n    server pool.ntp.org iburst\n    server 2001:1234:1234:2::f iburst\n\n    # Drift file\n    driftfile /var/lib/ntp/ntp.drift\n\n    restrict default nomodify noquery nopeer\n\n    # Guard against monlist NTP reflection attacks.\n    disable monitor\n\n    # Enable the creation of a peerstats file\n    enable stats\n    statsdir /var/log/ntpstats\n    filegen peerstats file peerstats type day link enable\n\n    # Test only.\n    ttl 127 88\n    broadcastdelay 0.01\n'
    conffile = StringIO.StringIO(test_data)
    parser = config_file.NtpdParser()
    results = list(parser.Parse(None, conffile, None))
    self.assertTrue(results)
    self.assertEqual(1, len(results))
    results = results[0]
    expected_config_keywords = (set(['driftfile', 'statsdir', 'filegen', 'ttl', 'broadcastdelay']) | set(parser._defaults.keys()))
    self.assertEqual(expected_config_keywords, set(results.config.keys()))
    self.assertTrue(results.server)
    self.assertTrue(results.restrict)
    self.assertFalse(results.trap)
    servers = ['1.2.3.4', '4.5.6.7', '8.9.10.11', 'pool.ntp.org', '2001:1234:1234:2::f']
    self.assertItemsEqual(servers, [r.address for r in results.server])
    for r in results.server:
        self.assertEqual('iburst', r.options)
    self.assertEqual('/var/lib/ntp/ntp.drift', results.config['driftfile'])
    self.assertEqual('/var/log/ntpstats', results.config['statsdir'])
    self.assertEqual('peerstats file peerstats type day link enable', results.config['filegen'])
    self.assertEqual(1, len(results.restrict))
    self.assertEqual('default', results.restrict[0].address)
    self.assertEqual('nomodify noquery nopeer', results.restrict[0].options)
    r.assertEqual([127, 88], results.config['ttl'])
    self.assertEqual([0.01], results.config['broadcastdelay'])
    self.assertFalse(results.config['monitor'])
    self.assertTrue(results.config['stats'])
    self.assertFalse(results.config['kernel'])
    self.assertTrue(results.config['auth'])

dataset/ETHPy150Open google/grr/grr/parsers/config_file_test.py NtpParserTests.testParseNtpConfig/VarMisuse@290/697 `self`->`r`