mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Use ID rather than Name to identify a container when sharing namespace
Fix: https://github.com/moby/moby/issues/34307 Signed-off-by: Chen Min <chenmin46@huawei.com>
This commit is contained in:
parent
db73f3daee
commit
b6e5ea8e57
2 changed files with 75 additions and 0 deletions
|
@ -3,6 +3,7 @@
|
|||
package daemon
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -18,6 +19,44 @@ import (
|
|||
"github.com/docker/docker/volume/store"
|
||||
)
|
||||
|
||||
type fakeContainerGetter struct {
|
||||
containers map[string]*container.Container
|
||||
}
|
||||
|
||||
func (f *fakeContainerGetter) GetContainer(cid string) (*container.Container, error) {
|
||||
container, ok := f.containers[cid]
|
||||
if !ok {
|
||||
return nil, errors.New("container not found")
|
||||
}
|
||||
return container, nil
|
||||
}
|
||||
|
||||
// Unix test as uses settings which are not available on Windows
|
||||
func TestAdjustSharedNamespaceContainerName(t *testing.T) {
|
||||
fakeID := "abcdef1234567890"
|
||||
hostConfig := &containertypes.HostConfig{
|
||||
IpcMode: containertypes.IpcMode("container:base"),
|
||||
PidMode: containertypes.PidMode("container:base"),
|
||||
NetworkMode: containertypes.NetworkMode("container:base"),
|
||||
}
|
||||
containerStore := &fakeContainerGetter{}
|
||||
containerStore.containers = make(map[string]*container.Container)
|
||||
containerStore.containers["base"] = &container.Container{
|
||||
ID: fakeID,
|
||||
}
|
||||
|
||||
adaptSharedNamespaceContainer(containerStore, hostConfig)
|
||||
if hostConfig.IpcMode != containertypes.IpcMode("container:"+fakeID) {
|
||||
t.Errorf("Expected IpcMode to be container:%s", fakeID)
|
||||
}
|
||||
if hostConfig.PidMode != containertypes.PidMode("container:"+fakeID) {
|
||||
t.Errorf("Expected PidMode to be container:%s", fakeID)
|
||||
}
|
||||
if hostConfig.NetworkMode != containertypes.NetworkMode("container:"+fakeID) {
|
||||
t.Errorf("Expected NetworkMode to be container:%s", fakeID)
|
||||
}
|
||||
}
|
||||
|
||||
// Unix test as uses settings which are not available on Windows
|
||||
func TestAdjustCPUShares(t *testing.T) {
|
||||
tmp, err := ioutil.TempDir("", "docker-daemon-unix-test-")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue