From: gcalvino Date: Mon, 16 Apr 2018 14:26:09 +0000 (+0200) Subject: Get Metric_UUID directly from VIM X-Git-Tag: v4.0.0~14^2 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F74%2F5974%2F6;p=osm%2FMON.git Get Metric_UUID directly from VIM Change-Id: I9b8c47b2fd7987f8834dc7c90e826d9d2789ce51 Signed-off-by: gcalvino --- diff --git a/osm_mon/plugins/OpenStack/Gnocchi/metrics.py b/osm_mon/plugins/OpenStack/Gnocchi/metrics.py index 1dc9496..a30b732 100644 --- a/osm_mon/plugins/OpenStack/Gnocchi/metrics.py +++ b/osm_mon/plugins/OpenStack/Gnocchi/metrics.py @@ -111,9 +111,12 @@ class Metrics(object): # Generate and send a response message try: + + metric_id = self.get_metric_id(endpoint, auth_token, METRIC_MAPPINGS[values['metric_name']], + values['resource_uuid']) resp_message = self._response.generate_response( 'read_metric_data_response', - m_id=values['metric_uuid'], + m_id=metric_id, m_name=values['metric_name'], r_id=values['resource_uuid'], cor_id=values['correlation_id'], @@ -127,7 +130,8 @@ class Metrics(object): elif message.key == "delete_metric_request": # delete the specified metric in the request - metric_id = values['metric_uuid'] + metric_id = self.get_metric_id(endpoint, auth_token, METRIC_MAPPINGS[values['metric_name']], + values['resource_uuid']) status = self.delete_metric( endpoint, auth_token, metric_id) @@ -348,7 +352,6 @@ class Metrics(object): def get_metric_id(self, endpoint, auth_token, metric_name, resource_id): """Check if the desired metric already exists for the resource.""" url = "{}/v1/resource/generic/%s".format(endpoint) % resource_id - try: # Try return the metric id if it exists result = Common.perform_request( @@ -374,8 +377,9 @@ class Metrics(object): timestamps = [] data = [] try: + #get metric_id + metric_id = self.get_metric_id(endpoint, auth_token, METRIC_MAPPINGS[values['metric_name']], values['resource_uuid']) # Try and collect measures - metric_id = values['metric_uuid'] collection_unit = values['collection_unit'].upper() collection_period = values['collection_period'] diff --git a/osm_mon/test/OpenStack/test_metric_calls.py b/osm_mon/test/OpenStack/test_metric_calls.py index b77df5e..51282b1 100644 --- a/osm_mon/test/OpenStack/test_metric_calls.py +++ b/osm_mon/test/OpenStack/test_metric_calls.py @@ -238,13 +238,16 @@ class TestMetricCalls(unittest.TestCase): self.assertEqual(metric_name, "my_invalid_metric") self.assertEqual(norm_name, None) + @mock.patch.object(metric_req.Metrics, "get_metric_id") @mock.patch.object(Common, "perform_request") - def test_valid_read_data_req(self, perf_req): + def test_valid_read_data_req(self, perf_req, get_metric): """Test the read metric data function, for a valid call.""" - values = {"metric_uuid": "metric_id", + values = {"metric_name": "disk_write_ops", + "resource_uuid": "resource_id", "collection_unit": "DAY", "collection_period": 1} + get_metric.return_value = "metric_id" self.metrics.read_metric_data(endpoint, auth_token, values) perf_req.assert_called_once() diff --git a/osm_mon/test/OpenStack/test_metric_req.py b/osm_mon/test/OpenStack/test_metric_req.py index 6a924d9..0869b56 100644 --- a/osm_mon/test/OpenStack/test_metric_req.py +++ b/osm_mon/test/OpenStack/test_metric_req.py @@ -68,14 +68,16 @@ class TestMetricReq(unittest.TestCase): @mock.patch.object(Common, "get_auth_token", mock.Mock()) @mock.patch.object(Common, 'get_endpoint', mock.Mock()) @mock.patch.object(metric_req.Metrics, "delete_metric") - def test_delete_metric_key(self, del_metric): + @mock.patch.object(metric_req.Metrics, "get_metric_id") + def test_delete_metric_key(self, get_metric_id, del_metric): """Test the functionality for a delete metric request.""" # Mock a message value and key message = Message() message.key = "delete_metric_request" - message.value = json.dumps({"vim_uuid": "test_id", "metric_uuid": "my_metric_id"}) + message.value = json.dumps({"vim_uuid": "test_id", "metric_name": "disk_write_ops", "resource_uuid": "my_r_id"}) # Call the metric functionality and check delete request + get_metric_id.return_value = "my_metric_id" self.metrics.metric_calls(message) del_metric.assert_called_with(mock.ANY, mock.ANY, "my_metric_id")