daemon: Wait for a TunTap device to exist before trying to configure

addresses.
This commit is contained in:
tgoff0 2014-12-15 22:24:17 +00:00
parent 6084b4f416
commit a0d4ac4ec4

View file

@ -76,15 +76,11 @@ class TunTap(PyCoreNetIf):
# mutedetach(["tunctl", "-d", self.localname]) # mutedetach(["tunctl", "-d", self.localname])
self.up = False self.up = False
def install(self): def waitfordevice(self):
''' Install this TAP into its namespace. This is not done from the '''\
startup() method but called at a later time when a userspace Check for presence of device - tap device may not appear right
program (running on the host) has had a chance to open the socket away waits ~= stime * ( 2 ** attempts) seconds
end of the TAP.
''' '''
netns = str(self.node.pid)
# check for presence of device - tap device may not appear right away
# waits ~= stime * ( 2 ** attempts) seconds
attempts = 9 attempts = 9
stime = 0.01 stime = 0.01
while attempts > 0: while attempts > 0:
@ -100,7 +96,15 @@ class TunTap(PyCoreNetIf):
time.sleep(stime) time.sleep(stime)
stime *= 2 stime *= 2
attempts -= 1 attempts -= 1
# install tap device into namespace
def install(self):
''' Install this TAP into its namespace. This is not done from the
startup() method but called at a later time when a userspace
program (running on the host) has had a chance to open the socket
end of the TAP.
'''
self.waitfordevice()
netns = str(self.node.pid)
try: try:
check_call([IP_BIN, "link", "set", self.localname, "netns", netns]) check_call([IP_BIN, "link", "set", self.localname, "netns", netns])
except Exception, e: except Exception, e:
@ -116,6 +120,7 @@ class TunTap(PyCoreNetIf):
def setaddrs(self): def setaddrs(self):
''' Set interface addresses based on self.addrlist. ''' Set interface addresses based on self.addrlist.
''' '''
self.waitfordevice()
for addr in self.addrlist: for addr in self.addrlist:
self.node.cmd([IP_BIN, "addr", "add", str(addr), self.node.cmd([IP_BIN, "addr", "add", str(addr),
"dev", self.name]) "dev", self.name])