fix wait_for looping when missing net module (#73963)

fixes #43486
This commit is contained in:
Brian Coca 2021-03-23 11:12:49 -04:00 committed by GitHub
parent 6856e751ff
commit c1eed681aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 27 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- wait_for module, move missing socket into function to get proper comparrison in time.

View file

@ -369,28 +369,33 @@ class LinuxTCPConnectionInfo(TCPConnectionInfo):
for family in self.source_file.keys(): for family in self.source_file.keys():
if not os.path.isfile(self.source_file[family]): if not os.path.isfile(self.source_file[family]):
continue continue
f = open(self.source_file[family]) try:
for tcp_connection in f.readlines(): f = open(self.source_file[family])
tcp_connection = tcp_connection.strip().split() for tcp_connection in f.readlines():
if tcp_connection[self.local_address_field] == 'local_address': tcp_connection = tcp_connection.strip().split()
continue if tcp_connection[self.local_address_field] == 'local_address':
if (tcp_connection[self.connection_state_field] not in continue
[get_connection_state_id(_connection_state) for _connection_state in self.module.params['active_connection_states']]): if (tcp_connection[self.connection_state_field] not in
continue [get_connection_state_id(_connection_state) for _connection_state in self.module.params['active_connection_states']]):
(local_ip, local_port) = tcp_connection[self.local_address_field].split(':') continue
if self.port != local_port: (local_ip, local_port) = tcp_connection[self.local_address_field].split(':')
continue if self.port != local_port:
(remote_ip, remote_port) = tcp_connection[self.remote_address_field].split(':') continue
if (family, remote_ip) in self.exclude_ips: (remote_ip, remote_port) = tcp_connection[self.remote_address_field].split(':')
continue if (family, remote_ip) in self.exclude_ips:
if any(( continue
(family, local_ip) in self.ips, if any((
(family, self.match_all_ips[family]) in self.ips, (family, local_ip) in self.ips,
local_ip.startswith(self.ipv4_mapped_ipv6_address['prefix']) and (family, self.match_all_ips[family]) in self.ips,
(family, self.ipv4_mapped_ipv6_address['match_all']) in self.ips, local_ip.startswith(self.ipv4_mapped_ipv6_address['prefix']) and
)): (family, self.ipv4_mapped_ipv6_address['match_all']) in self.ips,
active_connections += 1 )):
f.close() active_connections += 1
except IOError as e:
pass
finally:
f.close()
return active_connections return active_connections
@ -651,11 +656,9 @@ def main():
end = start + datetime.timedelta(seconds=timeout) end = start + datetime.timedelta(seconds=timeout)
tcpconns = TCPConnectionInfo(module) tcpconns = TCPConnectionInfo(module)
while datetime.datetime.utcnow() < end: while datetime.datetime.utcnow() < end:
try: if tcpconns.get_active_connections_count() == 0:
if tcpconns.get_active_connections_count() == 0: break
break
except IOError:
pass
# Conditions not yet met, wait and try again # Conditions not yet met, wait and try again
time.sleep(module.params['sleep']) time.sleep(module.params['sleep'])
else: else: