...
 
Commits (46)
......@@ -8,3 +8,8 @@ netns-bin/netns_run
netlab/bird6/bird*
netlab/bird4/bird*
netlab-int/cf-ospf/__pycache__
netlab-int/tests/__pycache__
netlab-int/.NOTES.md
192.168.1.0/24 dev ve0 proto kernel scope link src 192.168.1.1
192.168.1.0/24 dev ve0 proto bird scope link metric 32
192.168.11.0/24 dev ve1 proto kernel scope link src 192.168.11.1
192.168.11.0/24 dev ve1 proto bird scope link metric 32
192.168.14.0/24 dev ve2 proto kernel scope link src 192.168.14.2
192.168.14.0/24 dev ve2 proto bird scope link metric 32
192.168.2.0/24 dev ve0 proto kernel scope link src 192.168.2.1
192.168.2.0/24 dev ve0 proto bird scope link metric 32
192.168.11.0/24 dev ve2 proto kernel scope link src 192.168.11.2
192.168.11.0/24 dev ve2 proto bird scope link metric 32
192.168.12.0/24 dev ve1 proto kernel scope link src 192.168.12.1
192.168.12.0/24 dev ve1 proto bird scope link metric 32
192.168.3.0/24 dev ve0 proto kernel scope link src 192.168.3.1
192.168.3.0/24 dev ve0 proto bird scope link metric 32
192.168.12.0/24 dev ve2 proto kernel scope link src 192.168.12.2
192.168.12.0/24 dev ve2 proto bird scope link metric 32
192.168.13.0/24 dev ve1 proto kernel scope link src 192.168.13.1
192.168.13.0/24 dev ve1 proto bird scope link metric 32
192.168.4.0/24 dev ve0 proto kernel scope link src 192.168.4.1
192.168.4.0/24 dev ve0 proto bird scope link metric 32
192.168.13.0/24 dev ve2 proto kernel scope link src 192.168.13.2
192.168.13.0/24 dev ve2 proto bird scope link metric 32
192.168.14.0/24 dev ve1 proto kernel scope link src 192.168.14.1
192.168.14.0/24 dev ve1 proto bird scope link metric 32
#!/usr/bin/env python3
import sys
import time
import pytest
import argparse
sys.path.insert(0, 'tests')
import support_functions as sf
protocol = sys.argv[1]
state = sys.argv[2]
if state == 'save':
time.sleep(4)
sf.create_folder()
sf.number_of_devs(sf.devices)
sf.get_tables(sf.devices)
elif state == 'check':
time.sleep(4)
pytest.main(["-v", "tests/test_support_functions.py"])
sf.clear_temp()
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('protocol')
parser.add_argument('state')
args = parser.parse_args()
cf-ospf
\ No newline at end of file
#!/bin/bash
while getopts ":p:s:" OPTION; do
case "${OPTION}" in
p)
PROTOCOL=${OPTARG}
;;
s)
STATE=${OPTARG}
if [ $STATE == 'save' ]; then
./start -c $PROTOCOL
python3 $PROTOCOL/test_case.py $PROTOCOL $STATE
./stop
elif [ $STATE == 'check' ]; then
./start -c $PROTOCOL
python3 $PROTOCOL/test_case.py $PROTOCOL $STATE
./stop
fi
;;
esac
done
#!/bin/bash
. netlab_lib
while getopts ":c:h:" OPTION; do
case "${OPTION}" in
c)
CONF=${OPTARG}
if [ -d "$CONF" ]; then
echo -e "Creating symlink config --> $CONF\n"
ln -s "${CONF}" config
. netlab_lib
. config/config
else
echo "Incorrect name of protocol"
fi
;;
. config/config
h|--h)
echo -e "USAGE: $0 [-c <cf-ospf|cf-babel|...> ]\n"
;;
esac
done
......@@ -3,3 +3,5 @@
. netlab_lib
netlab_stop
unlink config
#!/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