Commit 284bb418 authored by Matous Holinka's avatar Matous Holinka

Netlab: folder *tests* contains 2 new py-files.

parent 7a86833c
#!/usr/bin/env python3
import os
import re
import sys
import argparse
devices = []
protocol = sys.argv[1]
def create_folder():
"""Create new folder if there is none"""
try:
os.mkdir(f'{protocol}/data')
except FileExistsError:
print(f'Already exists, continue with the existing\n')
def number_of_devs(dev):
"""Get number of devices"""
for _ in os.listdir():
pattern = str(re.findall(r'[m][\d{1}]', _)).strip('[\"\']')
pattern.replace('n', '')
if pattern != '':
dev.append(pattern)
print(f'Loaded devs --> {dev}')
return dev
def get_tables(dev):
"""Get tables and save them as referencial data"""
for _ in devices:
os.system(f'ip netns exec {_} ip route show > \
{protocol}/data/{protocol}_table_{_}.txt'
)
print(f'{protocol}_table_{_}.txt')
print()
def clear_temp():
"""Remove checking tables"""
for _ in os.listdir('temp/'):
if 'checking_table' in _:
print(f'Removing file {_}')
os.remove(f'temp/{_}')
print()
if __name__ == '__main__':
create_folder()
number_of_devs(devices)
get_table(devices)
clear_temp()
#!/usr/bin/env python3
import re
import os
import pytest
def test_create_folder():
"""Check if there is any folder with the tables*"""
assert 'data' in os.listdir(f'cf-ospf/')
def test_number_of_devs():
"""Check the number of devices match to the tables"""
num_of_devices = []
for _ in os.listdir('cf-ospf/data/'):
pattern = str(re.findall(r'[m][\d{1}]', _)).strip('[\"\']')
pattern.replace('n', '')
if pattern != '':
num_of_devices.append(pattern)
num_of_tables = len(os.listdir(f'cf-ospf/data/'))
assert len(num_of_devices) == num_of_tables
def test_get_tables():
"""Check the content of actual tables and the original"""
stack1, stack2 = [], []
for num in range(1, 5):
os.system(f'ip netns exec m{num} ip route show > temp/checking_table_m{num}')
with open(f'temp/checking_table_m{num}', 'r') as rt1:
for i, line in enumerate(rt1.readlines(), 1):
stack1.append((i, line))
with open(f'cf-ospf/data/cf-ospf_table_m{num}.txt', 'r') as rt2:
for j, line in enumerate(rt2.readlines(), 1):
stack2.append((j, line))
for n, _ in enumerate(stack1):
try:
assert stack1[n] == stack2[n]
except IndexError:
continue
def test_clear_temp():
"""Check if there are any files in temp"""
assert len(os.listdir()) != 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