api: fix integration tests
Signed-off-by: Andrey Vagin <avagin@openvz.org>
This commit is contained in:
parent
bbeae7445a
commit
daca745c4c
|
@ -5,7 +5,6 @@ import (
|
|||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"syscall"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/libcontainer"
|
||||
|
@ -192,6 +191,20 @@ func newTestRoot() (string, error) {
|
|||
return dir, nil
|
||||
}
|
||||
|
||||
func waitProcess(pid int, t *testing.T) {
|
||||
p, err := os.FindProcess(pid)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
status, err := p.Wait()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !status.Success() {
|
||||
t.Fatal(status)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnter(t *testing.T) {
|
||||
if testing.Short() {
|
||||
return
|
||||
|
@ -229,12 +242,12 @@ func TestEnter(t *testing.T) {
|
|||
|
||||
var stdout, stdout2 bytes.Buffer
|
||||
|
||||
pconfig := libcontainer.ProcessConfig{
|
||||
pconfig := libcontainer.Process{
|
||||
Args: []string{"sh", "-c", "cat && readlink /proc/self/ns/pid"},
|
||||
Stdin: stdinR,
|
||||
Stdout: &stdout,
|
||||
}
|
||||
pid, err := container.StartProcess(&pconfig)
|
||||
pid, err := container.Start(&pconfig)
|
||||
stdinR.Close()
|
||||
defer stdinW.Close()
|
||||
if err != nil {
|
||||
|
@ -250,7 +263,7 @@ func TestEnter(t *testing.T) {
|
|||
pconfig.Stdin = stdinR2
|
||||
pconfig.Stdout = &stdout2
|
||||
|
||||
pid2, err := container.StartProcess(&pconfig)
|
||||
pid2, err := container.Start(&pconfig)
|
||||
stdinR2.Close()
|
||||
defer stdinW2.Close()
|
||||
if err != nil {
|
||||
|
@ -273,27 +286,11 @@ func TestEnter(t *testing.T) {
|
|||
}
|
||||
|
||||
// Wait processes
|
||||
var status syscall.WaitStatus
|
||||
|
||||
stdinW2.Close()
|
||||
exitCode, err := container.WaitProcess(pid2)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
status = syscall.WaitStatus(exitCode)
|
||||
if status.ExitStatus() != 0 {
|
||||
t.Fatal(exitCode)
|
||||
}
|
||||
waitProcess(pid2, t)
|
||||
|
||||
stdinW.Close()
|
||||
exitCode, err = container.WaitProcess(pid)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
status = syscall.WaitStatus(exitCode)
|
||||
if status.ExitStatus() != 0 {
|
||||
t.Fatal(exitCode)
|
||||
}
|
||||
waitProcess(pid, t)
|
||||
|
||||
// Check that both processes live in the same pidns
|
||||
pidns := string(stdout.Bytes())
|
||||
|
@ -345,11 +342,11 @@ func TestFreeze(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
pconfig := libcontainer.ProcessConfig{
|
||||
pconfig := libcontainer.Process{
|
||||
Args: []string{"cat"},
|
||||
Stdin: stdinR,
|
||||
}
|
||||
pid, err := container.StartProcess(&pconfig)
|
||||
pid, err := container.Start(&pconfig)
|
||||
stdinR.Close()
|
||||
defer stdinW.Close()
|
||||
if err != nil {
|
||||
|
@ -364,7 +361,7 @@ func TestFreeze(t *testing.T) {
|
|||
if err := container.Pause(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
state, err := container.RunState()
|
||||
state, err := container.Status()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"runtime"
|
||||
|
||||
"github.com/docker/libcontainer"
|
||||
_ "github.com/docker/libcontainer/namespaces/nsenter"
|
||||
_ "github.com/docker/libcontainer/nsenter"
|
||||
)
|
||||
|
||||
// init runs the libcontainer initialization code because of the busybox style needs
|
||||
|
|
|
@ -3,7 +3,6 @@ package integration
|
|||
import (
|
||||
"syscall"
|
||||
|
||||
"github.com/docker/libcontainer/cgroups"
|
||||
"github.com/docker/libcontainer/configs"
|
||||
"github.com/docker/libcontainer/devices"
|
||||
)
|
||||
|
@ -15,7 +14,6 @@ import (
|
|||
func newTemplateConfig(rootfs string) *configs.Config {
|
||||
return &configs.Config{
|
||||
RootFs: rootfs,
|
||||
Tty: false,
|
||||
Capabilities: []string{
|
||||
"CHOWN",
|
||||
"DAC_OVERRIDE",
|
||||
|
@ -39,16 +37,14 @@ func newTemplateConfig(rootfs string) *configs.Config {
|
|||
{Type: configs.NEWPID},
|
||||
{Type: configs.NEWNET},
|
||||
}),
|
||||
Cgroups: &cgroups.Cgroup{
|
||||
Cgroups: &configs.Cgroup{
|
||||
Name: "test",
|
||||
Parent: "integration",
|
||||
AllowAllDevices: false,
|
||||
AllowedDevices: devices.DefaultAllowedDevices,
|
||||
},
|
||||
|
||||
MountConfig: &configs.MountConfig{
|
||||
DeviceNodes: devices.DefaultAutoCreatedDevices,
|
||||
},
|
||||
Hostname: "integration",
|
||||
Env: []string{
|
||||
"HOME=/root",
|
||||
|
|
|
@ -91,9 +91,8 @@ func runContainer(config *configs.Config, console string, args ...string) (buffe
|
|||
|
||||
buffers = newStdBuffers()
|
||||
|
||||
process := &libcontainer.ProcessConfig{
|
||||
process := &libcontainer.Process{
|
||||
Args: args,
|
||||
Env: make([]string, 0),
|
||||
Stdin: buffers.Stdin,
|
||||
Stdout: buffers.Stdout,
|
||||
Stderr: buffers.Stderr,
|
||||
|
@ -110,7 +109,7 @@ func runContainer(config *configs.Config, console string, args ...string) (buffe
|
|||
}
|
||||
defer container.Destroy()
|
||||
|
||||
pid, err := container.StartProcess(process)
|
||||
pid, err := container.Start(process)
|
||||
if err != nil {
|
||||
return nil, -1, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue