Merge pull request #641 from yifan-gu/fix_readonly

stage1: Override image manifest's readOnly field for volume mounts.
This commit is contained in:
Yifan Gu
2015-03-25 16:41:43 -07:00
2 changed files with 89 additions and 1 deletions
+8 -1
View File
@@ -288,7 +288,14 @@ func (c *Container) appToNspawnArgs(ra *schema.RuntimeApp, am *schema.ImageManif
}
opt := make([]string, 4)
if mp.ReadOnly {
// If the readonly flag in the pod manifest is not nil,
// then use it to override the readonly flag in the image manifest.
readOnly := mp.ReadOnly
if vol.ReadOnly != nil {
readOnly = *vol.ReadOnly
}
if readOnly {
opt[0] = "--bind-ro="
} else {
opt[0] = "--bind="
+81
View File
@@ -15,7 +15,11 @@
package main
import (
"strings"
"testing"
"github.com/coreos/rocket/Godeps/_workspace/src/github.com/appc/spec/schema"
"github.com/coreos/rocket/Godeps/_workspace/src/github.com/appc/spec/schema/types"
)
func TestQuoteExec(t *testing.T) {
@@ -45,3 +49,80 @@ func TestQuoteExec(t *testing.T) {
}
}
}
// TestAppToNspawnArgsOverridesImageManifestReadOnly tests
// that the ImageManifest's `readOnly` volume setting will be
// overrided by PodManifest.
func TestAppToNspawnArgsOverridesImageManifestReadOnly(t *testing.T) {
falseVar := false
trueVar := true
tests := []struct {
imageManifestVolumeReadOnly bool
podManifestVolumeReadOnly *bool
expectReadOnly bool
}{
{
false,
nil,
false,
},
{
false,
&falseVar,
false,
},
{
false,
&trueVar,
true,
},
{
true,
nil,
true,
},
{
true,
&falseVar,
false,
},
{
true,
&trueVar,
true,
},
}
for i, tt := range tests {
imageManifest := &schema.ImageManifest{
App: &types.App{
MountPoints: []types.MountPoint{
{
Name: "foo-mount",
Path: "/app/foo",
ReadOnly: tt.imageManifestVolumeReadOnly,
},
},
},
}
podManifest := &schema.PodManifest{
Volumes: []types.Volume{
{
Name: "foo-mount",
Kind: "host",
Source: "/host/foo",
ReadOnly: tt.podManifestVolumeReadOnly,
},
},
}
c := &Container{Manifest: podManifest}
output, err := c.appToNspawnArgs(&schema.RuntimeApp{}, imageManifest)
if err != nil {
t.Errorf("#%d: unexpected error: `%v`", i, err)
}
if ro := strings.HasPrefix(output[0], "--bind-ro"); ro != tt.expectReadOnly {
t.Errorf("#%d: expected: readOnly: %v, saw: %v", i, tt.expectReadOnly, ro)
}
}
}