daemon: initial pass to revamp how node linking and link management is done, provides a consistent way to link all wired nodes and allows them to be configured for tc for the same behavior across the board
This commit is contained in:
parent
d684b8eb5a
commit
cd7f1a641e
19 changed files with 1393 additions and 1556 deletions
|
@ -46,14 +46,17 @@ class TestLinks:
|
|||
)
|
||||
|
||||
# then
|
||||
assert len(session.link_manager.links()) == 1
|
||||
assert node1.get_iface(iface1_data.id)
|
||||
assert node2.get_iface(iface2_data.id)
|
||||
assert iface1 is not None
|
||||
assert iface1.options == LINK_OPTIONS
|
||||
assert iface1.has_netem
|
||||
assert node1.get_iface(iface1_data.id)
|
||||
assert iface2 is not None
|
||||
assert iface1.local_options == LINK_OPTIONS
|
||||
assert iface1.has_local_netem
|
||||
assert iface2.local_options == LINK_OPTIONS
|
||||
assert iface2.has_local_netem
|
||||
assert iface2.options == LINK_OPTIONS
|
||||
assert iface2.has_netem
|
||||
assert node1.get_iface(iface1_data.id)
|
||||
|
||||
def test_add_node_to_net(self, session: Session, ip_prefixes: IpPrefixes):
|
||||
# given
|
||||
|
@ -62,16 +65,20 @@ class TestLinks:
|
|||
iface1_data = ip_prefixes.create_iface(node1)
|
||||
|
||||
# when
|
||||
iface, _ = session.add_link(
|
||||
iface1, iface2 = session.add_link(
|
||||
node1.id, node2.id, iface1_data=iface1_data, options=LINK_OPTIONS
|
||||
)
|
||||
|
||||
# then
|
||||
assert node2.links()
|
||||
assert len(session.link_manager.links()) == 1
|
||||
assert iface1 is not None
|
||||
assert iface1.options == LINK_OPTIONS
|
||||
assert iface1.has_netem
|
||||
assert node1.get_iface(iface1_data.id)
|
||||
assert iface is not None
|
||||
assert iface.local_options == LINK_OPTIONS
|
||||
assert iface.has_local_netem
|
||||
assert iface2 is not None
|
||||
assert iface2.options == LINK_OPTIONS
|
||||
assert iface2.has_netem
|
||||
assert node2.get_iface(iface1_data.id)
|
||||
|
||||
def test_add_net_to_node(self, session: Session, ip_prefixes: IpPrefixes):
|
||||
# given
|
||||
|
@ -80,32 +87,37 @@ class TestLinks:
|
|||
iface2_data = ip_prefixes.create_iface(node2)
|
||||
|
||||
# when
|
||||
_, iface = session.add_link(
|
||||
iface1, iface2 = session.add_link(
|
||||
node1.id, node2.id, iface2_data=iface2_data, options=LINK_OPTIONS
|
||||
)
|
||||
|
||||
# then
|
||||
assert node1.links()
|
||||
assert node2.get_iface(iface2_data.id)
|
||||
assert iface is not None
|
||||
assert iface.local_options == LINK_OPTIONS
|
||||
assert iface.has_local_netem
|
||||
assert len(session.link_manager.links()) == 1
|
||||
assert iface1 is not None
|
||||
assert iface1.options == LINK_OPTIONS
|
||||
assert iface1.has_netem
|
||||
assert node1.get_iface(iface1.id)
|
||||
assert iface2 is not None
|
||||
assert iface2.options == LINK_OPTIONS
|
||||
assert iface2.has_netem
|
||||
assert node2.get_iface(iface2.id)
|
||||
|
||||
def test_add_net_to_net(self, session):
|
||||
def test_add_net_to_net(self, session: Session):
|
||||
# given
|
||||
node1 = session.add_node(SwitchNode)
|
||||
node2 = session.add_node(SwitchNode)
|
||||
|
||||
# when
|
||||
iface, _ = session.add_link(node1.id, node2.id, options=LINK_OPTIONS)
|
||||
iface1, iface2 = session.add_link(node1.id, node2.id, options=LINK_OPTIONS)
|
||||
|
||||
# then
|
||||
assert node1.links()
|
||||
assert iface is not None
|
||||
assert iface.local_options == LINK_OPTIONS
|
||||
assert iface.options == LINK_OPTIONS
|
||||
assert iface.has_local_netem
|
||||
assert iface.has_netem
|
||||
assert len(session.link_manager.links()) == 1
|
||||
assert iface1 is not None
|
||||
assert iface1.options == LINK_OPTIONS
|
||||
assert iface1.has_netem
|
||||
assert iface2 is not None
|
||||
assert iface2.options == LINK_OPTIONS
|
||||
assert iface2.has_netem
|
||||
|
||||
def test_add_node_to_node_uni(self, session: Session, ip_prefixes: IpPrefixes):
|
||||
# given
|
||||
|
@ -141,48 +153,52 @@ class TestLinks:
|
|||
)
|
||||
|
||||
# then
|
||||
assert len(session.link_manager.links()) == 1
|
||||
assert node1.get_iface(iface1_data.id)
|
||||
assert node2.get_iface(iface2_data.id)
|
||||
assert iface1 is not None
|
||||
assert iface1.options == link_options1
|
||||
assert iface1.has_netem
|
||||
assert iface2 is not None
|
||||
assert iface1.local_options == link_options1
|
||||
assert iface1.has_local_netem
|
||||
assert iface2.local_options == link_options2
|
||||
assert iface2.has_local_netem
|
||||
assert iface2.options == link_options2
|
||||
assert iface2.has_netem
|
||||
|
||||
def test_update_node_to_net(self, session: Session, ip_prefixes: IpPrefixes):
|
||||
# given
|
||||
node1 = session.add_node(CoreNode)
|
||||
node2 = session.add_node(SwitchNode)
|
||||
iface1_data = ip_prefixes.create_iface(node1)
|
||||
iface1, _ = session.add_link(node1.id, node2.id, iface1_data)
|
||||
assert iface1.local_options != LINK_OPTIONS
|
||||
iface1, iface2 = session.add_link(node1.id, node2.id, iface1_data)
|
||||
assert len(session.link_manager.links()) == 1
|
||||
assert iface1.options != LINK_OPTIONS
|
||||
assert iface2.options != LINK_OPTIONS
|
||||
|
||||
# when
|
||||
session.update_link(
|
||||
node1.id, node2.id, iface1_id=iface1_data.id, options=LINK_OPTIONS
|
||||
)
|
||||
session.update_link(node1.id, node2.id, iface1.id, iface2.id, LINK_OPTIONS)
|
||||
|
||||
# then
|
||||
assert iface1.local_options == LINK_OPTIONS
|
||||
assert iface1.has_local_netem
|
||||
assert iface1.options == LINK_OPTIONS
|
||||
assert iface1.has_netem
|
||||
assert iface2.options == LINK_OPTIONS
|
||||
assert iface2.has_netem
|
||||
|
||||
def test_update_net_to_node(self, session: Session, ip_prefixes: IpPrefixes):
|
||||
# given
|
||||
node1 = session.add_node(SwitchNode)
|
||||
node2 = session.add_node(CoreNode)
|
||||
iface2_data = ip_prefixes.create_iface(node2)
|
||||
_, iface2 = session.add_link(node1.id, node2.id, iface2_data=iface2_data)
|
||||
assert iface2.local_options != LINK_OPTIONS
|
||||
iface1, iface2 = session.add_link(node1.id, node2.id, iface2_data=iface2_data)
|
||||
assert iface1.options != LINK_OPTIONS
|
||||
assert iface2.options != LINK_OPTIONS
|
||||
|
||||
# when
|
||||
session.update_link(
|
||||
node1.id, node2.id, iface2_id=iface2_data.id, options=LINK_OPTIONS
|
||||
)
|
||||
session.update_link(node1.id, node2.id, iface1.id, iface2.id, LINK_OPTIONS)
|
||||
|
||||
# then
|
||||
assert iface2.local_options == LINK_OPTIONS
|
||||
assert iface2.has_local_netem
|
||||
assert iface1.options == LINK_OPTIONS
|
||||
assert iface1.has_netem
|
||||
assert iface2.options == LINK_OPTIONS
|
||||
assert iface2.has_netem
|
||||
|
||||
def test_update_ptp(self, session: Session, ip_prefixes: IpPrefixes):
|
||||
# given
|
||||
|
@ -191,55 +207,68 @@ class TestLinks:
|
|||
iface1_data = ip_prefixes.create_iface(node1)
|
||||
iface2_data = ip_prefixes.create_iface(node2)
|
||||
iface1, iface2 = session.add_link(node1.id, node2.id, iface1_data, iface2_data)
|
||||
assert iface1.local_options != LINK_OPTIONS
|
||||
assert iface2.local_options != LINK_OPTIONS
|
||||
assert iface1.options != LINK_OPTIONS
|
||||
assert iface2.options != LINK_OPTIONS
|
||||
|
||||
# when
|
||||
session.update_link(
|
||||
node1.id, node2.id, iface1_data.id, iface2_data.id, LINK_OPTIONS
|
||||
)
|
||||
session.update_link(node1.id, node2.id, iface1.id, iface2.id, LINK_OPTIONS)
|
||||
|
||||
# then
|
||||
assert iface1.local_options == LINK_OPTIONS
|
||||
assert iface1.has_local_netem
|
||||
assert iface2.local_options == LINK_OPTIONS
|
||||
assert iface2.has_local_netem
|
||||
assert iface1.options == LINK_OPTIONS
|
||||
assert iface1.has_netem
|
||||
assert iface2.options == LINK_OPTIONS
|
||||
assert iface2.has_netem
|
||||
|
||||
def test_update_net_to_net(self, session: Session, ip_prefixes: IpPrefixes):
|
||||
# given
|
||||
node1 = session.add_node(SwitchNode)
|
||||
node2 = session.add_node(SwitchNode)
|
||||
iface1, _ = session.add_link(node1.id, node2.id)
|
||||
assert iface1.local_options != LINK_OPTIONS
|
||||
iface1, iface2 = session.add_link(node1.id, node2.id)
|
||||
assert iface1.options != LINK_OPTIONS
|
||||
assert iface2.options != LINK_OPTIONS
|
||||
|
||||
# when
|
||||
session.update_link(node1.id, node2.id, options=LINK_OPTIONS)
|
||||
session.update_link(node1.id, node2.id, iface1.id, iface2.id, LINK_OPTIONS)
|
||||
|
||||
# then
|
||||
assert iface1.local_options == LINK_OPTIONS
|
||||
assert iface1.has_local_netem
|
||||
assert iface1.options == LINK_OPTIONS
|
||||
assert iface1.has_netem
|
||||
assert iface2.options == LINK_OPTIONS
|
||||
assert iface2.has_netem
|
||||
|
||||
def test_update_error(self, session: Session, ip_prefixes: IpPrefixes):
|
||||
# given
|
||||
node1 = session.add_node(CoreNode)
|
||||
node2 = session.add_node(CoreNode)
|
||||
iface1_data = ip_prefixes.create_iface(node1)
|
||||
iface2_data = ip_prefixes.create_iface(node2)
|
||||
iface1, iface2 = session.add_link(node1.id, node2.id, iface1_data, iface2_data)
|
||||
assert iface1.options != LINK_OPTIONS
|
||||
assert iface2.options != LINK_OPTIONS
|
||||
|
||||
# when
|
||||
with pytest.raises(CoreError):
|
||||
session.delete_link(node1.id, INVALID_ID, iface1.id, iface2.id)
|
||||
|
||||
def test_clear_net_to_net(self, session: Session, ip_prefixes: IpPrefixes):
|
||||
# given
|
||||
node1 = session.add_node(SwitchNode)
|
||||
node2 = session.add_node(SwitchNode)
|
||||
iface1, _ = session.add_link(node1.id, node2.id, options=LINK_OPTIONS)
|
||||
assert iface1.local_options == LINK_OPTIONS
|
||||
assert iface1.has_local_netem
|
||||
iface1, iface2 = session.add_link(node1.id, node2.id, options=LINK_OPTIONS)
|
||||
assert iface1.options == LINK_OPTIONS
|
||||
assert iface1.has_netem
|
||||
assert iface2.options == LINK_OPTIONS
|
||||
assert iface2.has_netem
|
||||
|
||||
# when
|
||||
options = LinkOptions(delay=0, bandwidth=0, loss=0.0, dup=0, jitter=0, buffer=0)
|
||||
session.update_link(node1.id, node2.id, options=options)
|
||||
session.update_link(node1.id, node2.id, iface1.id, iface2.id, options)
|
||||
|
||||
# then
|
||||
assert iface1.local_options.is_clear()
|
||||
assert not iface1.has_local_netem
|
||||
assert iface1.options.is_clear()
|
||||
assert not iface1.has_netem
|
||||
assert iface2.options.is_clear()
|
||||
assert not iface2.has_netem
|
||||
|
||||
def test_delete_node_to_node(self, session: Session, ip_prefixes: IpPrefixes):
|
||||
# given
|
||||
|
@ -247,82 +276,100 @@ class TestLinks:
|
|||
node2 = session.add_node(CoreNode)
|
||||
iface1_data = ip_prefixes.create_iface(node1)
|
||||
iface2_data = ip_prefixes.create_iface(node2)
|
||||
session.add_link(node1.id, node2.id, iface1_data, iface2_data)
|
||||
assert node1.get_iface(iface1_data.id)
|
||||
assert node2.get_iface(iface2_data.id)
|
||||
iface1, iface2 = session.add_link(node1.id, node2.id, iface1_data, iface2_data)
|
||||
assert len(session.link_manager.links()) == 1
|
||||
assert node1.get_iface(iface1.id)
|
||||
assert node2.get_iface(iface2.id)
|
||||
|
||||
# when
|
||||
session.delete_link(node1.id, node2.id, iface1_data.id, iface2_data.id)
|
||||
session.delete_link(node1.id, node2.id, iface1.id, iface2.id)
|
||||
|
||||
# then
|
||||
assert iface1_data.id not in node1.ifaces
|
||||
assert iface2_data.id not in node2.ifaces
|
||||
assert len(session.link_manager.links()) == 0
|
||||
assert iface1.id not in node1.ifaces
|
||||
assert iface2.id not in node2.ifaces
|
||||
|
||||
def test_delete_node_to_net(self, session: Session, ip_prefixes: IpPrefixes):
|
||||
# given
|
||||
node1 = session.add_node(CoreNode)
|
||||
node2 = session.add_node(SwitchNode)
|
||||
iface1_data = ip_prefixes.create_iface(node1)
|
||||
session.add_link(node1.id, node2.id, iface1_data)
|
||||
assert node1.get_iface(iface1_data.id)
|
||||
iface1, iface2 = session.add_link(node1.id, node2.id, iface1_data)
|
||||
assert len(session.link_manager.links()) == 1
|
||||
assert node1.get_iface(iface1.id)
|
||||
assert node2.get_iface(iface2.id)
|
||||
|
||||
# when
|
||||
session.delete_link(node1.id, node2.id, iface1_id=iface1_data.id)
|
||||
session.delete_link(node1.id, node2.id, iface1.id, iface2.id)
|
||||
|
||||
# then
|
||||
assert iface1_data.id not in node1.ifaces
|
||||
assert len(session.link_manager.links()) == 0
|
||||
assert iface1.id not in node1.ifaces
|
||||
assert iface2.id not in node2.ifaces
|
||||
|
||||
def test_delete_net_to_node(self, session: Session, ip_prefixes: IpPrefixes):
|
||||
# given
|
||||
node1 = session.add_node(SwitchNode)
|
||||
node2 = session.add_node(CoreNode)
|
||||
iface2_data = ip_prefixes.create_iface(node2)
|
||||
session.add_link(node1.id, node2.id, iface2_data=iface2_data)
|
||||
assert node2.get_iface(iface2_data.id)
|
||||
iface1, iface2 = session.add_link(node1.id, node2.id, iface2_data=iface2_data)
|
||||
assert len(session.link_manager.links()) == 1
|
||||
assert node1.get_iface(iface1.id)
|
||||
assert node2.get_iface(iface2.id)
|
||||
|
||||
# when
|
||||
session.delete_link(node1.id, node2.id, iface2_id=iface2_data.id)
|
||||
session.delete_link(node1.id, node2.id, iface1.id, iface2.id)
|
||||
|
||||
# then
|
||||
assert iface2_data.id not in node2.ifaces
|
||||
assert len(session.link_manager.links()) == 0
|
||||
assert iface1.id not in node1.ifaces
|
||||
assert iface2.id not in node2.ifaces
|
||||
|
||||
def test_delete_net_to_net(self, session: Session, ip_prefixes: IpPrefixes):
|
||||
# given
|
||||
node1 = session.add_node(SwitchNode)
|
||||
node2 = session.add_node(SwitchNode)
|
||||
session.add_link(node1.id, node2.id)
|
||||
assert node1.get_linked_iface(node2)
|
||||
iface1, iface2 = session.add_link(node1.id, node2.id)
|
||||
assert len(session.link_manager.links()) == 1
|
||||
assert node1.get_iface(iface1.id)
|
||||
assert node2.get_iface(iface2.id)
|
||||
|
||||
# when
|
||||
session.delete_link(node1.id, node2.id)
|
||||
session.delete_link(node1.id, node2.id, iface1.id, iface2.id)
|
||||
|
||||
# then
|
||||
assert not node1.get_linked_iface(node2)
|
||||
assert len(session.link_manager.links()) == 0
|
||||
assert iface1.id not in node1.ifaces
|
||||
assert iface2.id not in node2.ifaces
|
||||
|
||||
def test_delete_node_error(self, session: Session, ip_prefixes: IpPrefixes):
|
||||
# given
|
||||
node1 = session.add_node(SwitchNode)
|
||||
node2 = session.add_node(SwitchNode)
|
||||
session.add_link(node1.id, node2.id)
|
||||
assert node1.get_linked_iface(node2)
|
||||
iface1, iface2 = session.add_link(node1.id, node2.id)
|
||||
assert len(session.link_manager.links()) == 1
|
||||
assert node1.get_iface(iface1.id)
|
||||
assert node2.get_iface(iface2.id)
|
||||
|
||||
# when
|
||||
with pytest.raises(CoreError):
|
||||
session.delete_link(node1.id, INVALID_ID)
|
||||
session.delete_link(node1.id, INVALID_ID, iface1.id, iface2.id)
|
||||
with pytest.raises(CoreError):
|
||||
session.delete_link(INVALID_ID, node2.id)
|
||||
session.delete_link(INVALID_ID, node2.id, iface1.id, iface2.id)
|
||||
|
||||
def test_delete_net_to_net_error(self, session: Session, ip_prefixes: IpPrefixes):
|
||||
# given
|
||||
node1 = session.add_node(SwitchNode)
|
||||
node2 = session.add_node(SwitchNode)
|
||||
node3 = session.add_node(SwitchNode)
|
||||
session.add_link(node1.id, node2.id)
|
||||
assert node1.get_linked_iface(node2)
|
||||
iface1, iface2 = session.add_link(node1.id, node2.id)
|
||||
assert len(session.link_manager.links()) == 1
|
||||
assert node1.get_iface(iface1.id)
|
||||
assert node2.get_iface(iface2.id)
|
||||
|
||||
# when
|
||||
with pytest.raises(CoreError):
|
||||
session.delete_link(node1.id, node3.id)
|
||||
session.delete_link(node1.id, node3.id, iface1.id, iface2.id)
|
||||
|
||||
def test_delete_node_to_net_error(self, session: Session, ip_prefixes: IpPrefixes):
|
||||
# given
|
||||
|
@ -330,12 +377,14 @@ class TestLinks:
|
|||
node2 = session.add_node(SwitchNode)
|
||||
node3 = session.add_node(SwitchNode)
|
||||
iface1_data = ip_prefixes.create_iface(node1)
|
||||
iface1, _ = session.add_link(node1.id, node2.id, iface1_data)
|
||||
assert iface1
|
||||
iface1, iface2 = session.add_link(node1.id, node2.id, iface1_data)
|
||||
assert len(session.link_manager.links()) == 1
|
||||
assert node1.get_iface(iface1.id)
|
||||
assert node2.get_iface(iface2.id)
|
||||
|
||||
# when
|
||||
with pytest.raises(CoreError):
|
||||
session.delete_link(node1.id, node3.id)
|
||||
session.delete_link(node1.id, node3.id, iface1.id, iface2.id)
|
||||
|
||||
def test_delete_net_to_node_error(self, session: Session, ip_prefixes: IpPrefixes):
|
||||
# given
|
||||
|
@ -343,12 +392,14 @@ class TestLinks:
|
|||
node2 = session.add_node(CoreNode)
|
||||
node3 = session.add_node(SwitchNode)
|
||||
iface2_data = ip_prefixes.create_iface(node2)
|
||||
_, iface2 = session.add_link(node1.id, node2.id, iface2_data=iface2_data)
|
||||
assert iface2
|
||||
iface1, iface2 = session.add_link(node1.id, node2.id, iface2_data=iface2_data)
|
||||
assert len(session.link_manager.links()) == 1
|
||||
assert node1.get_iface(iface1.id)
|
||||
assert node2.get_iface(iface2.id)
|
||||
|
||||
# when
|
||||
with pytest.raises(CoreError):
|
||||
session.delete_link(node1.id, node3.id)
|
||||
session.delete_link(node1.id, node3.id, iface1.id, iface2.id)
|
||||
|
||||
def test_delete_node_to_node_error(self, session: Session, ip_prefixes: IpPrefixes):
|
||||
# given
|
||||
|
@ -358,9 +409,10 @@ class TestLinks:
|
|||
iface1_data = ip_prefixes.create_iface(node1)
|
||||
iface2_data = ip_prefixes.create_iface(node2)
|
||||
iface1, iface2 = session.add_link(node1.id, node2.id, iface1_data, iface2_data)
|
||||
assert iface1
|
||||
assert iface2
|
||||
assert len(session.link_manager.links()) == 1
|
||||
assert node1.get_iface(iface1.id)
|
||||
assert node2.get_iface(iface2.id)
|
||||
|
||||
# when
|
||||
with pytest.raises(CoreError):
|
||||
session.delete_link(node1.id, node3.id)
|
||||
session.delete_link(node1.id, node3.id, iface1.id, iface2.id)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue