17706: when a container request has no container associated (e.g. when
authorWard Vandewege <ward@curii.com>
Thu, 20 May 2021 20:05:29 +0000 (16:05 -0400)
committerWard Vandewege <ward@curii.com>
Thu, 20 May 2021 20:05:29 +0000 (16:05 -0400)
       it is in the Uncommitted state), skip it instead of erroring out.

Arvados-DCO-1.1-Signed-off-by: Ward Vandewege <ward@curii.com>

lib/costanalyzer/costanalyzer.go
lib/costanalyzer/costanalyzer_test.go
sdk/go/arvadostest/fixtures.go

index 402e0ec81a160e677a1aefb8df82d589f01c3e20..71cb59093ab2b7c9ba6e7ffcbe71d4cab513acd0 100644 (file)
@@ -406,6 +406,11 @@ func generateCrCsv(logger *logrus.Logger, uuid string, arv *arvadosclient.Arvado
        if err != nil {
                return nil, fmt.Errorf("error loading cr object %s: %s", uuid, err)
        }
+       if len(cr.ContainerUUID) == 0 {
+               // Nothing to do! E.g. a CR in 'Uncommitted' state.
+               logger.Infof("No container associated with container request %s, skipping\n", crUUID)
+               return nil, nil
+       }
        var container arvados.Container
        err = loadObject(logger, ac, crUUID, cr.ContainerUUID, cache, &container)
        if err != nil {
index f4d8d1073068651d8e0f0c0bc72eb91316108763..8bb507d3772fca21ae5e187b03fd1b8979a34fb2 100644 (file)
@@ -290,6 +290,18 @@ func (*Suite) TestDoubleContainerRequestUUID(c *check.C) {
        c.Check(string(aggregateCostReport), check.Matches, "(?ms).*TOTAL,49.28334000")
 }
 
+func (*Suite) TestUncommittedContainerRequest(c *check.C) {
+       var stdout, stderr bytes.Buffer
+       // Run costanalyzer with 2 container request uuids, one of which is in the Uncommitted state, without output directory specified
+       exitcode := Command.RunCommand("costanalyzer.test", []string{arvadostest.UncommittedContainerRequestUUID, arvadostest.CompletedDiagnosticsContainerRequest2UUID}, &bytes.Buffer{}, &stdout, &stderr)
+       c.Check(exitcode, check.Equals, 0)
+       c.Assert(stderr.String(), check.Not(check.Matches), "(?ms).*supplied uuids in .*")
+       c.Assert(stderr.String(), check.Matches, "(?ms).*No container associated with container request .*")
+
+       // Check that the total amount was printed to stdout
+       c.Check(stdout.String(), check.Matches, "0.00588088\n")
+}
+
 func (*Suite) TestMultipleContainerRequestUUIDWithReuse(c *check.C) {
        var stdout, stderr bytes.Buffer
        // Run costanalyzer with 2 container request uuids, without output directory specified
index aeb5a47e6d0559df094ee3cbec5432d3b3b8f2ce..4b22c08265b2f095d99996c35f37e92677050b1f 100644 (file)
@@ -62,6 +62,8 @@ const (
        CompletedDiagnosticsHasher2ContainerUUID        = "zzzzz-dz642-diagcomphasher2"
        CompletedDiagnosticsHasher3ContainerUUID        = "zzzzz-dz642-diagcomphasher3"
 
+       UncommittedContainerRequestUUID = "zzzzz-xvhdp-cr4uncommittedc"
+
        Hasher1LogCollectionUUID = "zzzzz-4zz18-dlogcollhash001"
        Hasher2LogCollectionUUID = "zzzzz-4zz18-dlogcollhash002"
        Hasher3LogCollectionUUID = "zzzzz-4zz18-dlogcollhash003"