From b8651bfd72e5f633be1a33d0a880559cc9669078 Mon Sep 17 00:00:00 2001 From: Steve Wills Date: Wed, 13 Sep 2017 10:59:18 -0400 Subject: [PATCH 1/3] Make get_system_task_capacity portable Signed-off-by: Steve Wills --- awx/main/utils/common.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/awx/main/utils/common.py b/awx/main/utils/common.py index 291ff0722e..6430770ac7 100644 --- a/awx/main/utils/common.py +++ b/awx/main/utils/common.py @@ -17,6 +17,7 @@ import threading import contextlib import tempfile import six +import psutil # Decorator from decorator import decorator @@ -581,12 +582,8 @@ def get_system_task_capacity(): from django.conf import settings if hasattr(settings, 'SYSTEM_TASK_CAPACITY'): return settings.SYSTEM_TASK_CAPACITY - try: - out = subprocess.check_output(['free', '-m']) - except subprocess.CalledProcessError: - logger.exception('Problem obtaining capacity from system.') - return 0 - total_mem_value = out.split()[7] + mem = psutil.virtual_memory() + total_mem_value = mem.total/1024/1024 if int(total_mem_value) <= 2048: return 50 return 50 + ((int(total_mem_value) / 1024) - 2) * 75 From f0cf3258315da307edfa4e889a81d704a8709dac Mon Sep 17 00:00:00 2001 From: Steve Wills Date: Wed, 13 Sep 2017 11:37:57 -0400 Subject: [PATCH 2/3] Add whitespace around arithmetic operator Signed-off-by: Steve Wills --- awx/main/utils/common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/awx/main/utils/common.py b/awx/main/utils/common.py index 6430770ac7..5505c6592c 100644 --- a/awx/main/utils/common.py +++ b/awx/main/utils/common.py @@ -583,7 +583,7 @@ def get_system_task_capacity(): if hasattr(settings, 'SYSTEM_TASK_CAPACITY'): return settings.SYSTEM_TASK_CAPACITY mem = psutil.virtual_memory() - total_mem_value = mem.total/1024/1024 + total_mem_value = mem.total / 1024 / 1024 if int(total_mem_value) <= 2048: return 50 return 50 + ((int(total_mem_value) / 1024) - 2) * 75 From 769ee8ac54bd4634b127721af431c87e1ac1b85b Mon Sep 17 00:00:00 2001 From: Steve Wills Date: Wed, 13 Sep 2017 11:55:44 -0400 Subject: [PATCH 3/3] Remove unnecessary int coercion Signed-off-by: Steve Wills --- awx/main/utils/common.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/awx/main/utils/common.py b/awx/main/utils/common.py index 5505c6592c..345f4790ea 100644 --- a/awx/main/utils/common.py +++ b/awx/main/utils/common.py @@ -584,9 +584,9 @@ def get_system_task_capacity(): return settings.SYSTEM_TASK_CAPACITY mem = psutil.virtual_memory() total_mem_value = mem.total / 1024 / 1024 - if int(total_mem_value) <= 2048: + if total_mem_value <= 2048: return 50 - return 50 + ((int(total_mem_value) / 1024) - 2) * 75 + return 50 + ((total_mem_value / 1024) - 2) * 75 _inventory_updates = threading.local()