From af643baa328ae3d4b7076054bba648c4b8bf8056 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Fri, 2 Jun 2017 20:09:00 +0200 Subject: vm: overhaul VM infrastructure currently has several problems: - Config struct is complete mess with a superset of params for all VM types - verification of Config is mess spread across several places - there is no place where VM code could do global initialization like creating GCE connection, uploading GCE image to GCS, matching adb devices with consoles, etc - it hard to add private VM implementations such impl would need to add code to config package which would lead to constant merge conflicts - interface for VM implementation is mixed with interface for VM users this does not allow to provide best interface for both of them - there is no way to add common code for all VM implementations This change solves these problems by: - splitting VM interface for users (vm package) and VM interface for VM implementations (vmimpl pacakge), this in turn allows to add common code - adding Pool concept that allows to do global initialization and config checking at the right time - decoupling manager config from VM-specific config each VM type now defines own config Note: manager configs need to be changed after this change: VM-specific parts are moved to own "vm" subobject. Note: this change also drops "local" VM type. Its story was long unclear and there is now syz-stress which solves the same problem. --- pkg/config/config.go | 6 +++--- pkg/config/config_test.go | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'pkg/config') diff --git a/pkg/config/config.go b/pkg/config/config.go index 461ebdabc..03d4b283e 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -11,7 +11,7 @@ import ( "strings" ) -func Load(filename string, cfg interface{}) error { +func LoadFile(filename string, cfg interface{}) error { if filename == "" { return fmt.Errorf("no config file specified") } @@ -19,10 +19,10 @@ func Load(filename string, cfg interface{}) error { if err != nil { return fmt.Errorf("failed to read config file: %v", err) } - return load(data, cfg) + return LoadData(data, cfg) } -func load(data []byte, cfg interface{}) error { +func LoadData(data []byte, cfg interface{}) error { if err := checkUnknownFields(data, reflect.ValueOf(cfg).Type()); err != nil { return err } diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index e36dd9ee9..79836f39e 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -161,7 +161,7 @@ func TestLoad(t *testing.T) { for i, test := range tests { t.Run(fmt.Sprint(i), func(t *testing.T) { var cfg Config - err := load([]byte(test.input), &cfg) + err := LoadData([]byte(test.input), &cfg) errStr := "" if err != nil { errStr = err.Error() @@ -178,15 +178,15 @@ func TestLoad(t *testing.T) { func TestLoadBadType(t *testing.T) { want := "config type is not pointer to struct" - if err := load([]byte("{}"), 1); err == nil || err.Error() != want { + if err := LoadData([]byte("{}"), 1); err == nil || err.Error() != want { t.Fatalf("got '%v', want '%v'", err, want) } i := 0 - if err := load([]byte("{}"), &i); err == nil || err.Error() != want { + if err := LoadData([]byte("{}"), &i); err == nil || err.Error() != want { t.Fatalf("got '%v', want '%v'", err, want) } s := struct{}{} - if err := load([]byte("{}"), s); err == nil || err.Error() != want { + if err := LoadData([]byte("{}"), s); err == nil || err.Error() != want { t.Fatalf("got '%v', want '%v'", err, want) } } -- cgit mrf-deployment