1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
17 "git.arvados.org/arvados.git/lib/config"
18 "git.arvados.org/arvados.git/sdk/go/arvados"
19 "git.arvados.org/arvados.git/sdk/go/arvadosclient"
20 "git.arvados.org/arvados.git/sdk/go/arvadostest"
21 "git.arvados.org/arvados.git/sdk/go/ctxlog"
22 "git.arvados.org/arvados.git/sdk/go/keepclient"
26 var _ = Suite(&integrationSuite{})
28 type integrationSuite struct {
30 image arvados.Collection
31 input arvados.Collection
35 cr arvados.ContainerRequest
36 client *arvados.Client
37 ac *arvadosclient.ArvadosClient
38 kc *keepclient.KeepClient
40 logCollection arvados.Collection
41 outputCollection arvados.Collection
44 func (s *integrationSuite) SetUpSuite(c *C) {
45 _, err := exec.LookPath("docker")
47 c.Skip("looks like docker is not installed")
50 arvadostest.StartKeep(2, true)
52 out, err := exec.Command("docker", "load", "--input", busyboxDockerImage(c)).CombinedOutput()
55 out, err = exec.Command("arv-keepdocker", "--no-resume", "busybox:uclibc").Output()
56 imageUUID := strings.TrimSpace(string(out))
57 c.Logf("image uuid %s", imageUUID)
58 if !c.Check(err, IsNil) {
59 if err, ok := err.(*exec.ExitError); ok {
60 c.Logf("%s", err.Stderr)
64 err = arvados.NewClientFromEnv().RequestAndDecode(&s.image, "GET", "arvados/v1/collections/"+imageUUID, nil, nil)
66 c.Logf("image pdh %s", s.image.PortableDataHash)
68 s.client = arvados.NewClientFromEnv()
69 s.ac, err = arvadosclient.New(s.client)
71 s.kc = keepclient.New(s.ac)
72 fs, err := s.input.FileSystem(s.client, s.kc)
74 f, err := fs.OpenFile("inputfile", os.O_CREATE|os.O_WRONLY, 0755)
76 _, err = f.Write([]byte("inputdata"))
80 s.input.ManifestText, err = fs.MarshalManifest(".")
82 err = s.client.RequestAndDecode(&s.input, "POST", "arvados/v1/collections", nil, map[string]interface{}{
83 "ensure_unique_name": true,
84 "collection": map[string]interface{}{
85 "manifest_text": s.input.ManifestText,
89 c.Logf("input pdh %s", s.input.PortableDataHash)
92 func (s *integrationSuite) TearDownSuite(c *C) {
93 os.Unsetenv("ARVADOS_KEEP_SERVICES")
98 err := s.client.RequestAndDecode(nil, "POST", "database/reset", nil, nil)
102 func (s *integrationSuite) SetUpTest(c *C) {
103 os.Unsetenv("ARVADOS_KEEP_SERVICES")
105 s.stdin = bytes.Buffer{}
106 s.stdout = bytes.Buffer{}
107 s.stderr = bytes.Buffer{}
108 s.logCollection = arvados.Collection{}
109 s.outputCollection = arvados.Collection{}
110 s.cr = arvados.ContainerRequest{
113 OutputPath: "/mnt/out",
114 ContainerImage: s.image.PortableDataHash,
115 Mounts: map[string]arvados.Mount{
118 Content: []interface{}{
120 map[string]string{"foo": "bar"},
126 PortableDataHash: s.input.PortableDataHash,
133 RuntimeConstraints: arvados.RuntimeConstraints{
141 func (s *integrationSuite) setup(c *C) {
142 err := s.client.RequestAndDecode(&s.cr, "POST", "arvados/v1/container_requests", nil, map[string]interface{}{"container_request": map[string]interface{}{
143 "priority": s.cr.Priority,
145 "command": s.cr.Command,
146 "output_path": s.cr.OutputPath,
147 "container_image": s.cr.ContainerImage,
148 "mounts": s.cr.Mounts,
149 "runtime_constraints": s.cr.RuntimeConstraints,
150 "use_existing": false,
153 c.Assert(s.cr.ContainerUUID, Not(Equals), "")
154 err = s.client.RequestAndDecode(nil, "POST", "arvados/v1/containers/"+s.cr.ContainerUUID+"/lock", nil, nil)
158 func (s *integrationSuite) TestRunTrivialContainerWithDocker(c *C) {
160 s.testRunTrivialContainer(c)
163 func (s *integrationSuite) TestRunTrivialContainerWithSingularity(c *C) {
164 s.engine = "singularity"
165 s.testRunTrivialContainer(c)
168 func (s *integrationSuite) TestRunTrivialContainerWithLocalKeepstore(c *C) {
169 for _, trial := range []struct {
173 matchStartupMessage Checker
175 {"none", Not(Matches), Not(Matches), Not(Matches)},
176 {"all", Matches, Matches, Matches},
177 {"errors", Not(Matches), Not(Matches), Matches},
179 c.Logf("=== testing with Containers.LocalKeepLogsToContainerLog: %q", trial.logConfig)
182 cfg, err := config.NewLoader(nil, ctxlog.TestLogger(c)).Load()
184 cluster, err := cfg.GetCluster("")
186 for uuid, volume := range cluster.Volumes {
187 volume.AccessViaHosts = nil
188 volume.Replication = 2
189 cluster.Volumes[uuid] = volume
191 cluster.Containers.LocalKeepLogsToContainerLog = trial.logConfig
194 err = json.NewEncoder(&s.stdin).Encode(ConfigData{
202 s.testRunTrivialContainer(c)
204 fs, err := s.logCollection.FileSystem(s.client, s.kc)
206 f, err := fs.Open("keepstore.txt")
207 if trial.logConfig == "none" {
209 c.Check(os.IsNotExist(err), Equals, true)
212 buf, err := ioutil.ReadAll(f)
214 c.Check(string(buf), trial.matchGetReq, `(?ms).*"reqMethod":"GET".*`)
215 c.Check(string(buf), trial.matchPutReq, `(?ms).*"reqMethod":"PUT".*,"reqPath":"0e3bcff26d51c895a60ea0d4585e134d".*`)
220 func (s *integrationSuite) testRunTrivialContainer(c *C) {
221 if err := exec.Command("which", s.engine).Run(); err != nil {
222 c.Skip(fmt.Sprintf("%s: %s", s.engine, err))
224 s.cr.Command = []string{"sh", "-c", "cat /mnt/in/inputfile >/mnt/out/inputfile && cat /mnt/json >/mnt/out/json && ! touch /mnt/in/shouldbereadonly && mkdir /mnt/out/emptydir"}
228 "-runtime-engine=" + s.engine,
229 "-enable-memory-limit=false",
232 if s.stdin.Len() > 0 {
233 args = append([]string{"-stdin-config=true"}, args...)
235 code := command{}.RunCommand("crunch-run", args, &s.stdin, io.MultiWriter(&s.stdout, os.Stderr), io.MultiWriter(&s.stderr, os.Stderr))
236 c.Logf("\n===== stdout =====\n%s", s.stdout.String())
237 c.Logf("\n===== stderr =====\n%s", s.stderr.String())
238 c.Check(code, Equals, 0)
239 err := s.client.RequestAndDecode(&s.cr, "GET", "arvados/v1/container_requests/"+s.cr.UUID, nil, nil)
241 c.Logf("Finished container request: %#v", s.cr)
243 var log arvados.Collection
244 err = s.client.RequestAndDecode(&log, "GET", "arvados/v1/collections/"+s.cr.LogUUID, nil, nil)
246 fs, err := log.FileSystem(s.client, s.kc)
248 if d, err := fs.Open("/"); c.Check(err, IsNil) {
249 fis, err := d.Readdir(-1)
251 for _, fi := range fis {
255 f, err := fs.Open(fi.Name())
257 buf, err := ioutil.ReadAll(f)
259 c.Logf("\n===== %s =====\n%s", fi.Name(), buf)
262 s.logCollection = log
264 var output arvados.Collection
265 err = s.client.RequestAndDecode(&output, "GET", "arvados/v1/collections/"+s.cr.OutputUUID, nil, nil)
267 fs, err = output.FileSystem(s.client, s.kc)
269 if f, err := fs.Open("inputfile"); c.Check(err, IsNil) {
271 buf, err := ioutil.ReadAll(f)
273 c.Check(string(buf), Equals, "inputdata")
275 if f, err := fs.Open("json"); c.Check(err, IsNil) {
277 buf, err := ioutil.ReadAll(f)
279 c.Check(string(buf), Equals, `["foo",{"foo":"bar"},null]`)
281 if fi, err := fs.Stat("emptydir"); c.Check(err, IsNil) {
282 c.Check(fi.IsDir(), Equals, true)
284 if d, err := fs.Open("emptydir"); c.Check(err, IsNil) {
286 fis, err := d.Readdir(-1)
288 // crunch-run still saves a ".keep" file to preserve
289 // empty dirs even though that shouldn't be
290 // necessary. Ideally we would do:
291 // c.Check(fis, HasLen, 0)
292 for _, fi := range fis {
293 c.Check(fi.Name(), Equals, ".keep")
296 s.outputCollection = output