renamed session.session_id to session.id

This commit is contained in:
bharnden 2019-04-08 10:39:36 -07:00
parent 6672fd0f7a
commit 73bc56e4c3
11 changed files with 89 additions and 90 deletions

View file

@ -389,7 +389,7 @@ class CoreBroker(object):
sid = self.session_id_master sid = self.session_id_master
if sid is None: if sid is None:
# this is the master session # this is the master session
sid = self.session.session_id sid = self.session.id
key = (sid << 16) ^ hash(n1num) ^ (hash(n2num) << 8) key = (sid << 16) ^ hash(n1num) ^ (hash(n2num) << 8)
return key & 0xFFFFFFFF return key & 0xFFFFFFFF
@ -697,7 +697,7 @@ class CoreBroker(object):
tlvdata += coreapi.CoreConfigTlv.pack(ConfigTlvs.DATA_TYPES.value, (ConfigDataTypes.STRING.value,)) tlvdata += coreapi.CoreConfigTlv.pack(ConfigTlvs.DATA_TYPES.value, (ConfigDataTypes.STRING.value,))
tlvdata += coreapi.CoreConfigTlv.pack(ConfigTlvs.VALUES.value, tlvdata += coreapi.CoreConfigTlv.pack(ConfigTlvs.VALUES.value,
"%s:%s:%s" % (server.name, server.host, server.port)) "%s:%s:%s" % (server.name, server.host, server.port))
tlvdata += coreapi.CoreConfigTlv.pack(ConfigTlvs.SESSION.value, "%s" % self.session.session_id) tlvdata += coreapi.CoreConfigTlv.pack(ConfigTlvs.SESSION.value, "%s" % self.session.id)
msg = coreapi.CoreConfMessage.pack(0, tlvdata) msg = coreapi.CoreConfMessage.pack(0, tlvdata)
server.sock.send(msg) server.sock.send(msg)
@ -973,7 +973,7 @@ class CoreBroker(object):
filename = os.path.join(self.session.session_dir, "servers") filename = os.path.join(self.session.session_dir, "servers")
master = self.session_id_master master = self.session_id_master
if master is None: if master is None:
master = self.session.session_id master = self.session.id
try: try:
with open(filename, "w") as f: with open(filename, "w") as f:
f.write("master=%s\n" % master) f.write("master=%s\n" % master)

View file

