e1a9b9a96a
Change upgrades the monasca-notification to leverage the capabilities of both oslo.log and oslo.conf: - configuration of logging separated from application settings - ability to enforce data types for application settings - ability to use oslo.config-generator capabilities - automatic configuration parsing done by oslo.cfg That change will bring it closer to the rest of monasca components where such transition has happened already. However, in the rest of monasca, oslo.cfg was partially or fully implemented whereas monasca-notification has been relying on YAML based configuration file. Therefore backward compatybility for such format will be kept for now. Story: 2000959 Task: 4093 Task: 4092 Change-Id: Ia75c3b60d0fada854178f21ca5ccb9e6a880f37f
61 lines
1.9 KiB
Python
61 lines
1.9 KiB
Python
# (C) Copyright 2015 Hewlett Packard Enterprise Development LP
|
|
# Copyright 2017 Fujitsu LIMITED
|
|
#
|
|
# 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.
|
|
|
|
import mock
|
|
|
|
import pymysql
|
|
|
|
from monasca_notification.common.repositories import exceptions as exc
|
|
from monasca_notification.common.repositories.mysql import mysql_repo
|
|
from tests import base
|
|
|
|
|
|
class TestMySqlRepo(base.BaseTestCase):
|
|
def setUp(self):
|
|
super(TestMySqlRepo, self).setUp()
|
|
self.conf_default(group='mysql', host='localhost',
|
|
port=3306, user='bar',
|
|
passwd='1', db='2')
|
|
|
|
@mock.patch('monasca_notification.common.repositories.mysql.mysql_repo.pymysql')
|
|
def testReconnect(self, mock_mysql):
|
|
m = mock.MagicMock()
|
|
|
|
m.cursor.side_effect = pymysql.Error
|
|
|
|
mock_mysql.connect.return_value = m
|
|
mock_mysql.Error = pymysql.Error
|
|
|
|
repo = mysql_repo.MysqlRepo(base.config.CONF)
|
|
|
|
alarm = {'alarmDefinitionId': 'foo',
|
|
'newState': 'bar'}
|
|
|
|
def get_notification(repo, alarm):
|
|
g = repo.fetch_notifications(alarm)
|
|
for x in g:
|
|
pass
|
|
|
|
try:
|
|
get_notification(repo, alarm)
|
|
except exc.DatabaseException:
|
|
try:
|
|
get_notification(repo, alarm)
|
|
except Exception:
|
|
pass
|
|
|
|
self.assertEqual(mock_mysql.connect.call_count, 2)
|