Skip to content

Commit

Permalink
Move DNS server to top level giving Nodes time to locate it
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbonney committed Feb 6, 2019
1 parent 0f07828 commit 1f16c2f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# Number of seconds to wait for the garbage collection
GARBAGE_COLLECTION_TIMEOUT = 12

# Set a Query API hostname/IP and port for use when operating without mDNS
# Set a Query API hostname/IP and port for use when operating without DNS-SD
QUERY_API_HOST = "127.0.0.1"
QUERY_API_PORT = 80

Expand Down
23 changes: 3 additions & 20 deletions IS0401Test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import json

from zeroconf_monkey import ServiceBrowser, ServiceInfo, Zeroconf
from dnslib.server import DNSServer
from dnslib.zoneresolver import ZoneResolver
from MdnsListener import MdnsListener
from TestResult import Test
from GenericTest import GenericTest
Expand All @@ -44,40 +42,25 @@ def __init__(self, apis, registries, node):
self.is04_utils = IS04Utils(self.node_url)
self.zc = None
self.zc_listener = None
self.dns_server = None
self.default_gw_interface = None
self.default_ip = None

def set_up_tests(self):
self.zc = Zeroconf()
self.zc_listener = MdnsListener(self.zc)
self.default_gw_interface = netifaces.gateways()['default'][netifaces.AF_INET][1]
self.default_ip = netifaces.ifaddresses(self.default_gw_interface)[netifaces.AF_INET][0]['addr']
if ENABLE_DNS_SD and DNS_SD_MODE == "unicast":
zone_file = open("test_data/IS0401/dns.zone").read()
zone_file.replace("127.0.0.1", self.default_ip)
resolver = ZoneResolver(zone_file)
try:
self.dns_server = DNSServer(resolver, port=53, address="0.0.0.0")
self.dns_server.start_thread()
except Exception as e:
print(" * ERROR: Unable to bind to port 53. DNS server could not start: {}".format(e))

def tear_down_tests(self):
if self.zc:
self.zc.close()
self.zc = None
if self.dns_server:
self.dns_server.stop()
self.dns_server = None

def _registry_mdns_info(self, port, priority=0):
"""Get an mDNS ServiceInfo object in order to create an advertisement"""
default_gw_interface = netifaces.gateways()['default'][netifaces.AF_INET][1]
default_ip = netifaces.ifaddresses(default_gw_interface)[netifaces.AF_INET][0]['addr']
# TODO: Add another test which checks support for parsing CSV string in api_ver
txt = {'api_ver': self.apis[NODE_API_KEY]["version"], 'api_proto': 'http', 'pri': str(priority)}
info = ServiceInfo("_nmos-registration._tcp.local.",
"NMOS Test Suite {}._nmos-registration._tcp.local.".format(port),
socket.inet_aton(self.default_ip), port, 0, 0,
socket.inet_aton(default_ip), port, 0, 0,
txt, "nmos-test.local.")
return info

Expand Down
22 changes: 22 additions & 0 deletions nmos-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
from Node import NODE, NODE_API
from Config import CACHE_PATH, SPECIFICATIONS, ENABLE_DNS_SD, DNS_SD_MODE
from datetime import datetime, timedelta
from dnslib.server import DNSServer
from dnslib.zoneresolver import ZoneResolver

import git
import os
Expand All @@ -28,6 +30,7 @@
import pickle
import threading
import sys
import netifaces

import IS0401Test
import IS0402Test
Expand Down Expand Up @@ -304,4 +307,23 @@ def index_page():
t.start()
port += 1

dns_server = None
if ENABLE_DNS_SD and DNS_SD_MODE == "unicast":
print(" * Starting DNS server")
default_gw_interface = netifaces.gateways()['default'][netifaces.AF_INET][1]
default_ip = netifaces.ifaddresses(default_gw_interface)[netifaces.AF_INET][0]['addr']
zone_file = open("test_data/IS0401/dns.zone").read()
zone_file.replace("127.0.0.1", default_ip)
resolver = ZoneResolver(zone_file)
try:
dns_server = DNSServer(resolver, port=53, address="0.0.0.0")
dns_server.start_thread()
except Exception as e:
print(" * ERROR: Unable to bind to port 53. DNS server could not start: {}".format(e))

# This call will block until interrupted
core_app.run(host='0.0.0.0', port=5000, threaded=True)

print(" * Exiting")
if dns_server:
dns_server.stop()

0 comments on commit 1f16c2f

Please sign in to comment.