blob: 90c2f9a52e2dcbe21a4ca3eb059cbd05d33f58de [file] [log] [blame]
barfab@chromium.orgb6d29932012-04-11 09:46:43 +02001# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Chris Masonef7ae5252010-04-21 08:21:25 -07002# 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
barfab@chromium.orgb6d29932012-04-11 09:46:43 +02006
7import common
Eric Lif7b81922011-03-04 14:39:35 -08008from autotest_lib.client.bin import utils
Chris Masonef7ae5252010-04-21 08:21:25 -07009
10class LocalDns(object):
11 """a wrapper around miniFakeDns that handles managing running the server
12 in a separate thread.
13 """
14
Chris Masone7d04f572010-05-30 18:07:11 -070015 def __init__(self, fake_ip="127.0.0.1", local_port=53):
Chris Masonef7ae5252010-04-21 08:21:25 -070016 import miniFakeDns # So we don't need to install it in the chroot.
Chris Masonee0d39132011-07-29 19:06:42 -070017 self._dns = miniFakeDns.DNSServer(fake_ip=fake_ip, port=local_port)
Chris Masonef7ae5252010-04-21 08:21:25 -070018 self._stopper = threading.Event()
19 self._thread = threading.Thread(target=self._dns.run,
20 args=(self._stopper,))
21
22
23 def run(self):
24 self._thread.start()
25
26
27 def stop(self):
28 self._stopper.set()
29 self._thread.join()