updated logging.warn to logging.warning due to deprecation in python3, fixed python 2/3 filter issue in tests, fixed utf decoding for some missed popen commands

This commit is contained in:
Blake Harnden 2019-06-03 14:36:21 -07:00
parent 69b1297002
commit 597bd21994
14 changed files with 70 additions and 66 deletions

View file

@ -236,7 +236,7 @@ class CoreBroker(object):
return 0
if len(msghdr) != coreapi.CoreMessage.header_len:
logging.warn("warning: broker received not enough data len=%s", len(msghdr))
logging.warning("warning: broker received not enough data len=%s", len(msghdr))
return len(msghdr)
msgtype, msgflags, msglen = coreapi.CoreMessage.unpack_header(msghdr)
@ -413,7 +413,7 @@ class CoreBroker(object):
remotenum = n2num
if key in self.tunnels.keys():
logging.warn("tunnel with key %s (%s-%s) already exists!", key, n1num, n2num)
logging.warning("tunnel with key %s (%s-%s) already exists!", key, n1num, n2num)
else:
_id = key & ((1 << 16) - 1)
logging.info("adding tunnel for %s-%s to %s with key %s", n1num, n2num, remoteip, key)
@ -452,17 +452,17 @@ class CoreBroker(object):
# add other nets here that do not require tunnels
if nodeutils.is_node(net, NodeTypes.EMANE_NET):
logging.warn("emane network does not require a tunnel")
logging.warning("emane network does not require a tunnel")
return None
server_interface = getattr(net, "serverintf", None)
if nodeutils.is_node(net, NodeTypes.CONTROL_NET) and server_interface is not None:
logging.warn("control networks with server interfaces do not need a tunnel")
logging.warning("control networks with server interfaces do not need a tunnel")
return None
servers = self.getserversbynode(node_id)
if len(servers) < 2:
logging.warn("not enough servers to create a tunnel: %s", servers)
logging.warning("not enough servers to create a tunnel: %s", servers)
return None
hosts = []
@ -678,7 +678,7 @@ class CoreBroker(object):
"""
server = self.getserverbyname(servername)
if server is None:
logging.warn("ignoring unknown server: %s", servername)
logging.warning("ignoring unknown server: %s", servername)
return
if server.sock is None or server.host is None or server.port is None:
@ -754,10 +754,10 @@ class CoreBroker(object):
try:
nodecls = nodeutils.get_node_class(NodeTypes(nodetype))
except KeyError:
logging.warn("broker invalid node type %s", nodetype)
logging.warning("broker invalid node type %s", nodetype)
return handle_locally, servers
if nodecls is None:
logging.warn("broker unimplemented node type %s", nodetype)
logging.warning("broker unimplemented node type %s", nodetype)
return handle_locally, servers
if issubclass(nodecls, CoreNetworkBase) and nodetype != NodeTypes.WIRELESS_LAN.value:
# network node replicated on all servers; could be optimized
@ -1091,12 +1091,12 @@ class CoreBroker(object):
control_nets = value.split()
if len(control_nets) < 2:
logging.warn("multiple controlnet prefixes do not exist")
logging.warning("multiple controlnet prefixes do not exist")
return
servers = self.session.broker.getservernames()
if len(servers) < 2:
logging.warn("not distributed")
logging.warning("not distributed")
return
servers.remove("localhost")

View file

@ -120,7 +120,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
time.sleep(1)
wait += 1
if wait == timeout:
logging.warn("queue failed to be empty, finishing request handler")
logging.warning("queue failed to be empty, finishing request handler")
break
logging.info("client disconnected: notifying threads")
@ -129,7 +129,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
logging.info("waiting for thread: %s", thread.getName())
thread.join(timeout)
if thread.isAlive():
logging.warn("joining %s failed: still alive after %s sec", thread.getName(), timeout)
logging.warning("joining %s failed: still alive after %s sec", thread.getName(), timeout)
logging.info("connection closed: %s", self.client_address)
if self.session:
@ -422,7 +422,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
message_type, message_flags, message_len = coreapi.CoreMessage.unpack_header(header)
if message_len == 0:
logging.warn("received message with no data")
logging.warning("received message with no data")
data = b""
while len(data) < message_len:
@ -629,7 +629,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
"""
replies = []
if message.flags & MessageFlags.ADD.value and message.flags & MessageFlags.DELETE.value:
logging.warn("ignoring invalid message: add and delete flag both set")
logging.warning("ignoring invalid message: add and delete flag both set")
return ()
node_type = None
@ -1009,7 +1009,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
self.session.location.reset()
else:
if not config_data.data_values:
logging.warn("location data missing")
logging.warning("location data missing")
else:
values = [float(x) for x in config_data.data_values.split("|")]
@ -1144,7 +1144,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
node = self.session.get_node(node_id)
if node is None:
logging.warn("request to configure service for unknown node %s", node_id)
logging.warning("request to configure service for unknown node %s", node_id)
return replies
services = ServiceShim.servicesfromopaque(opaque)
@ -1247,7 +1247,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
model_class = self.session.mobility.models.get(object_name)
if not model_class:
logging.warn("model class does not exist: %s", object_name)
logging.warning("model class does not exist: %s", object_name)
return []
config = self.session.mobility.get_model_config(node_id, object_name)
@ -1256,7 +1256,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
elif message_type != ConfigFlags.RESET:
# store the configuration values for later use, when the node
if not object_name:
logging.warn("no configuration object for node: %s", node_id)
logging.warning("no configuration object for node: %s", node_id)
return []
parsed_config = {}
@ -1317,7 +1317,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
model_class = self.session.emane.models.get(object_name)
if not model_class:
logging.warn("model class does not exist: %s", object_name)
logging.warning("model class does not exist: %s", object_name)
return []
config = self.session.emane.get_model_config(node_id, object_name)
@ -1326,7 +1326,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
elif message_type != ConfigFlags.RESET:
# store the configuration values for later use, when the node
if not object_name:
logging.warn("no configuration object for node: %s", node_id)
logging.warning("no configuration object for node: %s", node_id)
return []
parsed_config = {}
@ -1353,11 +1353,11 @@ class CoreHandler(socketserver.BaseRequestHandler):
compressed_data = message.get_tlv(FileTlvs.COMPRESSED_DATA.value)
if compressed_data:
logging.warn("Compressed file data not implemented for File message.")
logging.warning("Compressed file data not implemented for File message.")
return ()
if source_name and data:
logging.warn("ignoring invalid File message: source and data TLVs are both present")
logging.warning("ignoring invalid File message: source and data TLVs are both present")
return ()
# some File Messages store custom files in services,
@ -1435,7 +1435,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
self.session.start_mobility(node_ids=(node.id,))
return ()
logging.warn("dropping unhandled Event message with node number")
logging.warning("dropping unhandled Event message with node number")
return ()
self.session.set_state(event_type)
@ -1454,7 +1454,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
self.send_node_emulation_id(_id)
elif event_type == EventTypes.RUNTIME_STATE:
if self.session.master:
logging.warn("Unexpected event message: RUNTIME state received at session master")
logging.warning("Unexpected event message: RUNTIME state received at session master")
else:
# master event queue is started in session.checkruntime()
self.session.start_events()
@ -1462,7 +1462,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
self.session.data_collect()
elif event_type == EventTypes.SHUTDOWN_STATE:
if self.session.master:
logging.warn("Unexpected event message: SHUTDOWN state received at session master")
logging.warning("Unexpected event message: SHUTDOWN state received at session master")
elif event_type in {EventTypes.START, EventTypes.STOP, EventTypes.RESTART, EventTypes.PAUSE,
EventTypes.RECONFIGURE}:
handled = False
@ -1477,7 +1477,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
self.session.mobility_event(event_data)
handled = True
if not handled:
logging.warn("Unhandled event message: event type %s ", event_type.name)
logging.warning("Unhandled event message: event type %s ", event_type.name)
elif event_type == EventTypes.FILE_OPEN:
filename = event_data.name
self.session.open_xml(filename, start=False)
@ -1492,14 +1492,14 @@ class CoreHandler(socketserver.BaseRequestHandler):
name = event_data.name
data = event_data.data
if etime is None:
logging.warn("Event message scheduled event missing start time")
logging.warning("Event message scheduled event missing start time")
return ()
if message.flags & MessageFlags.ADD.value:
self.session.add_event(float(etime), node=node, name=name, data=data)
else:
raise NotImplementedError
else:
logging.warn("unhandled event message: event type %s", event_type)
logging.warning("unhandled event message: event type %s", event_type)
return ()
@ -1518,7 +1518,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
try:
node = self.session.get_node(node_id)
except KeyError:
logging.warn("ignoring event for service '%s', unknown node '%s'", name, node_id)
logging.warning("ignoring event for service '%s', unknown node '%s'", name, node_id)
return
fail = ""
@ -1556,7 +1556,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
if num > 1:
unknown_data += ", "
num -= 1
logging.warn("Event requested for unknown service(s): %s", unknown_data)
logging.warning("Event requested for unknown service(s): %s", unknown_data)
unknown_data = "Unknown:" + unknown_data
event_data = EventData(
@ -1595,7 +1595,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
session = self.coreemu.sessions.get(session_id)
if session is None:
logging.warn("session %s not found", session_id)
logging.warning("session %s not found", session_id)
continue
logging.info("request to modify to session: %s", session.id)
@ -1655,7 +1655,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
logging.info("request to terminate session %s", session_id)
self.coreemu.delete_session(session_id)
else:
logging.warn("unhandled session flags for session %s", session_id)
logging.warning("unhandled session flags for session %s", session_id)
return ()

View file

@ -115,11 +115,11 @@ class EmaneCommEffectModel(emanemodel.EmaneModel):
"""
service = self.session.emane.service
if service is None:
logging.warn("%s: EMANE event service unavailable", self.name)
logging.warning("%s: EMANE event service unavailable", self.name)
return
if netif is None or netif2 is None:
logging.warn("%s: missing NEM information", self.name)
logging.warning("%s: missing NEM information", self.name)
return
# TODO: batch these into multiple events per transmission

View file

@ -807,7 +807,7 @@ class EmaneManager(ModelManager):
for event in events:
txnemid, attrs = event
if "latitude" not in attrs or "longitude" not in attrs or "altitude" not in attrs:
logging.warn("dropped invalid location event")
logging.warning("dropped invalid location event")
continue
# yaw,pitch,roll,azimuth,elevation,velocity are unhandled

View file

@ -156,4 +156,4 @@ class EmaneModel(WirelessModel):
:param core.netns.vif.Veth netif2: interface two
:return: nothing
"""
logging.warn("emane model(%s) does not support link configuration", self.name)
logging.warning("emane model(%s) does not support link configuration", self.name)

View file

@ -1038,7 +1038,7 @@ class Session(object):
if os.path.isfile(environment_config_file):
utils.load_config(environment_config_file, env)
except IOError:
logging.warn("environment configuration file does not exist: %s", environment_config_file)
logging.warning("environment configuration file does not exist: %s", environment_config_file)
# attempt to read and add user environment file
if self.user:
@ -1625,7 +1625,7 @@ class Session(object):
if current_time > 0:
if event_time <= current_time:
logging.warn("could not schedule past event for time %s (run time is now %s)", event_time, current_time)
logging.warning("could not schedule past event for time %s (run time is now %s)", event_time, current_time)
return
event_time = event_time - current_time

View file

@ -71,7 +71,7 @@ class MobilityManager(ModelManager):
try:
node = self.session.get_node(node_id)
except KeyError:
logging.warn("skipping mobility configuration for unknown node: %s", node_id)
logging.warning("skipping mobility configuration for unknown node: %s", node_id)
continue
for model_name in self.models:
@ -111,7 +111,7 @@ class MobilityManager(ModelManager):
try:
cls = self.models[model]
except KeyError:
logging.warn("Ignoring event for unknown model '%s'", model)
logging.warning("Ignoring event for unknown model '%s'", model)
continue
if cls.config_type in [RegisterTlvs.WIRELESS.value, RegisterTlvs.MOBILITY.value]:
@ -120,11 +120,11 @@ class MobilityManager(ModelManager):
continue
if model is None:
logging.warn("Ignoring event, %s has no model", node.name)
logging.warning("Ignoring event, %s has no model", node.name)
continue
if cls.name != model.name:
logging.warn("Ignoring event for %s wrong model %s,%s", node.name, cls.name, model.name)
logging.warning("Ignoring event for %s wrong model %s,%s", node.name, cls.name, model.name)
continue
if event_type == EventTypes.STOP.value or event_type == EventTypes.RESTART.value:

View file

@ -169,7 +169,7 @@ class VnodeClient(object):
# wait for and return exit status
status = p.wait()
if status:
logging.warn("cmd exited with status %s: %s", status, args)
logging.warning("cmd exited with status %s: %s", status, args)
return status
def term(self, sh="/bin/sh"):
@ -247,16 +247,16 @@ class VnodeClient(object):
elif line[3] == "link":
interface["inet6link"].append(line[1])
else:
logging.warn("unknown scope: %s" % line[3])
logging.warning("unknown scope: %s" % line[3])
err = stderr.read()
stdout.close()
stderr.close()
status = p.wait()
if status:
logging.warn("nonzero exist status (%s) for cmd: %s", status, args)
logging.warning("nonzero exist status (%s) for cmd: %s", status, args)
if err:
logging.warn("error output: %s", err)
logging.warning("error output: %s", err)
self._addr[ifname] = interface
return interface
@ -275,11 +275,11 @@ class VnodeClient(object):
# ignore first line
stdout.readline()
# second line has count names
tmp = stdout.readline().strip().split("|")
tmp = stdout.readline().decode("utf-8").strip().split("|")
rxkeys = tmp[1].split()
txkeys = tmp[2].split()
for line in stdout:
line = line.strip().split()
line = line.decode("utf-8").strip().split()
devname, tmp = line[0].split(":")
if tmp:
line.insert(1, tmp)
@ -296,9 +296,9 @@ class VnodeClient(object):
stderr.close()
status = p.wait()
if status:
logging.warn("nonzero exist status (%s) for cmd: %s", status, args)
logging.warning("nonzero exist status (%s) for cmd: %s", status, args)
if err:
logging.warn("error output: %s", err)
logging.warning("error output: %s", err)
if ifname is not None:
return stats[ifname]
else:

View file

@ -481,7 +481,12 @@ class CoreNetwork(CoreNetworkBase):
netem += ["loss", "%s%%" % min(loss, 100)]
if duplicate is not None and duplicate > 0:
netem += ["duplicate", "%s%%" % min(duplicate, 100)]
if delay <= 0 and jitter <= 0 and loss <= 0 and duplicate <= 0:
delay_check = delay is None or delay <= 0
jitter_check = jitter is None or jitter <= 0
loss_check = loss is None or loss <= 0
duplicate_check = duplicate is None or duplicate <= 0
if all([delay_check, jitter_check, loss_check, duplicate_check]):
# possibly remove netem if it exists and parent queue wasn't removed
if not netif.getparam("has_netem"):
return

View file

@ -7,14 +7,13 @@ a list of available services to the GUI and for configuring individual
services.
"""
import enum
import logging
import time
from multiprocessing.pool import ThreadPool
import enum
from core.constants import which
from core import CoreCommandError, utils
from core.constants import which
from core.emulator.data import FileData
from core.emulator.enumerations import MessageFlags
from core.emulator.enumerations import RegisterTlvs
@ -318,7 +317,7 @@ class CoreServices(object):
logging.debug("checking for service with service manager: %s", name)
service = ServiceManager.get(name)
if not service:
logging.warn("default service %s is unknown", name)
logging.warning("default service %s is unknown", name)
else:
results.append(service)
return results
@ -376,7 +375,7 @@ class CoreServices(object):
for service_name in services:
service = self.get_service(node.id, service_name, default_service=True)
if not service:
logging.warn("unknown service(%s) for node(%s)", service_name, node.name)
logging.warning("unknown service(%s) for node(%s)", service_name, node.name)
continue
logging.info("adding service to node(%s): %s", node.name, service_name)
node.addservice(service)
@ -464,15 +463,15 @@ class CoreServices(object):
:return: nothing
"""
logging.info("starting node(%s) service(%s) validation(%s)", node.name, service.name,
service.validation_mode.name)
service.validation_mode.name)
# create service directories
for directory in service.dirs:
try:
node.privatedir(directory)
except (CoreCommandError, ValueError) as e:
logging.warn("error mounting private dir '%s' for service '%s': %s",
directory, service.name, e)
logging.warning("error mounting private dir '%s' for service '%s': %s",
directory, service.name, e)
# create service files
self.create_service_files(node, service)
@ -640,13 +639,13 @@ class CoreServices(object):
# retrieve custom service
service = self.get_service(node_id, service_name)
if service is None:
logging.warn("received file name for unknown service: %s", service_name)
logging.warning("received file name for unknown service: %s", service_name)
return
# validate file being set is valid
config_files = service.configs
if file_name not in config_files:
logging.warn("received unknown file(%s) for service(%s)", file_name, service_name)
logging.warning("received unknown file(%s) for service(%s)", file_name, service_name)
return
# set custom service file data

