| 1 |
# Copyright(c) 2021 Inspur |
| 2 |
# |
| 3 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
# you may not use this file except in compliance with the License. |
| 5 |
# You may obtain a copy of the License at |
| 6 |
# |
| 7 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
# |
| 9 |
# Unless required by applicable law or agreed to in writing, software |
| 10 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
# See the License for the specific language governing permissions and |
| 13 |
# limitations under the License. |
| 14 |
|
| 15 |
import tempfile |
| 16 |
|
| 17 |
from oslo_config import fixture as fixture_config |
| 18 |
import testtools |
| 19 |
import yaml |
| 20 |
|
| 21 |
from masakarimonitors.hostmonitor.consul_check import matrix_helper |
| 22 |
|
| 23 |
|
| 24 |
class TestMatrixManager(testtools.TestCase): |
| 25 |
|
| 26 |
def setUp(self): |
| 27 |
super(TestMatrixManager, self).setUp() |
| 28 |
self.CONF = self.useFixture(fixture_config.Config()).conf |
| 29 |
|
| 30 |
def test_get_matrix_and_sequence_from_file(self): |
| 31 |
matrix_cfg = { |
| 32 |
'sequence': ['manage', 'tenant', 'storage'], |
| 33 |
'matrix': [{"health": ["up", "up", "up"], |
| 34 |
"action": ['test']}] |
| 35 |
} |
| 36 |
tmp_cfg = tempfile.NamedTemporaryFile(mode='w', delete=False) |
| 37 |
tmp_cfg.write(yaml.safe_dump(matrix_cfg)) |
| 38 |
tmp_cfg.close() |
| 39 |
self.CONF.set_override('matrix_config_file', |
| 40 |
tmp_cfg.name, group='consul') |
| 41 |
|
| 42 |
matrix_manager = matrix_helper.MatrixManager(self.CONF) |
| 43 |
self.assertEqual(matrix_cfg.get('sequence'), |
| 44 |
matrix_manager.get_sequence()) |
| 45 |
self.assertEqual(matrix_cfg.get('matrix'), |
| 46 |
matrix_manager.get_matrix()) |
| 47 |
|
| 48 |
def test_get_default_matrix_and_sequence(self): |
| 49 |
self.CONF.set_override('matrix_config_file', None, group='consul') |
| 50 |
|
| 51 |
matrix_manager = matrix_helper.MatrixManager(self.CONF) |
| 52 |
self.assertEqual(matrix_helper.DEFAULT_SEQUENCE, |
| 53 |
matrix_manager.get_sequence()) |
| 54 |
self.assertEqual(matrix_helper.DEFAULT_MATRIX, |
| 55 |
matrix_manager.get_matrix()) |