From 30d81e05c98933bc688856d7c1e6a802a37eb52e Mon Sep 17 00:00:00 2001 From: Ace Pace Date: Tue, 9 Jan 2018 18:37:59 +0200 Subject: [PATCH] CR fixes --- chaos_monkey/network/tcp_scanner.py | 15 +++++++-------- chaos_monkey/network/tools.py | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/chaos_monkey/network/tcp_scanner.py b/chaos_monkey/network/tcp_scanner.py index e149da8e7..7b37c3278 100644 --- a/chaos_monkey/network/tcp_scanner.py +++ b/chaos_monkey/network/tcp_scanner.py @@ -28,13 +28,12 @@ class TcpScanner(HostScanner, HostFinger): shuffle(target_ports) ports, banners = check_tcp_ports(host.ip_addr, target_ports, self._config.tcp_scan_timeout / 1000.0) - if len(ports) != 0: - for target_port, banner in zip(ports, banners): - service = 'tcp-' + str(target_port) - host.services[service] = {} - if banner: - host.services[service]['banner'] = banner - if only_one_port: - break + for target_port, banner in zip(ports, banners): + service = 'tcp-' + str(target_port) + host.services[service] = {} + if banner: + host.services[service]['banner'] = banner + if only_one_port: + break return len(ports) != 0 diff --git a/chaos_monkey/network/tools.py b/chaos_monkey/network/tools.py index 4ce8fed2e..b26fe5d20 100644 --- a/chaos_monkey/network/tools.py +++ b/chaos_monkey/network/tools.py @@ -132,7 +132,7 @@ def check_tcp_ports(ip, ports, timeout=DEFAULT_TIMEOUT, get_banner=False): time_left) # any read_socket is automatically a writesocket num_replies = len(write_sockets) + len(err_sockets) - if num_replies == len(port_attempts) or time_left == 0: + if num_replies == len(port_attempts) or time_left <= 0: break else: time_left -= SLEEP_BETWEEN_POLL