X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/efe3cb087cc269daa5e41f669ecbb4c0d14bcfc6..87bf45c8c4db3c7dd58edabab429286dcabfcd7d:/lib/dispatchcloud/test/stub_driver.go diff --git a/lib/dispatchcloud/test/stub_driver.go b/lib/dispatchcloud/test/stub_driver.go index 917853cf83..5873e49221 100644 --- a/lib/dispatchcloud/test/stub_driver.go +++ b/lib/dispatchcloud/test/stub_driver.go @@ -62,6 +62,7 @@ func (sd *StubDriver) InstanceSet(params json.RawMessage, id cloud.InstanceSetID } sis := StubInstanceSet{ driver: sd, + logger: logger, servers: map[cloud.InstanceID]*StubVM{}, } sd.instanceSets = append(sd.instanceSets, &sis) @@ -91,6 +92,7 @@ func (sd *StubDriver) ReleaseCloudOps(n int) { type StubInstanceSet struct { driver *StubDriver + logger logrus.FieldLogger servers map[cloud.InstanceID]*StubVM mtx sync.RWMutex stopped bool @@ -99,7 +101,7 @@ type StubInstanceSet struct { allowInstancesCall time.Time } -func (sis *StubInstanceSet) Create(it arvados.InstanceType, image cloud.ImageID, tags cloud.InstanceTags, authKey ssh.PublicKey) (cloud.Instance, error) { +func (sis *StubInstanceSet) Create(it arvados.InstanceType, image cloud.ImageID, tags cloud.InstanceTags, cmd cloud.InitCommand, authKey ssh.PublicKey) (cloud.Instance, error) { if sis.driver.HoldCloudOps { sis.driver.holdCloudOps <- true } @@ -123,6 +125,7 @@ func (sis *StubInstanceSet) Create(it arvados.InstanceType, image cloud.ImageID, id: cloud.InstanceID(fmt.Sprintf("stub-%s-%x", it.ProviderType, math_rand.Int63())), tags: copyTags(tags), providerType: it.ProviderType, + initCommand: cmd, } svm.SSHService = SSHService{ HostKey: sis.driver.HostKey, @@ -184,6 +187,7 @@ type StubVM struct { sis *StubInstanceSet id cloud.InstanceID tags cloud.InstanceTags + initCommand cloud.InitCommand providerType string SSHService SSHService running map[string]bool @@ -226,13 +230,12 @@ func (svm *StubVM) Exec(env map[string]string, command string, stdin io.Reader, fmt.Fprint(stderr, "crunch-run: command not found\n") return 1 } - if strings.HasPrefix(command, "source /dev/stdin; crunch-run --detach ") { - stdinKV := map[string]string{} - for _, line := range strings.Split(string(stdinData), "\n") { - kv := strings.SplitN(strings.TrimPrefix(line, "export "), "=", 2) - if len(kv) == 2 && len(kv[1]) > 0 { - stdinKV[kv[0]] = kv[1] - } + if strings.HasPrefix(command, "crunch-run --detach --stdin-env ") { + var stdinKV map[string]string + err := json.Unmarshal(stdinData, &stdinKV) + if err != nil { + fmt.Fprintf(stderr, "unmarshal stdin: %s (stdin was: %q)\n", err, stdinData) + return 1 } for _, name := range []string{"ARVADOS_API_HOST", "ARVADOS_API_TOKEN"} { if stdinKV[name] == "" { @@ -248,7 +251,7 @@ func (svm *StubVM) Exec(env map[string]string, command string, stdin io.Reader, svm.Unlock() time.Sleep(svm.CrunchRunDetachDelay) fmt.Fprintf(stderr, "starting %s\n", uuid) - logger := logrus.WithFields(logrus.Fields{ + logger := svm.sis.logger.WithFields(logrus.Fields{ "Instance": svm.id, "ContainerUUID": uuid, })