Add unit test cases for Ranger-agent health check
This patch also disable health check for heat component during upstream gate process. Change-Id: Ic5717f00212e924c059654c93d26fd2f2002438e
This commit is contained in:
parent
8fb22dab18
commit
02114b616b
|
@ -18,6 +18,7 @@ resource_status_check_wait = 15
|
|||
api_paste_config = /etc/ranger-agent/api-paste.ini
|
||||
transport_url = rabbit://stackrabbit:devstack@127.0.0.1:5672/
|
||||
enable_rds_callback_check = True
|
||||
enable_heat_health_check = True
|
||||
|
||||
[api]
|
||||
# Address to bind the API server to
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_config import cfg
|
||||
import oslo_db
|
||||
|
||||
from ord.client import heat
|
||||
|
@ -20,6 +21,13 @@ from ord.db.sqlalchemy import api as db_api
|
|||
from ord.openstack.common import log as logging
|
||||
|
||||
|
||||
CONF = cfg.CONF
|
||||
CONF.register_opts([
|
||||
cfg.BoolOpt('enable_heat_health_check',
|
||||
default=True,
|
||||
help='enable health check on heat')
|
||||
])
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
@ -46,19 +54,20 @@ class HealthCheck(object):
|
|||
status['database'] = 'failed'
|
||||
|
||||
# Check Heat connectivity
|
||||
try:
|
||||
LOG.debug("Health Heat test starting")
|
||||
heat.HeatClient().delete_stack('none_existence_id')
|
||||
except exc.HEATStackDeleteError as heatex:
|
||||
LOG.error('Health Heat Test Exp in %s: %r',
|
||||
cls.__name__, heatex, exc_info=True)
|
||||
if 'MessagingTimeout' in heatex.message:
|
||||
if CONF.enable_heat_health_check:
|
||||
try:
|
||||
LOG.debug("Health Heat test starting")
|
||||
heat.HeatClient().delete_stack('none_existence_id')
|
||||
except exc.HEATStackDeleteError as heatex:
|
||||
if 'MessagingTimeout' in heatex.message:
|
||||
LOG.error('Health Heat Test Exp in %s: %r',
|
||||
cls.__name__, heatex, exc_info=True)
|
||||
status['heat'] = 'failed'
|
||||
else:
|
||||
status['heat'] = 'passed'
|
||||
except Exception:
|
||||
LOG.error('Unknown Heat Test Exp in %s',
|
||||
cls.__name__, exc_info=True)
|
||||
status['heat'] = 'failed'
|
||||
else:
|
||||
status['heat'] = 'passed'
|
||||
except Exception:
|
||||
LOG.error('Unknown Heat Test Exp in %s',
|
||||
cls.__name__, exc_info=True)
|
||||
status['heat'] = 'failed'
|
||||
|
||||
return status
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
# Copyright (c) 2019 ATT
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
"""
|
||||
Unit Tests for ord.api.test_healthcheck
|
||||
"""
|
||||
import mock
|
||||
from mock import patch
|
||||
|
||||
from ord.api import healthcheck
|
||||
from ord.db import api as db_api
|
||||
from ord.tests import base
|
||||
import oslo_db
|
||||
|
||||
|
||||
class OrdApiHealthcheckTestCase(base.BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(OrdApiHealthcheckTestCase, self).setUp()
|
||||
self.addCleanup(mock.patch.stopall)
|
||||
|
||||
@patch.object(db_api, 'retrieve_health_record', return_value={})
|
||||
def test_execute_health_check_success(self, mock_retrieve):
|
||||
status = healthcheck.HealthCheck.execute_health_check()
|
||||
self.assertEqual(status['database'], 'passed')
|
||||
|
||||
@patch.object(db_api, 'retrieve_health_record',
|
||||
side_effect=oslo_db.exception.DBConnectionError())
|
||||
def test_execute_health_check_failure(self, mock_retrieve):
|
||||
status = healthcheck.HealthCheck.execute_health_check()
|
||||
|
||||
self.assertEqual(status['database'], 'failed')
|
|
@ -81,3 +81,10 @@ class TestORDNotify(base.BaseTestCase):
|
|||
db_api.retrieve_target_by_status("fake_id")
|
||||
mock_session.assert_called_once_with()
|
||||
assert mock_query.called
|
||||
|
||||
@mock.patch.object(db_api, 'get_session')
|
||||
@mock.patch.object(db_api, 'model_query')
|
||||
def test_retrieve_health_record(self, mock_query, mock_session):
|
||||
db_api.retrieve_health_record()
|
||||
mock_session.assert_called_once_with()
|
||||
assert mock_query.called
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
# Copyright (c) 2019 ATT
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
"""
|
||||
Unit Tests for ord.engine.healthcheck
|
||||
"""
|
||||
import mock
|
||||
from mock import patch
|
||||
|
||||
from ord.client import heat
|
||||
from ord.common import exceptions as exc
|
||||
from ord.db.sqlalchemy import api as db_api
|
||||
from ord.engine import healthcheck
|
||||
from ord.tests import base
|
||||
|
||||
import oslo_db
|
||||
|
||||
|
||||
class OrdEngineHealthcheckTestCase(base.BaseTestCase):
|
||||
|
||||
PATH_PREFIX = ''
|
||||
|
||||
def setUp(self):
|
||||
super(OrdEngineHealthcheckTestCase, self).setUp()
|
||||
self.addCleanup(mock.patch.stopall)
|
||||
|
||||
@patch.object(heat.HeatClient, 'delete_stack', return_value='id')
|
||||
@patch.object(heat, 'HeatClient')
|
||||
@patch.object(db_api, 'retrieve_health_record', return_value={})
|
||||
def test_execute_health_check_db_success(self, mock_retrieve,
|
||||
mock_heat, mock_delete):
|
||||
status = healthcheck.HealthCheck.execute_health_check()
|
||||
|
||||
expected = {'database': 'passed', 'heat': 'unknown'}
|
||||
self.assertEqual(status, expected)
|
||||
|
||||
@patch.object(heat.HeatClient, 'delete_stack', return_value='id')
|
||||
@patch.object(heat, 'HeatClient')
|
||||
@patch.object(db_api, 'retrieve_health_record',
|
||||
side_effect=oslo_db.exception.DBConnectionError())
|
||||
def test_execute_health_check_db_failure(self, mock_retrieve,
|
||||
mock_heat, mock_delete):
|
||||
status = healthcheck.HealthCheck.execute_health_check()
|
||||
|
||||
expected = {'database': 'failed', 'heat': 'unknown'}
|
||||
self.assertEqual(status, expected)
|
||||
|
||||
@patch.object(heat.HeatClient, 'delete_stack',
|
||||
side_effect=exc.HEATStackDeleteError())
|
||||
@patch.object(db_api, 'retrieve_health_record', return_value={})
|
||||
def test_execute_health_check_heat_success(self, mock_retrieve,
|
||||
mock_delete):
|
||||
status = healthcheck.HealthCheck.execute_health_check()
|
||||
|
||||
expected = {'database': 'passed', 'heat': 'passed'}
|
||||
self.assertEqual(status, expected)
|
||||
|
||||
@patch.object(heat.HeatClient, 'delete_stack',
|
||||
side_effect=exc.HEATStackDeleteError('MessagingTimeout'))
|
||||
@patch.object(db_api, 'retrieve_health_record', return_value={})
|
||||
def test_execute_health_check_heat_failure(self, mock_retrieve,
|
||||
mock_delete):
|
||||
status = healthcheck.HealthCheck.execute_health_check()
|
||||
|
||||
expected = {'database': 'passed', 'heat': 'failed'}
|
||||
self.assertEqual(status, expected)
|
Loading…
Reference in New Issue