diff options
author | Matthew Heon <matthew.heon@gmail.com> | 2018-01-16 13:53:23 -0500 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-01-17 15:26:43 +0000 |
commit | ff77941a31352c40d13bdac3786e84e916f2bc94 (patch) | |
tree | 0fe16d41451255b55c68165426d7cf082463873a | |
parent | 54e258bfde8f6164abf3cd0e6d8d18b1643cc91d (diff) | |
download | podman-ff77941a31352c40d13bdac3786e84e916f2bc94.tar.gz podman-ff77941a31352c40d13bdac3786e84e916f2bc94.tar.bz2 podman-ff77941a31352c40d13bdac3786e84e916f2bc94.zip |
Fix in-memory state tests
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
Closes: #229
Approved by: rhatdan
-rw-r--r-- | libpod/container.go | 6 | ||||
-rw-r--r-- | libpod/in_memory_state.go | 27 |
2 files changed, 17 insertions, 16 deletions
diff --git a/libpod/container.go b/libpod/container.go index 4d6fe3a5e..2ee87163d 100644 --- a/libpod/container.go +++ b/libpod/container.go @@ -336,7 +336,11 @@ func (c *Container) Dependencies() []string { dependsCtrs[c.config.CgroupNsCtr] = true } - depends := make([]string, len(dependsCtrs), 0) + if len(dependsCtrs) == 0 { + return []string{} + } + + depends := make([]string, 0, len(dependsCtrs)) for ctr, _ := range dependsCtrs { depends = append(depends, ctr) } diff --git a/libpod/in_memory_state.go b/libpod/in_memory_state.go index 9a2b74c2a..55162e6c8 100644 --- a/libpod/in_memory_state.go +++ b/libpod/in_memory_state.go @@ -26,6 +26,8 @@ func NewInMemoryState() (State, error) { state.pods = make(map[string]*Pod) state.containers = make(map[string]*Container) + state.ctrDepends = make(map[string][]string) + state.podNameIndex = registrar.NewRegistrar() state.ctrNameIndex = registrar.NewRegistrar() @@ -131,13 +133,10 @@ func (s *InMemoryState) AddContainer(ctr *Container) error { s.containers[ctr.ID()] = ctr // Add containers this container depends on - s.addCtrToDependsMap(ctr.ID(), ctr.config.IPCNsCtr) - s.addCtrToDependsMap(ctr.ID(), ctr.config.MountNsCtr) - s.addCtrToDependsMap(ctr.ID(), ctr.config.NetNsCtr) - s.addCtrToDependsMap(ctr.ID(), ctr.config.PIDNsCtr) - s.addCtrToDependsMap(ctr.ID(), ctr.config.UserNsCtr) - s.addCtrToDependsMap(ctr.ID(), ctr.config.UTSNsCtr) - s.addCtrToDependsMap(ctr.ID(), ctr.config.CgroupNsCtr) + depCtrs := ctr.Dependencies() + for _, depCtr := range depCtrs { + s.addCtrToDependsMap(ctr.ID(), depCtr) + } return nil } @@ -167,13 +166,11 @@ func (s *InMemoryState) RemoveContainer(ctr *Container) error { delete(s.ctrDepends, ctr.ID()) - s.removeCtrFromDependsMap(ctr.ID(), ctr.config.IPCNsCtr) - s.removeCtrFromDependsMap(ctr.ID(), ctr.config.MountNsCtr) - s.removeCtrFromDependsMap(ctr.ID(), ctr.config.NetNsCtr) - s.removeCtrFromDependsMap(ctr.ID(), ctr.config.PIDNsCtr) - s.removeCtrFromDependsMap(ctr.ID(), ctr.config.UserNsCtr) - s.removeCtrFromDependsMap(ctr.ID(), ctr.config.UTSNsCtr) - s.removeCtrFromDependsMap(ctr.ID(), ctr.config.CgroupNsCtr) + // Remove us from container dependencies + depCtrs := ctr.Dependencies() + for _, depCtr := range depCtrs { + s.removeCtrFromDependsMap(ctr.ID(), depCtr) + } return nil } @@ -479,7 +476,7 @@ func (s *InMemoryState) removeCtrFromDependsMap(ctrID, dependsID string) { return } - newArr := make([]string, len(arr), 0) + newArr := make([]string, 0, len(arr)) for _, id := range arr { if id != ctrID { |