Commit 321a6bca by Belákovics Ádám

updated logging for tests

parent efdbf7ed
Pipeline #681 passed with stage
in 0 seconds
......@@ -15,18 +15,18 @@
# You should have received a copy of the GNU General Public License along
# with CIRCLE. If not, see <>.
import random
import datetime
import json
import random
from logging import getLogger
from django.conf import settings
from django.core.cache import cache
from django.utils.translation import ugettext_noop
from django.utils import timezone
from django.conf import settings
from django.utils.translation import ugettext_noop
from common.models import HumanReadableException
from logging import getLogger
from circle.settings.base import SCHEDULER_METHOD
from common.models import HumanReadableException
logger = getLogger(__name__)
......@@ -93,7 +93,9 @@ def common_random(instance, nodes):
def advanced_with_time_stamp(instance, nodes):
nodes = common_select(instance, nodes)
nodes.sort(key=sorting_key, reverse=True)'SCHEDLOG: %s', nodes)"SCHEDLOG: {}".format(json.dumps({
"event": "after_sort",
"list": map(lambda node: unicode(node), nodes)})))
result = nodes[0]
return result
......@@ -110,8 +112,10 @@ def select_node(instance, nodes):
else: # Default method is the random
result = common_random(instance, nodes)'SCHEDLOG: Scheduler method: %s selected', unicode(SCHEDULER_METHOD))'SCHEDLOG: select_node: %s for %s', unicode(result), unicode(instance))"SCHEDLOG: {}".format(json.dumps(
{"event": "select",
"node": unicode(result),
"vm": unicode(instance)})))
......@@ -127,17 +131,26 @@ def sorting_key(node):
key = free_cpu_time(node) * corr
key = free_ram(node) * corr'SCHEDLOG: node: %s score: %s freecpu: %s freeram: %s', unicode(node), unicode(key), unicode(free_cpu_time(node)), unicode(free_ram(node)))"SCHEDLOG: {}".format(json.dumps({
"event": "sort",
"node": unicode(node),
"sorting_key": unicode(key),
"free_cpu_time": unicode(free_cpu_time(node)),
"free_ram": unicode(free_ram(node)),
"last_scheduled_correction_factor": unicode(last_scheduled_correction_factor(node))})))
return key
def set_time_stamp(node):
def get_time_stamp(node):
time_stamp = cache.get('time_stamp{}'.format(
if time_stamp:
return time_stamp
return datetime.datetime(1970,1,1, tzinfo=timezone.get_current_timezone())
return datetime.datetime(1970, 1, 1, tzinfo=timezone.get_current_timezone())
def last_scheduled_correction_factor(node):
"""Returns the time correction factor for a node.
......@@ -149,7 +162,8 @@ def last_scheduled_correction_factor(node):
factor = 0
current_time =
time_difference_in_seconds = (current_time - get_time_stamp(node)).total_seconds()
time_difference_in_seconds = (
current_time - get_time_stamp(node)).total_seconds()
factor = time_difference_in_seconds/float(max_time_diff)
if factor > 1:
factor = 1
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 sign in to comment