Add ipv6 support to fake network models
Currently, the functions in fake_network_cache_model all default to building a fake ipv4 network, and so the easiest way to test against a fake ipv6 network is to manually create ipv6 components (subnets, routes, ips) and plug them into the default fake VIF. This makes testing ipv6 functionality rather error-prone and laborious. This patch adds an option to create ipv6 models. Change-Id: I9aacbc45ce79cab05c6611d38fc2daaf2ba5dab7 Co-Authored-By: Ellen Hui <ellenfkh@gmail.com> Closes-Bug: #1336094
This commit is contained in:
parent
4990e60f2d
commit
93a22d4702
|
@ -16,62 +16,94 @@
|
||||||
from nova.network import model
|
from nova.network import model
|
||||||
|
|
||||||
|
|
||||||
def new_ip(ip_dict=None):
|
def new_ip(ip_dict=None, version=4):
|
||||||
new_ip = dict(address='192.168.1.100')
|
if version == 6:
|
||||||
|
new_ip = dict(address='fd00::1:100', version=6)
|
||||||
|
elif version == 4:
|
||||||
|
new_ip = dict(address='192.168.1.100')
|
||||||
ip_dict = ip_dict or {}
|
ip_dict = ip_dict or {}
|
||||||
new_ip.update(ip_dict)
|
new_ip.update(ip_dict)
|
||||||
return model.IP(**new_ip)
|
return model.IP(**new_ip)
|
||||||
|
|
||||||
|
|
||||||
def new_fixed_ip(ip_dict=None):
|
def new_fixed_ip(ip_dict=None, version=4):
|
||||||
new_fixed_ip = dict(address='192.168.1.100')
|
if version == 6:
|
||||||
|
new_fixed_ip = dict(address='fd00::1:100', version=6)
|
||||||
|
elif version == 4:
|
||||||
|
new_fixed_ip = dict(address='192.168.1.100')
|
||||||
ip_dict = ip_dict or {}
|
ip_dict = ip_dict or {}
|
||||||
new_fixed_ip.update(ip_dict)
|
new_fixed_ip.update(ip_dict)
|
||||||
return model.FixedIP(**new_fixed_ip)
|
return model.FixedIP(**new_fixed_ip)
|
||||||
|
|
||||||
|
|
||||||
def new_route(route_dict=None):
|
def new_route(route_dict=None, version=4):
|
||||||
new_route = dict(
|
if version == 6:
|
||||||
cidr='0.0.0.0/24',
|
new_route = dict(
|
||||||
gateway=new_ip(dict(address='192.168.1.1')),
|
cidr='::/48',
|
||||||
interface='eth0')
|
gateway=new_ip(dict(address='fd00::1:1'), version=6),
|
||||||
|
interface='eth0')
|
||||||
|
elif version == 4:
|
||||||
|
new_route = dict(
|
||||||
|
cidr='0.0.0.0/24',
|
||||||
|
gateway=new_ip(dict(address='192.168.1.1')),
|
||||||
|
interface='eth0')
|
||||||
|
|
||||||
route_dict = route_dict or {}
|
route_dict = route_dict or {}
|
||||||
new_route.update(route_dict)
|
new_route.update(route_dict)
|
||||||
return model.Route(**new_route)
|
return model.Route(**new_route)
|
||||||
|
|
||||||
|
|
||||||
def new_subnet(subnet_dict=None):
|
def new_subnet(subnet_dict=None, version=4):
|
||||||
new_subnet = dict(
|
if version == 6:
|
||||||
cidr='10.10.0.0/24',
|
new_subnet = dict(
|
||||||
dns=[new_ip(dict(address='1.2.3.4')),
|
cidr='fd00::/48',
|
||||||
new_ip(dict(address='2.3.4.5'))],
|
dns=[new_ip(dict(address='1:2:3:4::'), version=6),
|
||||||
gateway=new_ip(dict(address='10.10.0.1')),
|
new_ip(dict(address='2:3:4:5::'), version=6)],
|
||||||
ips=[new_fixed_ip(dict(address='10.10.0.2')),
|
gateway=new_ip(dict(address='fd00::1'), version=6),
|
||||||
new_fixed_ip(dict(address='10.10.0.3'))],
|
ips=[new_fixed_ip(dict(address='fd00::2'), version=6),
|
||||||
routes=[new_route()])
|
new_fixed_ip(dict(address='fd00::3'), version=6)],
|
||||||
|
routes=[new_route(version=6)],
|
||||||
|
version=6)
|
||||||
|
elif version == 4:
|
||||||
|
new_subnet = dict(
|
||||||
|
cidr='10.10.0.0/24',
|
||||||
|
dns=[new_ip(dict(address='1.2.3.4')),
|
||||||
|
new_ip(dict(address='2.3.4.5'))],
|
||||||
|
gateway=new_ip(dict(address='10.10.0.1')),
|
||||||
|
ips=[new_fixed_ip(dict(address='10.10.0.2')),
|
||||||
|
new_fixed_ip(dict(address='10.10.0.3'))],
|
||||||
|
routes=[new_route()])
|
||||||
subnet_dict = subnet_dict or {}
|
subnet_dict = subnet_dict or {}
|
||||||
new_subnet.update(subnet_dict)
|
new_subnet.update(subnet_dict)
|
||||||
return model.Subnet(**new_subnet)
|
return model.Subnet(**new_subnet)
|
||||||
|
|
||||||
|
|
||||||
def new_network(network_dict=None):
|
def new_network(network_dict=None, version=4):
|
||||||
new_net = dict(
|
if version == 6:
|
||||||
id=1,
|
new_net = dict(
|
||||||
bridge='br0',
|
id=1,
|
||||||
label='public',
|
bridge='br0',
|
||||||
subnets=[new_subnet(), new_subnet(dict(cidr='255.255.255.255'))])
|
label='public',
|
||||||
|
subnets=[new_subnet(version=6),
|
||||||
|
new_subnet(dict(cidr='ffff:ffff:ffff:ffff::'),
|
||||||
|
version=6)])
|
||||||
|
elif version == 4:
|
||||||
|
new_net = dict(
|
||||||
|
id=1,
|
||||||
|
bridge='br0',
|
||||||
|
label='public',
|
||||||
|
subnets=[new_subnet(), new_subnet(dict(cidr='255.255.255.255'))])
|
||||||
network_dict = network_dict or {}
|
network_dict = network_dict or {}
|
||||||
new_net.update(network_dict)
|
new_net.update(network_dict)
|
||||||
return model.Network(**new_net)
|
return model.Network(**new_net)
|
||||||
|
|
||||||
|
|
||||||
def new_vif(vif_dict=None):
|
def new_vif(vif_dict=None, version=4):
|
||||||
vif = dict(
|
vif = dict(
|
||||||
id=1,
|
id=1,
|
||||||
address='aa:aa:aa:aa:aa:aa',
|
address='aa:aa:aa:aa:aa:aa',
|
||||||
type='bridge',
|
type='bridge',
|
||||||
network=new_network())
|
network=new_network(version=version))
|
||||||
vif_dict = vif_dict or {}
|
vif_dict = vif_dict or {}
|
||||||
vif.update(vif_dict)
|
vif.update(vif_dict)
|
||||||
return model.VIF(**vif)
|
return model.VIF(**vif)
|
||||||
|
|
Loading…
Reference in New Issue