From 6f5431413448f52f3ae5c88553b7f7ee1532b9fd Mon Sep 17 00:00:00 2001 From: Ward Vandewege Date: Sun, 6 Dec 2020 10:54:11 -0500 Subject: [PATCH] 17187: costanalyzer: print the total from the aggregate cost accounting across all uuids to stdout. Arvados-DCO-1.1-Signed-off-by: Ward Vandewege --- lib/costanalyzer/costanalyzer.go | 6 ++++++ lib/costanalyzer/costanalyzer_test.go | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/lib/costanalyzer/costanalyzer.go b/lib/costanalyzer/costanalyzer.go index 01a9d9fdb6..bca23b1535 100644 --- a/lib/costanalyzer/costanalyzer.go +++ b/lib/costanalyzer/costanalyzer.go @@ -94,6 +94,9 @@ Usage: In order to get the data for the uuids supplied, the ARVADOS_API_HOST and ARVADOS_API_TOKEN environment variables must be set. + This program prints the total dollar amount from the aggregate cost + accounting across all provided uuids on stdout. + Options: `, prog) flags.PrintDefaults() @@ -548,5 +551,8 @@ func costanalyzer(prog string, args []string, loader *config.Loader, logger *log return } logger.Infof("Aggregate cost accounting for all supplied uuids in %s\n", aFile) + // Output the total dollar amount on stdout + fmt.Fprintf(stdout, "%s\n", strconv.FormatFloat(total, 'f', 8, 64)) + return } diff --git a/lib/costanalyzer/costanalyzer_test.go b/lib/costanalyzer/costanalyzer_test.go index 36421dc7f2..48e7733e18 100644 --- a/lib/costanalyzer/costanalyzer_test.go +++ b/lib/costanalyzer/costanalyzer_test.go @@ -290,6 +290,12 @@ func (*Suite) TestMultipleContainerRequestUUIDWithReuse(c *check.C) { c.Check(exitcode, check.Equals, 0) c.Assert(stderr.String(), check.Matches, "(?ms).*supplied uuids in .*") + // Check that the total amount was printed to stdout + c.Check(stdout.String(), check.Matches, "0.01492030\n") + + stdout.Truncate(0) + stderr.Truncate(0) + // Run costanalyzer with 2 container request uuids exitcode = Command.RunCommand("costanalyzer.test", []string{"-uuid", arvadostest.CompletedDiagnosticsContainerRequest1UUID, "-uuid", arvadostest.CompletedDiagnosticsContainerRequest2UUID, "-output", "results"}, &bytes.Buffer{}, &stdout, &stderr) c.Check(exitcode, check.Equals, 0) -- 2.30.2