diff --git a/libvirt/tests/cfg/virtual_network/network/elements_and_attributes/static_route.cfg b/libvirt/tests/cfg/virtual_network/network/elements_and_attributes/static_route.cfg new file mode 100644 index 0000000000..a8faa84384 --- /dev/null +++ b/libvirt/tests/cfg/virtual_network/network/elements_and_attributes/static_route.cfg @@ -0,0 +1,12 @@ +- virtual_network.network.static_route: + type = static_route + start_vm = "no" + variants: + - start_test: + net_name = "network_def" + net_attrs = {'name': net_name, 'forward': {'mode': 'nat'}, 'ips': [{'dhcp_ranges': {'attrs': {'start': '192.168.120.2', 'end': '192.168.120.254'}}, 'address': '192.168.120.1', 'netmask': '255.255.255.0'}, {'family': 'ipv6', 'address': '2001:db8:ca2:2::1', 'prefix': '64'}], 'routes': [{'address':'192.168.222.0','prefix':'24','gateway':'192.168.120.2'}, {'family':'ipv6','address':'2001:db8:ca2:3::','prefix':'64','gateway':'2001:db8:ca2:2::2'},{'family':'ipv6','address':'2001:db9:4:1::','prefix':'64','gateway':'2001:db8:ca2:2::3','metric':'2'}]} + ip_associated_route = '192.168.120.0/24' + ip_defined_route = '192.168.222.0/24' + ip6_associated_route = '2001:db8:ca2:2::/64' + ip6_defined_routes = "['2001:db8:ca2:3::/64', '2001:db9:4:1::/64']" + diff --git a/libvirt/tests/src/virtual_network/network/elements_and_attributes/static_route.py b/libvirt/tests/src/virtual_network/network/elements_and_attributes/static_route.py new file mode 100644 index 0000000000..b615e2f4f7 --- /dev/null +++ b/libvirt/tests/src/virtual_network/network/elements_and_attributes/static_route.py @@ -0,0 +1,40 @@ +import re +from virttest.utils_libvirt import libvirt_network + + +from virttest import virsh + +from avocado.utils import process + + +def run(test, params, env): + """ + Test network static route. + """ + net_name = params.get("net_name") + net_attrs = eval(params.get('net_attrs', '{}')) + ip_associated_route = params.get("ip_associated_route") + ip_defined_route = params.get("ip_defined_route") + ip6_associated_route = params.get("ip6_associated_route") + ip6_defined_routes = eval(params.get("ip6_defined_routes")) + try: + libvirt_network.create_or_del_network(net_attrs) + virsh.net_dumpxml(net_name, ignore_status=True) + net_info = virsh.net_info(net_name).stdout.strip() + bridge = re.search(r'Bridge:\s+(\S+)', net_info).group(1) + ip_route_cmd = "ip route | grep %s" % bridge + cmd_ret1 = process.run(ip_route_cmd, shell=True, ignore_status=False) + if not re.search(ip_associated_route, cmd_ret1.stdout_text): + test.fail("The ip addr associated route '%s' is not in result." % ip_associated_route) + if not re.search(ip_defined_route, cmd_ret1.stdout_text): + test.fail("The defined static route '%s' is not in result." % ip_defined_route) + ip6_route_cmd = "ip -6 route | grep %s" % bridge + cmd_ret2 = process.run(ip6_route_cmd, shell=True, ignore_status=False) + if not re.search(ip6_associated_route, cmd_ret2.stdout_text): + test.fail("The ip6 addr associated route '%s' is not in result." % ip6_associated_route) + for ip6_def_route in ip6_defined_routes: + if not re.search(ip6_def_route, cmd_ret2.stdout_text): + test.fail("The defined ip6 static route '%s' is not in result." % ip6_def_route) + finally: + virsh.net_destroy(net_name) + virsh.net_undefine(net_name)