added a simple test for a tunnel node, although better testing awwma to require configuration outside of core
This commit is contained in:
parent
b62076c240
commit
d915436c7d
3 changed files with 102 additions and 26 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue