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