-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automate VIRT-298910 - [Static route] Start virtual networks with static route defined. Signed-off-by: Yanqiu Zhang <[email protected]>
- Loading branch information
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
libvirt/tests/cfg/virtual_network/network/elements_and_attributes/static_route.cfg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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']" | ||
|
44 changes: 44 additions & 0 deletions
44
libvirt/tests/src/virtual_network/network/elements_and_attributes/static_route.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import re | ||
import logging | ||
from virttest.utils_libvirt import libvirt_network | ||
|
||
|
||
from virttest import virsh | ||
from virttest.utils_test import libvirt | ||
from virttest.libvirt_xml import xcepts, network_xml | ||
|
||
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_defined_route) | ||
finally: | ||
virsh.net_destroy(net_name) | ||
virsh.net_undefine(net_name) | ||
|