Commit 261ba83e authored by Petr Špaček's avatar Petr Špaček

testserver: support custom scenarios

The testserver can now read scenario specified on command line and use
it instead of the built-in one. This is very useful for testing
pydnstest.testserver module.
parent b96ac898
from __future__ import absolute_import
import argparse
import fileinput
import logging
import threading
import select
......@@ -12,6 +14,7 @@ import itertools
from pydnstest import scenario
def get_local_addr_str(family, iface):
""" Returns pattern string for localhost address """
if family == socket.AF_INET:
......@@ -280,6 +283,16 @@ if __name__ == '__main__':
# Self-test code
# Usage: $PYTHON -m pydnstest.testserver
logging.basicConfig(level=logging.DEBUG)
argparser = argparse.ArgumentParser()
argparser.add_argument('--scenario', help='path to test scenario',
required=False)
args = argparser.parse_args()
if args.scenario:
test_scenario, test_config = scenario.parse_file(fileinput.input(args.scenario))
else:
test_scenario, test_config = empty_test_case()
test_scenario.current_step = test_scenario.steps[0]
DEFAULT_IFACE = 0
CHILD_IFACE = 0
if "SOCKET_WRAPPER_DEFAULT_IFACE" in os.environ:
......@@ -288,9 +301,9 @@ if __name__ == '__main__':
DEFAULT_IFACE = 10
os.environ["SOCKET_WRAPPER_DEFAULT_IFACE"] = "{}".format(DEFAULT_IFACE)
test_scenario, test_config = empty_test_case()
server = TestServer(test_scenario, test_config, DEFAULT_IFACE)
server.start()
logging.info("[==========] Mirror server running at %s", server.address())
try:
while True:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment