Make cerberusdashboard independant of sticks

* make sure import sticksclient module does not block cerberusdashboard
* make sure buttons to create ticket are not displayed if module
sticksclient does not exist or if sticks api is not available

Change-Id: Id8a3711963679dce52e7ab15ad617dba24ae0445
This commit is contained in:
Romain Ziba 2015-06-10 16:07:01 +02:00
parent d20784133f
commit d24e33e2b3
5 changed files with 32 additions and 8 deletions

View File

@ -19,7 +19,13 @@ import logging
from cerberusclient import client as cerberus_client
from horizon.utils.memoized import memoized # noqa
from openstack_dashboard.api import base
from sticksclient import client as sticks_client
try:
from sticksclient import client as sticks_client
from sticksclient.common import exceptions as sticks_exc
except ImportError:
sticks_exc = None
sticks_client = None
pass
from cerberusdashboard.utils import importutils
@ -130,3 +136,16 @@ def security_alarm_put_ticket_id(request, sa_id, ticket_id):
def ticket_create(request, data):
"""Create a ticket from a security report."""
return sticksclient(request).tickets.create(data)
def is_sticks_available(request):
"""Create a ticket from a security report."""
if sticks_client is None:
LOG.exception("No module named sticksclient")
return False
try:
return isinstance(sticksclient(request).tickets.list(
data={'project': request.user.tenant_id}), list)
except sticks_exc.CommunicationError as e:
LOG.exception(e)
return False

View File

@ -15,9 +15,13 @@
#
from cerberusclient.common import exceptions as cerberusclient
from sticksclient.common import exceptions as sticksclient
try:
from sticksclient.common import exceptions as sticksclient
# HTTPInternalServerError is thrown by Redmine when project does not exist
# This error may change in the future (refer to sticks client)
RECOVERABLE = (sticksclient.HTTPInternalServerError,)
except ImportError:
RECOVERABLE = ()
pass
NOT_FOUND = (cerberusclient.HTTPNotFound,)
# HTTPInternalServerError is thrown by Redmine when project does not exist
# This error may change in the future (refer to sticks client)
RECOVERABLE = (sticksclient.HTTPInternalServerError,)

View File

@ -52,7 +52,8 @@ class CreateTicket(tables.BatchAction):
def allowed(self, request, alarm=None):
"""Allow terminate action if instance not currently being deleted."""
return not(is_associated(alarm))
return not(is_associated(alarm)) \
and api.cerberus.is_sticks_available(request)
def action(self, request, alarm_id):
alarm = api.cerberus.security_alarm_get(request, alarm_id)

View File

@ -53,7 +53,8 @@ class CreateTicket(tables.BatchAction):
def allowed(self, request, report=None):
"""Allow terminate action if instance not currently being deleted."""
return not(is_associated(report))
return not(is_associated(report)) \
and api.cerberus.is_sticks_available(request)
def action(self, request, report_id):
report = api.cerberus.security_report_get(request, report_id)

View File

@ -4,7 +4,6 @@ summary = Dashboard for Openstack Cerberus
description-file =
README.rst
author = OpenStack
version = 1.2-1
author-email = openstack-dev@lists.openstack.org
home-page = http://www.openstack.org/
classifier =