blob: 8ce2ad01c5158060a4349488ec2d248968b26d0a [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
5import logging, threading, time, utils
6
7class LocalDns(object):
8 """a wrapper around miniFakeDns that handles managing running the server
9 in a separate thread.
10 """
11
Chris Masone7d04f572010-05-30 18:07:11 -070012 def __init__(self, fake_ip="127.0.0.1", local_port=53):
Chris Masonef7ae5252010-04-21 08:21:25 -070013 import miniFakeDns # So we don't need to install it in the chroot.
Chris Masone7d04f572010-05-30 18:07:11 -070014 self._dns = miniFakeDns.DNSServer(fake_ip="127.0.0.1", port=local_port)
Chris Masonef7ae5252010-04-21 08:21:25 -070015 self._stopper = threading.Event()
16 self._thread = threading.Thread(target=self._dns.run,
17 args=(self._stopper,))
18
19
20 def run(self):
21 self._thread.start()
22
23
24 def stop(self):
25 self._stopper.set()
26 self._thread.join()