Windows: Updates Windows Vendoring

Updates windows dependent libraries for vendoing.
This commit is contained in:
Nathan Gieseker
2019-01-23 18:43:18 -08:00
parent a686cc4bd8
commit 9a429d8d25
839 changed files with 282895 additions and 774 deletions

View File

@ -0,0 +1,76 @@
package testutilities
import (
"os"
"testing"
"github.com/Microsoft/hcsshim/internal/uvm"
)
// CreateWCOWUVM creates a WCOW utility VM with all default options. Returns the
// UtilityVM object; folder used as its scratch
func CreateWCOWUVM(t *testing.T, id, image string) (*uvm.UtilityVM, []string, string) {
return CreateWCOWUVMFromOptsWithImage(t, uvm.NewDefaultOptionsWCOW(id, ""), image)
}
// CreateWCOWUVMFromOpts creates a WCOW utility VM with the passed opts.
func CreateWCOWUVMFromOpts(t *testing.T, opts *uvm.OptionsWCOW) *uvm.UtilityVM {
if opts == nil || len(opts.LayerFolders) < 2 {
t.Fatalf("opts must bet set with LayerFolders")
}
uvm, err := uvm.CreateWCOW(opts)
if err != nil {
t.Fatal(err)
}
if err := uvm.Start(); err != nil {
uvm.Close()
t.Fatal(err)
}
return uvm
}
// CreateWCOWUVMFromOptsWithImage creates a WCOW utility VM with the passed opts
// builds the LayerFolders based on `image`. Returns the UtilityVM object;
// folder used as its scratch
func CreateWCOWUVMFromOptsWithImage(t *testing.T, opts *uvm.OptionsWCOW, image string) (*uvm.UtilityVM, []string, string) {
if opts == nil {
t.Fatal("opts must be set")
}
uvmLayers := LayerFolders(t, image)
scratchDir := CreateTempDir(t)
defer func() {
if t.Failed() {
os.RemoveAll(scratchDir)
}
}()
opts.LayerFolders = append(opts.LayerFolders, uvmLayers...)
opts.LayerFolders = append(opts.LayerFolders, scratchDir)
return CreateWCOWUVMFromOpts(t, opts), uvmLayers, scratchDir
}
// CreateLCOWUVM with all default options.
func CreateLCOWUVM(t *testing.T, id string) *uvm.UtilityVM {
return CreateLCOWUVMFromOpts(t, uvm.NewDefaultOptionsLCOW(id, ""))
}
// CreateLCOWUVMFromOpts creates an LCOW utility VM with the specified options.
func CreateLCOWUVMFromOpts(t *testing.T, opts *uvm.OptionsLCOW) *uvm.UtilityVM {
if opts == nil {
t.Fatal("opts must be set")
}
uvm, err := uvm.CreateLCOW(opts)
if err != nil {
t.Fatal(err)
}
if err := uvm.Start(); err != nil {
uvm.Close()
t.Fatal(err)
}
return uvm
}

View File

@ -0,0 +1,21 @@
package testutilities
import (
"encoding/json"
"io/ioutil"
"testing"
specs "github.com/opencontainers/runtime-spec/specs-go"
)
func GetDefaultLinuxSpec(t *testing.T) *specs.Spec {
content, err := ioutil.ReadFile(`assets\defaultlinuxspec.json`)
if err != nil {
t.Fatalf("failed to read defaultlinuxspec.json: %s", err.Error())
}
spec := specs.Spec{}
if err := json.Unmarshal(content, &spec); err != nil {
t.Fatalf("failed to unmarshal contents of defaultlinuxspec.json: %s", err.Error())
}
return &spec
}

View File

@ -0,0 +1,21 @@
package testutilities
import (
"encoding/json"
"io/ioutil"
"testing"
specs "github.com/opencontainers/runtime-spec/specs-go"
)
func GetDefaultWindowsSpec(t *testing.T) *specs.Spec {
content, err := ioutil.ReadFile(`assets\defaultwindowsspec.json`)
if err != nil {
t.Fatalf("failed to read defaultwindowsspec.json: %s", err.Error())
}
spec := specs.Spec{}
if err := json.Unmarshal(content, &spec); err != nil {
t.Fatalf("failed to unmarshal contents of defaultwindowsspec.json: %s", err.Error())
}
return &spec
}

View File

