diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2017-06-02 20:09:00 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2017-06-03 11:31:42 +0200 |
| commit | af643baa328ae3d4b7076054bba648c4b8bf8056 (patch) | |
| tree | 6e4687c745b63352dec21f6ac2a6a7d8fa1201c4 /pkg/config | |
| parent | 96b8d4e99c7812f91633ea6cd1aee5867965e742 (diff) | |
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.
Diffstat (limited to 'pkg/config')
| -rw-r--r-- | pkg/config/config.go | 6 | ||||
| -rw-r--r-- | pkg/config/config_test.go | 8 |
2 files changed, 7 insertions, 7 deletions
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) } } |
