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 (cherry picked from commite912b02c3b
) (cherry picked from commit21dfd95bbe
)
This commit is contained in:
parent
ccbda4ee6d
commit
f26718f557
|
@ -1385,11 +1385,14 @@ class IfcfgNetConfig(os_net_config.NetConfig):
|
|||
|
||||
for interface in apply_routes:
|
||||
logger.debug('Applying routes for interface %s' % interface[0])
|
||||
commands = self.iproute2_route_commands(interface[0],
|
||||
interface[1])
|
||||
filename = self.root_dir + route_config_path(interface[0])
|
||||
commands = self.iproute2_route_commands(filename, interface[1])
|
||||
for command in commands:
|
||||
args = command.split()
|
||||
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:
|
||||
logger.warning("Error in 'ip %s', restarting %s:\n%s" %
|
||||
(command, interface[0], str(e)))
|
||||
|
|
|
@ -1786,6 +1786,8 @@ class TestIfcfgNetConfigApply(base.TestCase):
|
|||
expected_commands = ['addr add 192.168.1.2/24 dev em1',
|
||||
'addr del 192.168.0.2/23 dev em1',
|
||||
'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 172.19.0.0/24 via 192.168.0.1 dev em1']
|
||||
|
||||
|
|
Loading…
Reference in New Issue