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):
self.wrong_node_message()
return Node.objects.annotate(
number_of_VMs=Count('instance_set')).select_related('host')
def wrong_node_message(self):
for node in Node.objects.all():
if node.monitor_info is None:
messages.error(self.request, "Can't reach "+node.name+" 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_:
raise
else:
......@@ -363,21 +364,23 @@ class Node(OperatedMixin, TimeStampedModel):
def driver_version(self):
return self.info.get('driver_version')
def get_monitor_info(self, metric):
if self.monitor_info is None:
return 0
elif self.monitor_info.get(metric) is None:
return 0
else:
return self.monitor_info.get(metric)
@property
@node_available
def cpu_usage(self):
if self.monitor_info.get('cpu.percent') is not None:
return self.monitor_info.get('cpu.percent') / 100
else:
return 0
return self.get_monitor_info('cpu.percent') / 100
@property
@node_available
def ram_usage(self):
if self.monitor_info.get('memory.usage') is not None:
return self.monitor_info.get('memory.usage') / 100
else:
return 0
return self.get_monitor_info('memory.usage') / 100
@property
@node_available
......
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