Get rid of irrelevant notification

Some notifications didn't give end user any information, especially when
there were no nodes in error state. This patch makes them not appear
anymore.

Change-Id: Ic5f42972287f475c1a3158a57a8a0ab9e870e18e
Closes-bug: #1506008
This commit is contained in:
Maciej Kwiek 2015-12-09 16:43:30 +01:00
parent 63478723bb
commit e56d020620
2 changed files with 44 additions and 14 deletions

View File

@ -451,8 +451,8 @@ class NailgunReceiver(object):
"""
# Due to design of UI, that shows all notifications,
# we should notify provision task only then the task is top-level task
if task.name == consts.TASK_NAMES.provision \
and task.parent_id is not None:
if (task.name == consts.TASK_NAMES.provision
and task.parent_id is not None) or message is None:
return
notifier.notify(
@ -537,8 +537,7 @@ class NailgunReceiver(object):
else:
message = u"\n".join(nodes_info)
else:
message = (u"Unknown nodes. Please wait for master task to "
u"report which nodes were affected")
message = None
return message
@classmethod
@ -551,15 +550,15 @@ class NailgunReceiver(object):
# a lot of clutter for user
notify_message = message.split('\n\n')[0]
else:
message = u"{0} has failed. Check these nodes:\n{1}".format(
task_name,
cls._generate_error_message(
task,
error_types=('deploy', 'provision'),
names_only=True
)
error_message = cls._generate_error_message(
task,
error_types=('deploy', 'provision'),
names_only=True
)
notify_message = message
message = u"{0} has failed. Check these nodes:\n{1}".format(
task_name, error_message
)
notify_message = message if error_message is not None else None
cls._notify(task, consts.NOTIFICATION_TOPICS.error, notify_message)
data = {'status': status, 'progress': progress, 'message': message}

View File

@ -18,6 +18,7 @@ import uuid
from oslo_serialization import jsonutils
from nailgun import consts
from nailgun.db.sqlalchemy.models import Notification
from nailgun.db.sqlalchemy.models import Task
from nailgun.errors import errors
@ -62,7 +63,7 @@ class TestNotification(BaseIntegrationTest):
"discover",
"discover message")
def test_notification_deploy_error(self):
def test_notification_deploy_error_without_nodes(self):
cluster = self.env.create_cluster(api=False)
receiver = rcvr.NailgunReceiver()
@ -72,7 +73,37 @@ class TestNotification(BaseIntegrationTest):
cluster_id=cluster.id
)
self.db.add(task)
self.db.commit()
self.db.flush()
kwargs = {
'task_uuid': task.uuid,
'status': 'error',
}
receiver.deploy_resp(**kwargs)
notifications = self.db.query(Notification).filter_by(
cluster_id=cluster.id
).all()
self.assertEqual(len(notifications), 0)
def test_notification_deploy_error_with_nodes(self):
self.env.create(api=False,
nodes_kwargs=[
{
'status': consts.NODE_STATUSES.error,
'error_type': consts.NODE_ERRORS.deploy
}])
cluster = self.env.clusters[0]
receiver = rcvr.NailgunReceiver()
task = Task(
uuid=str(uuid.uuid4()),
name="super",
cluster_id=cluster.id
)
self.db.add(task)
self.db.flush()
kwargs = {
'task_uuid': task.uuid,