14495: Add warnings when estimateDockerImageSize gets bad input
authorPeter Amstutz <pamstutz@veritasgenetics.com>
Thu, 13 Dec 2018 15:37:26 +0000 (10:37 -0500)
committerPeter Amstutz <pamstutz@veritasgenetics.com>
Thu, 13 Dec 2018 15:37:26 +0000 (10:37 -0500)
Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <pamstutz@veritasgenetics.com>

lib/dispatchcloud/node_size.go
lib/dispatchcloud/node_size_test.go

index 7706e411b4b721be1c1ff378ac49ebe03fc92333..339e042c1aa0d15cb3f6cf1994c6146bf34de11d 100644 (file)
@@ -38,10 +38,12 @@ var pdhRegexp = regexp.MustCompile(`^[0-9a-f]{32}\+(\d+)$`)
 func estimateDockerImageSize(collectionPDH string) int64 {
        m := pdhRegexp.FindStringSubmatch(collectionPDH)
        if m == nil {
+               log.Printf("estimateDockerImageSize: '%v' did not match pdhRegexp, returning 0", collectionPDH)
                return 0
        }
        n, err := strconv.ParseInt(m[1], 10, 64)
        if err != nil || n < 122 {
+               log.Printf("estimateDockerImageSize: short manifest %v or error (%v), returning 0", n, err)
                return 0
        }
        // To avoid having to fetch the collection, take advantage of
index e948538160ea943e3d4ea080c181e1e7cf108c48..eef86f74775134b4c6b0848d0b2897c5d47bef29 100644 (file)
@@ -128,4 +128,16 @@ func (*NodeSizeSuite) TestScratchForDockerImage(c *check.C) {
        // Estimated size is 384 MiB (402653184 bytes)
        // Want to reserve 2x the estimated size, so 805306368 bytes
        c.Check(n, check.Equals, int64(805306368))
+
+       n = EstimateScratchSpace(&arvados.Container{
+               ContainerImage: "d5025c0f29f6eef304a7358afa82a822+-342",
+       })
+       // Parse error will return 0
+       c.Check(n, check.Equals, int64(0))
+
+       n = EstimateScratchSpace(&arvados.Container{
+               ContainerImage: "d5025c0f29f6eef304a7358afa82a822+34",
+       })
+       // Short manifest will return 0
+       c.Check(n, check.Equals, int64(0))
 }