updates to some log statements and fix to avoid an exception for finding enpoints in xml

This commit is contained in:
Blake J. Harnden 2018-05-01 12:28:20 -07:00
parent f5bff494c7
commit 181a47b8ca
3 changed files with 32 additions and 33 deletions

View file

@ -142,14 +142,13 @@ class CoreBroker(ConfigurableManager):
Close all active sockets; called when the session enters the Close all active sockets; called when the session enters the
data collect state data collect state
""" """
self.reset()
with self.servers_lock: with self.servers_lock:
while len(self.servers) > 0: while len(self.servers) > 0:
name, server = self.servers.popitem() name, server = self.servers.popitem()
if server.sock is not None: if server.sock is not None:
logger.info("closing connection with %s @ %s:%s" % logger.info("closing connection with %s: %s:%s", name, server.host, server.port)
(name, server.host, server.port))
server.close() server.close()
self.reset()
self.dorecvloop = False self.dorecvloop = False
if self.recvthread is not None: if self.recvthread is not None:
self.recvthread.join() self.recvthread.join()
@ -214,8 +213,7 @@ class CoreBroker(ConfigurableManager):
continue continue
rcvlen = self.recv(server) rcvlen = self.recv(server)
if rcvlen == 0: if rcvlen == 0:
logger.info("connection with %s @ %s:%s has closed" % ( logger.info("connection with server(%s) closed: %s:%s", server.name, server.host, server.port)
server.name, server.host, server.port))
def recv(self, server): def recv(self, server):
""" """
@ -236,18 +234,18 @@ class CoreBroker(ConfigurableManager):
return 0 return 0
if len(msghdr) != coreapi.CoreMessage.header_len: if len(msghdr) != coreapi.CoreMessage.header_len:
logger.info("warning: broker received not enough data len=%s" % len(msghdr)) logger.warn("warning: broker received not enough data len=%s", len(msghdr))
return len(msghdr) return len(msghdr)
msgtype, msgflags, msglen = coreapi.CoreMessage.unpack_header(msghdr) msgtype, msgflags, msglen = coreapi.CoreMessage.unpack_header(msghdr)
msgdata = server.sock.recv(msglen) msgdata = server.sock.recv(msglen)
data = msghdr + msgdata data = msghdr + msgdata
count = None count = None
logger.info("received message type: %s", MessageTypes(msgtype)) logger.debug("received message type: %s", MessageTypes(msgtype))
# snoop exec response for remote interactive TTYs # snoop exec response for remote interactive TTYs
if msgtype == MessageTypes.EXECUTE.value and msgflags & MessageFlags.TTY.value: if msgtype == MessageTypes.EXECUTE.value and msgflags & MessageFlags.TTY.value:
data = self.fixupremotetty(msghdr, msgdata, server.host) data = self.fixupremotetty(msghdr, msgdata, server.host)
logger.info("created remote tty message: %s", data) logger.debug("created remote tty message: %s", data)
elif msgtype == MessageTypes.NODE.value: elif msgtype == MessageTypes.NODE.value:
# snoop node delete response to decrement node counts # snoop node delete response to decrement node counts
if msgflags & MessageFlags.DELETE.value: if msgflags & MessageFlags.DELETE.value:
@ -293,22 +291,21 @@ class CoreBroker(ConfigurableManager):
with self.servers_lock: with self.servers_lock:
server = self.servers.get(name) server = self.servers.get(name)
if server is not None: if server is not None:
if host == server.host and port == server.port and \ if host == server.host and port == server.port and server.sock is not None:
server.sock is not None:
# leave this socket connected # leave this socket connected
return return
logger.info("closing connection with %s @ %s:%s" % (name, server.host, server.port)) logger.info("closing connection with %s @ %s:%s", name, server.host, server.port)
server.close() server.close()
del self.servers[name] del self.servers[name]
logger.info("adding broker server(%s): %s:%s" % (name, host, port)) logger.info("adding broker server(%s): %s:%s", name, host, port)
server = CoreDistributedServer(name, host, port) server = CoreDistributedServer(name, host, port)
if host is not None and port is not None: if host is not None and port is not None:
try: try:
server.connect() server.connect()
except IOError: except IOError:
logger.exception("error connecting to server %s:%s" % (host, port)) logger.exception("error connecting to server(%s): %s:%s", name, host, port)
if server.sock is not None: if server.sock is not None:
self.startrecvloop() self.startrecvloop()
self.servers[name] = server self.servers[name] = server
@ -328,7 +325,7 @@ class CoreBroker(ConfigurableManager):
logger.exception("error deleting server") logger.exception("error deleting server")
if server.sock is not None: if server.sock is not None:
logger.info("closing connection with %s @ %s:%s" % (server.name, server.host, server.port)) logger.info("closing connection with %s @ %s:%s", server.name, server.host, server.port)
server.close() server.close()
def getserverbyname(self, name): def getserverbyname(self, name):
@ -412,7 +409,7 @@ class CoreBroker(ConfigurableManager):
remotenum = n2num remotenum = n2num
if key in self.tunnels.keys(): if key in self.tunnels.keys():
logger.warn("tunnel with key %s (%s-%s) already exists!" % (key, n1num, n2num)) logger.warn("tunnel with key %s (%s-%s) already exists!", key, n1num, n2num)
else: else:
objid = key & ((1 << 16) - 1) objid = key & ((1 << 16) - 1)
logger.info("adding tunnel for %s-%s to %s with key %s", n1num, n2num, remoteip, key) logger.info("adding tunnel for %s-%s to %s with key %s", n1num, n2num, remoteip, key)
@ -494,7 +491,7 @@ class CoreBroker(ConfigurableManager):
gt = self.tunnels[key] gt = self.tunnels[key]
r.append(gt) r.append(gt)
continue continue
logger.info("adding tunnel for net %s to %s with key %s" % (node_id, host, key)) logger.info("adding tunnel for net %s to %s with key %s", node_id, host, key)
gt = GreTap(node=None, name=None, session=self.session, remoteip=host, key=key) gt = GreTap(node=None, name=None, session=self.session, remoteip=host, key=key)
self.tunnels[key] = gt self.tunnels[key] = gt
r.append(gt) r.append(gt)
@ -698,8 +695,7 @@ class CoreBroker(ConfigurableManager):
elif message.message_type == MessageTypes.CONFIG.value: elif message.message_type == MessageTypes.CONFIG.value:
# broadcast location and services configuration everywhere # broadcast location and services configuration everywhere
confobj = message.get_tlv(ConfigTlvs.OBJECT.value) confobj = message.get_tlv(ConfigTlvs.OBJECT.value)
if confobj == "location" or confobj == "services" or \ if confobj == "location" or confobj == "services" or confobj == "session" or confobj == "all":
confobj == "session" or confobj == "all":
servers = self.getservers() servers = self.getservers()
elif message.message_type == MessageTypes.FILE.value: elif message.message_type == MessageTypes.FILE.value:
# broadcast hook scripts and custom service files everywhere # broadcast hook scripts and custom service files everywhere
@ -735,10 +731,10 @@ class CoreBroker(ConfigurableManager):
""" """
server = self.getserverbyname(servername) server = self.getserverbyname(servername)
if server is None: if server is None:
logger.warn("ignoring unknown server: %s" % servername) logger.warn("ignoring unknown server: %s", servername)
return return
if server.sock is None or server.host is None or server.port is None: if server.sock is None or server.host is None or server.port is None:
logger.info("ignoring disconnected server: %s" % servername) logger.info("ignoring disconnected server: %s", servername)
return return
# communicate this session"s current state to the server # communicate this session"s current state to the server
@ -811,10 +807,10 @@ class CoreBroker(ConfigurableManager):
try: try:
nodecls = nodeutils.get_node_class(NodeTypes(nodetype)) nodecls = nodeutils.get_node_class(NodeTypes(nodetype))
except KeyError: except KeyError:
logger.warn("broker invalid node type %s" % nodetype) logger.warn("broker invalid node type %s", nodetype)
return handle_locally, servers return handle_locally, servers
if nodecls is None: if nodecls is None:
logger.warn("broker unimplemented node type %s" % nodetype) logger.warn("broker unimplemented node type %s", nodetype)
return handle_locally, servers return handle_locally, servers
if issubclass(nodecls, PyCoreNet) and nodetype != NodeTypes.WIRELESS_LAN.value: if issubclass(nodecls, PyCoreNet) and nodetype != NodeTypes.WIRELESS_LAN.value:
# network node replicated on all servers; could be optimized # network node replicated on all servers; could be optimized
@ -1013,11 +1009,10 @@ class CoreBroker(ConfigurableManager):
# local emulation server, handle this locally # local emulation server, handle this locally
handle_locally = True handle_locally = True
elif server.sock is None: elif server.sock is None:
logger.info("server %s @ %s:%s is disconnected" % ( logger.info("server %s @ %s:%s is disconnected", server.name, server.host, server.port)
server.name, server.host, server.port))
else: else:
logger.info("forwarding message to server: %s - %s:\n%s", logger.info("forwarding message to server(%s): %s:%s", server.name, server.host, server.port)
server.host, server.port, message) logger.debug("message being forwarded:\n%s", message)
server.sock.send(message.raw_message) server.sock.send(message.raw_message)
return handle_locally return handle_locally
@ -1045,7 +1040,7 @@ class CoreBroker(ConfigurableManager):
lhost, lport = server.sock.getsockname() lhost, lport = server.sock.getsockname()
f.write("%s %s %s %s %s\n" % (server.name, server.host, server.port, lhost, lport)) f.write("%s %s %s %s %s\n" % (server.name, server.host, server.port, lhost, lport))
except IOError: except IOError:
logger.exception("error writing server list to the file: %s" % filename) logger.exception("error writing server list to the file: %s", filename)
def writenodeserver(self, nodestr, server): def writenodeserver(self, nodestr, server):
""" """
@ -1072,7 +1067,7 @@ class CoreBroker(ConfigurableManager):
with open(filename, "w") as f: with open(filename, "w") as f:
f.write("%s\n%s\n" % (serverstr, nodestr)) f.write("%s\n%s\n" % (serverstr, nodestr))
except IOError: except IOError:
logger.exception("error writing server file %s for node %s" % (filename, name)) logger.exception("error writing server file %s for node %s", filename, name)
def local_instantiation_complete(self): def local_instantiation_complete(self):
""" """
@ -1126,9 +1121,9 @@ class CoreBroker(ConfigurableManager):
if values_str is None: if values_str is None:
return return
value_strings = values_str.split('|') value_strings = values_str.split("|")
for value_string in value_strings: for value_string in value_strings:
key, value = value_string.split('=', 1) key, value = value_string.split("=", 1)
if key == "controlnet": if key == "controlnet":
self.handle_distributed_control_net(message, value_strings, value_strings.index(value_string)) self.handle_distributed_control_net(message, value_strings, value_strings.index(value_string))
@ -1144,7 +1139,7 @@ class CoreBroker(ConfigurableManager):
:return: nothing :return: nothing
""" """
key_value = values[index] key_value = values[index]
key, value = key_value.split('=', 1) key, value = key_value.split("=", 1)
control_nets = value.split() control_nets = value.split()
if len(control_nets) < 2: if len(control_nets) < 2:

View file

@ -891,6 +891,10 @@ def get_endpoint(network_object, interface_object):
ep = None ep = None
l2devport = None l2devport = None
# skip if either are none
if not network_object or not interface_object:
return ep
# if ifcObj references an interface of a node and is part of this network # if ifcObj references an interface of a node and is part of this network
if interface_object.net.objid == network_object.objid and hasattr(interface_object, if interface_object.net.objid == network_object.objid and hasattr(interface_object,
'node') and interface_object.node: 'node') and interface_object.node:
@ -957,7 +961,7 @@ def get_endpoints(network_object):
if ep is not None: if ep is not None:
endpoints.append(ep) endpoints.append(ep)
except: except:
logger.exception("error geting endpoints, was skipped before") logger.debug("error geting endpoints, was skipped before")
return endpoints return endpoints

View file

@ -51,7 +51,7 @@ def cored(cfg, use_ovs):
sys.exit(1) sys.exit(1)
close_onexec(server.fileno()) close_onexec(server.fileno())
logger.debug("main server started, listening on: %s:%s", host, port) logger.info("server started, listening on: %s:%s", host, port)
server.serve_forever() server.serve_forever()