8a2e62d7e77c232618a9525873983ac3f321d594
[arvados.git] / lib / crunchrun / singularity_test.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 package crunchrun
6
7 import (
8         "os/exec"
9
10         . "gopkg.in/check.v1"
11 )
12
13 var _ = Suite(&singularitySuite{})
14
15 type singularitySuite struct {
16         executorSuite
17 }
18
19 func (s *singularitySuite) SetUpSuite(c *C) {
20         _, err := exec.LookPath("singularity")
21         if err != nil {
22                 c.Skip("looks like singularity is not installed")
23         }
24         s.newExecutor = func(c *C) {
25                 var err error
26                 s.executor, err = newSingularityExecutor(c.Logf)
27                 c.Assert(err, IsNil)
28         }
29 }
30
31 func (s *singularitySuite) TestInject(c *C) {
32         path, err := exec.LookPath("nsenter")
33         if err != nil || path != "/var/lib/arvados/bin/nsenter" {
34                 c.Skip("looks like /var/lib/arvados/bin/nsenter is not installed -- re-run `arvados-server install`?")
35         }
36         s.executorSuite.TestInject(c)
37 }
38
39 var _ = Suite(&singularityStubSuite{})
40
41 // singularityStubSuite tests don't really invoke singularity, so we
42 // can run them even if singularity is not installed.
43 type singularityStubSuite struct{}
44
45 func (s *singularityStubSuite) TestSingularityExecArgs(c *C) {
46         e, err := newSingularityExecutor(c.Logf)
47         c.Assert(err, IsNil)
48         err = e.Create(containerSpec{
49                 WorkingDir:      "/WorkingDir",
50                 Env:             map[string]string{"FOO": "bar"},
51                 BindMounts:      map[string]bindmount{"/mnt": {HostPath: "/hostpath", ReadOnly: true}},
52                 EnableNetwork:   false,
53                 CUDADeviceCount: 3,
54         })
55         c.Check(err, IsNil)
56         e.imageFilename = "/fake/image.sif"
57         cmd := e.execCmd("./singularity")
58         c.Check(cmd.Args, DeepEquals, []string{"./singularity", "exec", "--containall", "--cleanenv", "--pwd", "/WorkingDir", "--net", "--network=none", "--nv", "--bind", "/hostpath:/mnt:ro", "/fake/image.sif"})
59         c.Check(cmd.Env, DeepEquals, []string{"SINGULARITYENV_FOO=bar"})
60 }