Commit 107ce275 authored by Matous Holinka's avatar Matous Holinka

netlab: added file with simple tests

parent e118efee
#!/usr/share/python3
import os
protocol = 'cf-ospf'
def get_route_tables(prot):
"""
Save the txt tables into the proper directory
> In the future: Name of the device should be more specific than m1
(maX or mbX etc. )
"""
print('\n\nWRITTING ROUTE TABLES INTO:')
for n in range(1, 5):
os.system(f'ip netns exec m{n} ip route show > {prot}/out_m{n}.txt')
print(f'...out_m{n}.txt --> DONE!')
print('\nALL TABLES ARE COMPLETE')
get_route_tables(protocol)
#!/usr/share/python3
import os
import pytest
import get_table
def test_any_tables():
"""
Is there any file {protocol}/out.txt?
>>> raise exception
"""
with pytest.raises(FileNotFoundError):
file = open(f'../{get_table.protocol}/out.txt', 'r')
def test_all_tables():
"""
Are there all files .txt?
>>> Check if there is the list of names
"""
all_txts = os.listdir(f'{get_table.protocol}/')
outpts = [
'out_m1.txt',
'out_m2.txt',
'out_m3.txt',
'out_m4.txt'
]
for file in outpts:
assert file in all_txts
def test_target_in_tables():
"""
+ Initial test for routing tables
+ The first address should be equal to the variable *target*
"""
target = '192.168.1.0/24'
with open(f'{get_table.protocol}/out_m1.txt', 'r') as t1:
loaded = t1.readlines()
assert target in loaded[0]
def test_target_not_in_tables():
"""
+ Test with the specific incorrect address
+ Result should be *not in tables*
"""
inc_targ = '255.255.255.0/24'
with open(f'{get_table.protocol}/out_m1.txt', 'r') as t1:
loaded = t1.readlines()
assert inc_targ not in loaded[0]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment