blob: 4cbbdea3fedf28fd2b95739f4463d2f519c0032c [file] [log] [blame]
Chris Masonef7ae5252010-04-21 08:21:25 -07001# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
Eric Lif7b81922011-03-04 14:39:35 -08005import logging, threading, time
6from autotest_lib.client.bin import utils
Chris Masonef7ae5252010-04-21 08:21:25 -07007
8class LocalDns(object):
9 """a wrapper around miniFakeDns that handles managing running the server
10 in a separate thread.
11 """
12
Chris Masone7d04f572010-05-30 18:07:11 -070013 def __init__(self, fake_ip="127.0.0.1", local_port=53):
Chris Masonef7ae5252010-04-21 08:21:25 -070014 import miniFakeDns # So we don't need to install it in the chroot.
Chris Masonee0d39132011-07-29 19:06:42 -070015 self._dns = miniFakeDns.DNSServer(fake_ip=fake_ip, port=local_port)
Chris Masonef7ae5252010-04-21 08:21:25 -070016 self._stopper = threading.Event()
17 self._thread = threading.Thread(target=self._dns.run,
18 args=(self._stopper,))
19
20
21 def run(self):
22 self._thread.start()
23
24
25 def stop(self):
26 self._stopper.set()
27 self._thread.join()