Fix os-net-config interface restarts when applying routes
There is a bug in the os-net-config code that applies updates to existing routes. Instead of deleting routes that no longer exist in the config and adding routes on the fly that do, the process always fails so the interface gets restarted. This change fixes the external call to "/sbin/ip", but also fixes a bug where the name of the file containing the stored routes was being passed incorrectly. This caused os-net-config to always think there were no routes present, and to apply the new route without deleting the old route. This can lead to an error if the routes conflict. Change-Id: I4315e9812c641a667a1d5c6529cdba5d2f5bf640 Closes-bug: 1819212
This commit is contained in:
parent
3dcad07311
commit
e912b02c3b
|
@ -1562,11 +1562,14 @@ class IfcfgNetConfig(os_net_config.NetConfig):
|
||||||
|
|
||||||
for interface in apply_routes:
|
for interface in apply_routes:
|
||||||
logger.debug('Applying routes for interface %s' % interface[0])
|
logger.debug('Applying routes for interface %s' % interface[0])
|
||||||
commands = self.iproute2_route_commands(interface[0],
|
filename = self.root_dir + route_config_path(interface[0])
|
||||||
interface[1])
|
commands = self.iproute2_route_commands(filename, interface[1])
|
||||||
for command in commands:
|
for command in commands:
|
||||||
|
args = command.split()
|
||||||
try:
|
try:
|
||||||
self.execute('Running ip %s' % command, ipcmd, command)
|
if len(args) > 0:
|
||||||
|
self.execute('Running ip %s' % command, ipcmd,
|
||||||
|
*args)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning("Error in 'ip %s', restarting %s:\n%s" %
|
logger.warning("Error in 'ip %s', restarting %s:\n%s" %
|
||||||
(command, interface[0], str(e)))
|
(command, interface[0], str(e)))
|
||||||
|
|
|
@ -1946,6 +1946,8 @@ class TestIfcfgNetConfigApply(base.TestCase):
|
||||||
expected_commands = ['addr add 192.168.1.2/24 dev em1',
|
expected_commands = ['addr add 192.168.1.2/24 dev em1',
|
||||||
'addr del 192.168.0.2/23 dev em1',
|
'addr del 192.168.0.2/23 dev em1',
|
||||||
'link set dev em1 mtu 1500',
|
'link set dev em1 mtu 1500',
|
||||||
|
'route del default via 192.168.1.1 dev em1',
|
||||||
|
'route del 172.19.0.0/24 via 192.168.1.1 dev em1',
|
||||||
'route add default via 192.168.0.1 dev em1',
|
'route add default via 192.168.0.1 dev em1',
|
||||||
'route add 172.19.0.0/24 via 192.168.0.1 dev em1']
|
'route add 172.19.0.0/24 via 192.168.0.1 dev em1']
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue