X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/10d70a1c08984a699ac3f6b893fe6d2141c5ad9e..7db74f672f64b3e647a98c1d8e5978b50d79538d:/lib/cloud/cloudtest/cmd.go diff --git a/lib/cloud/cloudtest/cmd.go b/lib/cloud/cloudtest/cmd.go index 1f94ea6da2..2dc13e5a51 100644 --- a/lib/cloud/cloudtest/cmd.go +++ b/lib/cloud/cloudtest/cmd.go @@ -11,14 +11,13 @@ import ( "fmt" "io" "os" - "os/user" - "git.curoverse.com/arvados.git/lib/cloud" - "git.curoverse.com/arvados.git/lib/config" - "git.curoverse.com/arvados.git/lib/dispatchcloud" - "git.curoverse.com/arvados.git/sdk/go/arvados" - "git.curoverse.com/arvados.git/sdk/go/ctxlog" - "golang.org/x/crypto/ssh" + "git.arvados.org/arvados.git/lib/cloud" + "git.arvados.org/arvados.git/lib/cmd" + "git.arvados.org/arvados.git/lib/config" + "git.arvados.org/arvados.git/lib/dispatchcloud" + "git.arvados.org/arvados.git/sdk/go/arvados" + "git.arvados.org/arvados.git/sdk/go/ctxlog" ) var Command command @@ -36,23 +35,14 @@ func (command) RunCommand(prog string, args []string, stdin io.Reader, stdout, s flags := flag.NewFlagSet("", flag.ContinueOnError) flags.SetOutput(stderr) configFile := flags.String("config", arvados.DefaultConfigFile, "Site configuration `file`") - instanceSetID := flags.String("instance-set-id", defaultInstanceSetID(), "InstanceSetID tag `value` to use on the test instance") + instanceSetID := flags.String("instance-set-id", "zzzzz-zzzzz-zzzzzzcloudtest", "InstanceSetID tag `value` to use on the test instance") imageID := flags.String("image-id", "", "Image ID to use when creating the test instance (if empty, use cluster config)") instanceType := flags.String("instance-type", "", "Instance type to create (if empty, use cheapest type in config)") destroyExisting := flags.Bool("destroy-existing", false, "Destroy any existing instances tagged with our InstanceSetID, instead of erroring out") shellCommand := flags.String("command", "", "Run an interactive shell command on the test instance when it boots") pauseBeforeDestroy := flags.Bool("pause-before-destroy", false, "Prompt and wait before destroying the test instance") - err = flags.Parse(args) - if err == flag.ErrHelp { - err = nil - return 0 - } else if err != nil { - return 2 - } - - if len(flags.Args()) != 0 { - flags.Usage() - return 2 + if ok, code := cmd.ParseFlags(flags, prog, args, "", stderr); !ok { + return code } logger := ctxlog.New(stderr, "text", "info") defer func() { @@ -64,7 +54,9 @@ func (command) RunCommand(prog string, args []string, stdin io.Reader, stdout, s logger.Info("exiting") }() - cfg, err := config.LoadFile(*configFile, logger) + loader := config.NewLoader(stdin, logger) + loader.Path = *configFile + cfg, err := loader.Load() if err != nil { return 1 } @@ -72,9 +64,9 @@ func (command) RunCommand(prog string, args []string, stdin io.Reader, stdout, s if err != nil { return 1 } - key, err := ssh.ParsePrivateKey([]byte(cluster.Containers.DispatchPrivateKey)) + key, err := config.LoadSSHKey(cluster.Containers.DispatchPrivateKey) if err != nil { - err = fmt.Errorf("error parsing configured Containers.DispatchPrivateKey: %s", err) + err = fmt.Errorf("error loading Containers.DispatchPrivateKey: %s", err) return 1 } driver, ok := dispatchcloud.Drivers[cluster.Containers.CloudVMs.Driver] @@ -93,22 +85,24 @@ func (command) RunCommand(prog string, args []string, stdin io.Reader, stdout, s tagKeyPrefix := cluster.Containers.CloudVMs.TagKeyPrefix tags[tagKeyPrefix+"CloudTestPID"] = fmt.Sprintf("%d", os.Getpid()) if !(&tester{ - Logger: logger, - Tags: tags, - TagKeyPrefix: tagKeyPrefix, - SetID: cloud.InstanceSetID(*instanceSetID), - DestroyExisting: *destroyExisting, - ProbeInterval: cluster.Containers.CloudVMs.ProbeInterval.Duration(), - SyncInterval: cluster.Containers.CloudVMs.SyncInterval.Duration(), - TimeoutBooting: cluster.Containers.CloudVMs.TimeoutBooting.Duration(), - Driver: driver, - DriverParameters: cluster.Containers.CloudVMs.DriverParameters, - ImageID: cloud.ImageID(*imageID), - InstanceType: it, - SSHKey: key, - SSHPort: cluster.Containers.CloudVMs.SSHPort, - BootProbeCommand: cluster.Containers.CloudVMs.BootProbeCommand, - ShellCommand: *shellCommand, + Logger: logger, + Tags: tags, + TagKeyPrefix: tagKeyPrefix, + SetID: cloud.InstanceSetID(*instanceSetID), + DestroyExisting: *destroyExisting, + ProbeInterval: cluster.Containers.CloudVMs.ProbeInterval.Duration(), + SyncInterval: cluster.Containers.CloudVMs.SyncInterval.Duration(), + TimeoutBooting: cluster.Containers.CloudVMs.TimeoutBooting.Duration(), + Driver: driver, + DriverParameters: cluster.Containers.CloudVMs.DriverParameters, + ImageID: cloud.ImageID(*imageID), + InstanceType: it, + SSHKey: key, + SSHPort: cluster.Containers.CloudVMs.SSHPort, + DeployPublicKey: cluster.Containers.CloudVMs.DeployPublicKey, + BootProbeCommand: cluster.Containers.CloudVMs.BootProbeCommand, + InstanceInitCommand: cloud.InitCommand(cluster.Containers.CloudVMs.InstanceInitCommand), + ShellCommand: *shellCommand, PauseBeforeDestroy: func() { if *pauseBeforeDestroy { logger.Info("waiting for operator to press Enter") @@ -122,15 +116,6 @@ func (command) RunCommand(prog string, args []string, stdin io.Reader, stdout, s return 0 } -func defaultInstanceSetID() string { - username := "" - if u, err := user.Current(); err == nil { - username = u.Username - } - hostname, _ := os.Hostname() - return fmt.Sprintf("cloudtest-%s@%s", username, hostname) -} - // Return the named instance type, or the cheapest type if name=="". func chooseInstanceType(cluster *arvados.Cluster, name string) (arvados.InstanceType, error) { if len(cluster.InstanceTypes) == 0 {