@ -57,7 +57,6 @@ class CoreHandler(SocketServer.BaseRequestHandler):
:param request: request object :param request: request object
:param str client_address: client address :param str client_address: client address
:param CoreServer server: core server instance :param CoreServer server: core server instance
:return:
""" """
self.done = False self.done = False
self.message_handlers = { self.message_handlers = {
@ -140,7 +139,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
self.session.broker.session_clients.remove(self) self.session.broker.session_clients.remove(self)
if not self.session.broker.session_clients and not self.session.is_active(): if not self.session.broker.session_clients and not self.session.is_active():
logging.info("no session clients left and not active, initiating shutdown") logging.info("no session clients left and not active, initiating shutdown")
self.coreemu.delete_session(self.session.session_id) self.coreemu.delete_session(self.session.id)
return SocketServer.BaseRequestHandler.finish(self) return SocketServer.BaseRequestHandler.finish(self)
@ -160,9 +159,9 @@ class CoreHandler(SocketServer.BaseRequestHandler):
num_sessions = 0 num_sessions = 0
with self._sessions_lock: with self._sessions_lock:
for session_id, session in self.coreemu.sessions.iteritems(): for _id, session in self.coreemu.sessions.iteritems():
num_sessions += 1 num_sessions += 1
id_list.append(str(session_id)) id_list.append(str(_id))
name = session.name name = session.name
if not name: if not name:
@ -372,7 +371,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
:return: register message data :return: register message data
""" """
logging.info("GUI has connected to session %d at %s", self.session.session_id, time.ctime()) logging.info("GUI has connected to session %d at %s", self.session.id, time.ctime())
tlv_data = "" tlv_data = ""
tlv_data += coreapi.CoreRegisterTlv.pack(RegisterTlvs.EXECUTE_SERVER.value, "core-daemon") tlv_data += coreapi.CoreRegisterTlv.pack(RegisterTlvs.EXECUTE_SERVER.value, "core-daemon")
@ -538,7 +537,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
# TODO: add shutdown handler for session # TODO: add shutdown handler for session
self.session = self.coreemu.create_session(port, master=False) self.session = self.coreemu.create_session(port, master=False)
# self.session.shutdown_handlers.append(self.session_shutdown) # self.session.shutdown_handlers.append(self.session_shutdown)
logging.debug("created new session for client: %s", self.session.session_id) logging.debug("created new session for client: %s", self.session.id)
# TODO: hack to associate this handler with this sessions broker for broadcasting # TODO: hack to associate this handler with this sessions broker for broadcasting
# TODO: broker needs to be pulled out of session to the server/handler level # TODO: broker needs to be pulled out of session to the server/handler level
@ -592,7 +591,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
:return: :return:
""" """
exception_data = ExceptionData( exception_data = ExceptionData(
session=str(self.session.session_id), session=str(self.session.id),
node=node, node=node,
date=time.ctime(), date=time.ctime(),
level=level.value, level=level.value,
@ -850,7 +849,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
try: try:
session.open_xml(file_name, start=True) session.open_xml(file_name, start=True)
except: except:
self.coreemu.delete_session(session.session_id) self.coreemu.delete_session(session.id)
raise raise
else: else:
thread = threading.Thread( thread = threading.Thread(
@ -908,7 +907,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
# find the session containing this client and set the session to master # find the session containing this client and set the session to master
for session in self.coreemu.sessions.itervalues(): for session in self.coreemu.sessions.itervalues():
if self in session.broker.session_clients: if self in session.broker.session_clients:
logging.debug("setting session to master: %s", session.session_id) logging.debug("setting session to master: %s", session.id)
session.master = True session.master = True
break break
@ -1591,7 +1590,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
logging.warn("session %s not found", session_id) logging.warn("session %s not found", session_id)
continue continue
logging.info("request to modify to session: %s", session.session_id) logging.info("request to modify to session: %s", session.id)
if names is not None: if names is not None:
session.name = names[index] session.name = names[index]
@ -1624,7 +1623,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
self.remove_session_handlers() self.remove_session_handlers()
self.session.broker.session_clients.remove(self) self.session.broker.session_clients.remove(self)
if not self.session.broker.session_clients and not self.session.is_active(): if not self.session.broker.session_clients and not self.session.is_active():
self.coreemu.delete_session(self.session.session_id) self.coreemu.delete_session(self.session.id)
# set session to join # set session to join
self.session = session self.session = session
@ -1727,7 +1726,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
type=ConfigFlags.UPDATE.value, type=ConfigFlags.UPDATE.value,
data_types=data_types, data_types=data_types,
data_values=values, data_values=values,
session=str(self.session.session_id), session=str(self.session.id),
opaque=opaque opaque=opaque
) )
self.session.broadcast_config(config_data) self.session.broadcast_config(config_data)

View file

@ -118,8 +118,8 @@ class IdGen(object):
class EmuSession(Session): class EmuSession(Session):
def __init__(self, session_id, config=None, mkdir=True): def __init__(self, _id, config=None, mkdir=True):
super(EmuSession, self).__init__(session_id, config, mkdir) super(EmuSession, self).__init__(_id, config, mkdir)
# object management # object management
self.node_id_gen = IdGen() self.node_id_gen = IdGen()
@ -620,7 +620,7 @@ class EmuSession(Session):
:return: nothing :return: nothing
""" """
logging.info("session(%s) shutting down", self.session_id) logging.info("session(%s) shutting down", self.id)
self.set_state(EventTypes.DATACOLLECT_STATE, send_event=True) self.set_state(EventTypes.DATACOLLECT_STATE, send_event=True)
self.set_state(EventTypes.SHUTDOWN_STATE, send_event=True) self.set_state(EventTypes.SHUTDOWN_STATE, send_event=True)
super(EmuSession, self).shutdown() super(EmuSession, self).shutdown()
@ -647,7 +647,7 @@ class EmuSession(Session):
:return: True if active, False otherwise :return: True if active, False otherwise
""" """
result = self.state in {EventTypes.RUNTIME_STATE.value, EventTypes.DATACOLLECT_STATE.value} result = self.state in {EventTypes.RUNTIME_STATE.value, EventTypes.DATACOLLECT_STATE.value}
logging.info("session(%s) checking if active: %s", self.session_id, result) logging.info("session(%s) checking if active: %s", self.id, result)
return result return result
def open_xml(self, file_name, start=False): def open_xml(self, file_name, start=False):

View file

@ -153,7 +153,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
session.set_state(EventTypes.DEFINITION_STATE) session.set_state(EventTypes.DEFINITION_STATE)
session.location.setrefgeo(47.57917, -122.13232, 2.0) session.location.setrefgeo(47.57917, -122.13232, 2.0)
session.location.refscale = 150000.0 session.location.refscale = 150000.0
return core_pb2.CreateSessionResponse(id=session.session_id, state=session.state) return core_pb2.CreateSessionResponse(id=session.id, state=session.state)
def DeleteSession(self, request, context): def DeleteSession(self, request, context):
logging.debug("delete session: %s", request) logging.debug("delete session: %s", request)
@ -344,7 +344,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
name=event.name, name=event.name,
data=event.data, data=event.data,
time=event_time, time=event_time,
session=session.session_id session=session.id
) )
yield session_event yield session_event
except Empty: except Empty:
@ -881,8 +881,8 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
try: try:
session.open_xml(temp_path, start=True) session.open_xml(temp_path, start=True)
return core_pb2.OpenXmlResponse(session=session.session_id, result=True) return core_pb2.OpenXmlResponse(session=session.id, result=True)
except IOError: except IOError:
logging.exception("error opening session file") logging.exception("error opening session file")
self.coreemu.delete_session(session.session_id) self.coreemu.delete_session(session.id)
context.abort(grpc.StatusCode.INVALID_ARGUMENT, "invalid xml file") context.abort(grpc.StatusCode.INVALID_ARGUMENT, "invalid xml file")

View file

@ -319,7 +319,7 @@ def expand_corepath(pathname, session=None, node=None):
""" """
if session is not None: if session is not None:
pathname = pathname.replace("~", "/home/%s" % session.user) pathname = pathname.replace("~", "/home/%s" % session.user)
pathname = pathname.replace("%SESSION%", str(session.session_id)) pathname = pathname.replace("%SESSION%", str(session.id))
pathname = pathname.replace("%SESSION_DIR%", session.session_dir) pathname = pathname.replace("%SESSION_DIR%", session.session_dir)
pathname = pathname.replace("%SESSION_USER%", session.user) pathname = pathname.replace("%SESSION_USER%", session.user)

View file

@ -648,7 +648,7 @@ class OvsGreTapBridge(OvsNet):
OvsNet.__init__(self, session=session, objid=objid, name=name, policy=policy, start=False) OvsNet.__init__(self, session=session, objid=objid, name=name, policy=policy, start=False)
self.grekey = key self.grekey = key
if self.grekey is None: if self.grekey is None:
self.grekey = self.session.session_id ^ self.objid self.grekey = self.session.id ^ self.objid
self.localnum = None self.localnum = None
self.remotenum = None self.remotenum = None

View file

@ -589,7 +589,7 @@ class GreTapBridge(LxBrNet):
LxBrNet.__init__(self, session=session, objid=objid, name=name, policy=policy, start=False) LxBrNet.__init__(self, session=session, objid=objid, name=name, policy=policy, start=False)
self.grekey = key self.grekey = key
if self.grekey is None: if self.grekey is None:
self.grekey = self.session.session_id ^ self.objid self.grekey = self.session.id ^ self.objid
self.localnum = None self.localnum = None
self.remotenum = None self.remotenum = None
self.remoteip = remoteip self.remoteip = remoteip

View file

@ -46,18 +46,18 @@ class Session(object):
CORE session manager. CORE session manager.
""" """
def __init__(self, session_id, config=None, mkdir=True): def __init__(self, _id, config=None, mkdir=True):
""" """
Create a Session instance. Create a Session instance.
:param int session_id: session id :param int _id: session id
:param dict config: session configuration :param dict config: session configuration
:param bool mkdir: flag to determine if a directory should be made :param bool mkdir: flag to determine if a directory should be made
""" """
self.session_id = session_id self.id = _id
# define and create session directory when desired # define and create session directory when desired
self.session_dir = os.path.join(tempfile.gettempdir(), "pycore.%s" % self.session_id) self.session_dir = os.path.join(tempfile.gettempdir(), "pycore.%s" % self.id)
if mkdir: if mkdir:
os.mkdir(self.session_dir) os.mkdir(self.session_dir)
@ -207,12 +207,12 @@ class Session(object):
state_name = state.name state_name = state.name
if self.state == state_value: if self.state == state_value:
logging.info("session(%s) is already in state: %s, skipping change", self.session_id, state_name) logging.info("session(%s) is already in state: %s, skipping change", self.id, state_name)
return return
self.state = state_value self.state = state_value
self._state_time = time.time() self._state_time = time.time()
logging.info("changing session(%s) to state %s", self.session_id, state_name) logging.info("changing session(%s) to state %s", self.id, state_name)
self.write_state(state_value) self.write_state(state_value)
self.run_hooks(state_value) self.run_hooks(state_value)
@ -397,7 +397,7 @@ class Session(object):
:return: :return:
""" """
env = os.environ.copy() env = os.environ.copy()
env["SESSION"] = "%s" % self.session_id env["SESSION"] = "%s" % self.id
env["SESSION_SHORT"] = "%s" % self.short_session_id() env["SESSION_SHORT"] = "%s" % self.short_session_id()
env["SESSION_DIR"] = "%s" % self.session_dir env["SESSION_DIR"] = "%s" % self.session_dir
env["SESSION_NAME"] = "%s" % self.name env["SESSION_NAME"] = "%s" % self.name
@ -562,7 +562,7 @@ class Session(object):
""" """
Log information about the session in its current state. Log information about the session in its current state.
""" """
logging.info("session id=%s name=%s state=%s", self.session_id, self.name, self.state) logging.info("session id=%s name=%s state=%s", self.id, self.name, self.state)
logging.info("file=%s thumbnail=%s node_count=%s/%s", logging.info("file=%s thumbnail=%s node_count=%s/%s",
self.file_name, self.thumbnail, self.get_node_count(), len(self.objects)) self.file_name, self.thumbnail, self.get_node_count(), len(self.objects))
@ -579,7 +579,7 @@ class Session(object):
exception_data = ExceptionData( exception_data = ExceptionData(
node=object_id, node=object_id,
session=str(self.session_id), session=str(self.id),
level=level, level=level,
source=source, source=source,
date=time.ctime(), date=time.ctime(),
@ -649,8 +649,8 @@ class Session(object):
# this is called from instantiate() after receiving an event message # this is called from instantiate() after receiving an event message
# for the instantiation state, and from the broker when distributed # for the instantiation state, and from the broker when distributed
# nodes have been started # nodes have been started
logging.info("session(%s) checking if not in runtime state, current state: %s", self.session_id, logging.info("session(%s) checking if not in runtime state, current state: %s", self.id,
coreapi.state_name(self.state)) coreapi.state_name(self.state))
if self.state == EventTypes.RUNTIME_STATE.value: if self.state == EventTypes.RUNTIME_STATE.value:
logging.info("valid runtime state found, returning") logging.info("valid runtime state found, returning")
return return
@ -696,7 +696,7 @@ class Session(object):
and links remain. and links remain.
""" """
node_count = self.get_node_count() node_count = self.get_node_count()
logging.info("session(%s) checking shutdown: %s nodes remaining", self.session_id, node_count) logging.info("session(%s) checking shutdown: %s nodes remaining", self.id, node_count)
shutdown = False shutdown = False
if node_count == 0: if node_count == 0:
@ -710,7 +710,7 @@ class Session(object):
Return a shorter version of the session ID, appropriate for Return a shorter version of the session ID, appropriate for
interface names, where length may be limited. interface names, where length may be limited.
""" """
ssid = (self.session_id >> 8) ^ (self.session_id & ((1 << 8) - 1)) ssid = (self.id >> 8) ^ (self.id & ((1 << 8) - 1))
return "%x" % ssid return "%x" % ssid
def boot_nodes(self): def boot_nodes(self):
@ -963,7 +963,7 @@ class Session(object):
logging.exception("error retrieving control net object") logging.exception("error retrieving control net object")
return return
header = "CORE session %s host entries" % self.session_id header = "CORE session %s host entries" % self.id
if remove: if remove:
logging.info("Removing /etc/hosts file entries.") logging.info("Removing /etc/hosts file entries.")
utils.file_demunge("/etc/hosts", header) utils.file_demunge("/etc/hosts", header)

View file

@ -194,7 +194,7 @@ class CoreServerTest(object):
# set services for host nodes # set services for host nodes
message = CoreConfMessage.create(0, [ message = CoreConfMessage.create(0, [
(ConfigTlvs.SESSION, str(self.session.session_id)), (ConfigTlvs.SESSION, str(self.session.id)),
(ConfigTlvs.OBJECT, "services"), (ConfigTlvs.OBJECT, "services"),
(ConfigTlvs.TYPE, 0), (ConfigTlvs.TYPE, 0),
(ConfigTlvs.DATA_TYPES, (10, 10, 10)), (ConfigTlvs.DATA_TYPES, (10, 10, 10)),

View file

@ -32,7 +32,7 @@ class TestGrpc:
assert session.state == response.state assert session.state == response.state
if session_id is not None: if session_id is not None:
assert response.id == session_id assert response.id == session_id
assert session.session_id == session_id assert session.id == session_id
@pytest.mark.parametrize("session_id, expected", [ @pytest.mark.parametrize("session_id, expected", [
(None, True), (None, True),
@ -43,7 +43,7 @@ class TestGrpc:
client = CoreGrpcClient() client = CoreGrpcClient()
session = grpc_server.coreemu.create_session() session = grpc_server.coreemu.create_session()
if session_id is None: if session_id is None:
session_id = session.session_id session_id = session.id
# then # then
with client.context_connect(): with client.context_connect():
@ -62,7 +62,7 @@ class TestGrpc:
# then # then
with client.context_connect(): with client.context_connect():
response = client.get_session(session.session_id) response = client.get_session(session.id)
# then # then
assert response.session.state == core_pb2.STATE_DEFINITION assert response.session.state == core_pb2.STATE_DEFINITION
@ -81,7 +81,7 @@ class TestGrpc:
# then # then
found_session = None found_session = None
for current_session in response.sessions: for current_session in response.sessions:
if current_session.id == session.session_id: if current_session.id == session.id:
found_session = current_session found_session = current_session
break break
assert len(response.sessions) == 1 assert len(response.sessions) == 1
@ -94,7 +94,7 @@ class TestGrpc:
# then # then
with client.context_connect(): with client.context_connect():
response = client.get_session_options(session.session_id) response = client.get_session_options(session.id)
# then # then
assert len(response.groups) > 0 assert len(response.groups) > 0
@ -106,7 +106,7 @@ class TestGrpc:
# then # then
with client.context_connect(): with client.context_connect():
response = client.get_session_location(session.session_id) response = client.get_session_location(session.id)
# then # then
assert response.scale == 1.0 assert response.scale == 1.0
@ -128,7 +128,7 @@ class TestGrpc:
lat_lon_alt = (1, 1, 1) lat_lon_alt = (1, 1, 1)
with client.context_connect(): with client.context_connect():
response = client.set_session_location( response = client.set_session_location(
session.session_id, session.id,
x=xyz[0], y=xyz[1], z=xyz[2], x=xyz[0], y=xyz[1], z=xyz[2],
lat=lat_lon_alt[0], lon=lat_lon_alt[1], alt=lat_lon_alt[2], lat=lat_lon_alt[0], lon=lat_lon_alt[1], alt=lat_lon_alt[2],
scale=scale scale=scale
@ -149,7 +149,7 @@ class TestGrpc:
option = "enablerj45" option = "enablerj45"
value = "1" value = "1"
with client.context_connect(): with client.context_connect():
response = client.set_session_options(session.session_id, {option: value}) response = client.set_session_options(session.id, {option: value})
# then # then
assert response.result is True assert response.result is True
@ -164,7 +164,7 @@ class TestGrpc:
# then # then
with client.context_connect(): with client.context_connect():
response = client.set_session_state(session.session_id, core_pb2.STATE_DEFINITION) response = client.set_session_state(session.id, core_pb2.STATE_DEFINITION)
# then # then
assert response.result is True assert response.result is True
@ -178,7 +178,7 @@ class TestGrpc:
# then # then
with client.context_connect(): with client.context_connect():
node = core_pb2.Node() node = core_pb2.Node()
response = client.add_node(session.session_id, node) response = client.add_node(session.id, node)
# then # then
assert response.id is not None assert response.id is not None
@ -192,7 +192,7 @@ class TestGrpc:
# then # then
with client.context_connect(): with client.context_connect():
response = client.get_node(session.session_id, node.objid) response = client.get_node(session.id, node.objid)
# then # then
assert response.node.id == node.objid assert response.node.id == node.objid
@ -211,7 +211,7 @@ class TestGrpc:
x, y = 10, 10 x, y = 10, 10
with client.context_connect(): with client.context_connect():
position = core_pb2.Position(x=x, y=y) position = core_pb2.Position(x=x, y=y)
response = client.edit_node(session.session_id, node_id, position) response = client.edit_node(session.id, node_id, position)
# then # then
assert response.result is expected assert response.result is expected
@ -231,7 +231,7 @@ class TestGrpc:
# then # then
with client.context_connect(): with client.context_connect():
response = client.delete_node(session.session_id, node_id) response = client.delete_node(session.id, node_id)
# then # then
assert response.result is expected assert response.result is expected
@ -249,7 +249,7 @@ class TestGrpc:
# then # then
with client.context_connect(): with client.context_connect():
response = client.get_hooks(session.session_id) response = client.get_hooks(session.id)
# then # then
assert len(response.hooks) == 1 assert len(response.hooks) == 1
@ -267,7 +267,7 @@ class TestGrpc:
file_name = "test" file_name = "test"
file_data = "echo hello" file_data = "echo hello"
with client.context_connect(): with client.context_connect():
response = client.add_hook(session.session_id, core_pb2.STATE_RUNTIME, file_name, file_data) response = client.add_hook(session.id, core_pb2.STATE_RUNTIME, file_name, file_data)
# then # then
assert response.result is True assert response.result is True
@ -280,7 +280,7 @@ class TestGrpc:
# then # then
with client.context_connect(): with client.context_connect():
client.save_xml(session.session_id, str(tmp)) client.save_xml(session.id, str(tmp))
# then # then
assert tmp.exists() assert tmp.exists()
@ -311,7 +311,7 @@ class TestGrpc:
# then # then
with client.context_connect(): with client.context_connect():
response = client.get_node_links(session.session_id, switch.objid) response = client.get_node_links(session.id, switch.objid)
# then # then
assert len(response.links) == 1 assert len(response.links) == 1
@ -328,7 +328,7 @@ class TestGrpc:
# then # then
with pytest.raises(grpc.RpcError): with pytest.raises(grpc.RpcError):
with client.context_connect(): with client.context_connect():
client.get_node_links(session.session_id, 3) client.get_node_links(session.id, 3)
def test_add_link(self, grpc_server, interface_helper): def test_add_link(self, grpc_server, interface_helper):
# given # given
@ -341,7 +341,7 @@ class TestGrpc:
# then # then
interface = interface_helper.create_interface(node.objid, 0) interface = interface_helper.create_interface(node.objid, 0)
with client.context_connect(): with client.context_connect():
response = client.add_link(session.session_id, node.objid, switch.objid, interface) response = client.add_link(session.id, node.objid, switch.objid, interface)
# then # then
assert response.result is True assert response.result is True
@ -357,7 +357,7 @@ class TestGrpc:
interface = interface_helper.create_interface(node.objid, 0) interface = interface_helper.create_interface(node.objid, 0)
with pytest.raises(grpc.RpcError): with pytest.raises(grpc.RpcError):
with client.context_connect(): with client.context_connect():
client.add_link(session.session_id, 1, 3, interface) client.add_link(session.id, 1, 3, interface)
def test_edit_link(self, grpc_server, ip_prefixes): def test_edit_link(self, grpc_server, ip_prefixes):
# given # given
@ -373,7 +373,7 @@ class TestGrpc:
# then # then
with client.context_connect(): with client.context_connect():
response = client.edit_link(session.session_id, node.objid, switch.objid, options) response = client.edit_link(session.id, node.objid, switch.objid, options)
# then # then
assert response.result is True assert response.result is True
@ -400,7 +400,7 @@ class TestGrpc:
# then # then
with client.context_connect(): with client.context_connect():
response = client.delete_link( response = client.delete_link(
session.session_id, node_one.objid, node_two.objid, interface_one.id, interface_two.id) session.id, node_one.objid, node_two.objid, interface_one.id, interface_two.id)
# then # then
assert response.result is True assert response.result is True
@ -414,7 +414,7 @@ class TestGrpc:
# then # then
with client.context_connect(): with client.context_connect():
response = client.get_wlan_config(session.session_id, wlan.objid) response = client.get_wlan_config(session.id, wlan.objid)
# then # then
assert len(response.groups) > 0 assert len(response.groups) > 0
@ -429,7 +429,7 @@ class TestGrpc:
# then # then
with client.context_connect(): with client.context_connect():
response = client.set_wlan_config(session.session_id, wlan.objid, {range_key: range_value}) response = client.set_wlan_config(session.id, wlan.objid, {range_key: range_value})
# then # then
assert response.result is True assert response.result is True
@ -443,7 +443,7 @@ class TestGrpc:
# then # then
with client.context_connect(): with client.context_connect():
response = client.get_emane_config(session.session_id) response = client.get_emane_config(session.id)
# then # then
assert len(response.groups) > 0 assert len(response.groups) > 0
@ -457,7 +457,7 @@ class TestGrpc:
# then # then
with client.context_connect(): with client.context_connect():
response = client.set_emane_config(session.session_id, {config_key: config_value}) response = client.set_emane_config(session.id, {config_key: config_value})
# then # then
assert response.result is True assert response.result is True
@ -479,7 +479,7 @@ class TestGrpc:
# then # then
with client.context_connect(): with client.context_connect():
response = client.get_emane_model_configs(session.session_id) response = client.get_emane_model_configs(session.id)
# then # then
assert len(response.configs) == 1 assert len(response.configs) == 1
@ -499,7 +499,7 @@ class TestGrpc:
# then # then
with client.context_connect(): with client.context_connect():
response = client.set_emane_model_config( response = client.set_emane_model_config(
session.session_id, emane_network.objid, EmaneIeee80211abgModel.name, {config_key: config_value}) session.id, emane_network.objid, EmaneIeee80211abgModel.name, {config_key: config_value})
# then # then
assert response.result is True assert response.result is True
@ -518,7 +518,7 @@ class TestGrpc:
# then # then
with client.context_connect(): with client.context_connect():
response = client.get_emane_model_config( response = client.get_emane_model_config(
session.session_id, emane_network.objid, EmaneIeee80211abgModel.name) session.id, emane_network.objid, EmaneIeee80211abgModel.name)
# then # then
assert len(response.groups) > 0 assert len(response.groups) > 0
@ -530,7 +530,7 @@ class TestGrpc:
# then # then
with client.context_connect(): with client.context_connect():
response = client.get_emane_models(session.session_id) response = client.get_emane_models(session.id)
# then # then
assert len(response.models) > 0 assert len(response.models) > 0
@ -544,7 +544,7 @@ class TestGrpc:
# then # then
with client.context_connect(): with client.context_connect():
response = client.get_mobility_configs(session.session_id) response = client.get_mobility_configs(session.id)
# then # then
assert len(response.configs) > 0 assert len(response.configs) > 0
@ -559,7 +559,7 @@ class TestGrpc:
# then # then
with client.context_connect(): with client.context_connect():
response = client.get_mobility_config(session.session_id, wlan.objid) response = client.get_mobility_config(session.id, wlan.objid)
# then # then
assert len(response.groups) > 0 assert len(response.groups) > 0
@ -574,7 +574,7 @@ class TestGrpc:
# then # then
with client.context_connect(): with client.context_connect():
response = client.set_mobility_config(session.session_id, wlan.objid, {config_key: config_value}) response = client.set_mobility_config(session.id, wlan.objid, {config_key: config_value})
# then # then
assert response.result is True assert response.result is True
@ -591,7 +591,7 @@ class TestGrpc:
# then # then
with client.context_connect(): with client.context_connect():
response = client.mobility_action(session.session_id, wlan.objid, core_pb2.MOBILITY_STOP) response = client.mobility_action(session.id, wlan.objid, core_pb2.MOBILITY_STOP)
# then # then
assert response.result is True assert response.result is True
@ -614,7 +614,7 @@ class TestGrpc:
# then # then
with client.context_connect(): with client.context_connect():
response = client.get_service_defaults(session.session_id) response = client.get_service_defaults(session.id)
# then # then
assert len(response.defaults) > 0 assert len(response.defaults) > 0
@ -628,7 +628,7 @@ class TestGrpc:
# then # then
with client.context_connect(): with client.context_connect():
response = client.set_service_defaults(session.session_id, {node_type: services}) response = client.set_service_defaults(session.id, {node_type: services})
# then # then
assert response.result is True assert response.result is True
@ -642,7 +642,7 @@ class TestGrpc:
# then # then
with client.context_connect(): with client.context_connect():
response = client.get_node_service(session.session_id, node.objid, "IPForward") response = client.get_node_service(session.id, node.objid, "IPForward")
# then # then
assert len(response.service.configs) > 0 assert len(response.service.configs) > 0
@ -655,7 +655,7 @@ class TestGrpc:
# then # then
with client.context_connect(): with client.context_connect():
response = client.get_node_service_file(session.session_id, node.objid, "IPForward", "ipforward.sh") response = client.get_node_service_file(session.id, node.objid, "IPForward", "ipforward.sh")
# then # then
assert response.data is not None assert response.data is not None
@ -670,7 +670,7 @@ class TestGrpc:
# then # then
with client.context_connect(): with client.context_connect():
response = client.set_node_service(session.session_id, node.objid, service_name, (), validate, ()) response = client.set_node_service(session.id, node.objid, service_name, (), validate, ())
# then # then
assert response.result is True assert response.result is True
@ -688,7 +688,7 @@ class TestGrpc:
# then # then
with client.context_connect(): with client.context_connect():
response = client.set_node_service_file(session.session_id, node.objid, service_name, file_name, file_data) response = client.set_node_service_file(session.id, node.objid, service_name, file_name, file_data)
# then # then
assert response.result is True assert response.result is True
@ -704,7 +704,7 @@ class TestGrpc:
# then # then
with client.context_connect(): with client.context_connect():
response = client.service_action(session.session_id, node.objid, service_name, core_pb2.SERVICE_STOP) response = client.service_action(session.id, node.objid, service_name, core_pb2.SERVICE_STOP)
# then # then
assert response.result is True assert response.result is True
@ -722,7 +722,7 @@ class TestGrpc:
# then # then
with client.context_connect(): with client.context_connect():
client.node_events(session.session_id, handle_event) client.node_events(session.id, handle_event)
time.sleep(0.1) time.sleep(0.1)
session.broadcast_node(node_data) session.broadcast_node(node_data)
@ -745,7 +745,7 @@ class TestGrpc:
# then # then
with client.context_connect(): with client.context_connect():
client.link_events(session.session_id, handle_event) client.link_events(session.id, handle_event)
time.sleep(0.1) time.sleep(0.1)
session.broadcast_link(link_data) session.broadcast_link(link_data)
@ -763,7 +763,7 @@ class TestGrpc:
# then # then
with client.context_connect(): with client.context_connect():
client.session_events(session.session_id, handle_event) client.session_events(session.id, handle_event)
time.sleep(0.1) time.sleep(0.1)
event = EventData(event_type=EventTypes.RUNTIME_STATE.value, time="%s" % time.time()) event = EventData(event_type=EventTypes.RUNTIME_STATE.value, time="%s" % time.time())
session.broadcast_event(event) session.broadcast_event(event)
@ -782,7 +782,7 @@ class TestGrpc:
# then # then
with client.context_connect(): with client.context_connect():
client.config_events(session.session_id, handle_event) client.config_events(session.id, handle_event)
time.sleep(0.1) time.sleep(0.1)
session_config = session.options.get_configs() session_config = session.options.get_configs()
config_data = ConfigShim.config_data(0, None, ConfigFlags.UPDATE.value, session.options, session_config) config_data = ConfigShim.config_data(0, None, ConfigFlags.UPDATE.value, session.options, session_config)
@ -802,7 +802,7 @@ class TestGrpc:
# then # then
with client.context_connect(): with client.context_connect():
client.exception_events(session.session_id, handle_event) client.exception_events(session.id, handle_event)
time.sleep(0.1) time.sleep(0.1)
session.exception(ExceptionLevels.FATAL, "test", None, "exception message") session.exception(ExceptionLevels.FATAL, "test", None, "exception message")
@ -821,7 +821,7 @@ class TestGrpc:
# then # then
with client.context_connect(): with client.context_connect():
client.file_events(session.session_id, handle_event) client.file_events(session.id, handle_event)
time.sleep(0.1) time.sleep(0.1)
file_data = session.services.get_service_file(node, "IPForward", "ipforward.sh") file_data = session.services.get_service_file(node, "IPForward", "ipforward.sh")
session.broadcast_file(file_data) session.broadcast_file(file_data)

View file

@ -360,11 +360,11 @@ class Ns3Session(Session):
A Session that starts an ns-3 simulation thread. A Session that starts an ns-3 simulation thread.
""" """
def __init__(self, session_id, persistent=False, duration=600): def __init__(self, _id, persistent=False, duration=600):
self.duration = duration self.duration = duration
self.nodes = ns.network.NodeContainer() self.nodes = ns.network.NodeContainer()
self.mobhelper = ns.mobility.MobilityHelper() self.mobhelper = ns.mobility.MobilityHelper()
Session.__init__(self, session_id) Session.__init__(self, _id)
def run(self, vis=False): def run(self, vis=False):
""" """