Commit 4fc8b149 by Chif Gergő

node list: Fix page load error when no task result

The page now loads when the node can't reach the monitor info values e.g. cpu percent. It gets a default value 0. And if a node's monitor info unreachable shows
an error message.
parent d53a5983
......@@ -210,9 +210,15 @@ class NodeList(LoginRequiredMixin, GraphMixin, SingleTableView):
return super(NodeList, self).get(*args, **kwargs)
def get_queryset(self):
return Node.objects.annotate(
def wrong_node_message(self):
for node in Node.objects.all():
if node.monitor_info is None:
messages.error(self.request, "Can't reach "" monitor info")
class NodeCreate(LoginRequiredMixin, SuperuserRequiredMixin, TemplateView):
......@@ -34,8 +34,9 @@ from django.db.models import (
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from django.contrib import messages
from celery.exceptions import TimeoutError
from celery.exceptions import TimeoutError, TaskRevokedError
from model_utils.models import TimeStampedModel
from taggit.managers import TaggableManager
......@@ -315,7 +316,7 @@ class Node(OperatedMixin, TimeStampedModel):
queue=self.get_remote_queue_name('vm', priority),
expires=timeout + 60)
return r.get(timeout=timeout)
except (TimeoutError, WorkerNotFound):
except (TimeoutError, WorkerNotFound, TaskRevokedError):
if raise_:
......@@ -363,21 +364,23 @@ class Node(OperatedMixin, TimeStampedModel):
def driver_version(self):
def get_monitor_info(self, metric):
if self.monitor_info is None:
return 0
elif self.monitor_info.get(metric) is None:
return 0
return self.monitor_info.get(metric)
def cpu_usage(self):
if self.monitor_info.get('cpu.percent') is not None:
return self.monitor_info.get('cpu.percent') / 100
return 0
return self.get_monitor_info('cpu.percent') / 100
def ram_usage(self):
if self.monitor_info.get('memory.usage') is not None:
return self.monitor_info.get('memory.usage') / 100
return 0
return self.get_monitor_info('memory.usage') / 100
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