# 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'],
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)
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(
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']
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()
@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")