From 8b688cc70e551faf4fa6d8bcbda2b1e03f2adf32 Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Thu, 29 Aug 2019 20:13:29 -0400 Subject: [PATCH] tests: enable raw_exec driver --- drivers/rawexec/driver_test.go | 26 ++++++++++++++++---------- drivers/rawexec/driver_unix_test.go | 11 +++++------ helper/pluginutils/catalog/testing.go | 10 +++++++++- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/drivers/rawexec/driver_test.go b/drivers/rawexec/driver_test.go index 3d86f3935..8028edfd6 100644 --- a/drivers/rawexec/driver_test.go +++ b/drivers/rawexec/driver_test.go @@ -32,6 +32,12 @@ func TestMain(m *testing.M) { } } +func newEnabledRawExecDriver(t *testing.T) *Driver { + d := NewRawExecDriver(testlog.HCLogger(t)).(*Driver) + d.config.Enabled = true + return d +} + func TestRawExecDriver_SetConfig(t *testing.T) { t.Parallel() require := require.New(t) @@ -73,7 +79,7 @@ func TestRawExecDriver_Fingerprint(t *testing.T) { fingerprintTest := func(config *Config, expected *drivers.Fingerprint) func(t *testing.T) { return func(t *testing.T) { require := require.New(t) - d := NewRawExecDriver(testlog.HCLogger(t)).(*Driver) + d := newEnabledRawExecDriver(t) harness := dtestutil.NewDriverHarness(t, d) defer harness.Kill() @@ -133,7 +139,7 @@ func TestRawExecDriver_StartWait(t *testing.T) { t.Parallel() require := require.New(t) - d := NewRawExecDriver(testlog.HCLogger(t)) + d := newEnabledRawExecDriver(t) harness := dtestutil.NewDriverHarness(t, d) defer harness.Kill() task := &drivers.TaskConfig{ @@ -175,12 +181,12 @@ func TestRawExecDriver_StartWaitRecoverWaitStop(t *testing.T) { t.Parallel() require := require.New(t) - d := NewRawExecDriver(testlog.HCLogger(t)) + d := newEnabledRawExecDriver(t) harness := dtestutil.NewDriverHarness(t, d) defer harness.Kill() // Disable cgroups so test works without root - config := &Config{NoCgroups: true} + config := &Config{NoCgroups: true, Enabled: true} var data []byte require.NoError(basePlug.MsgPackEncode(&data, config)) bconfig := &basePlug.Config{PluginConfig: data} @@ -219,7 +225,7 @@ func TestRawExecDriver_StartWaitRecoverWaitStop(t *testing.T) { originalStatus, err := d.InspectTask(task.ID) require.NoError(err) - d.(*Driver).tasks.Delete(task.ID) + d.tasks.Delete(task.ID) wg.Wait() require.True(waitDone) @@ -258,7 +264,7 @@ func TestRawExecDriver_Start_Wait_AllocDir(t *testing.T) { t.Parallel() require := require.New(t) - d := NewRawExecDriver(testlog.HCLogger(t)) + d := newEnabledRawExecDriver(t) harness := dtestutil.NewDriverHarness(t, d) defer harness.Kill() @@ -313,7 +319,7 @@ func TestRawExecDriver_Start_Kill_Wait_Cgroup(t *testing.T) { require := require.New(t) pidFile := "pid" - d := NewRawExecDriver(testlog.HCLogger(t)) + d := newEnabledRawExecDriver(t) harness := dtestutil.NewDriverHarness(t, d) defer harness.Kill() @@ -403,7 +409,7 @@ func TestRawExecDriver_Exec(t *testing.T) { t.Parallel() require := require.New(t) - d := NewRawExecDriver(testlog.HCLogger(t)) + d := newEnabledRawExecDriver(t) harness := dtestutil.NewDriverHarness(t, d) defer harness.Kill() @@ -476,8 +482,8 @@ func TestRawExecDriver_Disabled(t *testing.T) { t.Parallel() require := require.New(t) - d := NewRawExecDriver(testlog.HCLogger(t)) - d.(*Driver).config.Enabled = false + d := newEnabledRawExecDriver(t) + d.config.Enabled = false harness := dtestutil.NewDriverHarness(t, d) defer harness.Kill() diff --git a/drivers/rawexec/driver_unix_test.go b/drivers/rawexec/driver_unix_test.go index d921e53b3..8845d75d8 100644 --- a/drivers/rawexec/driver_unix_test.go +++ b/drivers/rawexec/driver_unix_test.go @@ -13,7 +13,6 @@ import ( "strings" "time" - "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/helper/testtask" "github.com/hashicorp/nomad/helper/uuid" basePlug "github.com/hashicorp/nomad/plugins/base" @@ -31,7 +30,7 @@ func TestRawExecDriver_User(t *testing.T) { } require := require.New(t) - d := NewRawExecDriver(testlog.HCLogger(t)) + d := newEnabledRawExecDriver(t) harness := dtestutil.NewDriverHarness(t, d) task := &drivers.TaskConfig{ @@ -63,7 +62,7 @@ func TestRawExecDriver_Signal(t *testing.T) { } require := require.New(t) - d := NewRawExecDriver(testlog.HCLogger(t)) + d := newEnabledRawExecDriver(t) harness := dtestutil.NewDriverHarness(t, d) task := &drivers.TaskConfig{ @@ -134,12 +133,12 @@ func TestRawExecDriver_StartWaitStop(t *testing.T) { t.Parallel() require := require.New(t) - d := NewRawExecDriver(testlog.HCLogger(t)) + d := newEnabledRawExecDriver(t) harness := dtestutil.NewDriverHarness(t, d) defer harness.Kill() // Disable cgroups so test works without root - config := &Config{NoCgroups: true} + config := &Config{NoCgroups: true, Enabled: true} var data []byte require.NoError(basePlug.MsgPackEncode(&data, config)) bconfig := &basePlug.Config{PluginConfig: data} @@ -204,7 +203,7 @@ func TestRawExec_ExecTaskStreaming(t *testing.T) { } require := require.New(t) - d := NewRawExecDriver(testlog.HCLogger(t)) + d := newEnabledRawExecDriver(t) harness := dtestutil.NewDriverHarness(t, d) defer harness.Kill() diff --git a/helper/pluginutils/catalog/testing.go b/helper/pluginutils/catalog/testing.go index 82dcbe630..741664ca4 100644 --- a/helper/pluginutils/catalog/testing.go +++ b/helper/pluginutils/catalog/testing.go @@ -10,7 +10,15 @@ import ( // TestPluginLoader returns a plugin loader populated only with internal plugins func TestPluginLoader(t testing.T) loader.PluginCatalog { - return TestPluginLoaderWithOptions(t, "", nil, nil) + driverConfigs := []*config.PluginConfig{ + { + Name: "raw_exec", + Config: map[string]interface{}{ + "enabled": true, + }, + }, + } + return TestPluginLoaderWithOptions(t, "", nil, driverConfigs) } // TestPluginLoaderWithOptions allows configuring the plugin loader fully.