Windows: Updates Windows Vendoring
Updates windows dependent libraries for vendoing.
This commit is contained in:
81
vendor/github.com/Microsoft/hcsshim/internal/schemaversion/schemaversion.go
generated
vendored
Normal file
81
vendor/github.com/Microsoft/hcsshim/internal/schemaversion/schemaversion.go
generated
vendored
Normal file
@ -0,0 +1,81 @@
|
||||
// +build windows
|
||||
|
||||
package schemaversion
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/Microsoft/hcsshim/internal/schema2"
|
||||
"github.com/Microsoft/hcsshim/osversion"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// SchemaV10 makes it easy for callers to get a v1.0 schema version object
|
||||
func SchemaV10() *hcsschema.Version {
|
||||
return &hcsschema.Version{Major: 1, Minor: 0}
|
||||
}
|
||||
|
||||
// SchemaV21 makes it easy for callers to get a v2.1 schema version object
|
||||
func SchemaV21() *hcsschema.Version {
|
||||
return &hcsschema.Version{Major: 2, Minor: 1}
|
||||
}
|
||||
|
||||
// isSupported determines if a given schema version is supported
|
||||
func IsSupported(sv *hcsschema.Version) error {
|
||||
if IsV10(sv) {
|
||||
return nil
|
||||
}
|
||||
if IsV21(sv) {
|
||||
if osversion.Get().Build < osversion.RS5 {
|
||||
return fmt.Errorf("unsupported on this Windows build")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown schema version %s", String(sv))
|
||||
}
|
||||
|
||||
// IsV10 determines if a given schema version object is 1.0. This was the only thing
|
||||
// supported in RS1..3. It lives on in RS5, but will be deprecated in a future release.
|
||||
func IsV10(sv *hcsschema.Version) bool {
|
||||
if sv.Major == 1 && sv.Minor == 0 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsV21 determines if a given schema version object is 2.0. This was introduced in
|
||||
// RS4, but not fully implemented. Recommended for applications using HCS in RS5
|
||||
// onwards.
|
||||
func IsV21(sv *hcsschema.Version) bool {
|
||||
if sv.Major == 2 && sv.Minor == 1 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// String returns a JSON encoding of a schema version object
|
||||
func String(sv *hcsschema.Version) string {
|
||||
b, err := json.Marshal(sv)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return string(b[:])
|
||||
}
|
||||
|
||||
// DetermineSchemaVersion works out what schema version to use based on build and
|
||||
// requested option.
|
||||
func DetermineSchemaVersion(requestedSV *hcsschema.Version) *hcsschema.Version {
|
||||
sv := SchemaV10()
|
||||
if osversion.Get().Build >= osversion.RS5 {
|
||||
sv = SchemaV21()
|
||||
}
|
||||
if requestedSV != nil {
|
||||
if err := IsSupported(requestedSV); err == nil {
|
||||
sv = requestedSV
|
||||
} else {
|
||||
logrus.Warnf("Ignoring unsupported requested schema version %+v", requestedSV)
|
||||
}
|
||||
}
|
||||
return sv
|
||||
}
|
63
vendor/github.com/Microsoft/hcsshim/internal/schemaversion/schemaversion_test.go
generated
vendored
Normal file
63
vendor/github.com/Microsoft/hcsshim/internal/schemaversion/schemaversion_test.go
generated
vendored
Normal file
@ -0,0 +1,63 @@
|
||||
package schemaversion
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"testing"
|
||||
|
||||
"github.com/Microsoft/hcsshim/internal/schema2"
|
||||
"github.com/Microsoft/hcsshim/osversion"
|
||||
_ "github.com/Microsoft/hcsshim/test/functional/manifest"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func init() {
|
||||
logrus.SetOutput(ioutil.Discard)
|
||||
}
|
||||
|
||||
func TestDetermineSchemaVersion(t *testing.T) {
|
||||
osv := osversion.Get()
|
||||
|
||||
if osv.Build >= osversion.RS5 {
|
||||
if sv := DetermineSchemaVersion(nil); !IsV21(sv) {
|
||||
t.Fatalf("expected v2")
|
||||
}
|
||||
if sv := DetermineSchemaVersion(SchemaV21()); !IsV21(sv) {
|
||||
t.Fatalf("expected requested v2")
|
||||
}
|
||||
if sv := DetermineSchemaVersion(SchemaV10()); !IsV10(sv) {
|
||||
t.Fatalf("expected requested v1")
|
||||
}
|
||||
if sv := DetermineSchemaVersion(&hcsschema.Version{}); !IsV21(sv) {
|
||||
t.Fatalf("expected requested v2")
|
||||
}
|
||||
|
||||
if err := IsSupported(SchemaV21()); err != nil {
|
||||
t.Fatalf("v2 expected to be supported")
|
||||
}
|
||||
if err := IsSupported(SchemaV10()); err != nil {
|
||||
t.Fatalf("v1 expected to be supported")
|
||||
}
|
||||
|
||||
} else {
|
||||
if sv := DetermineSchemaVersion(nil); !IsV10(sv) {
|
||||
t.Fatalf("expected v1")
|
||||
}
|
||||
// Pre RS5 will downgrade to v1 even if request v2
|
||||
if sv := DetermineSchemaVersion(SchemaV21()); !IsV10(sv) {
|
||||
t.Fatalf("expected requested v1")
|
||||
}
|
||||
if sv := DetermineSchemaVersion(SchemaV10()); !IsV10(sv) {
|
||||
t.Fatalf("expected requested v1")
|
||||
}
|
||||
if sv := DetermineSchemaVersion(&hcsschema.Version{}); !IsV10(sv) {
|
||||
t.Fatalf("expected requested v1")
|
||||
}
|
||||
|
||||
if err := IsSupported(SchemaV21()); err == nil {
|
||||
t.Fatalf("didn't expect v2 to be supported")
|
||||
}
|
||||
if err := IsSupported(SchemaV10()); err != nil {
|
||||
t.Fatalf("v1 expected to be supported")
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user