def test_collect_performance_stats_unsupported_metric(self, mock_hosts_stats): mock_hosts_stats.return_value = { "statsSpecificResponses": [ { "successful": True, "message": None, "startTimeInUsecs": 1476739262143200, "intervalInSecs": 20, "metric": "hypervisor_memory_usage_ppm", "values": [12345, 12345] } ] } cluster = AcropolisCluster(self.cluster_metadata) nodes = [mock.Mock(spec=AcropolisNode) for _ in xrange(4)] for id, node in enumerate(nodes): node.node_id.return_value = id node.cpu_capacity_in_hz = 12345 with mock.patch.object(cluster, "nodes") as mock_nodes: mock_nodes.return_value = nodes with mock.patch.object(cluster, "metrics") as mock_metrics: mock_metrics.return_value = [ CurieMetric(name=CurieMetric.kDatastoreRead, description="This should not be supported.", instance="*", type=CurieMetric.kGauge, consolidation=CurieMetric.kAvg, unit=CurieMetric.kKilobytes, rate=CurieMetric.kPerSecond)] with self.assertRaises(CurieTestException): cluster.collect_performance_stats()
def test_collect_performance_stats_empty(self, mock_hosts_stats): mock_hosts_stats.return_value = { "statsSpecificResponses": [ { "successful": True, "message": None, "startTimeInUsecs": 1476739262143200, "intervalInSecs": 20, "metric": "hypervisor_memory_usage_ppm", "values": [] }, { "successful": True, "message": None, "startTimeInUsecs": 1476739262143200, "intervalInSecs": 20, "metric": "hypervisor_num_transmitted_bytes", "values": [] }, { "successful": True, "message": None, "startTimeInUsecs": 1476739262143200, "intervalInSecs": 20, "metric": "hypervisor_cpu_usage_ppm", "values": [] }, { "successful": True, "message": None, "startTimeInUsecs": 1476739262143200, "intervalInSecs": 20, "metric": "hypervisor_num_received_bytes", "values": [] } ] } cluster = AcropolisCluster(self.cluster_metadata) nodes = [mock.Mock(spec=AcropolisNode) for _ in xrange(4)] for id, node in enumerate(nodes): node.node_id.return_value = id node.cpu_capacity_in_hz = 12345 with mock.patch.object(cluster, "nodes") as mock_nodes: mock_nodes.return_value = nodes results_map = cluster.collect_performance_stats() self.assertEqual(results_map.keys(), sorted(results_map.keys())) for node_id in results_map: self.assertEqual(len(results_map[node_id]), len(cluster.metrics()))