Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Fix inequality sign in logs #5047

Merged
merged 1 commit into from
Jan 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions golem/core/fileshelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,7 @@ def du(path):
logger.info("Can't open dir {}: {}".format(path, str(err)))
return "-1"

human_readable_size, idx = memoryhelper.dir_size_to_display(size)
return "{} {}".format(
human_readable_size,
memoryhelper.translate_resource_index(idx)
)
return memoryhelper.dir_size_to_display(size)


def relative_path(path, prefix):
Expand Down
23 changes: 20 additions & 3 deletions golem/task/taskserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
from golem.task.taskbase import AcceptClientVerdict
from golem.task.taskconnectionshelper import TaskConnectionsHelper
from golem.task.taskstate import TaskOp
from golem.tools import memoryhelper
from golem.utils import decode_hex
from .server import concent
from .server import helpers
Expand Down Expand Up @@ -1101,6 +1102,9 @@ def should_accept_provider( # pylint: disable=too-many-return-statements
provider_perf: float, max_memory_size: int,
offer_hash: str) -> bool:

# max_memory_size: int KiB
max_memory_size_b = int(max_memory_size) * 1024 # Bytes

node_name_id = short_node_id(node_id)
ids = f'provider={node_name_id}, task_id={task_id}'

Expand Down Expand Up @@ -1141,9 +1145,22 @@ def should_accept_provider( # pylint: disable=too-many-return-statements
})
return False

if min_memory > (int(max_memory_size) * 1024):
logger.info('insufficient provider memory size: '
f'{min_memory} B < {max_memory_size} KiB; {ids}')
if min_memory > max_memory_size_b:
logger.info(
'insufficient provider memory size:'
' %(available)s < %(min_memory)s;'
' Free at least %(missing)s; %(ids)s',
{
'min_memory': memoryhelper.dir_size_to_display(min_memory),
'available': memoryhelper.dir_size_to_display(
max_memory_size_b,
),
'missing': memoryhelper.dir_size_to_display(
min_memory - max_memory_size_b,
),
'ids': ids,
}
)
self.notify_provider_rejected(
node_id=node_id, task_id=task_id,
reason=self.RejectedReason.memory_size,
Expand Down
31 changes: 6 additions & 25 deletions golem/tools/memoryhelper.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,11 @@
import logging

logger = logging.getLogger("tools")

options = {
0: 'kB',
1: 'MB',
2: 'GB'
}


def dir_size_to_display(dir_size):
if dir_size // (1024 * 1024 * 1024) > 0:
dir_size = round(float(dir_size) / (1024 * 1024 * 1024), 1)
index = 2
elif dir_size // (1024 * 1024) > 0:
return f'{dir_size} GiB'
if dir_size // (1024 * 1024) > 0:
dir_size = round(float(dir_size) / (1024 * 1024), 1)
index = 1
else:
return f'{dir_size} MiB'
if dir_size // 1024 > 0:
dir_size = round(float(dir_size) / 1024, 1)
index = 0
return dir_size, index


def translate_resource_index(index):
if index in options:
return options[index]
else:
logger.error("Wrong memory unit index: {} ".format(index))
return ''
return f'{dir_size} KiB'
return f'{dir_size} B'
4 changes: 2 additions & 2 deletions tests/golem/task/test_taskserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,8 @@ def test_should_accept_provider_insufficient_memory_size(self, *_args):
_assert_log_msg(
cm,
f'INFO:{logger.name}:insufficient provider memory size: '
f'{estimated_memory} B < {DEFAULT_MAX_MEMORY_SIZE_KB} '
f'KiB; {ids}')
f'4.0 KiB < 4.0 KiB; Free at least 1 B;'
f' {ids}')

listener.assert_called_once_with(
sender=ANY,
Expand Down