19886: crunch-run records initial log with PDH
authorBrett Smith <brett.smith@curii.com>
Wed, 18 Jan 2023 19:35:58 +0000 (14:35 -0500)
committerBrett Smith <brett.smith@curii.com>
Wed, 18 Jan 2023 19:35:58 +0000 (14:35 -0500)
The API server will only propagate a container's log collection to
container requests when it is specified with a portable data hash. See
the top of ContainerRequest#update_collections.

Arvados-DCO-1.1-Signed-off-by: Brett Smith <brett.smith@curii.com>

lib/crunchrun/crunchrun.go
lib/crunchrun/crunchrun_test.go

index d322a3ac3c03f1eb178b9b2e6919de20cf30a390..6384f6a1cd7149998c6fa63588b2ec2745bc9bc7 100644 (file)
@@ -1427,18 +1427,25 @@ func (runner *ContainerRunner) saveLogCollection(final bool) (response arvados.C
 }
 
 // UpdateContainerRunning updates the container state to "Running"
-func (runner *ContainerRunner) UpdateContainerRunning() error {
+func (runner *ContainerRunner) UpdateContainerRunning(logId string) error {
        runner.cStateLock.Lock()
        defer runner.cStateLock.Unlock()
        if runner.cCancelled {
                return ErrCancelled
        }
-       return runner.DispatcherArvClient.Update("containers", runner.Container.UUID,
-               arvadosclient.Dict{"container": arvadosclient.Dict{
-                       "state":           "Running",
-                       "gateway_address": runner.gateway.Address,
-                       "log":             runner.logUUID,
-               }}, nil)
+       updates := arvadosclient.Dict{
+               "gateway_address": runner.gateway.Address,
+               "state":           "Running",
+       }
+       if logId != "" {
+               updates["log"] = logId
+       }
+       return runner.DispatcherArvClient.Update(
+               "containers",
+               runner.Container.UUID,
+               arvadosclient.Dict{"container": updates},
+               nil,
+       )
 }
 
 // ContainerToken returns the api_token the container (and any
@@ -1629,11 +1636,14 @@ func (runner *ContainerRunner) Run() (err error) {
                return
        }
 
-       _, err = runner.saveLogCollection(false)
-       if err != nil {
+       logCollection, err := runner.saveLogCollection(false)
+       var logId string
+       if err == nil {
+               logId = logCollection.PortableDataHash
+       } else {
                runner.CrunchLog.Printf("Error committing initial log collection: %v", err)
        }
-       err = runner.UpdateContainerRunning()
+       err = runner.UpdateContainerRunning(logId)
        if err != nil {
                return
        }
index 1997d21537a0b560d92ddd9167971661749cd5ac..fdb6338cb6359cca0718bdb4212362b9a05b0aa7 100644 (file)
@@ -595,7 +595,7 @@ func (s *TestSuite) TestUpdateContainerRunning(c *C) {
        cr, err := NewContainerRunner(s.client, api, kc, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
        c.Assert(err, IsNil)
 
-       err = cr.UpdateContainerRunning()
+       err = cr.UpdateContainerRunning("")
        c.Check(err, IsNil)
 
        c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Running")
@@ -925,7 +925,11 @@ func (s *TestSuite) TestCommitNodeInfoBeforeStart(c *C) {
        c.Check(manifest_text, Matches, `\. .+ \d+:\d{2,}:node\.json( .+)?\n`)
 
        c.Assert(container_update, NotNil)
-       c.Check(container_update["container"].(arvadosclient.Dict)["log"], Matches, `zzzzz-4zz18-[0-9a-z]{15}`)
+       // As of Arvados 2.5.0, the container update must specify its log in PDH
+       // format for the API server to propagate it to container requests, which
+       // is what we care about for this test.
+       expect_pdh := fmt.Sprintf("%x+%d", md5.Sum([]byte(manifest_text)), len(manifest_text))
+       c.Check(container_update["container"].(arvadosclient.Dict)["log"], Equals, expect_pdh)
 }
 
 func (s *TestSuite) TestContainerRecordLog(c *C) {