def test_copy_metric(self): """Test copy of a single metric with aggregated points.""" cmd_copy = command_copy.CommandCopy() # Chack that _METRIC_2 is empty for i in range(3): pts = self.accessor.fetch_points(self._METRIC_2, self._POINTS_START, self._POINTS_END, stage=self._METRIC_2.retention[i]) self.assertEqual(list(pts), []) # Copy points from _METRIC_1 to _METRIC_2 cmd_copy._copy_metric(self.accessor, self._METRIC_1, self._METRIC_2, self._POINTS_START, self._POINTS_END) self.accessor.flush() # Check that both metrics have same points for i in range(3): pts = self.accessor.fetch_points(self._METRIC_1, self._POINTS_START, self._POINTS_END, stage=self._METRIC_1.retention[i], aggregated=False) pts_copy = self.accessor.fetch_points( self._METRIC_2, self._POINTS_START, self._POINTS_END, stage=self._METRIC_2.retention[i], aggregated=False) self.assertEqual(list(pts), list(pts_copy))
def test_copy_metric_with_retention(self): """Test copy of a metric with aggregated points and retention override. A given dst_stage should have the same points of the src_stage that have the same precision, or no point at all. """ cmd_copy = command_copy.CommandCopy() cmd_copy._copy_metric(self.accessor, self._METRIC_1, self._METRIC_3, self._POINTS_START, self._POINTS_END) self.accessor.flush() for i in range(3): pts = self.accessor.fetch_points(self._METRIC_1, self._POINTS_START, self._POINTS_END, stage=self._METRIC_1.retention[i], aggregated=False) pts_copy = self.accessor.fetch_points( self._METRIC_3, self._POINTS_START, self._POINTS_END, stage=self._METRIC_3.retention[i], aggregated=False) if i == 0: self.assertNotEqual(list(pts), list(pts_copy)) else: self.assertEqual(list(pts), list(pts_copy))
def test_get_metric_tuples_with_directory(self): """Test retrieve of a single couple of metrics.""" cmd_copy = command_copy.CommandCopy() # Test with subdirectory names arguments self.assertEqual(len(list(list_metrics(self.accessor, "*.**"))), 2) metric_tuples = cmd_copy._get_metric_tuples( accessor=self.accessor, src="test", dst="copy", src_retention="", dst_retention="", recursive=True, dry_run=False ) self.assertEqual(len(list(metric_tuples)), 2) self.assertEqual(len(list(list_metrics(self.accessor, "*.**"))), 4)
def test_get_metric_tuples_with_metric(self): """Test retrieve of a single couple of metrics.""" cmd_copy = command_copy.CommandCopy() # Test with metric names arguments expected_metric_tuples = [(self._METRIC_1, self._METRIC_2)] metric_tuples = cmd_copy._get_metric_tuples(accessor=self.accessor, src=self._METRIC_1_NAME, dst=self._METRIC_2_NAME, src_retention="", dst_retention="", recursive=False, dry_run=False) self.assertEqual(list(metric_tuples), expected_metric_tuples)
def test_get_metric_tuples_with_retention(self): """Test retrieve of a single couples of metrics overrinding retentions.""" cmd_copy = command_copy.CommandCopy() metric_tuples = cmd_copy._get_metric_tuples( accessor=self.accessor, src=self._METRIC_1_NAME, dst=self._METRIC_2_NAME, src_retention="18*42s", dst_retention="50*300s", recursive=False, dry_run=False ) retention_str = [m.metadata.retention.as_string for m in list(metric_tuples)[ 0]] self.assertEqual(len(retention_str), 2) self.assertIn("18*42s", retention_str) self.assertIn("50*300s", retention_str)
def test_get_metric_tuples(self): """Test retrieve of a single metric.""" cmd_copy = command_copy.CommandCopy() # Test with metric names arguments expected_metric_tuples = [ (self._METRIC_1, self._METRIC_2) ] metric_tuples = cmd_copy._get_metric_tuples( accessor=self.accessor, src=self._METRIC_1_NAME, dst=self._METRIC_2_NAME, recursive=False, dry_run=False ) self.assertEqual(list(metric_tuples), expected_metric_tuples) # Test with subdirectory names arguments self.assertEqual(len(list(list_metrics(self.accessor, "*.**"))), 2) metric_tuples = cmd_copy._get_metric_tuples( accessor=self.accessor, src="test", dst="copy", recursive=True, dry_run=False ) self.assertEqual(len(list(metric_tuples)), 2) self.assertEqual(len(list(list_metrics(self.accessor, "*.**"))), 4)
command_du, command_graphite_web, command_info, command_list, command_read, command_repair, command_shell, command_stats, command_syncdb, command_test, command_write, ) COMMANDS = [ command_clean.CommandClean(), command_copy.CommandCopy(), command_daemon.CommandDaemon(), command_delete.CommandDelete(), command_du.CommandDu(), command_graphite_web.CommandGraphiteWeb(), command_info.CommandInfo(), command_list.CommandList(), command_read.CommandRead(), command_repair.CommandRepair(), command_shell.CommandShell(), command_stats.CommandStats(), command_syncdb.CommandSyncdb(), command_test.CommandTest(), command_write.CommandWrite(), ]