| 1 |
# |
| 2 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 3 |
# not use this file except in compliance with the License. You may obtain |
| 4 |
# a copy of the License at |
| 5 |
# |
| 6 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 7 |
# |
| 8 |
# Unless required by applicable law or agreed to in writing, software |
| 9 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 10 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 11 |
# License for the specific language governing permissions and limitations |
| 12 |
# under the License. |
| 13 |
|
| 14 |
import testtools |
| 15 |
from unittest import mock |
| 16 |
|
| 17 |
from aodhclient.v2 import metrics_cli |
| 18 |
|
| 19 |
|
| 20 |
class MetricsTest(testtools.TestCase): |
| 21 |
def setUp(self): |
| 22 |
super().setUp() |
| 23 |
self.app = mock.Mock() |
| 24 |
self.metrics_mgr_mock = self.app.client_manager.alarming.metrics |
| 25 |
self.parser = mock.Mock() |
| 26 |
self.metrics = ( |
| 27 |
metrics_cli.CliMetrics(self.app, self.parser)) |
| 28 |
|
| 29 |
def test_metrics(self): |
| 30 |
self.metrics_mgr_mock.get.return_value = { |
| 31 |
"evaluation_results": [ |
| 32 |
{ |
| 33 |
"alarm_id": "b8e17f58-089a-43fc-a96b-e9bcac4d4b53", |
| 34 |
"project_id": "2dd8edd6c8c24f49bf04670534f6b357", |
| 35 |
"state_counters": { |
| 36 |
"insufficient data": 1646, |
| 37 |
"ok": 0, |
| 38 |
"alarm": 0 |
| 39 |
} |
| 40 |
}, |
| 41 |
{ |
| 42 |
"alarm_id": "fa386719-67e3-42ff-aec8-17e547dac77a", |
| 43 |
"project_id": "2dd8edd6c8c24f49bf04670534f6b357", |
| 44 |
"state_counters": { |
| 45 |
"insufficient data": 4, |
| 46 |
"ok": 923, |
| 47 |
"alarm": 0 |
| 48 |
} |
| 49 |
}, |
| 50 |
{ |
| 51 |
"alarm_id": "0788bf8b-fc1f-4889-b5fd-5acd4d287bc3", |
| 52 |
"project_id": "d45b070bcce04ca99546128a40854e7c", |
| 53 |
"state_counters": { |
| 54 |
"insufficient data": 1646, |
| 55 |
"ok": 0, |
| 56 |
"alarm": 0 |
| 57 |
} |
| 58 |
} |
| 59 |
] |
| 60 |
} |
| 61 |
ret = self.metrics.take_action([]) |
| 62 |
|
| 63 |
self.metrics_mgr_mock.get.assert_called_once_with() |
| 64 |
self.assertIn('name', ret[0]) |
| 65 |
self.assertIn('evaluation_result', ret[1][0]) |