Skip to content

Commit 8178fda

Browse files
authored
Merge pull request #428 from Mashimiao/rename-add-root-check
Rename CheckRootfsPath and add Root check for hyper-v
2 parents 5753b3a + b904a5e commit 8178fda

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

validate/validate.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func NewValidatorFromPath(bundlePath string, hostSpecific bool, platform string)
9696
// CheckAll checks all parts of runtime bundle
9797
func (v *Validator) CheckAll() (msgs []string) {
9898
msgs = append(msgs, v.CheckPlatform()...)
99-
msgs = append(msgs, v.CheckRootfsPath()...)
99+
msgs = append(msgs, v.CheckRoot()...)
100100
msgs = append(msgs, v.CheckMandatoryFields()...)
101101
msgs = append(msgs, v.CheckSemVer()...)
102102
msgs = append(msgs, v.CheckMounts()...)
@@ -109,9 +109,20 @@ func (v *Validator) CheckAll() (msgs []string) {
109109
return
110110
}
111111

112-
// CheckRootfsPath checks status of v.spec.Root.Path
113-
func (v *Validator) CheckRootfsPath() (msgs []string) {
114-
logrus.Debugf("check rootfs path")
112+
// CheckRoot checks status of v.spec.Root
113+
func (v *Validator) CheckRoot() (msgs []string) {
114+
logrus.Debugf("check root")
115+
116+
if v.platform == "windows" && v.spec.Windows.HyperV != nil {
117+
if v.spec.Root != nil {
118+
msgs = append(msgs, fmt.Sprintf("for Hyper-V containers, Root must not be set"))
119+
return
120+
}
121+
return
122+
} else if v.spec.Root == nil {
123+
msgs = append(msgs, fmt.Sprintf("for non-Hyper-V containers, Root must be set"))
124+
return
125+
}
115126

116127
absBundlePath, err := filepath.Abs(v.bundlePath)
117128
if err != nil {

validate/validate_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@ func checkErrors(t *testing.T, title string, msgs []string, valid bool) {
1818
}
1919
}
2020

21-
func TestCheckRootfsPath(t *testing.T) {
21+
func TestCheckRoot(t *testing.T) {
2222
tmpBundle, err := ioutil.TempDir("", "oci-check-rootfspath")
2323
if err != nil {
24-
t.Fatalf("Failed to create a TempDir in 'CheckRootfsPath'")
24+
t.Fatalf("Failed to create a TempDir in 'CheckRoot'")
2525
}
2626
defer os.RemoveAll(tmpBundle)
2727

2828
rootfsDir := "rootfs"
2929
rootfsNonDir := "rootfsfile"
3030
rootfsNonExists := "rootfsnil"
3131
if err := os.MkdirAll(filepath.Join(tmpBundle, rootfsDir), 0700); err != nil {
32-
t.Fatalf("Failed to create a rootfs directory in 'CheckRootfsPath'")
32+
t.Fatalf("Failed to create a rootfs directory in 'CheckRoot'")
3333
}
3434
if _, err := os.Create(filepath.Join(tmpBundle, rootfsNonDir)); err != nil {
35-
t.Fatalf("Failed to create a non-directory rootfs in 'CheckRootfsPath'")
35+
t.Fatalf("Failed to create a non-directory rootfs in 'CheckRoot'")
3636
}
3737

3838
cases := []struct {
@@ -48,7 +48,7 @@ func TestCheckRootfsPath(t *testing.T) {
4848
}
4949
for _, c := range cases {
5050
v := NewValidator(&rspec.Spec{Root: &rspec.Root{Path: c.val}}, tmpBundle, false, "linux")
51-
checkErrors(t, "CheckRootfsPath "+c.val, v.CheckRootfsPath(), c.expected)
51+
checkErrors(t, "CheckRoot "+c.val, v.CheckRoot(), c.expected)
5252
}
5353
}
5454

0 commit comments

Comments
 (0)