Commit b5cc2bee authored by Bryton Lacquement's avatar Bryton Lacquement 🚪 Committed by Julien Muchembled

fixup! Add support for Python 3

/reviewed-on nexedi/slapos.toolbox!63
parent 789d2d56
......@@ -7,7 +7,7 @@ Uses:
- /proc/meminfo
"""
from __future__ import print_function
from __future__ import division, print_function
import sys
import sqlite3
......@@ -41,8 +41,8 @@ def getMemoryInfo(database, time, date):
finally:
database.close()
memory_info["used_percent"] = memory_info["used"] * 100.0 / memory_info["total"]
memory_info["free_percent"] = memory_info["free"] * 100.0 / memory_info["total"]
memory_info["used_percent"] = memory_info["used"] * 100 / memory_info["total"]
memory_info["free_percent"] = memory_info["free"] * 100 / memory_info["total"]
return (memory_info, "")
def checkMemoryUsage(database_path, time, date, threshold, key="used", unit="byte"):
......
from __future__ import division
from zope.interface import implementer
from slapos.grid.promise import interface
from slapos.grid.promise.generic import GenericPromise
......@@ -81,14 +83,14 @@ class RunPromise(GenericPromise):
usage_output = ""
total_inode = stat.f_files
free_inode = stat.f_ffree
usage = round((float(total_inode - free_inode) / total_inode), 4) * 100
usage = round(((total_inode - free_inode) / total_inode), 4) * 100
if usage > max_inode_usage:
return "Disk Inodes usages is really high: %s%%" % usage
elif os.path.exists('/tmp'):
# check if /tmp is mounted on another disk than path
tmp_stat = os.statvfs('/tmp')
if tmp_stat.f_blocks != stat.f_blocks:
tmp_usage = round((float(tmp_stat.f_files - tmp_stat.f_ffree) / tmp_stat.f_files), 4) * 100
tmp_usage = round(((tmp_stat.f_files - tmp_stat.f_ffree) / tmp_stat.f_files), 4) * 100
if tmp_usage > max_inode_usage:
return "Disk Inodes usage is high: %s%%" % tmp_usage
return ""
......@@ -160,8 +162,8 @@ class RunPromise(GenericPromise):
self.logger.info("Disk usage: OK")
return
free_space = round(free_space/(1024.0*1024*1024), 2)
min_space = round(min_free_size/(1024.0*1024*1024), 2)
free_space = round(free_space/(1024*1024*1024), 2)
min_space = round(min_free_size/(1024*1024*1024), 2)
self.logger.error('Free disk space low: remaining %s G (threshold: %s G)' % (
free_space, min_space))
......
......@@ -30,11 +30,7 @@ class RunPromise(GenericPromise):
return
try:
subprocess.subprocess.check_output(
args,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
subprocess.check_output(args, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
result = e.output.strip()
self.logger.error(message, result if str is bytes else
......
......@@ -540,7 +540,7 @@ class QemuQMPWrapper(object):
memory_id_list.append({
'memdev': mem_dev,
'id': dimm['data']['id'],
'size': dimm['data']['size']/(1024 * 1024),
'size': dimm['data']['size']//(1024 * 1024),
})
memory_id_list = sorted(memory_id_list, key=itemgetter('id'))
......@@ -558,7 +558,7 @@ class QemuQMPWrapper(object):
if (mem_size % slot_size) != 0:
raise ValueError("Memory size %r is not a multiple of %r" % (mem_size,
slot_size))
if (mem_size / slot_size) > slot_amount:
if (mem_size // slot_size) > slot_amount:
raise ValueError("No enough slots available to add %sMB of RAM" % mem_size)
current_size //= (1024 * 1024)
......@@ -616,7 +616,7 @@ class QemuQMPWrapper(object):
final_mem_size = 0
for mem in mem_info['hotplugged']:
final_mem_size += mem['size']
final_mem_size = final_mem_size / (1024 * 1024) # get size in MB
final_mem_size //= (1024 * 1024) # get size in MB
if mem_size != final_mem_size:
raise ValueError("Consistency error: Expected %s MB of hotplugged RAM " \
"but current RAM size is %s MB" % (mem_size, final_mem_size))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment