Merge "Re-enable important py3k checks for monitoring kube-memory"

This commit is contained in:
Zuul 2021-10-28 14:29:49 +00:00 committed by Gerrit Code Review
commit 3ff8c48cc3
2 changed files with 15 additions and 8 deletions

View File

@ -18,6 +18,7 @@ Usage: kube-memory [-h] [--debug]
import argparse
import json
import logging
import math
import os
import re
import subprocess
@ -52,6 +53,14 @@ GREP_CMD = ["grep", "-rs", "total_rss"]
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):
"""Convert a string that represents memory in bytes into mebibytes(MiB)
@ -59,8 +68,8 @@ def mem_to_mebibytes(n_bytes):
e.g., '1829108992' is converted to 1744.374.
"""
try:
mebibytes = (float(n_bytes) / BYTES_IN_MEBIBYTE)
return str(round(mebibytes, DECIMAL_DIGITS))
mebibytes = (float(n_bytes) / BYTES_IN_MEBIBYTE) # pylint: disable=W1619
return str(py2_round(mebibytes, DECIMAL_DIGITS))
except (ValueError, TypeError):
return "-"
@ -435,13 +444,13 @@ def gather_info_and_display():
mem_info['MemAvailable'])) * KBYTE
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()
# Calculate platform memory in terms of percent reserved
if reserved_mebib > 0.0:
platform_memory_percent = round(
100 * platform_mebib / reserved_mebib, DECIMAL_DIGITS)
platform_memory_percent = py2_round(
100 * platform_mebib / reserved_mebib, DECIMAL_DIGITS) # pylint: disable=W1619
pt_platf = prettytable.PrettyTable(
['Reserved',

View File

@ -135,9 +135,7 @@ enable=E1603,E1609,E1610,E1602,E1606,E1608,E1607,E1605,E1604,E1601,E1611,W1652,
# C0111: Missing %s docstring
# Disable Python3 checkers:
# W1618: no-absolute-import
# W1619: old-division
# W1633: round-builtin
disable= R0914, R0915, W0703, C0325, C0111, C0330, W1618, W1619, W1633
disable= R0914, R0915, W0703, C0325, C0111, C0330, W1618
[REPORTS]