Replace aliased imports of logrus
Docker already did this: https://github.com/docker/docker/issues/11762 libcontainer should also do it. Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
This commit is contained in:
parent
a1fe3f1c7a
commit
e5a7aad7eb
|
@ -4,7 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/docker/libcontainer/cgroups"
|
"github.com/docker/libcontainer/cgroups"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -23,75 +23,75 @@ func blkioStatEntryEquals(expected, actual []cgroups.BlkioStatEntry) error {
|
||||||
|
|
||||||
func expectBlkioStatsEquals(t *testing.T, expected, actual cgroups.BlkioStats) {
|
func expectBlkioStatsEquals(t *testing.T, expected, actual cgroups.BlkioStats) {
|
||||||
if err := blkioStatEntryEquals(expected.IoServiceBytesRecursive, actual.IoServiceBytesRecursive); err != nil {
|
if err := blkioStatEntryEquals(expected.IoServiceBytesRecursive, actual.IoServiceBytesRecursive); err != nil {
|
||||||
log.Printf("blkio IoServiceBytesRecursive do not match - %s\n", err)
|
logrus.Printf("blkio IoServiceBytesRecursive do not match - %s\n", err)
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := blkioStatEntryEquals(expected.IoServicedRecursive, actual.IoServicedRecursive); err != nil {
|
if err := blkioStatEntryEquals(expected.IoServicedRecursive, actual.IoServicedRecursive); err != nil {
|
||||||
log.Printf("blkio IoServicedRecursive do not match - %s\n", err)
|
logrus.Printf("blkio IoServicedRecursive do not match - %s\n", err)
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := blkioStatEntryEquals(expected.IoQueuedRecursive, actual.IoQueuedRecursive); err != nil {
|
if err := blkioStatEntryEquals(expected.IoQueuedRecursive, actual.IoQueuedRecursive); err != nil {
|
||||||
log.Printf("blkio IoQueuedRecursive do not match - %s\n", err)
|
logrus.Printf("blkio IoQueuedRecursive do not match - %s\n", err)
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := blkioStatEntryEquals(expected.SectorsRecursive, actual.SectorsRecursive); err != nil {
|
if err := blkioStatEntryEquals(expected.SectorsRecursive, actual.SectorsRecursive); err != nil {
|
||||||
log.Printf("blkio SectorsRecursive do not match - %s\n", err)
|
logrus.Printf("blkio SectorsRecursive do not match - %s\n", err)
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := blkioStatEntryEquals(expected.IoServiceTimeRecursive, actual.IoServiceTimeRecursive); err != nil {
|
if err := blkioStatEntryEquals(expected.IoServiceTimeRecursive, actual.IoServiceTimeRecursive); err != nil {
|
||||||
log.Printf("blkio IoServiceTimeRecursive do not match - %s\n", err)
|
logrus.Printf("blkio IoServiceTimeRecursive do not match - %s\n", err)
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := blkioStatEntryEquals(expected.IoWaitTimeRecursive, actual.IoWaitTimeRecursive); err != nil {
|
if err := blkioStatEntryEquals(expected.IoWaitTimeRecursive, actual.IoWaitTimeRecursive); err != nil {
|
||||||
log.Printf("blkio IoWaitTimeRecursive do not match - %s\n", err)
|
logrus.Printf("blkio IoWaitTimeRecursive do not match - %s\n", err)
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := blkioStatEntryEquals(expected.IoMergedRecursive, actual.IoMergedRecursive); err != nil {
|
if err := blkioStatEntryEquals(expected.IoMergedRecursive, actual.IoMergedRecursive); err != nil {
|
||||||
log.Printf("blkio IoMergedRecursive do not match - %v vs %v\n", expected.IoMergedRecursive, actual.IoMergedRecursive)
|
logrus.Printf("blkio IoMergedRecursive do not match - %v vs %v\n", expected.IoMergedRecursive, actual.IoMergedRecursive)
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := blkioStatEntryEquals(expected.IoTimeRecursive, actual.IoTimeRecursive); err != nil {
|
if err := blkioStatEntryEquals(expected.IoTimeRecursive, actual.IoTimeRecursive); err != nil {
|
||||||
log.Printf("blkio IoTimeRecursive do not match - %s\n", err)
|
logrus.Printf("blkio IoTimeRecursive do not match - %s\n", err)
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func expectThrottlingDataEquals(t *testing.T, expected, actual cgroups.ThrottlingData) {
|
func expectThrottlingDataEquals(t *testing.T, expected, actual cgroups.ThrottlingData) {
|
||||||
if expected != actual {
|
if expected != actual {
|
||||||
log.Printf("Expected throttling data %v but found %v\n", expected, actual)
|
logrus.Printf("Expected throttling data %v but found %v\n", expected, actual)
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func expectMemoryStatEquals(t *testing.T, expected, actual cgroups.MemoryStats) {
|
func expectMemoryStatEquals(t *testing.T, expected, actual cgroups.MemoryStats) {
|
||||||
if expected.Usage != actual.Usage {
|
if expected.Usage != actual.Usage {
|
||||||
log.Printf("Expected memory usage %d but found %d\n", expected.Usage, actual.Usage)
|
logrus.Printf("Expected memory usage %d but found %d\n", expected.Usage, actual.Usage)
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
if expected.MaxUsage != actual.MaxUsage {
|
if expected.MaxUsage != actual.MaxUsage {
|
||||||
log.Printf("Expected memory max usage %d but found %d\n", expected.MaxUsage, actual.MaxUsage)
|
logrus.Printf("Expected memory max usage %d but found %d\n", expected.MaxUsage, actual.MaxUsage)
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
for key, expValue := range expected.Stats {
|
for key, expValue := range expected.Stats {
|
||||||
actValue, ok := actual.Stats[key]
|
actValue, ok := actual.Stats[key]
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Printf("Expected memory stat key %s not found\n", key)
|
logrus.Printf("Expected memory stat key %s not found\n", key)
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
if expValue != actValue {
|
if expValue != actValue {
|
||||||
log.Printf("Expected memory stat value %d but found %d\n", expValue, actValue)
|
logrus.Printf("Expected memory stat value %d but found %d\n", expValue, actValue)
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if expected.Failcnt != actual.Failcnt {
|
if expected.Failcnt != actual.Failcnt {
|
||||||
log.Printf("Expected memory failcnt %d but found %d\n", expected.Failcnt, actual.Failcnt)
|
logrus.Printf("Expected memory failcnt %d but found %d\n", expected.Failcnt, actual.Failcnt)
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/docker/libcontainer/cgroups"
|
"github.com/docker/libcontainer/cgroups"
|
||||||
"github.com/docker/libcontainer/configs"
|
"github.com/docker/libcontainer/configs"
|
||||||
)
|
)
|
||||||
|
@ -102,7 +102,7 @@ func (c *linuxContainer) Start(process *Process) error {
|
||||||
if err := parent.start(); err != nil {
|
if err := parent.start(); err != nil {
|
||||||
// terminate the process to ensure that it properly is reaped.
|
// terminate the process to ensure that it properly is reaped.
|
||||||
if err := parent.terminate(); err != nil {
|
if err := parent.terminate(); err != nil {
|
||||||
log.Warn(err)
|
logrus.Warn(err)
|
||||||
}
|
}
|
||||||
return newSystemError(err)
|
return newSystemError(err)
|
||||||
}
|
}
|
||||||
|
@ -227,7 +227,7 @@ func (c *linuxContainer) Destroy() error {
|
||||||
}
|
}
|
||||||
if !c.config.Namespaces.Contains(configs.NEWPID) {
|
if !c.config.Namespaces.Contains(configs.NEWPID) {
|
||||||
if err := killCgroupProcesses(c.cgroupManager); err != nil {
|
if err := killCgroupProcesses(c.cgroupManager); err != nil {
|
||||||
log.Warn(err)
|
logrus.Warn(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = c.cgroupManager.Destroy()
|
err = c.cgroupManager.Destroy()
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/docker/libcontainer/cgroups"
|
"github.com/docker/libcontainer/cgroups"
|
||||||
"github.com/docker/libcontainer/configs"
|
"github.com/docker/libcontainer/configs"
|
||||||
"github.com/docker/libcontainer/netlink"
|
"github.com/docker/libcontainer/netlink"
|
||||||
|
@ -234,7 +234,7 @@ func setupRlimits(config *configs.Config) error {
|
||||||
func killCgroupProcesses(m cgroups.Manager) error {
|
func killCgroupProcesses(m cgroups.Manager) error {
|
||||||
var procs []*os.Process
|
var procs []*os.Process
|
||||||
if err := m.Freeze(configs.Frozen); err != nil {
|
if err := m.Freeze(configs.Frozen); err != nil {
|
||||||
log.Warn(err)
|
logrus.Warn(err)
|
||||||
}
|
}
|
||||||
pids, err := m.GetPids()
|
pids, err := m.GetPids()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -245,16 +245,16 @@ func killCgroupProcesses(m cgroups.Manager) error {
|
||||||
if p, err := os.FindProcess(pid); err == nil {
|
if p, err := os.FindProcess(pid); err == nil {
|
||||||
procs = append(procs, p)
|
procs = append(procs, p)
|
||||||
if err := p.Kill(); err != nil {
|
if err := p.Kill(); err != nil {
|
||||||
log.Warn(err)
|
logrus.Warn(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := m.Freeze(configs.Thawed); err != nil {
|
if err := m.Freeze(configs.Thawed); err != nil {
|
||||||
log.Warn(err)
|
logrus.Warn(err)
|
||||||
}
|
}
|
||||||
for _, p := range procs {
|
for _, p := range procs {
|
||||||
if _, err := p.Wait(); err != nil {
|
if _, err := p.Wait(); err != nil {
|
||||||
log.Warn(err)
|
logrus.Warn(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"runtime"
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/docker/libcontainer"
|
"github.com/docker/libcontainer"
|
||||||
"github.com/docker/libcontainer/cgroups/systemd"
|
"github.com/docker/libcontainer/cgroups/systemd"
|
||||||
_ "github.com/docker/libcontainer/nsenter"
|
_ "github.com/docker/libcontainer/nsenter"
|
||||||
|
@ -21,10 +21,10 @@ func init() {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
factory, err := libcontainer.New("")
|
factory, err := libcontainer.New("")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("unable to initialize for container: %s", err)
|
logrus.Fatalf("unable to initialize for container: %s", err)
|
||||||
}
|
}
|
||||||
if err := factory.StartInitialization(); err != nil {
|
if err := factory.StartInitialization(); err != nil {
|
||||||
log.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,18 +39,18 @@ func TestMain(m *testing.M) {
|
||||||
ret int = 0
|
ret int = 0
|
||||||
)
|
)
|
||||||
|
|
||||||
log.SetOutput(os.Stderr)
|
logrus.SetOutput(os.Stderr)
|
||||||
log.SetLevel(log.InfoLevel)
|
logrus.SetLevel(logrus.InfoLevel)
|
||||||
|
|
||||||
factory, err = libcontainer.New(".", libcontainer.Cgroupfs)
|
factory, err = libcontainer.New(".", libcontainer.Cgroupfs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
logrus.Error(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
if systemd.UseSystemd() {
|
if systemd.UseSystemd() {
|
||||||
systemdFactory, err = libcontainer.New(".", libcontainer.SystemdCgroups)
|
systemdFactory, err = libcontainer.New(".", libcontainer.SystemdCgroups)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
logrus.Error(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/codegangsta/cli"
|
"github.com/codegangsta/cli"
|
||||||
"github.com/docker/libcontainer"
|
"github.com/docker/libcontainer"
|
||||||
_ "github.com/docker/libcontainer/nsenter"
|
_ "github.com/docker/libcontainer/nsenter"
|
||||||
|
@ -13,7 +13,7 @@ var initCommand = cli.Command{
|
||||||
Name: "init",
|
Name: "init",
|
||||||
Usage: "runs the init process inside the namespace",
|
Usage: "runs the init process inside the namespace",
|
||||||
Action: func(context *cli.Context) {
|
Action: func(context *cli.Context) {
|
||||||
log.SetLevel(log.DebugLevel)
|
logrus.SetLevel(logrus.DebugLevel)
|
||||||
runtime.GOMAXPROCS(1)
|
runtime.GOMAXPROCS(1)
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
factory, err := libcontainer.New("")
|
factory, err := libcontainer.New("")
|
||||||
|
|
|
@ -3,7 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/codegangsta/cli"
|
"github.com/codegangsta/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -29,18 +29,18 @@ func main() {
|
||||||
}
|
}
|
||||||
app.Before = func(context *cli.Context) error {
|
app.Before = func(context *cli.Context) error {
|
||||||
if context.GlobalBool("debug") {
|
if context.GlobalBool("debug") {
|
||||||
log.SetLevel(log.DebugLevel)
|
logrus.SetLevel(logrus.DebugLevel)
|
||||||
}
|
}
|
||||||
if path := context.GlobalString("log-file"); path != "" {
|
if path := context.GlobalString("log-file"); path != "" {
|
||||||
f, err := os.Create(path)
|
f, err := os.Create(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.SetOutput(f)
|
logrus.SetOutput(f)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if err := app.Run(os.Args); err != nil {
|
if err := app.Run(os.Args); err != nil {
|
||||||
log.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
log "github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/codegangsta/cli"
|
"github.com/codegangsta/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -14,16 +14,16 @@ var oomCommand = cli.Command{
|
||||||
Action: func(context *cli.Context) {
|
Action: func(context *cli.Context) {
|
||||||
container, err := getContainer(context)
|
container, err := getContainer(context)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
n, err := container.NotifyOOM()
|
n, err := container.NotifyOOM()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
for x := range n {
|
for x := range n {
|
||||||
// hack for calm down go1.4 gofmt
|
// hack for calm down go1.4 gofmt
|
||||||
_ = x
|
_ = x
|
||||||
log.Printf("OOM notification received")
|
logrus.Printf("OOM notification received")
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
log "github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/codegangsta/cli"
|
"github.com/codegangsta/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -14,10 +14,10 @@ var pauseCommand = cli.Command{
|
||||||
Action: func(context *cli.Context) {
|
Action: func(context *cli.Context) {
|
||||||
container, err := getContainer(context)
|
container, err := getContainer(context)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
if err = container.Pause(); err != nil {
|
if err = container.Pause(); err != nil {
|
||||||
log.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -31,10 +31,10 @@ var unpauseCommand = cli.Command{
|
||||||
Action: func(context *cli.Context) {
|
Action: func(context *cli.Context) {
|
||||||
container, err := getContainer(context)
|
container, err := getContainer(context)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
if err = container.Resume(); err != nil {
|
if err = container.Resume(); err != nil {
|
||||||
log.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
log "github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/codegangsta/cli"
|
"github.com/codegangsta/cli"
|
||||||
|
@ -36,7 +36,7 @@ func loadFactory(context *cli.Context) (libcontainer.Factory, error) {
|
||||||
if systemd.UseSystemd() {
|
if systemd.UseSystemd() {
|
||||||
cgm = libcontainer.SystemdCgroups
|
cgm = libcontainer.SystemdCgroups
|
||||||
} else {
|
} else {
|
||||||
log.Warn("systemd cgroup flag passed, but systemd support for managing cgroups is not available.")
|
logrus.Warn("systemd cgroup flag passed, but systemd support for managing cgroups is not available.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return libcontainer.New(context.GlobalString("root"), cgm)
|
return libcontainer.New(context.GlobalString("root"), cgm)
|
||||||
|
|
Loading…
Reference in New Issue