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/helper/testlog"
|
||||
"github.com/hashicorp/nomad/helper/testtask"
|
||||
"github.com/hashicorp/nomad/helper/uuid"
|
||||
"github.com/hashicorp/nomad/nomad/mock"
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
)
|
||||
|
@ -112,11 +111,13 @@ type testContext struct {
|
|||
func testDriverContexts(t *testing.T, task *structs.Task) *testContext {
|
||||
cfg := testConfig(t)
|
||||
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 {
|
||||
t.Fatalf("AllocDir.Build() failed: %v", err)
|
||||
}
|
||||
alloc := mock.Alloc()
|
||||
|
||||
// Build a temp driver so we can call FSIsolation and build the task dir
|
||||
tmpdrv, err := NewDriver(task.Driver, NewEmptyDriverContext())
|
||||
|
|
|
@ -699,9 +699,12 @@ func (d *RktDriver) Start(ctx *ExecContext, task *structs.Task) (*StartResponse,
|
|||
}
|
||||
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
|
||||
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)
|
||||
driverNetwork, err = rktGetDriverNetwork(uuid, driverConfig.PortMap, d.logger)
|
||||
if err != nil && !pluginClient.Exited() {
|
||||
|
|
|
@ -144,6 +144,8 @@ func TestRktDriver_Start_Wait(t *testing.T) {
|
|||
"image": "coreos.com/etcd:v2.0.4",
|
||||
"command": "/etcd",
|
||||
"args": []string{"--version"},
|
||||
// Disable networking to speed up test as it's not needed
|
||||
"net": []string{"none"},
|
||||
},
|
||||
LogConfig: &structs.LogConfig{
|
||||
MaxFiles: 10,
|
||||
|
@ -214,6 +216,8 @@ func TestRktDriver_Start_Wait_Skip_Trust(t *testing.T) {
|
|||
"image": "coreos.com/etcd:v2.0.4",
|
||||
"command": "/etcd",
|
||||
"args": []string{"--version"},
|
||||
// Disable networking to speed up test as it's not needed
|
||||
"net": []string{"none"},
|
||||
},
|
||||
LogConfig: &structs.LogConfig{
|
||||
MaxFiles: 10,
|
||||
|
@ -273,11 +277,11 @@ func TestRktDriver_Start_Wait_AllocDir(t *testing.T) {
|
|||
Name: "rkttest_alpine",
|
||||
Driver: "rkt",
|
||||
Config: map[string]interface{}{
|
||||
"image": "docker://alpine",
|
||||
"image": "docker://redis:3.2-alpine",
|
||||
"command": "/bin/sh",
|
||||
"args": []string{
|
||||
"-c",
|
||||
fmt.Sprintf(`echo -n %s > foo/%s`, string(exp), file),
|
||||
fmt.Sprintf("echo -n %s > /foo/%s", string(exp), file),
|
||||
},
|
||||
"net": []string{"none"},
|
||||
"volumes": []string{fmt.Sprintf("%s:/foo", tmpvol)},
|
||||
|
@ -335,12 +339,14 @@ func TestRktDriver_UserGroup(t *testing.T) {
|
|||
require := assert.New(t)
|
||||
|
||||
task := &structs.Task{
|
||||
Name: "etcd",
|
||||
Name: "sleepy",
|
||||
Driver: "rkt",
|
||||
User: "nobody",
|
||||
Config: map[string]interface{}{
|
||||
"image": "docker://redis:3.2",
|
||||
"group": "nogroup",
|
||||
"image": "docker://redis:3.2-alpine",
|
||||
"group": "nogroup",
|
||||
"command": "sleep",
|
||||
"args": []string{"9000"},
|
||||
},
|
||||
LogConfig: &structs.LogConfig{
|
||||
MaxFiles: 10,
|
||||
|
@ -357,32 +363,30 @@ func TestRktDriver_UserGroup(t *testing.T) {
|
|||
d := NewRktDriver(tctx.DriverCtx)
|
||||
|
||||
_, err := d.Prestart(tctx.ExecCtx, task)
|
||||
require.Nil(err)
|
||||
require.NoError(err)
|
||||
resp, err := d.Start(tctx.ExecCtx, task)
|
||||
require.Nil(err)
|
||||
require.NoError(err)
|
||||
defer resp.Handle.Kill()
|
||||
|
||||
timeout := time.Duration(testutil.TestMultiplier()*15) * time.Second
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||
defer cancel()
|
||||
ctx := context.Background()
|
||||
|
||||
// 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) {
|
||||
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 {
|
||||
err = fmt.Errorf("original error: %v; code: %d; raw output: %s", err, code, string(raw))
|
||||
return false, err
|
||||
}
|
||||
if code != 0 {
|
||||
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) {
|
||||
t.Fatalf("err: %v", err)
|
||||
})
|
||||
|
||||
require.Nil(resp.Handle.Kill())
|
||||
require.NoError(resp.Handle.Kill())
|
||||
}
|
||||
|
||||
func TestRktTrustPrefix(t *testing.T) {
|
||||
|
@ -460,10 +464,10 @@ func TestRktDriver_PortMapping(t *testing.T) {
|
|||
}
|
||||
|
||||
task := &structs.Task{
|
||||
Name: "etcd",
|
||||
Name: "redis",
|
||||
Driver: "rkt",
|
||||
Config: map[string]interface{}{
|
||||
"image": "docker://redis:3.2",
|
||||
"image": "docker://redis:3.2-alpine",
|
||||
"port_map": []map[string]string{
|
||||
{
|
||||
"main": "6379-tcp",
|
||||
|
@ -529,10 +533,10 @@ func TestRktDriver_PortsMapping_Host(t *testing.T) {
|
|||
}
|
||||
|
||||
task := &structs.Task{
|
||||
Name: "etcd",
|
||||
Name: "redis",
|
||||
Driver: "rkt",
|
||||
Config: map[string]interface{}{
|
||||
"image": "docker://redis:latest",
|
||||
"image": "docker://redis:3.2-alpine",
|
||||
"net": []string{"host"},
|
||||
},
|
||||
LogConfig: &structs.LogConfig{
|
||||
|
|
Loading…
Reference in a new issue