import pytest from utils import require_user from pr2test.tools import interface_exists from pr2test.context_manager import make_test_matrix from pyroute2 import NDB test_matrix = make_test_matrix( targets=['local', 'netns'], dbs=['sqlite3/:memory:', 'postgres/pr2test'] ) def test_multiple_sources(context): ''' NDB should work with multiple netlink sources Check that it actually works: * with multiple sources of different kind * without the default "localhost" RTNL source ''' nsname = context.new_nsname # # NB: no 'localhost' record -- important ! sources = [ {'target': 'localhost0', 'kind': 'local'}, {'target': 'localhost1', 'kind': 'netns', 'netns': nsname}, {'target': 'localhost2', 'kind': 'local'}, ] ndb = None #
import uuid import pytest from pyroute2 import NDB from pr2test.tools import interface_exists from pr2test.tools import address_exists from pr2test.context_manager import make_test_matrix test_matrix = make_test_matrix(dbs=['sqlite3/:memory:', 'postgres/pr2test']) @pytest.mark.parametrize('context', test_matrix, indirect=True) def test_move(context): ifname = context.new_ifname ifaddr = context.new_ipaddr nsname = context.new_nsname context.ndb.sources.add(netns=nsname) # create the interface (context.ndb.interfaces.create(ifname=ifname, kind='dummy').commit()) # move it to a netns (context.ndb.interfaces[ifname].set('net_ns_fd', nsname).commit()) # setup the interface only when it is moved (context.ndb.interfaces.wait(target=nsname, ifname=ifname).set( 'state', 'up').set('address', '00:11:22:33:44:55').add_ip('%s/24' % ifaddr).commit()) assert interface_exists(nsname,
import pytest from pr2test.tools import interface_exists from pr2test.context_manager import make_test_matrix tnl_matrix = make_test_matrix( targets=['local', 'netns'], types=['gre', 'ipip', 'sit'], dbs=['sqlite3/:memory:', 'postgres/pr2test'], ) def _test_tunnel_endpoints(context, state): ifname = context.new_ifname ipaddr_local1 = context.new_ipaddr ipaddr_local2 = context.new_ipaddr ipaddr_remote = context.new_ipaddr kind = context.kind (context.ndb.interfaces.create( **{ 'ifname': ifname, 'state': state, 'kind': kind, f'{kind}_local': ipaddr_local1, f'{kind}_remote': ipaddr_remote, }).commit()) def match(ifname, ipaddr): return (lambda x: x.get_nested('IFLA_LINKINFO', 'IFLA_INFO_KIND') == kind and x.get_attr('IFLA_IFNAME') == ifname and x.get_nested( 'IFLA_LINKINFO',
import time import pytest from pr2test.context_manager import make_test_matrix from pr2test.context_manager import skip_if_not_supported wait_timeout = 30 test_matrix = make_test_matrix(targets=['local', 'netns']) @pytest.mark.parametrize('context', test_matrix, indirect=True) @skip_if_not_supported def test_addr_add(context): index, ifname = context.default_interface ipaddr = context.new_ipaddr ipr = context.ipr ndb = context.ndb ipr.addr('add', index=index, address=ipaddr, prefixlen=24) ndb.addresses.wait(index=index, address=ipaddr, timeout=wait_timeout) @pytest.mark.parametrize('context', test_matrix, indirect=True) @skip_if_not_supported def test_addr_replace(context): index, ifname = context.default_interface ipaddr1 = context.new_ipaddr ipaddr2 = context.new_ipaddr ipr = context.ipr ndb = context.ndb ipr.addr('add', index=index, address=ipaddr1, prefixlen=24)
import random import pytest from pr2test.tools import route_exists from pr2test.tools import address_exists from pr2test.tools import interface_exists from pr2test.context_manager import make_test_matrix from pyroute2.netlink.rtnl.rtmsg import rtmsg test_matrix = make_test_matrix(targets=['local', 'netns'], tables=[None, 501, 5001], dbs=['sqlite3/:memory:', 'postgres/pr2test']) @pytest.mark.parametrize('context', test_matrix, indirect=True) def test_basic(context): ifaddr = context.new_ipaddr router = context.new_ipaddr ifname = context.new_ifname ipnet = str(context.ipnets[1].network) table = context.table (context .ndb .interfaces .create(ifname=ifname, kind='dummy', state='up') .ipaddr .create(address=ifaddr, prefixlen=24) .commit())