From f98677deb932dcb09268e73ada43e932e1922886 Mon Sep 17 00:00:00 2001 From: Difrex Date: Wed, 5 Oct 2016 11:46:51 +0300 Subject: [PATCH] fix reload in empty discovery --- surok.py | 15 ++++++++------- surok/discovery.py | 25 ++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/surok.py b/surok.py index 4bea4d7..124d58e 100755 --- a/surok.py +++ b/surok.py @@ -68,15 +68,16 @@ while 1: conf['loglevel'] = 'info' # Resolve services - app_hosts = resolve(app_conf, conf) + if resolve(app_conf, conf) != 404: + app_hosts = resolve(app_conf, conf) - # Populate my dictionary - my = {"services": app_hosts, - "conf_name": app_conf['conf_name']} + # Populate my dictionary + my = {"services": app_hosts, + "conf_name": app_conf['conf_name']} - # Generate config from template - service_conf = gen(my, app_conf['template']) + # Generate config from template + service_conf = gen(my, app_conf['template']) - first = reload_conf(service_conf, app_conf, first, conf) + first = reload_conf(service_conf, app_conf, first, conf) sleep(conf['wait_time']) diff --git a/surok/discovery.py b/surok/discovery.py index 5e5ad05..e60d873 100644 --- a/surok/discovery.py +++ b/surok/discovery.py @@ -40,8 +40,30 @@ def resolve(app, conf): if ports is not None: for port_name in ports: fqdn = '_' + port_name + '.' + '_' + service['name'] + '.' + group + '._tcp.' + domain + + # Fast fix of empty query result + # ------------------------------ + try: + do_query_test = do_query(fqdn, conf['loglevel']) + if do_query_test['state'] == 404: + return 404 + except: + pass + # ------------------------------ + hosts[service['name']][port_name] = do_query(fqdn, conf['loglevel']) else: + + # Fast fix of empty query result + # ------------------------------ + try: + do_query_test = do_query(fqdn, conf['loglevel']) + if do_query_test['state'] == 404: + return 404 + except: + pass + # ------------------------------ + fqdn = '_' + service['name'] + '.' + group + '._tcp.' + domain hosts[service['name']] = do_query(fqdn, conf['loglevel']) @@ -62,6 +84,7 @@ def do_query(fqdn, loglevel): servers.append(server) except DNSException: if loglevel != 'info': - logging.warning("Could not resolve " + fqdn) + logging.error("Could not resolve " + fqdn) + return {"state": 404} return servers