@ -0,0 +1,54 @@
package testutilities
import (
"bytes"
"encoding/json"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
)
var imageLayers map[string][]string
func init() {
imageLayers = make(map[string][]string)
}
func LayerFolders(t *testing.T, imageName string) []string {
if _, ok := imageLayers[imageName]; !ok {
imageLayers[imageName] = getLayers(t, imageName)
}
return imageLayers[imageName]
}
func getLayers(t *testing.T, imageName string) []string {
cmd := exec.Command("docker", "inspect", imageName, "-f", `"{{.GraphDriver.Data.dir}}"`)
var out bytes.Buffer
cmd.Stdout = &out
if err := cmd.Run(); err != nil {
t.Skipf("Failed to find layers for %q. Check docker images", imageName)
}
imagePath := strings.Replace(strings.TrimSpace(out.String()), `"`, ``, -1)
layers := getLayerChain(t, imagePath)
return append([]string{imagePath}, layers...)
}
func getLayerChain(t *testing.T, layerFolder string) []string {
jPath := filepath.Join(layerFolder, "layerchain.json")
content, err := ioutil.ReadFile(jPath)
if os.IsNotExist(err) {
t.Fatalf("layerchain not found")
} else if err != nil {
t.Fatalf("failed to read layerchain")
}
var layerChain []string
err = json.Unmarshal(content, &layerChain)
if err != nil {
t.Fatalf("failed to unmarshal layerchain")
}
return layerChain
}

View File

@ -0,0 +1,19 @@
package testutilities
import (
"testing"
"github.com/Microsoft/hcsshim/osversion"
)
func RequiresBuild(t *testing.T, b uint16) {
if osversion.Get().Build < b {
t.Skipf("Requires build %d+", b)
}
}
func RequiresExactBuild(t *testing.T, b uint16) {
if osversion.Get().Build != b {
t.Skipf("Requires exact build %d", b)
}
}

View File

@ -0,0 +1,59 @@
package testutilities
import (
"path/filepath"
"testing"
"github.com/Microsoft/hcsshim/internal/hcs"
"github.com/Microsoft/hcsshim/internal/lcow"
"github.com/Microsoft/hcsshim/internal/uvm"
"github.com/Microsoft/hcsshim/internal/wclayer"
)
const lcowGlobalSVMID = "test.lcowglobalsvm"
var (
lcowGlobalSVM *uvm.UtilityVM
lcowCacheScratchFile string
)
func init() {
if hcsSystem, err := hcs.OpenComputeSystem(lcowGlobalSVMID); err == nil {
hcsSystem.Terminate()
}
}
// CreateWCOWBlankRWLayer uses HCS to create a temp test directory containing a
// read-write layer containing a disk that can be used as a containers scratch
// space. The VHD is created with VM group access
// TODO: This is wrong. Need to search the folders.
func CreateWCOWBlankRWLayer(t *testing.T, imageLayers []string) string {
// uvmFolder, err := LocateUVMFolder(imageLayers)
// if err != nil {
// t.Fatalf("failed to locate UVM folder from %+v: %s", imageLayers, err)
// }
tempDir := CreateTempDir(t)
if err := wclayer.CreateScratchLayer(tempDir, imageLayers); err != nil {
t.Fatalf("Failed CreateScratchLayer: %s", err)
}
return tempDir
}
// CreateLCOWBlankRWLayer uses an LCOW utility VM to create a blank
// VHDX and format it ext4. If vmID is supplied, it grants access to the
// destination file. This can then be used as a scratch space for a container,
// or for a "service VM".
func CreateLCOWBlankRWLayer(t *testing.T, vmID string) string {
if lcowGlobalSVM == nil {
lcowGlobalSVM = CreateLCOWUVM(t, lcowGlobalSVMID)
lcowCacheScratchFile = filepath.Join(CreateTempDir(t), "sandbox.vhdx")
}
tempDir := CreateTempDir(t)
if err := lcow.CreateScratch(lcowGlobalSVM, filepath.Join(tempDir, "sandbox.vhdx"), lcow.DefaultScratchSizeGB, lcowCacheScratchFile, vmID); err != nil {
t.Fatalf("failed to create EXT4 scratch for LCOW test cases: %s", err)
}
return tempDir
}

View File

@ -0,0 +1,15 @@
package testutilities
import (
"io/ioutil"
"testing"
)
// CreateTempDir creates a temporary directory
func CreateTempDir(t *testing.T) string {
tempDir, err := ioutil.TempDir("", "test")
if err != nil {
t.Fatalf("failed to create temporary directory: %s", err)
}
return tempDir
}