Skip to content

Commit

Permalink
auto VIRT-298910
Browse files Browse the repository at this point in the history
Automate VIRT-298910 - [Static route] Start virtual networks with static
route defined.

Signed-off-by: Yanqiu Zhang <[email protected]>
  • Loading branch information
yanqzhan committed Sep 27, 2024
1 parent 2c75700 commit 33cc667
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
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']"

Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 33cc667

Please sign in to comment.