barfab@chromium.org | b6d2993 | 2012-04-11 09:46:43 +0200 | [diff] [blame^] | 1 | # Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Chris Masone | f7ae525 | 2010-04-21 08:21:25 -0700 | [diff] [blame] | 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 |
barfab@chromium.org | b6d2993 | 2012-04-11 09:46:43 +0200 | [diff] [blame^] | 6 | |
| 7 | import common |
Eric Li | f7b8192 | 2011-03-04 14:39:35 -0800 | [diff] [blame] | 8 | from autotest_lib.client.bin import utils |
Chris Masone | f7ae525 | 2010-04-21 08:21:25 -0700 | [diff] [blame] | 9 | |
| 10 | class LocalDns(object): |
| 11 | """a wrapper around miniFakeDns that handles managing running the server |
| 12 | in a separate thread. |
| 13 | """ |
| 14 | |
Chris Masone | 7d04f57 | 2010-05-30 18:07:11 -0700 | [diff] [blame] | 15 | def __init__(self, fake_ip="127.0.0.1", local_port=53): |
Chris Masone | f7ae525 | 2010-04-21 08:21:25 -0700 | [diff] [blame] | 16 | 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] | 17 | self._dns = miniFakeDns.DNSServer(fake_ip=fake_ip, port=local_port) |
Chris Masone | f7ae525 | 2010-04-21 08:21:25 -0700 | [diff] [blame] | 18 | 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() |