From d915436c7d4b02a22d8315eacb7c739304d02eb6 Mon Sep 17 00:00:00 2001 From: "Blake J. Harnden" Date: Thu, 3 Aug 2017 09:37:22 -0700 Subject: [PATCH] added a simple test for a tunnel node, although better testing awwma to require configuration outside of core --- daemon/core/mobility.py | 1 - daemon/tests/conftest.py | 15 ++++- daemon/tests/test_distributed.py | 112 +++++++++++++++++++++++++------ 3 files changed, 102 insertions(+), 26 deletions(-) diff --git a/daemon/core/mobility.py b/daemon/core/mobility.py index 57915688..12fc129b 100644 --- a/daemon/core/mobility.py +++ b/daemon/core/mobility.py @@ -212,7 +212,6 @@ class MobilityManager(ConfigurableManager): try: n = self.session.get_object(nodenum) except KeyError: - logger.exception("error getting session object, this was ignored before") continue if n.model: n.model.update(moved, moved_netifs) diff --git a/daemon/tests/conftest.py b/daemon/tests/conftest.py index 9ff75a59..f18e279a 100644 --- a/daemon/tests/conftest.py +++ b/daemon/tests/conftest.py @@ -62,7 +62,7 @@ def node_message(objid, name, emulation_server=None, node_type=NodeTypes.DEFAULT return CoreNodeMessage.create(MessageFlags.ADD.value, values) -def link_message(n1, n2, intf_one=None, address_one=None, intf_two=None, address_two=None): +def link_message(n1, n2, intf_one=None, address_one=None, intf_two=None, address_two=None, key=None): """ Convenience method for creating link TLV messages. @@ -72,6 +72,7 @@ def link_message(n1, n2, intf_one=None, address_one=None, intf_two=None, address :param core.misc.ipaddress.IpAddress address_one: node one ip4 address :param int intf_two: node two interface id :param core.misc.ipaddress.IpAddress address_two: node two ip4 address + :param int key: tunnel key for link if needed :return: tlv mesage :rtype: core.api.coreapi.CoreLinkMessage """ @@ -81,7 +82,7 @@ def link_message(n1, n2, intf_one=None, address_one=None, intf_two=None, address if address_two: mac_two = MacAddress.random() - return CoreLinkMessage.create(MessageFlags.ADD.value, [ + values = [ (LinkTlvs.N1_NUMBER, n1), (LinkTlvs.N2_NUMBER, n2), (LinkTlvs.DELAY, 0), @@ -98,7 +99,12 @@ def link_message(n1, n2, intf_one=None, address_one=None, intf_two=None, address (LinkTlvs.INTERFACE2_IP4, address_two), (LinkTlvs.INTERFACE2_IP4_MASK, 24), (LinkTlvs.INTERFACE2_MAC, mac_two), - ]) + ] + + if key: + values.append((LinkTlvs.KEY, key)) + + return CoreLinkMessage.create(MessageFlags.ADD.value, values) def command_message(node, command): @@ -258,6 +264,9 @@ class CoreServerTest(object): self.request_handler = None def setup(self, distributed_address): + # validate address + assert distributed_address, "distributed server address was not provided" + # create session self.session = self.server.create_session(1) self.session.master = True diff --git a/daemon/tests/test_distributed.py b/daemon/tests/test_distributed.py index dc36d62d..1a8b5d9f 100644 --- a/daemon/tests/test_distributed.py +++ b/daemon/tests/test_distributed.py @@ -9,6 +9,7 @@ from core.enumerations import EventTypes from core.enumerations import ExecuteTlvs from core.enumerations import MessageFlags from core.enumerations import NodeTypes +from core.misc.ipaddress import IpAddress def validate_response(replies, _): @@ -29,25 +30,26 @@ def validate_response(replies, _): class TestDistributed: def test_distributed(self, cored, distributed_address): """ - Test session broker creation. + Test creating a distributed network. :param core.coreserver.CoreServer conftest.Core cored: core daemon server to test with :param str distributed_address: distributed server to test against """ - - assert distributed_address, "distributed server address was not provided" - # initialize server for testing cored.setup(distributed_address) # create local node - message = conftest.node_message(1, "n1", model="host") + message = conftest.node_message( + objid=1, + name="n1", + model="host" + ) cored.request_handler.handle_message(message) # create distributed node and assign to distributed server message = conftest.node_message( - 2, - "n2", + objid=2, + name="n2", emulation_server=cored.distributed_server, model="host" ) @@ -55,8 +57,8 @@ class TestDistributed: # create distributed switch and assign to distributed server message = conftest.node_message( - 3, - "n3", + objid=3, + name="n3", emulation_server=cored.distributed_server, node_type=NodeTypes.SWITCH ) @@ -64,12 +66,22 @@ class TestDistributed: # link message one ip4_address = cored.prefix.addr(1) - message = conftest.link_message(1, 3, intf_one=0, address_one=ip4_address) + message = conftest.link_message( + n1=1, + n2=3, + intf_one=0, + address_one=ip4_address + ) cored.request_handler.handle_message(message) # link message two ip4_address = cored.prefix.addr(2) - message = conftest.link_message(3, 2, intf_two=0, address_two=ip4_address) + message = conftest.link_message( + n1=3, + n2=2, + intf_two=0, + address_two=ip4_address + ) cored.request_handler.handle_message(message) # change session to instantiation state @@ -84,25 +96,26 @@ class TestDistributed: def test_prouter(self, cored, distributed_address): """ - Test session broker creation. + Test creating a distributed prouter node. :param core.coreserver.CoreServer conftest.Core cored: core daemon server to test with :param str distributed_address: distributed server to test against """ - - assert distributed_address, "distributed server address was not provided" - # initialize server for testing cored.setup(distributed_address) # create local node - message = conftest.node_message(1, "n1", model="host") + message = conftest.node_message( + objid=1, + name="n1", + model="host" + ) cored.request_handler.handle_message(message) # create distributed node and assign to distributed server message = conftest.node_message( - 2, - "n2", + objid=2, + name="n2", emulation_server=cored.distributed_server, node_type=NodeTypes.PHYSICAL, model="prouter" @@ -111,20 +124,30 @@ class TestDistributed: # create distributed switch and assign to distributed server message = conftest.node_message( - 3, - "n3", + objid=3, + name="n3", node_type=NodeTypes.SWITCH ) cored.request_handler.handle_message(message) # link message one ip4_address = cored.prefix.addr(1) - message = conftest.link_message(1, 3, intf_one=0, address_one=ip4_address) + message = conftest.link_message( + n1=1, + n2=3, + intf_one=0, + address_one=ip4_address + ) cored.request_handler.handle_message(message) # link message two ip4_address = cored.prefix.addr(2) - message = conftest.link_message(3, 2, intf_two=0, address_two=ip4_address) + message = conftest.link_message( + n1=3, + n2=2, + intf_two=0, + address_two=ip4_address + ) cored.request_handler.handle_message(message) # change session to instantiation state @@ -137,3 +160,48 @@ class TestDistributed: cored.request_handler.dispatch_replies = validate_response cored.request_handler.handle_message(message) cored.request_handler.handle_message(message) + + def test_tunnel(self, cored, distributed_address): + """ + Test session broker creation. + + :param core.coreserver.CoreServer conftest.Core cored: core daemon server to test with + :param str distributed_address: distributed server to test against + """ + # initialize server for testing + cored.setup(distributed_address) + + # create local node + message = conftest.node_message( + objid=1, + name="n1", + model="host" + ) + cored.request_handler.handle_message(message) + + # create distributed node and assign to distributed server + message = conftest.node_message( + objid=2, + name=distributed_address, + emulation_server=cored.distributed_server, + node_type=NodeTypes.TUNNEL + ) + cored.request_handler.handle_message(message) + + # link message one + ip4_address = cored.prefix.addr(1) + address_two = IpAddress.from_string(distributed_address) + message = conftest.link_message( + n1=1, + n2=2, + intf_one=0, + address_one=ip4_address, + intf_two=0, + address_two=address_two, + key=1 + ) + cored.request_handler.handle_message(message) + + # change session to instantiation state + message = conftest.state_message(EventTypes.INSTANTIATION_STATE) + cored.request_handler.handle_message(message)