1
0
mirror of https://github.com/CumulusNetworks/ifupdown2.git synced 2024-05-06 15:54:50 +00:00

addons: vrf: Fix to kill current ssh on 'sudo ifreload -a' to enable mgmt VRF

Ticket: CM-11080
Reviewed By: roopa, dsa, dave olson, daniel, julien
Testing Done: yes, with mgmt VRF configured

This patch parses '/usr/bin/pstree -Aps <pid>' output to find
the pid of current ssh session, and send 'sudo ifreload -a'
to background before killing itself.

Signed-off-by: Nikhil <nikhil@cumulusnetworks.com>
This commit is contained in:
Nikhil
2016-05-25 16:16:22 -07:00
committed by Julien Fortin
parent 1a13da934b
commit be27627277

View File

@ -19,6 +19,7 @@ from ifupdownaddons.modulebase import moduleBase
from ifupdownaddons.bondutil import bondutil from ifupdownaddons.bondutil import bondutil
from ifupdownaddons.iproute2 import iproute2 from ifupdownaddons.iproute2 import iproute2
from ifupdownaddons.dhclient import dhclient from ifupdownaddons.dhclient import dhclient
from ifupdownaddons.utilsbase import *
class vrfPrivFlags: class vrfPrivFlags:
PROCESSED = 0x1 PROCESSED = 0x1
@ -632,8 +633,18 @@ class vrf(moduleBase):
if not proc: if not proc:
return return
cmdl = ['/bin/ps', '--no-headers', '-fp', str(os.getppid())] pid = None
pid = utils.exec_commandl(cmdl).split()[2] # outpt of '/usr/bin/pstree -Aps <pid>':
# 'systemd(1)---sshd(990)---sshd(16112)---sshd(16126)---bash(16127)---sudo(16756)---ifreload(16761)---pstree(16842)\n'
# get the above output to following format
# ['systemd(1)', 'sshd(990)', 'sshd(16112)', 'sshd(16126)', 'bash(16127)', 'sudo(16756)', 'ifreload(16761)', 'pstree(16850)']
pstree = list(reversed(utils.exec_command('/usr/bin/pstree -Aps %s' %os.getpid()).strip().split('---')))
for index, process in enumerate(pstree):
# check the parent of SSH process to make sure
# we don't kill SSH server or systemd process
if 'sshd' in process and 'sshd' in pstree[index + 1]:
pid = filter(lambda x: x.isdigit(), process)
break
self.logger.info("%s: killing active ssh sessions: %s" self.logger.info("%s: killing active ssh sessions: %s"
%(ifacename, str(proc))) %(ifacename, str(proc)))