1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
16 "git.arvados.org/arvados.git/sdk/go/arvados"
17 "git.arvados.org/arvados.git/sdk/go/arvadosclient"
18 "git.arvados.org/arvados.git/sdk/go/arvadostest"
19 "git.arvados.org/arvados.git/sdk/go/keepclient"
23 var _ = Suite(&integrationSuite{})
25 type integrationSuite struct {
27 image arvados.Collection
28 input arvados.Collection
32 cr arvados.ContainerRequest
33 client *arvados.Client
34 ac *arvadosclient.ArvadosClient
35 kc *keepclient.KeepClient
38 func (s *integrationSuite) SetUpSuite(c *C) {
39 arvadostest.StartKeep(2, true)
41 out, err := exec.Command("docker", "load", "--input", busyboxDockerImage(c)).CombinedOutput()
44 out, err = exec.Command("arv-keepdocker", "--no-resume", "busybox:uclibc").Output()
45 imageUUID := strings.TrimSpace(string(out))
46 c.Logf("image uuid %s", imageUUID)
48 err = arvados.NewClientFromEnv().RequestAndDecode(&s.image, "GET", "arvados/v1/collections/"+imageUUID, nil, nil)
50 c.Logf("image pdh %s", s.image.PortableDataHash)
52 s.client = arvados.NewClientFromEnv()
53 s.ac, err = arvadosclient.New(s.client)
55 s.kc = keepclient.New(s.ac)
56 fs, err := s.input.FileSystem(s.client, s.kc)
58 f, err := fs.OpenFile("inputfile", os.O_CREATE|os.O_WRONLY, 0755)
60 _, err = f.Write([]byte("inputdata"))
64 s.input.ManifestText, err = fs.MarshalManifest(".")
66 err = s.client.RequestAndDecode(&s.input, "POST", "arvados/v1/collections", nil, map[string]interface{}{
67 "ensure_unique_name": true,
68 "collection": map[string]interface{}{
69 "manifest_text": s.input.ManifestText,
73 c.Logf("input pdh %s", s.input.PortableDataHash)
76 func (s *integrationSuite) TearDownSuite(c *C) {
77 err := s.client.RequestAndDecode(nil, "POST", "database/reset", nil, nil)
81 func (s *integrationSuite) SetUpTest(c *C) {
83 s.stdin = bytes.Buffer{}
84 s.stdout = bytes.Buffer{}
85 s.stderr = bytes.Buffer{}
86 s.cr = arvados.ContainerRequest{
89 OutputPath: "/mnt/out",
90 ContainerImage: s.image.PortableDataHash,
91 Mounts: map[string]arvados.Mount{
94 Content: []interface{}{
96 map[string]string{"foo": "bar"},
102 PortableDataHash: s.input.PortableDataHash,
109 RuntimeConstraints: arvados.RuntimeConstraints{
117 func (s *integrationSuite) setup(c *C) {
118 err := s.client.RequestAndDecode(&s.cr, "POST", "arvados/v1/container_requests", nil, map[string]interface{}{"container_request": map[string]interface{}{
119 "priority": s.cr.Priority,
121 "command": s.cr.Command,
122 "output_path": s.cr.OutputPath,
123 "container_image": s.cr.ContainerImage,
124 "mounts": s.cr.Mounts,
125 "runtime_constraints": s.cr.RuntimeConstraints,
126 "use_existing": false,
129 c.Assert(s.cr.ContainerUUID, Not(Equals), "")
130 err = s.client.RequestAndDecode(nil, "POST", "arvados/v1/containers/"+s.cr.ContainerUUID+"/lock", nil, nil)
134 func (s *integrationSuite) TestRunTrivialContainerWithDocker(c *C) {
136 s.testRunTrivialContainer(c)
139 func (s *integrationSuite) TestRunTrivialContainerWithSingularity(c *C) {
140 s.engine = "singularity"
141 s.testRunTrivialContainer(c)
144 func (s *integrationSuite) testRunTrivialContainer(c *C) {
145 if err := exec.Command("which", s.engine).Run(); err != nil {
146 c.Skip(fmt.Sprintf("%s: %s", s.engine, err))
148 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"}
150 code := command{}.RunCommand("crunch-run", []string{
151 "-runtime-engine=" + s.engine,
152 "-enable-memory-limit=false",
154 }, &s.stdin, io.MultiWriter(&s.stdout, os.Stderr), io.MultiWriter(&s.stderr, os.Stderr))
155 c.Check(code, Equals, 0)
156 err := s.client.RequestAndDecode(&s.cr, "GET", "arvados/v1/container_requests/"+s.cr.UUID, nil, nil)
158 c.Logf("Finished container request: %#v", s.cr)
160 var log arvados.Collection
161 err = s.client.RequestAndDecode(&log, "GET", "arvados/v1/collections/"+s.cr.LogUUID, nil, nil)
163 fs, err := log.FileSystem(s.client, s.kc)
165 if d, err := fs.Open("/"); c.Check(err, IsNil) {
166 fis, err := d.Readdir(-1)
168 for _, fi := range fis {
172 f, err := fs.Open(fi.Name())
174 buf, err := ioutil.ReadAll(f)
176 c.Logf("\n===== %s =====\n%s", fi.Name(), buf)
180 var output arvados.Collection
181 err = s.client.RequestAndDecode(&output, "GET", "arvados/v1/collections/"+s.cr.OutputUUID, nil, nil)
183 fs, err = output.FileSystem(s.client, s.kc)
185 if f, err := fs.Open("inputfile"); c.Check(err, IsNil) {
187 buf, err := ioutil.ReadAll(f)
189 c.Check(string(buf), Equals, "inputdata")
191 if f, err := fs.Open("json"); c.Check(err, IsNil) {
193 buf, err := ioutil.ReadAll(f)
195 c.Check(string(buf), Equals, `["foo",{"foo":"bar"},null]`)
197 if fi, err := fs.Stat("emptydir"); c.Check(err, IsNil) {
198 c.Check(fi.IsDir(), Equals, true)
200 if d, err := fs.Open("emptydir"); c.Check(err, IsNil) {
202 fis, err := d.Readdir(-1)
204 // crunch-run still saves a ".keep" file to preserve
205 // empty dirs even though that shouldn't be
206 // necessary. Ideally we would do:
207 // c.Check(fis, HasLen, 0)
208 for _, fi := range fis {
209 c.Check(fi.Name(), Equals, ".keep")