X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_mon%2Ftest%2FOpenStack%2Funit%2Ftest_alarm_req.py;h=e5f0d867140c327e7520fcd85bc848c1a29dc910;hb=e2fe4582e9569ea8146e945f278179126821ab76;hp=41b683658d720715fc650af363d8c70d02acbee8;hpb=b726161f9fe605ceb418d9b5df12d295bff28c3a;p=osm%2FMON.git diff --git a/osm_mon/test/OpenStack/unit/test_alarm_req.py b/osm_mon/test/OpenStack/unit/test_alarm_req.py index 41b6836..e5f0d86 100644 --- a/osm_mon/test/OpenStack/unit/test_alarm_req.py +++ b/osm_mon/test/OpenStack/unit/test_alarm_req.py @@ -137,18 +137,30 @@ class TestAlarmKeys(unittest.TestCase): @mock.patch.object(Common, 'get_auth_token', mock.Mock()) @mock.patch.object(Common, 'get_endpoint', mock.Mock()) @mock.patch.object(DatabaseManager, 'save_alarm', mock.Mock()) + @mock.patch.object(Common, "perform_request") @mock.patch.object(AuthManager, 'get_credentials') @mock.patch.object(alarm_req.Alarming, 'configure_alarm') - def test_config_alarm_key(self, config_alarm, get_creds): + def test_config_alarm_key(self, config_alarm, get_creds, perf_req): """Test the functionality for a create alarm request.""" # Mock a message with config alarm key and value message = Message() message.key = 'create_alarm_request' - message.value = json.dumps({'alarm_create_request': {'correlation_id': 1}}) - + message.value = json.dumps({'alarm_create_request': {'correlation_id': 1, 'threshold_value': 50, + 'operation': 'GT', 'metric_name': 'cpu_utilization', + 'vdu_name': 'vdu', + 'vnf_member_index': '1', + 'ns_id': '1', + 'resource_uuid': '123'}}) + mock_perf_req_return_value = {"metrics": {"cpu_util": 123}} + perf_req.return_value = type('obj', (object,), {'text': json.dumps(mock_perf_req_return_value, sort_keys=True)}) get_creds.return_value = mock_creds # Call alarming functionality and check config alarm call - config_alarm.return_value = 'my_alarm_id', True + config_alarm.return_value = 'my_alarm_id' self.alarming.alarming(message, 'test_id') - config_alarm.assert_called_with(mock.ANY, mock.ANY, mock.ANY, {'correlation_id': 1}, {}) + config_alarm.assert_called_with(mock.ANY, mock.ANY, {'correlation_id': 1, 'threshold_value': 50, + 'operation': 'GT', + 'metric_name': 'cpu_utilization', + 'vdu_name': 'vdu', + 'vnf_member_index': '1', 'ns_id': '1', + 'resource_uuid': '123'}, {})