Skip to content

Commit 866bb1b

Browse files
committed
Minor fixes
1 parent 7afa8ef commit 866bb1b

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

net-dhcp/network.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -145,21 +145,28 @@ def create_endpoint():
145145
.set('state', 'up')
146146
.commit())
147147

148-
time.sleep(0.5)
149-
if_container = (ndb.interfaces[if_container]
150-
.set('state', 'up')
151-
.commit())
152-
(bridge
153-
.add_port(if_host)
154-
.commit())
148+
try:
149+
start = time.time()
150+
while isinstance(if_container, str) and time.time() - start < 10:
151+
try:
152+
if_container = (ndb.interfaces[if_container]
153+
.set('state', 'up')
154+
.commit())
155+
except KeyError:
156+
time.sleep(0.5)
157+
if isinstance(if_container, str):
158+
raise NetDhcpError(f'timed out waiting for {if_container} to appear in host')
155159

156-
res_iface = {
157-
'MacAddress': '',
158-
'Address': '',
159-
'AddressIPv6': ''
160-
}
160+
(bridge
161+
.add_port(if_host)
162+
.commit())
163+
164+
res_iface = {
165+
'MacAddress': '',
166+
'Address': '',
167+
'AddressIPv6': ''
168+
}
161169

162-
try:
163170
if 'MacAddress' in req_iface and req_iface['MacAddress']:
164171
(if_container
165172
.set('address', req_iface['MacAddress'])
@@ -199,9 +206,10 @@ def try_addr(type_):
199206
except Exception as e:
200207
logger.exception(e)
201208

202-
(bridge
203-
.del_port(if_host)
204-
.commit())
209+
if not isinstance(if_container, str):
210+
(bridge
211+
.del_port(if_host)
212+
.commit())
205213
(if_host
206214
.remove()
207215
.commit())

net-dhcp/udhcpc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def __init__(self, iface, v6=False, once=False, hostname=None, event_listener=No
6767
self._event_queue = posix_ipc.MessageQueue(f'/udhcpc{self._suffix}_{iface["address"].replace(":", "_")}', \
6868
flags=os.O_CREAT | os.O_EXCL, max_messages=2, max_message_size=1024)
6969
self.proc = Popen(cmdline, env={'EVENT_QUEUE': self._event_queue.name}, stdin=subprocess.DEVNULL,
70-
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, preexec_fn=close_fds)
70+
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
7171
if hostname:
7272
logger.debug('[udhcpc%s#%d] using hostname "%s"', self._suffix, self.proc.pid, hostname)
7373

0 commit comments

Comments
 (0)