X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_mon%2Ftest%2FOpenStack%2Fintegration%2Ftest_metric_integration.py;h=578c8b191d04b1107ee52bb6bc3ab244d598d9a7;hb=93699898c51364cde193d8d441f4aed45670e7bf;hp=eb672dabd1708f9a52a4afb12ac4ef3f76d50061;hpb=a4ffa936b4f8a2bfcd1b64541e00c93aac449a56;p=osm%2FMON.git diff --git a/osm_mon/test/OpenStack/integration/test_metric_integration.py b/osm_mon/test/OpenStack/integration/test_metric_integration.py index eb672da..578c8b1 100644 --- a/osm_mon/test/OpenStack/integration/test_metric_integration.py +++ b/osm_mon/test/OpenStack/integration/test_metric_integration.py @@ -31,7 +31,6 @@ from kafka.errors import KafkaError from osm_mon.core.auth import AuthManager from osm_mon.core.database import VimCredentials -from osm_mon.core.message_bus.producer import KafkaProducer as Producer from kafka import KafkaConsumer from kafka import KafkaProducer @@ -40,7 +39,7 @@ import mock from osm_mon.plugins.OpenStack import response -from osm_mon.plugins.OpenStack.Gnocchi import metrics +from osm_mon.plugins.OpenStack.Gnocchi import metric_handler from osm_mon.plugins.OpenStack.common import Common @@ -50,13 +49,12 @@ mock_creds = VimCredentials() mock_creds.config = '{}' -@mock.patch.object(Producer, "publish_alarm_request", mock.Mock()) @mock.patch.object(Common, "get_auth_token", mock.Mock()) @mock.patch.object(Common, "get_endpoint", mock.Mock()) class MetricIntegrationTest(unittest.TestCase): def setUp(self): # Set up common and alarming class instances - self.metric_req = metrics.Metrics() + self.metric_req = metric_handler.OpenstackMetricHandler() self.openstack_auth = Common() try: @@ -75,8 +73,8 @@ class MetricIntegrationTest(unittest.TestCase): @mock.patch.object(Common, "perform_request") @mock.patch.object(AuthManager, 'get_credentials') - @mock.patch.object(metrics.Metrics, "configure_metric") - @mock.patch.object(response.OpenStack_Response, "generate_response") + @mock.patch.object(metric_handler.OpenstackMetricHandler, "configure_metric") + @mock.patch.object(response.OpenStackResponseBuilder, "generate_response") def test_create_metric_req(self, resp, config_metric, get_creds, perf_req): """Test Gnocchi create metric request message from producer.""" # Set-up message, producer and consumer for tests @@ -94,21 +92,21 @@ class MetricIntegrationTest(unittest.TestCase): for message in self.req_consumer: if message.key == "create_metric_request": # A valid metric is created - config_metric.return_value = "metric_id", "resource_id", True - self.metric_req.metric_calls(message, 'test_id') + config_metric.return_value = "metric_id", "resource_id" + self.metric_req.handle_request(message, 'test_id') # A response message is generated and sent by MON's producer resp.assert_called_with( 'create_metric_response', status=True, cor_id=123, - metric_id="metric_id", r_id="resource_id") + metric_id="metric_id", resource_id="resource_id") return self.fail("No message received in consumer") @mock.patch.object(Common, "perform_request") @mock.patch.object(AuthManager, 'get_credentials') - @mock.patch.object(metrics.Metrics, "delete_metric") - @mock.patch.object(response.OpenStack_Response, "generate_response") + @mock.patch.object(metric_handler.OpenstackMetricHandler, "delete_metric") + @mock.patch.object(response.OpenStackResponseBuilder, "generate_response") def test_delete_metric_req(self, resp, del_metric, get_creds, perf_req): """Test Gnocchi delete metric request message from producer.""" # Set-up message, producer and consumer for tests @@ -129,12 +127,12 @@ class MetricIntegrationTest(unittest.TestCase): if message.key == "delete_metric_request": # Metric has been deleted del_metric.return_value = True - self.metric_req.metric_calls(message, 'test_id') + self.metric_req.handle_request(message, 'test_id') # A response message is generated and sent by MON's producer resp.assert_called_with( - 'delete_metric_response', m_id='1', - m_name="cpu_utilization", status=True, r_id="resource_id", + 'delete_metric_response', metric_id='1', + metric_name="cpu_utilization", status=True, resource_id="resource_id", cor_id=123) return @@ -142,8 +140,8 @@ class MetricIntegrationTest(unittest.TestCase): @mock.patch.object(Common, "perform_request") @mock.patch.object(AuthManager, 'get_credentials') - @mock.patch.object(metrics.Metrics, "read_metric_data") - @mock.patch.object(response.OpenStack_Response, "generate_response") + @mock.patch.object(metric_handler.OpenstackMetricHandler, "read_metric_data") + @mock.patch.object(response.OpenStackResponseBuilder, "generate_response") def test_read_metric_data_req(self, resp, read_data, get_creds, perf_req): """Test Gnocchi read metric data request message from producer.""" # Set-up message, producer and consumer for tests @@ -165,21 +163,21 @@ class MetricIntegrationTest(unittest.TestCase): if message.key == "read_metric_data_request": # Mock empty lists generated by the request message read_data.return_value = [], [] - self.metric_req.metric_calls(message, 'test_id') + self.metric_req.handle_request(message, 'test_id') # A response message is generated and sent by MON's producer resp.assert_called_with( - 'read_metric_data_response', m_id='1', - m_name="cpu_utilization", r_id="resource_id", cor_id=123, times=[], - metrics=[]) + 'read_metric_data_response', metric_id='1', + metric_name="cpu_utilization", resource_id="resource_id", cor_id=123, times=[], + metrics=[], status=True) return self.fail("No message received in consumer") @mock.patch.object(Common, "perform_request") @mock.patch.object(AuthManager, 'get_credentials') - @mock.patch.object(metrics.Metrics, "list_metrics") - @mock.patch.object(response.OpenStack_Response, "generate_response") + @mock.patch.object(metric_handler.OpenstackMetricHandler, "list_metrics") + @mock.patch.object(response.OpenStackResponseBuilder, "generate_response") def test_list_metrics_req(self, resp, list_metrics, get_creds, perf_req): """Test Gnocchi list metrics request message from producer.""" # Set-up message, producer and consumer for tests @@ -200,23 +198,23 @@ class MetricIntegrationTest(unittest.TestCase): if message.key == "list_metric_request": # Mock an empty list generated by the request list_metrics.return_value = [] - self.metric_req.metric_calls(message, 'test_id') + self.metric_req.handle_request(message, 'test_id') # A response message is generated and sent by MON's producer resp.assert_called_with( - 'list_metric_response', m_list=[], cor_id=123) + 'list_metric_response', metric_list=[], cor_id=123, status=True) return self.fail("No message received in consumer") @mock.patch.object(Common, "perform_request") @mock.patch.object(AuthManager, 'get_credentials') - @mock.patch.object(metrics.Metrics, "get_metric_id") - @mock.patch.object(response.OpenStack_Response, "generate_response") + @mock.patch.object(metric_handler.OpenstackMetricHandler, "get_metric_id") + @mock.patch.object(response.OpenStackResponseBuilder, "generate_response") def test_update_metrics_req(self, resp, get_id, get_creds, perf_req): """Test Gnocchi update metric request message from KafkaProducer.""" # Set-up message, producer and consumer for tests - payload = {"metric_create_request": {"metric_name": "my_metric", + payload = {"metric_update_request": {"metric_name": "my_metric", "correlation_id": 123, "resource_uuid": "resource_id", }} @@ -232,13 +230,13 @@ class MetricIntegrationTest(unittest.TestCase): if message.key == "update_metric_request": # Gnocchi doesn't support metric updates get_id.return_value = "metric_id" - self.metric_req.metric_calls(message, 'test_id') + self.metric_req.handle_request(message, 'test_id') # Response message is generated and sent via MON's producer # No metric update has taken place resp.assert_called_with( 'update_metric_response', status=False, cor_id=123, - r_id="resource_id", m_id="metric_id") + resource_id="resource_id", metric_id="metric_id") return self.fail("No message received in consumer")