From cedb6818a381e397ed22489f61f51564dae13dfa Mon Sep 17 00:00:00 2001 From: Cyril Levis Date: Tue, 13 Dec 2022 17:26:45 +0100 Subject: [PATCH] fix: handle big list of hp disk we cant use p.wait() if too much data. --- netbox_agent/raid/hp.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/netbox_agent/raid/hp.py b/netbox_agent/raid/hp.py index 2d6bcd6..7308625 100644 --- a/netbox_agent/raid/hp.py +++ b/netbox_agent/raid/hp.py @@ -18,20 +18,20 @@ def ssacli(sub_command): stdout=subprocess.PIPE, stderr=subprocess.STDOUT ) - p.wait() - stdout = p.stdout.read().decode("utf-8") - if p.returncode != 0 and 'does not have any physical' not in stdout: + stdout, stderr = p.communicate() + stdout = stdout.decode("utf-8") + if p.returncode != 0: mesg = "Failed to execute command '{}':\n{}".format( " ".join(command), stdout ) raise HPRaidControllerError(mesg) + + if 'does not have any physical' in stdout: + return list() else: - if 'does not have any physical' in stdout: - return list() - else: - lines = stdout.split('\n') - lines = list(filter(None, lines)) - return lines + lines = stdout.split('\n') + lines = list(filter(None, lines)) + return lines def _test_if_valid_line(line): ignore_patterns = ['Note:', 'Error:', 'is not loaded', 'README', ' failure', ' cache']