Petr Horáček has uploaded a new change for review. Change subject: ovs: remove ip address from used NIC ......................................................................
ovs: remove ip address from used NIC In order to move IP address from NIC to internal northbound iface, we must drop it from underlying NIC. Change-Id: I66e0be6ea8583fae1814bb8fc776dd243932b192 Bug-Url: https://bugzilla.redhat.com/1195208 Signed-off-by: Petr Horáček <phora...@redhat.com> --- M lib/vdsm/network/netswitch.py M tests/network/func_static_ip_test.py M tests/network/netfunctestlib.py 3 files changed, 64 insertions(+), 5 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/58/59958/1 diff --git a/lib/vdsm/network/netswitch.py b/lib/vdsm/network/netswitch.py index 0e05e37..2412384 100644 --- a/lib/vdsm/network/netswitch.py +++ b/lib/vdsm/network/netswitch.py @@ -190,9 +190,14 @@ # TODO: This should be moved to network/api.py when we solve rollback # transactions. for net in nets2remove: + _drop_static_ip_config(net) _drop_dhcp_config(net) for net, attrs in six.iteritems(nets2add): + nic = attrs.get('nic') + if nic: + _drop_static_ip_config(nic) + _set_static_ip_config(net, attrs) _set_dhcp_config(net, attrs) @@ -211,8 +216,11 @@ dhclient.run(iface, 4, ipv4.defaultRoute, duid_source, blocking_dhcp) -def _set_static_ip_config(iface, attrs): +def _drop_static_ip_config(iface): address.flush(iface) + + +def _set_static_ip_config(iface, attrs): ipv4 = address.IPv4(*_ipv4_conf_params(attrs)) ipv6 = address.IPv6(*_ipv6_conf_params(attrs)) address.add(iface, ipv4, ipv6) diff --git a/tests/network/func_static_ip_test.py b/tests/network/func_static_ip_test.py index 5ddcb46..493b0ec 100644 --- a/tests/network/func_static_ip_test.py +++ b/tests/network/func_static_ip_test.py @@ -22,8 +22,10 @@ from nose.plugins.attrib import attr +from vdsm.network.ipwrapper import linkSet, addrAdd + from .netfunctestlib import NetFuncTestCase, NOCHK -from .nettestlib import dummy_devices +from .nettestlib import dummy_device, dummy_devices NETWORK_NAME = 'test-network' BOND_NAME = 'bond1' @@ -31,6 +33,7 @@ IPv4_ADDRESS = '192.0.2.1' IPv4_NETMASK = '255.255.255.0' +IPv4_PREFIX_LEN = '24' IPv6_ADDRESS = 'fdb3:84e5:4ff4:55e3::1/64' IPv4 = [4] @@ -116,3 +119,41 @@ class NetworkStaticIpBasicOvsTest(NetworkStaticIpBasicTemplate): __test__ = True switch = 'ovs' + + +@attr(type='functional') +class AttachNicWithStaticIpTemplate(NetFuncTestCase): + __test__ = False + + def test_remove_static_ip_from_used_nic(self): + with dummy_device() as nic: + addrAdd(nic, IPv4_ADDRESS, IPv4_PREFIX_LEN) + + NETCREATE = {NETWORK_NAME: {'nic': nic, 'switch': self.switch}} + with self.setupNetworks(NETCREATE, {}, NOCHK): + nic_netinfo = self.netinfo.nics[nic] + self.assertDisabledIPv4(nic_netinfo) + + def test_network_with_ip_that_was_used_by_nic(self): + with dummy_device() as nic: + addrAdd(nic, IPv4_ADDRESS, IPv4_PREFIX_LEN) + + NETCREATE = {NETWORK_NAME: { + 'nic': nic, 'ipaddr': IPv4_ADDRESS, 'netmask': IPv4_NETMASK, + 'switch': self.switch}} + with self.setupNetworks(NETCREATE, {}, NOCHK): + self.assertNetwork(NETWORK_NAME, NETCREATE[NETWORK_NAME]) + nic_netinfo = self.netinfo.nics[nic] + self.assertDisabledIPv4(nic_netinfo) + + +@attr(type='functional', switch='legacy') +class AttachNicWithStaticIpLegacyTest(AttachNicWithStaticIpTemplate): + __test__ = True + switch = 'legacy' + + +@attr(type='functional', switch='ovs') +class AttachNicWithStaticIpOvsTest(AttachNicWithStaticIpTemplate): + __test__ = True + switch = 'ovs' diff --git a/tests/network/netfunctestlib.py b/tests/network/netfunctestlib.py index ecd8b9b..7dca190 100644 --- a/tests/network/netfunctestlib.py +++ b/tests/network/netfunctestlib.py @@ -244,9 +244,7 @@ self.assertNotIn(bond, self.running_config.bonds) def assertNetworkIp(self, net, attrs): - if ('ipaddr' not in attrs and attrs.get('bootproto') != 'dhcp' and - 'ipv6addr' not in attrs and 'dhcpv6' not in attrs and - 'ipv6autoconf' not in attrs): + if _ipv4_is_unused(attrs) and _ipv6_is_unused(attrs): return network_netinfo = self.netinfo.networks[net] @@ -271,6 +269,9 @@ if attrs.get('bootproto') == 'dhcp': self.assertDHCPv4(network_netinfo) self.assertDHCPv4(topdev_netinfo) + if _ipv4_is_unused(attrs): + self.assertDisabledIPv4(network_netinfo) + self.assertDisabledIPv4(topdev_netinfo) if 'ipv6addr' in attrs: self.assertStaticIPv6(attrs, network_netinfo) @@ -295,6 +296,11 @@ self.assertTrue(ipinfo['dhcpv4']) self.assertNotEqual(ipinfo['addr'], '') self.assertGreater(len(ipinfo['ipv4addrs']), 0) + + def assertDisabledIPv4(self, ipinfo): + self.assertFalse(ipinfo['dhcpv4']) + self.assertEqual(ipinfo['addr'], '') + self.assertEqual([], ipinfo['ipv4addrs']) def assertDisabledIPv6(self, ipinfo): # TODO: We need to report if IPv6 is enabled on iface/host and @@ -336,6 +342,10 @@ self.assertEqual(running_config['bonds'], kernel_config['bonds']) +def _ipv4_is_unused(attrs): + return 'ipaddr' not in attrs and attrs.get('bootproto') != 'dhcp' + + def _ipv6_is_unused(attrs): return ('ipv6addr' not in attrs and 'ipv6autoconf' not in attrs and 'dhcpv6' not in attrs and ipv6_supported()) -- To view, visit https://gerrit.ovirt.org/59958 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I66e0be6ea8583fae1814bb8fc776dd243932b192 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Petr Horáček <phora...@redhat.com> _______________________________________________ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/admin/lists/vdsm-patches@lists.fedorahosted.org