Skip to content
This repository was archived by the owner on Apr 21, 2021. It is now read-only.

Commit d2b5e63

Browse files
author
Zhou Hao
authored
Merge pull request opencontainers#584 from liangchenye/windows
check RootOnWindowsRequired
2 parents 35924b6 + 1cbf66a commit d2b5e63

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

specerror/config.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ const (
1414
RootOnWindowsRequired
1515
// RootOnHyperVNotSet represents "For Hyper-V Containers, this field MUST NOT be set."
1616
RootOnHyperVNotSet
17-
// RootOnNonHyperVRequired represents "On all other platforms, this field is REQUIRED."
18-
RootOnNonHyperVRequired
17+
// RootOnNonWindowsRequired represents "On all other platforms, this field is REQUIRED."
18+
RootOnNonWindowsRequired
1919
// RootPathOnWindowsGUID represents "On Windows, `path` MUST be a volume GUID path."
2020
RootPathOnWindowsGUID
2121
// RootPathOnPosixConvention represents "The value SHOULD be the conventional `rootfs`."
@@ -145,7 +145,7 @@ func init() {
145145
register(SpecVersionInSemVer, rfc2119.Must, specificationVersionRef)
146146
register(RootOnWindowsRequired, rfc2119.Required, rootRef)
147147
register(RootOnHyperVNotSet, rfc2119.Must, rootRef)
148-
register(RootOnNonHyperVRequired, rfc2119.Required, rootRef)
148+
register(RootOnNonWindowsRequired, rfc2119.Required, rootRef)
149149
register(RootPathOnWindowsGUID, rfc2119.Must, rootRef)
150150
register(RootPathOnPosixConvention, rfc2119.Should, rootRef)
151151
register(RootPathExist, rfc2119.Must, rootRef)

validate/validate.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,21 @@ func (v *Validator) CheckJSONSchema() (errs error) {
171171
func (v *Validator) CheckRoot() (errs error) {
172172
logrus.Debugf("check root")
173173

174-
if v.platform == "windows" && v.spec.Windows != nil && v.spec.Windows.HyperV != nil {
175-
if v.spec.Root != nil {
174+
if v.platform == "windows" && v.spec.Windows != nil {
175+
if v.spec.Windows.HyperV != nil {
176+
if v.spec.Root != nil {
177+
errs = multierror.Append(errs,
178+
specerror.NewError(specerror.RootOnHyperVNotSet, fmt.Errorf("for Hyper-V containers, Root must not be set"), rspec.Version))
179+
}
180+
return
181+
} else if v.spec.Root == nil {
176182
errs = multierror.Append(errs,
177-
specerror.NewError(specerror.RootOnHyperVNotSet, fmt.Errorf("for Hyper-V containers, Root must not be set"), rspec.Version))
183+
specerror.NewError(specerror.RootOnWindowsRequired, fmt.Errorf("on Windows, for Windows Server Containers, this field is REQUIRED"), rspec.Version))
178184
return
179185
}
180-
return
181-
} else if v.spec.Root == nil {
186+
} else if v.platform != "windows" && v.spec.Root == nil {
182187
errs = multierror.Append(errs,
183-
specerror.NewError(specerror.RootOnNonHyperVRequired, fmt.Errorf("for non-Hyper-V containers, Root must be set"), rspec.Version))
188+
specerror.NewError(specerror.RootOnNonWindowsRequired, fmt.Errorf("on all other platforms, this field is REQUIRED"), rspec.Version))
184189
return
185190
}
186191

validate/validate_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,8 @@ func TestCheckRoot(t *testing.T) {
296296
{rspec.Spec{Windows: &rspec.Windows{HyperV: &rspec.WindowsHyperV{}}, Root: nil}, "windows", specerror.NonError},
297297
{rspec.Spec{Windows: &rspec.Windows{}, Root: &rspec.Root{Path: filepath.Join(tmpBundle, "rootfs")}}, "windows", specerror.RootPathOnWindowsGUID},
298298
{rspec.Spec{Windows: &rspec.Windows{}, Root: &rspec.Root{Path: "\\\\?\\Volume{ec84d99e-3f02-11e7-ac6c-00155d7682cf}\\"}}, "windows", specerror.NonError},
299-
{rspec.Spec{Root: nil}, "linux", specerror.RootOnNonHyperVRequired},
299+
{rspec.Spec{Windows: &rspec.Windows{}, Root: nil}, "windows", specerror.RootOnWindowsRequired},
300+
{rspec.Spec{Root: nil}, "linux", specerror.RootOnNonWindowsRequired},
300301
{rspec.Spec{Root: &rspec.Root{Path: "maverick-rootfs"}}, "linux", specerror.RootPathOnPosixConvention},
301302
{rspec.Spec{Root: &rspec.Root{Path: "rootfs"}}, "linux", specerror.NonError},
302303
{rspec.Spec{Root: &rspec.Root{Path: filepath.Join(tmpBundle, rootfsNonExists)}}, "linux", specerror.RootPathExist},

0 commit comments

Comments
 (0)