From 0a3a6be1505e3cc509708f9e6dbff21eebd05473 Mon Sep 17 00:00:00 2001 From: Ales Musil Date: Tue, 29 Jan 2019 13:39:13 +0100 Subject: [PATCH] net: Add subnet option into config The subnet for IPv6 is now taken from separate parameter in config file if provided. --- lago/providers/libvirt/network.py | 8 +++++++- tests/functional-sdk/test_sdk_sanity.py | 10 ++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lago/providers/libvirt/network.py b/lago/providers/libvirt/network.py index 66e024c5..4087d897 100644 --- a/lago/providers/libvirt/network.py +++ b/lago/providers/libvirt/network.py @@ -52,6 +52,9 @@ def name(self): def gw(self): return self._spec.get('gw') + def subnet(self): + return self._spec.get('subnet') + def mtu(self): if self.libvirt_con.getLibVersion() > 3001001: return self._spec.get('mtu', '1500') @@ -180,7 +183,10 @@ def _ipv6_prefix(self, subnet, const='fd8f:1391:3a82:'): def _libvirt_xml(self): net_raw_xml = libvirt_utils.get_template('net_nat_template.xml') - subnet = self.gw().split('.')[2] + subnet = self.subnet() + if not subnet: + subnet = self.gw().split('.')[2] + ipv6_prefix = self._ipv6_prefix(subnet=subnet) mtu = self.mtu() diff --git a/tests/functional-sdk/test_sdk_sanity.py b/tests/functional-sdk/test_sdk_sanity.py index 10c26a31..5dcdc599 100644 --- a/tests/functional-sdk/test_sdk_sanity.py +++ b/tests/functional-sdk/test_sdk_sanity.py @@ -62,6 +62,10 @@ def init_str(images): dhcp: start: 100 end: 254 + + net-03: + type: nat + subnet: 250 """ ) template = Environment(loader=BaseLoader()).from_string(init_template) @@ -110,6 +114,12 @@ def test_custom_gateway(vms, nets, init_dict): assert nets[net_name].gw() == net['gw'] +def test_custom_subnet(vms, nets, init_dict): + for net_name, net in init_dict['nets'].iteritems(): + if 'subnet' in net: + assert nets[net_name].subnet() == net['subnet'] + + def test_vm_is_running(vms, vm_name): vm = vms[vm_name] assert vm.running()