Re-enable important py3k checks for monitoring kube-memory
Re-enabling some of the disabled tox warnings present on the pylint.rc file Re-enabling: W1619: old-division W1633: round-builtin Test Plan: Sanity test run on AIO-SX: PASS: test_system_health_pre_session[pods] PASS: test_system_health_pre_session[alarms] PASS: test_system_health_pre_session[system_apps] PASS: test_wr_analytics[deploy_and_remove] PASS: test_horizon_host_inventory_display PASS: test_lock_unlock_host[controller] PASS: test_pod_to_pod_connection PASS: test_pod_to_service_connection PASS: test_host_to_service_connection Story: 2006796 Task: 43444 Signed-off-by: Bernardo Decco <bernardo.deccodesiqueira@windriver.com> Change-Id: I00dc37bbd8f60f475f85e4f0463b7c066a719f1f
This commit is contained in:
parent
e5bdd73802
commit
a469d8ad9b
@ -18,6 +18,7 @@ Usage: kube-memory [-h] [--debug]
|
|||||||
import argparse
|
import argparse
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
import math
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
@ -51,6 +52,14 @@ GREP_CMD = ["grep", "-rs", "total_rss"]
|
|||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def py2_round(number, decimal=0):
|
||||||
|
# This function will keep the behavior of py2 round method
|
||||||
|
param = 10 ** decimal
|
||||||
|
if number > 0:
|
||||||
|
return float(math.floor((number * param) + 0.5)) / param # pylint: disable=W1619
|
||||||
|
return float(math.ceil((number * param) - 0.5)) / param # pylint: disable=W1619
|
||||||
|
|
||||||
|
|
||||||
def mem_to_mebibytes(n_bytes):
|
def mem_to_mebibytes(n_bytes):
|
||||||
"""Convert a string that represents memory in bytes into mebibytes(MiB)
|
"""Convert a string that represents memory in bytes into mebibytes(MiB)
|
||||||
|
|
||||||
@ -58,8 +67,8 @@ def mem_to_mebibytes(n_bytes):
|
|||||||
e.g., '1829108992' is converted to 1744.374.
|
e.g., '1829108992' is converted to 1744.374.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
mebibytes = (float(n_bytes) / BYTES_IN_MEBIBYTE)
|
mebibytes = (float(n_bytes) / BYTES_IN_MEBIBYTE) # pylint: disable=W1619
|
||||||
return str(round(mebibytes, DECIMAL_DIGITS))
|
return str(py2_round(mebibytes, DECIMAL_DIGITS))
|
||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError):
|
||||||
return "-"
|
return "-"
|
||||||
|
|
||||||
@ -434,13 +443,13 @@ def gather_info_and_display():
|
|||||||
mem_info['MemAvailable'])) * KBYTE
|
mem_info['MemAvailable'])) * KBYTE
|
||||||
total_mebib = float(anon_mebib + avail_mebib)
|
total_mebib = float(anon_mebib + avail_mebib)
|
||||||
|
|
||||||
anon_percent = round(100 * anon_mebib / total_mebib, DECIMAL_DIGITS)
|
anon_percent = py2_round(100 * anon_mebib / total_mebib, DECIMAL_DIGITS) # pylint: disable=W1619
|
||||||
|
|
||||||
reserved_mebib = get_platform_reserved_memory()
|
reserved_mebib = get_platform_reserved_memory()
|
||||||
# Calculate platform memory in terms of percent reserved
|
# Calculate platform memory in terms of percent reserved
|
||||||
if reserved_mebib > 0.0:
|
if reserved_mebib > 0.0:
|
||||||
platform_memory_percent = round(
|
platform_memory_percent = py2_round(
|
||||||
100 * platform_mebib / reserved_mebib, DECIMAL_DIGITS)
|
100 * platform_mebib / reserved_mebib, DECIMAL_DIGITS) # pylint: disable=W1619
|
||||||
|
|
||||||
pt_platf = prettytable.PrettyTable(
|
pt_platf = prettytable.PrettyTable(
|
||||||
['Reserved',
|
['Reserved',
|
||||||
|
@ -135,9 +135,7 @@ enable=E1603,E1609,E1610,E1602,E1606,E1608,E1607,E1605,E1604,E1601,E1611,W1652,
|
|||||||
# C0111: Missing %s docstring
|
# C0111: Missing %s docstring
|
||||||
# Disable Python3 checkers:
|
# Disable Python3 checkers:
|
||||||
# W1618: no-absolute-import
|
# W1618: no-absolute-import
|
||||||
# W1619: old-division
|
disable= R0914, R0915, W0703, C0325, C0111, C0330, W1618
|
||||||
# W1633: round-builtin
|
|
||||||
disable= R0914, R0915, W0703, C0325, C0111, C0330, W1618, W1619, W1633
|
|
||||||
|
|
||||||
[REPORTS]
|
[REPORTS]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user