Chris Masone | f7ae525 | 2010-04-21 08:21:25 -0700 | [diff] [blame] | 1 | # 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 Li | f7b8192 | 2011-03-04 14:39:35 -0800 | [diff] [blame] | 5 | import logging, threading, time |
| 6 | from autotest_lib.client.bin import utils |
Chris Masone | f7ae525 | 2010-04-21 08:21:25 -0700 | [diff] [blame] | 7 | |
| 8 | class LocalDns(object): |
| 9 | """a wrapper around miniFakeDns that handles managing running the server |
| 10 | in a separate thread. |
| 11 | """ |
| 12 | |
Chris Masone | 7d04f57 | 2010-05-30 18:07:11 -0700 | [diff] [blame] | 13 | def __init__(self, fake_ip="127.0.0.1", local_port=53): |
Chris Masone | f7ae525 | 2010-04-21 08:21:25 -0700 | [diff] [blame] | 14 | import miniFakeDns # So we don't need to install it in the chroot. |
Chris Masone | e0d3913 | 2011-07-29 19:06:42 -0700 | [diff] [blame^] | 15 | self._dns = miniFakeDns.DNSServer(fake_ip=fake_ip, port=local_port) |
Chris Masone | f7ae525 | 2010-04-21 08:21:25 -0700 | [diff] [blame] | 16 | 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() |