Merge pull request #4490 from hashicorp/b-rkt-test-failure
Fix and speedup rkt tests
This commit is contained in:
commit
6d9bdeaba0
|
@ -15,7 +15,6 @@ import (
|
||||||
"github.com/hashicorp/nomad/client/driver/env"
|
"github.com/hashicorp/nomad/client/driver/env"
|
||||||
"github.com/hashicorp/nomad/helper/testlog"
|
"github.com/hashicorp/nomad/helper/testlog"
|
||||||
"github.com/hashicorp/nomad/helper/testtask"
|
"github.com/hashicorp/nomad/helper/testtask"
|
||||||
"github.com/hashicorp/nomad/helper/uuid"
|
|
||||||
"github.com/hashicorp/nomad/nomad/mock"
|
"github.com/hashicorp/nomad/nomad/mock"
|
||||||
"github.com/hashicorp/nomad/nomad/structs"
|
"github.com/hashicorp/nomad/nomad/structs"
|
||||||
)
|
)
|
||||||
|
@ -112,11 +111,13 @@ type testContext struct {
|
||||||
func testDriverContexts(t *testing.T, task *structs.Task) *testContext {
|
func testDriverContexts(t *testing.T, task *structs.Task) *testContext {
|
||||||
cfg := testConfig(t)
|
cfg := testConfig(t)
|
||||||
cfg.Node = mock.Node()
|
cfg.Node = mock.Node()
|
||||||
allocDir := allocdir.NewAllocDir(testlog.Logger(t), filepath.Join(cfg.AllocDir, uuid.Generate()))
|
alloc := mock.Alloc()
|
||||||
|
alloc.NodeID = cfg.Node.ID
|
||||||
|
|
||||||
|
allocDir := allocdir.NewAllocDir(testlog.Logger(t), filepath.Join(cfg.AllocDir, alloc.ID))
|
||||||
if err := allocDir.Build(); err != nil {
|
if err := allocDir.Build(); err != nil {
|
||||||
t.Fatalf("AllocDir.Build() failed: %v", err)
|
t.Fatalf("AllocDir.Build() failed: %v", err)
|
||||||
}
|
}
|
||||||
alloc := mock.Alloc()
|
|
||||||
|
|
||||||
// Build a temp driver so we can call FSIsolation and build the task dir
|
// Build a temp driver so we can call FSIsolation and build the task dir
|
||||||
tmpdrv, err := NewDriver(task.Driver, NewEmptyDriverContext())
|
tmpdrv, err := NewDriver(task.Driver, NewEmptyDriverContext())
|
||||||
|
|
|
@ -699,9 +699,12 @@ func (d *RktDriver) Start(ctx *ExecContext, task *structs.Task) (*StartResponse,
|
||||||
}
|
}
|
||||||
go h.run()
|
go h.run()
|
||||||
|
|
||||||
// Only return a driver network if *not* using host networking
|
// Do not attempt to retrieve driver network if one won't exist:
|
||||||
|
// - "host" means the container itself has no networking metadata
|
||||||
|
// - "none" means no network is configured
|
||||||
|
// https://coreos.com/rkt/docs/latest/networking/overview.html#no-loopback-only-networking
|
||||||
var driverNetwork *cstructs.DriverNetwork
|
var driverNetwork *cstructs.DriverNetwork
|
||||||
if network != "host" {
|
if network != "host" && network != "none" {
|
||||||
d.logger.Printf("[DEBUG] driver.rkt: retrieving network information for pod %q (UUID: %s) for task %q", img, uuid, d.taskName)
|
d.logger.Printf("[DEBUG] driver.rkt: retrieving network information for pod %q (UUID: %s) for task %q", img, uuid, d.taskName)
|
||||||
driverNetwork, err = rktGetDriverNetwork(uuid, driverConfig.PortMap, d.logger)
|
driverNetwork, err = rktGetDriverNetwork(uuid, driverConfig.PortMap, d.logger)
|
||||||
if err != nil && !pluginClient.Exited() {
|
if err != nil && !pluginClient.Exited() {
|
||||||
|
|
|
@ -144,6 +144,8 @@ func TestRktDriver_Start_Wait(t *testing.T) {
|
||||||
"image": "coreos.com/etcd:v2.0.4",
|
"image": "coreos.com/etcd:v2.0.4",
|
||||||
"command": "/etcd",
|
"command": "/etcd",
|
||||||
"args": []string{"--version"},
|
"args": []string{"--version"},
|
||||||
|
// Disable networking to speed up test as it's not needed
|
||||||
|
"net": []string{"none"},
|
||||||
},
|
},
|
||||||
LogConfig: &structs.LogConfig{
|
LogConfig: &structs.LogConfig{
|
||||||
MaxFiles: 10,
|
MaxFiles: 10,
|
||||||
|
@ -214,6 +216,8 @@ func TestRktDriver_Start_Wait_Skip_Trust(t *testing.T) {
|
||||||
"image": "coreos.com/etcd:v2.0.4",
|
"image": "coreos.com/etcd:v2.0.4",
|
||||||
"command": "/etcd",
|
"command": "/etcd",
|
||||||
"args": []string{"--version"},
|
"args": []string{"--version"},
|
||||||
|
// Disable networking to speed up test as it's not needed
|
||||||
|
"net": []string{"none"},
|
||||||
},
|
},
|
||||||
LogConfig: &structs.LogConfig{
|
LogConfig: &structs.LogConfig{
|
||||||
MaxFiles: 10,
|
MaxFiles: 10,
|
||||||
|
@ -273,11 +277,11 @@ func TestRktDriver_Start_Wait_AllocDir(t *testing.T) {
|
||||||
Name: "rkttest_alpine",
|
Name: "rkttest_alpine",
|
||||||
Driver: "rkt",
|
Driver: "rkt",
|
||||||
Config: map[string]interface{}{
|
Config: map[string]interface{}{
|
||||||
"image": "docker://alpine",
|
"image": "docker://redis:3.2-alpine",
|
||||||
"command": "/bin/sh",
|
"command": "/bin/sh",
|
||||||
"args": []string{
|
"args": []string{
|
||||||
"-c",
|
"-c",
|
||||||
fmt.Sprintf(`echo -n %s > foo/%s`, string(exp), file),
|
fmt.Sprintf("echo -n %s > /foo/%s", string(exp), file),
|
||||||
},
|
},
|
||||||
"net": []string{"none"},
|
"net": []string{"none"},
|
||||||
"volumes": []string{fmt.Sprintf("%s:/foo", tmpvol)},
|
"volumes": []string{fmt.Sprintf("%s:/foo", tmpvol)},
|
||||||
|
@ -335,12 +339,14 @@ func TestRktDriver_UserGroup(t *testing.T) {
|
||||||
require := assert.New(t)
|
require := assert.New(t)
|
||||||
|
|
||||||
task := &structs.Task{
|
task := &structs.Task{
|
||||||
Name: "etcd",
|
Name: "sleepy",
|
||||||
Driver: "rkt",
|
Driver: "rkt",
|
||||||
User: "nobody",
|
User: "nobody",
|
||||||
Config: map[string]interface{}{
|
Config: map[string]interface{}{
|
||||||
"image": "docker://redis:3.2",
|
"image": "docker://redis:3.2-alpine",
|
||||||
"group": "nogroup",
|
"group": "nogroup",
|
||||||
|
"command": "sleep",
|
||||||
|
"args": []string{"9000"},
|
||||||
},
|
},
|
||||||
LogConfig: &structs.LogConfig{
|
LogConfig: &structs.LogConfig{
|
||||||
MaxFiles: 10,
|
MaxFiles: 10,
|
||||||
|
@ -357,32 +363,30 @@ func TestRktDriver_UserGroup(t *testing.T) {
|
||||||
d := NewRktDriver(tctx.DriverCtx)
|
d := NewRktDriver(tctx.DriverCtx)
|
||||||
|
|
||||||
_, err := d.Prestart(tctx.ExecCtx, task)
|
_, err := d.Prestart(tctx.ExecCtx, task)
|
||||||
require.Nil(err)
|
require.NoError(err)
|
||||||
resp, err := d.Start(tctx.ExecCtx, task)
|
resp, err := d.Start(tctx.ExecCtx, task)
|
||||||
require.Nil(err)
|
require.NoError(err)
|
||||||
defer resp.Handle.Kill()
|
defer resp.Handle.Kill()
|
||||||
|
|
||||||
timeout := time.Duration(testutil.TestMultiplier()*15) * time.Second
|
ctx := context.Background()
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
// WaitUntil we can determine the user/group redis is running as
|
// WaitUntil we can determine the user/group redis is running as
|
||||||
expected := []byte("redis-server *:6379 nobody nogroup\n")
|
expected := []byte("\nnobody nogroup /bin/sleep 9000\n")
|
||||||
testutil.WaitForResult(func() (bool, error) {
|
testutil.WaitForResult(func() (bool, error) {
|
||||||
raw, code, err := resp.Handle.Exec(ctx, "/bin/bash", []string{"-c", "ps -eo args,user,group | grep ^redis"})
|
raw, code, err := resp.Handle.Exec(ctx, "ps", []string{"-o", "user,group,args"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
err = fmt.Errorf("original error: %v; code: %d; raw output: %s", err, code, string(raw))
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
if code != 0 {
|
if code != 0 {
|
||||||
return false, fmt.Errorf("unexpected exit code: %d", code)
|
return false, fmt.Errorf("unexpected exit code: %d", code)
|
||||||
}
|
}
|
||||||
return bytes.Equal(expected, raw), fmt.Errorf("expected %q but found %q", expected, raw)
|
return bytes.Contains(raw, expected), fmt.Errorf("expected %q but found:\n%s", expected, raw)
|
||||||
}, func(err error) {
|
}, func(err error) {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
})
|
})
|
||||||
|
|
||||||
require.Nil(resp.Handle.Kill())
|
require.NoError(resp.Handle.Kill())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRktTrustPrefix(t *testing.T) {
|
func TestRktTrustPrefix(t *testing.T) {
|
||||||
|
@ -460,10 +464,10 @@ func TestRktDriver_PortMapping(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
task := &structs.Task{
|
task := &structs.Task{
|
||||||
Name: "etcd",
|
Name: "redis",
|
||||||
Driver: "rkt",
|
Driver: "rkt",
|
||||||
Config: map[string]interface{}{
|
Config: map[string]interface{}{
|
||||||
"image": "docker://redis:3.2",
|
"image": "docker://redis:3.2-alpine",
|
||||||
"port_map": []map[string]string{
|
"port_map": []map[string]string{
|
||||||
{
|
{
|
||||||
"main": "6379-tcp",
|
"main": "6379-tcp",
|
||||||
|
@ -529,10 +533,10 @@ func TestRktDriver_PortsMapping_Host(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
task := &structs.Task{
|
task := &structs.Task{
|
||||||
Name: "etcd",
|
Name: "redis",
|
||||||
Driver: "rkt",
|
Driver: "rkt",
|
||||||
Config: map[string]interface{}{
|
Config: map[string]interface{}{
|
||||||
"image": "docker://redis:latest",
|
"image": "docker://redis:3.2-alpine",
|
||||||
"net": []string{"host"},
|
"net": []string{"host"},
|
||||||
},
|
},
|
||||||
LogConfig: &structs.LogConfig{
|
LogConfig: &structs.LogConfig{
|
||||||
|
|
Loading…
Reference in New Issue