View file

@ -377,7 +377,7 @@ def load_classes(path, clazz):
# validate path exists
logging.debug("attempting to load modules from path: %s", path)
if not os.path.isdir(path):
logging.warn("invalid custom module directory specified" ": %s" % path)
logging.warning("invalid custom module directory specified" ": %s" % path)
# check if path is in sys.path
parent_path = os.path.dirname(path)
if parent_path not in sys.path:

View file

@ -112,7 +112,7 @@ def build_node_platform_xml(emane_manager, control_net, node, nem_id, platform_x
nem_entries = {}
if node.model is None:
logging.warn("warning: EmaneNode %s has no associated model", node.name)
logging.warning("warning: EmaneNode %s has no associated model", node.name)
return nem_entries
for netif in node.netifs():

View file

@ -36,9 +36,9 @@ def createclients(sessiondir, clientcls=VnodeClient, cmdchnlfilterfunc=None):
:rtype: list
"""
direntries = map(lambda x: os.path.join(sessiondir, x), os.listdir(sessiondir))
cmdchnls = filter(lambda x: stat.S_ISSOCK(os.stat(x).st_mode), direntries)
cmdchnls = list(filter(lambda x: stat.S_ISSOCK(os.stat(x).st_mode), direntries))
if cmdchnlfilterfunc:
cmdchnls = filter(cmdchnlfilterfunc, cmdchnls)
cmdchnls = list(filter(cmdchnlfilterfunc, cmdchnls))
cmdchnls.sort()
return map(lambda x: clientcls(os.path.basename(x), x), cmdchnls)

View file

@ -31,7 +31,7 @@ def iperf(from_node, to_node, ip_prefixes):
vcmd, stdin, stdout, stderr = to_node.client.popen(["iperf", "-s", "-u", "-y", "C"])
from_node.cmd(["iperf", "-u", "-t", "5", "-c", address])
to_node.cmd(["killall", "-9", "iperf"])
return stdout.read().strip()
return stdout.read().decode("utf-8").strip()
class TestLinks: