aboutsummaryrefslogtreecommitdiffstats
path: root/vm
diff options
context:
space:
mode:
Diffstat (limited to 'vm')
-rw-r--r--vm/adb/adb.go2
-rw-r--r--vm/gce/gce.go6
-rw-r--r--vm/kvm/kvm.go2
-rw-r--r--vm/odroid/odroid.go11
-rw-r--r--vm/qemu/qemu.go12
-rw-r--r--vm/vmimpl/vmimpl.go1
6 files changed, 16 insertions, 18 deletions
diff --git a/vm/adb/adb.go b/vm/adb/adb.go
index f6bc12328..0daad7fd6 100644
--- a/vm/adb/adb.go
+++ b/vm/adb/adb.go
@@ -50,7 +50,7 @@ func ctor(env *vmimpl.Env) (vmimpl.Pool, error) {
Adb: "adb",
}
if err := config.LoadData(env.Config, cfg); err != nil {
- return nil, err
+ return nil, fmt.Errorf("failed to parse adb vm config: %v", err)
}
if _, err := exec.LookPath(cfg.Adb); err != nil {
return nil, err
diff --git a/vm/gce/gce.go b/vm/gce/gce.go
index d0a181250..eeae077a5 100644
--- a/vm/gce/gce.go
+++ b/vm/gce/gce.go
@@ -34,7 +34,6 @@ type Config struct {
Count int // number of VMs to use
Machine_Type string // GCE machine type (e.g. "n1-highcpu-2")
GCS_Path string // GCS path to upload image
- Sshkey string // root ssh key for the image
}
type Pool struct {
@@ -68,7 +67,7 @@ func ctor(env *vmimpl.Env) (vmimpl.Pool, error) {
Count: 1,
}
if err := config.LoadData(env.Config, cfg); err != nil {
- return nil, err
+ return nil, fmt.Errorf("failed to parse gce vm config: %v", err)
}
if cfg.Count < 1 || cfg.Count > 1000 {
return nil, fmt.Errorf("invalid config param count: %v, want [1, 1000]", cfg.Count)
@@ -82,7 +81,6 @@ func ctor(env *vmimpl.Env) (vmimpl.Pool, error) {
if cfg.GCS_Path == "" {
return nil, fmt.Errorf("gcs_path parameter is empty")
}
- cfg.Sshkey = osutil.Abs(cfg.Sshkey)
GCE, err := gce.NewContext()
if err != nil {
@@ -150,7 +148,7 @@ func (pool *Pool) Create(workdir string, index int) (vmimpl.Instance, error) {
pool.GCE.DeleteInstance(name, true)
}
}()
- sshKey := pool.cfg.Sshkey
+ sshKey := pool.env.Sshkey
sshUser := "root"
if sshKey == "" {
// Assuming image supports GCE ssh fanciness.
diff --git a/vm/kvm/kvm.go b/vm/kvm/kvm.go
index 5c4c0f036..8f17f260c 100644
--- a/vm/kvm/kvm.go
+++ b/vm/kvm/kvm.go
@@ -64,7 +64,7 @@ func ctor(env *vmimpl.Env) (vmimpl.Pool, error) {
Lkvm: "lkvm",
}
if err := config.LoadData(env.Config, cfg); err != nil {
- return nil, err
+ return nil, fmt.Errorf("failed to parse kvm vm config: %v", err)
}
if cfg.Count < 1 || cfg.Count > 1000 {
return nil, fmt.Errorf("invalid config param count: %v, want [1, 1000]", cfg.Count)
diff --git a/vm/odroid/odroid.go b/vm/odroid/odroid.go
index 69c77b9c6..2d1f0482e 100644
--- a/vm/odroid/odroid.go
+++ b/vm/odroid/odroid.go
@@ -39,7 +39,6 @@ type Config struct {
Hub_Bus int // host USB bus number for the USB hub
Hub_Device int // host USB device number for the USB hub
Hub_Port int // port on the USB hub to which Odroid is connected
- Sshkey string // root ssh key for the image
}
type Pool struct {
@@ -49,6 +48,7 @@ type Pool struct {
type instance struct {
cfg *Config
+ sshkey string
closed chan bool
debug bool
}
@@ -56,7 +56,7 @@ type instance struct {
func ctor(env *vmimpl.Env) (vmimpl.Pool, error) {
cfg := &Config{}
if err := config.LoadData(env.Config, cfg); err != nil {
- return nil, err
+ return nil, fmt.Errorf("failed to parse odroid vm config: %v", err)
}
if cfg.Host_Addr == "" {
return nil, fmt.Errorf("config param host_addr is empty")
@@ -76,8 +76,8 @@ func ctor(env *vmimpl.Env) (vmimpl.Pool, error) {
if cfg.Hub_Port == 0 {
return nil, fmt.Errorf("config param hub_port is empty")
}
- if !osutil.IsExist(cfg.Sshkey) {
- return nil, fmt.Errorf("ssh key '%v' does not exist", cfg.Sshkey)
+ if !osutil.IsExist(env.Sshkey) {
+ return nil, fmt.Errorf("ssh key '%v' does not exist", env.Sshkey)
}
if !osutil.IxExist(cfg.Console) {
return nil, fmt.Errorf("console file '%v' does not exist", cfg.Console)
@@ -96,6 +96,7 @@ func (pool *Pool) Count() int {
func (pool *Pool) Create(workdir string, index int) (vmimpl.Instance, error) {
inst := &instance{
cfg: pool.cfg,
+ sshkey: pool.env.Sshkey,
closed: make(chan bool),
debug: pool.env.Debug,
}
@@ -397,7 +398,7 @@ func (inst *instance) Run(timeout time.Duration, stop <-chan bool, command strin
func (inst *instance) sshArgs(portArg string) []string {
args := []string{
- "-i", inst.cfg.Sshkey,
+ "-i", inst.sshkey,
portArg, "22",
"-F", "/dev/null",
"-o", "ConnectionAttempts=10",
diff --git a/vm/qemu/qemu.go b/vm/qemu/qemu.go
index 62fb408f9..a264d00b1 100644
--- a/vm/qemu/qemu.go
+++ b/vm/qemu/qemu.go
@@ -34,12 +34,11 @@ type Config struct {
Count int // number of VMs to use
Qemu string // qemu binary name (qemu-system-x86_64 by default)
Qemu_Args string // additional command line arguments for qemu binary
- Kernel string // e.g. arch/x86/boot/bzImage
+ Kernel string // kernel for injected boot (e.g. arch/x86/boot/bzImage)
Cmdline string // kernel command line (can only be specified with kernel)
Initrd string // linux initial ramdisk. (optional)
Cpu int // number of VM CPUs
Mem int // amount of VM memory in MBs
- Sshkey string // root ssh key for the image
}
type Pool struct {
@@ -67,7 +66,7 @@ func ctor(env *vmimpl.Env) (vmimpl.Pool, error) {
Qemu: "qemu-system-x86_64",
}
if err := config.LoadData(env.Config, cfg); err != nil {
- return nil, err
+ return nil, fmt.Errorf("failed to parse qemu vm config: %v", err)
}
if cfg.Count < 1 || cfg.Count > 1000 {
return nil, fmt.Errorf("invalid config param count: %v, want [1, 1000]", cfg.Count)
@@ -86,8 +85,8 @@ func ctor(env *vmimpl.Env) (vmimpl.Pool, error) {
if !osutil.IsExist(env.Image) {
return nil, fmt.Errorf("image file '%v' does not exist", env.Image)
}
- if !osutil.IsExist(cfg.Sshkey) {
- return nil, fmt.Errorf("ssh key '%v' does not exist", cfg.Sshkey)
+ if !osutil.IsExist(env.Sshkey) {
+ return nil, fmt.Errorf("ssh key '%v' does not exist", env.Sshkey)
}
}
if cfg.Cpu <= 0 || cfg.Cpu > 1024 {
@@ -98,7 +97,6 @@ func ctor(env *vmimpl.Env) (vmimpl.Pool, error) {
}
cfg.Kernel = osutil.Abs(cfg.Kernel)
cfg.Initrd = osutil.Abs(cfg.Initrd)
- cfg.Sshkey = osutil.Abs(cfg.Sshkey)
pool := &Pool{
cfg: cfg,
env: env,
@@ -111,7 +109,7 @@ func (pool *Pool) Count() int {
}
func (pool *Pool) Create(workdir string, index int) (vmimpl.Instance, error) {
- sshkey := pool.cfg.Sshkey
+ sshkey := pool.env.Sshkey
if pool.env.Image == "9p" {
sshkey = filepath.Join(workdir, "key")
keygen := exec.Command("ssh-keygen", "-t", "rsa", "-b", "2048", "-N", "", "-C", "", "-f", sshkey)
diff --git a/vm/vmimpl/vmimpl.go b/vm/vmimpl/vmimpl.go
index 4c542429c..9d2fff183 100644
--- a/vm/vmimpl/vmimpl.go
+++ b/vm/vmimpl/vmimpl.go
@@ -48,6 +48,7 @@ type Env struct {
Name string
Workdir string
Image string
+ Sshkey string
Debug bool
Config []byte // json-serialized VM-type-specific config
}