Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
tests: Modify tests to take into account if pid ns needs to be shared
Browse files Browse the repository at this point in the history
Pid namespace sharing can be set for a container. Modify tests
to check for cases when this is set/not set.

Signed-off-by: Archana Shinde <[email protected]>
  • Loading branch information
amshinde committed May 25, 2018
1 parent e334596 commit ad9c33d
Showing 1 changed file with 71 additions and 20 deletions.
91 changes: 71 additions & 20 deletions grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,51 @@ var testSharedPidNs = "testSharedPidNs"
var testSharedUTSNs = "testSharedUTSNs"
var testSharedIPCNs = "testSharedIPCNs"

func testUpdateContainerConfigNamespaces(t *testing.T, sharedPidNs, sharedUTSNs, sharedIPCNs string, config, expected configs.Config) {
a := &agentGRPC{
sandbox: &sandbox{
sharedPidNs: namespace{
path: sharedPidNs,
},
sharedIPCNs: namespace{
path: sharedIPCNs,
},
sharedUTSNs: namespace{
path: sharedUTSNs,
},
func testUpdateContainerConfigNamespacesSharedPid(t *testing.T, sharedPidNs, sharedUTSNs, sharedIPCNs string, config, expected configs.Config) {
testUpdateContainerConfigNamespaces(t, sharedPidNs, sharedUTSNs, sharedIPCNs, config, expected, true)
}

func testUpdateContainerConfigNamespacesNonSharedPid(t *testing.T, sharedPidNs, sharedUTSNs, sharedIPCNs string, config, expected configs.Config) {
testUpdateContainerConfigNamespaces(t, sharedPidNs, sharedUTSNs, sharedIPCNs, config, expected, false)
}

func testUpdateContainerConfigNamespaces(t *testing.T, sharedPidNs, sharedUTSNs, sharedIPCNs string, config, expected configs.Config, sharedPid bool) {
s := &sandbox{
sharedPidNs: namespace{
path: sharedPidNs,
},
sharedIPCNs: namespace{
path: sharedIPCNs,
},
sharedUTSNs: namespace{
path: sharedUTSNs,
},
containers: make(map[string]*container),
}

contID := "testContainer"
ctr := &container{
id: contID,
useSandboxPidNs: sharedPid,
}

err := a.updateContainerConfigNamespaces(&config)
assert.Nil(t, err, "updateContainerConfigNamespaces() failed: %v", err)
s.containers[contID] = ctr

a := &agentGRPC{
sandbox: s,
}

a.updateContainerConfigNamespaces(&config, ctr)

assert.True(t, reflect.DeepEqual(config, expected),
"Config structures should be identical: got %+v, expecting %+v",
config, expected)

}

func TestUpdateContainerConfigNamespacesNonEmptyConfig(t *testing.T) {
config := configs.Config{
Namespaces: []configs.Namespace{
{
Type: configs.NEWPID,
},
{
Type: configs.NEWIPC,
},
Expand All @@ -65,11 +81,25 @@ func TestUpdateContainerConfigNamespacesNonEmptyConfig(t *testing.T) {

expectedConfig := configs.Config{
Namespaces: []configs.Namespace{
{
Type: configs.NEWIPC,
Path: testSharedIPCNs,
},
{
Type: configs.NEWUTS,
Path: testSharedUTSNs,
},
{
Type: configs.NEWPID,
Path: testSharedPidNs,
},
},
}

testUpdateContainerConfigNamespacesSharedPid(t, testSharedPidNs, testSharedUTSNs, testSharedIPCNs, config, expectedConfig)

expectedConfig = configs.Config{
Namespaces: []configs.Namespace{
{
Type: configs.NEWIPC,
Path: testSharedIPCNs,
Expand All @@ -78,20 +108,38 @@ func TestUpdateContainerConfigNamespacesNonEmptyConfig(t *testing.T) {
Type: configs.NEWUTS,
Path: testSharedUTSNs,
},
{
Type: configs.NEWPID,
Path: "",
},
},
}

testUpdateContainerConfigNamespaces(t, testSharedPidNs, testSharedUTSNs, testSharedIPCNs, config, expectedConfig)
testUpdateContainerConfigNamespacesNonSharedPid(t, testSharedPidNs, testSharedUTSNs, testSharedIPCNs, config, expectedConfig)
}

func TestUpdateContainerConfigNamespacesEmptyConfig(t *testing.T) {
expectedConfig := configs.Config{
Namespaces: []configs.Namespace{
{
Type: configs.NEWIPC,
Path: testSharedIPCNs,
},
{
Type: configs.NEWUTS,
Path: testSharedUTSNs,
},
{
Type: configs.NEWPID,
Path: testSharedPidNs,
},
},
}

testUpdateContainerConfigNamespacesSharedPid(t, testSharedPidNs, testSharedUTSNs, testSharedIPCNs, configs.Config{}, expectedConfig)

expectedConfig = configs.Config{
Namespaces: []configs.Namespace{
{
Type: configs.NEWIPC,
Path: testSharedIPCNs,
Expand All @@ -100,11 +148,14 @@ func TestUpdateContainerConfigNamespacesEmptyConfig(t *testing.T) {
Type: configs.NEWUTS,
Path: testSharedUTSNs,
},
{
Type: configs.NEWPID,
Path: "",
},
},
}

testUpdateContainerConfigNamespaces(t, testSharedPidNs, testSharedUTSNs, testSharedIPCNs, configs.Config{}, expectedConfig)
//testUpdateContainerConfigNamespaces(t, testSharedPidNs, configs.Config{}, expectedConfig)
testUpdateContainerConfigNamespacesNonSharedPid(t, testSharedPidNs, testSharedUTSNs, testSharedIPCNs, configs.Config{}, expectedConfig)
}

func testUpdateContainerConfigPrivileges(t *testing.T, spec *specs.Spec, config, expected configs.Config) {
Expand Down

0 comments on commit ad9c33d

Please sign in to comment.