2014-10-17 08:00:59 +08:00
|
|
|
package integration
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"runtime"
|
2015-05-01 23:27:04 +08:00
|
|
|
"testing"
|
2014-10-17 08:00:59 +08:00
|
|
|
|
2015-05-06 21:14:04 +08:00
|
|
|
"github.com/Sirupsen/logrus"
|
2015-06-22 10:29:59 +08:00
|
|
|
"github.com/opencontainers/runc/libcontainer"
|
|
|
|
"github.com/opencontainers/runc/libcontainer/cgroups/systemd"
|
|
|
|
_ "github.com/opencontainers/runc/libcontainer/nsenter"
|
2014-10-17 08:00:59 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// init runs the libcontainer initialization code because of the busybox style needs
|
|
|
|
// to work around the go runtime and the issues with forking
|
|
|
|
func init() {
|
|
|
|
if len(os.Args) < 2 || os.Args[1] != "init" {
|
|
|
|
return
|
|
|
|
}
|
2015-02-11 03:51:45 +08:00
|
|
|
runtime.GOMAXPROCS(1)
|
2014-10-17 08:00:59 +08:00
|
|
|
runtime.LockOSThread()
|
2015-02-14 07:43:14 +08:00
|
|
|
factory, err := libcontainer.New("")
|
2014-12-25 23:43:05 +08:00
|
|
|
if err != nil {
|
2015-05-06 21:14:04 +08:00
|
|
|
logrus.Fatalf("unable to initialize for container: %s", err)
|
2014-10-17 08:00:59 +08:00
|
|
|
}
|
2015-04-09 05:14:51 +08:00
|
|
|
if err := factory.StartInitialization(); err != nil {
|
2015-05-06 21:14:04 +08:00
|
|
|
logrus.Fatal(err)
|
2014-10-17 08:00:59 +08:00
|
|
|
}
|
|
|
|
}
|
2015-05-01 23:27:04 +08:00
|
|
|
|
|
|
|
var (
|
2015-05-06 21:14:04 +08:00
|
|
|
factory libcontainer.Factory
|
2015-05-01 23:27:04 +08:00
|
|
|
systemdFactory libcontainer.Factory
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
var (
|
|
|
|
err error
|
2016-04-12 16:12:23 +08:00
|
|
|
ret int
|
2015-05-01 23:27:04 +08:00
|
|
|
)
|
|
|
|
|
2015-05-06 21:14:04 +08:00
|
|
|
logrus.SetOutput(os.Stderr)
|
|
|
|
logrus.SetLevel(logrus.InfoLevel)
|
2015-05-01 23:27:04 +08:00
|
|
|
|
|
|
|
factory, err = libcontainer.New(".", libcontainer.Cgroupfs)
|
|
|
|
if err != nil {
|
2015-05-06 21:14:04 +08:00
|
|
|
logrus.Error(err)
|
2015-05-01 23:27:04 +08:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
if systemd.UseSystemd() {
|
|
|
|
systemdFactory, err = libcontainer.New(".", libcontainer.SystemdCgroups)
|
|
|
|
if err != nil {
|
2015-05-06 21:14:04 +08:00
|
|
|
logrus.Error(err)
|
2015-05-01 23:27:04 +08:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = m.Run()
|
|
|
|
os.Exit(ret)
|
|
|
|
}
|