Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

integration/docker: read default number of vCPUs from config file #351

Merged
merged 2 commits into from
May 30, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -40,3 +40,7 @@
[[constraint]]
name = "github.com/opencontainers/specs"
version = "1.0.1"

[[constraint]]
name = "github.com/BurntSushi/toml"
revision = "a368813c5e648fee92e5f6c30e3944ff9d5e8895"
96 changes: 96 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// Copyright (c) 2018 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
//

package tests

import (
"io/ioutil"

"github.com/BurntSushi/toml"
)

// RuntimeConfig is the runtime configuration
type RuntimeConfig struct {
Hypervisor map[string]hypervisor
Proxy map[string]proxy
Shim map[string]shim
Agent map[string]agent
Runtime runtime
}

type hypervisor struct {
Path string `toml:"path"`
Kernel string `toml:"kernel"`
Initrd string `toml:"initrd"`
Image string `toml:"image"`
Firmware string `toml:"firmware"`
MachineAccelerators string `toml:"machine_accelerators"`
KernelParams string `toml:"kernel_params"`
MachineType string `toml:"machine_type"`
DefaultVCPUs int32 `toml:"default_vcpus"`
DefaultMaxVCPUs uint32 `toml:"default_maxvcpus"`
DefaultMemSz uint32 `toml:"default_memory"`
DefaultBridges uint32 `toml:"default_bridges"`
Msize9p uint32 `toml:"msize_9p"`
BlockDeviceDriver string `toml:"block_device_driver"`
DisableBlockDeviceUse bool `toml:"disable_block_device_use"`
MemPrealloc bool `toml:"enable_mem_prealloc"`
HugePages bool `toml:"enable_hugepages"`
Swap bool `toml:"enable_swap"`
Debug bool `toml:"enable_debug"`
DisableNestingChecks bool `toml:"disable_nesting_checks"`
EnableIOThreads bool `toml:"enable_iothreads"`
}

type proxy struct {
Path string `toml:"path"`
Debug bool `toml:"enable_debug"`
}

type runtime struct {
Debug bool `toml:"enable_debug"`
InterNetworkModel string `toml:"internetworking_model"`
}

type shim struct {
Path string `toml:"path"`
Debug bool `toml:"enable_debug"`
}

type agent struct {
}

const (
// DefaultHypervisor default hypervisor
DefaultHypervisor = "qemu"

// DefaultProxy default proxy
DefaultProxy = "kata"

// DefaultAgent default agent
DefaultAgent = "kata"

// DefaultShim default shim
DefaultShim = "kata"

// DefaultRuntimeConfigPath is the default path to the runtime configuration file
DefaultRuntimeConfigPath = "/usr/share/defaults/kata-containers/configuration.toml"
)

// LoadRuntimeConfiguration loads runtime configuration
func LoadRuntimeConfiguration(configPath string) (RuntimeConfig, error) {
var config RuntimeConfig
configData, err := ioutil.ReadFile(configPath)
if err != nil {
return config, err
}

_, err = toml.Decode(string(configData), &config)
if err != nil {
return config, err
}

return config, err
}
22 changes: 2 additions & 20 deletions integration/docker/cpu_test.go
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@ package docker
import (
"fmt"
"math"
"strconv"
"strings"

. "github.com/kata-containers/tests"
@@ -16,24 +15,6 @@ import (
. "github.com/onsi/gomega"
)

func getDefaultVCPUs() int {
args := []string{"--rm", Image, "sh", "-c", "sleep 5; nproc"}
stdout, _, exitCode := dockerRun(args...)
if stdout == "" || exitCode != 0 {
LogIfFail("Failed to get default number of vCPUs")
return -1
}

stdout = strings.Trim(stdout, "\n\t ")
vcpus, err := strconv.Atoi(stdout)
if err != nil {
LogIfFail("Failed to convert '%s' to int", stdout)
return -1
}

return vcpus
}

func withCPUPeriodAndQuota(quota, period, defaultVCPUs int, fail bool) TableEntry {
var msg string

@@ -64,7 +45,7 @@ var _ = Describe("Hot plug CPUs", func() {
args []string
id string
vCPUs int
defaultVCPUs = getDefaultVCPUs()
defaultVCPUs int
waitTime int
maxTries int
checkCpusCmdFmt string
@@ -76,6 +57,7 @@ var _ = Describe("Hot plug CPUs", func() {
waitTime = 5
maxTries = 5
args = []string{"--rm", "--name", id}
defaultVCPUs = int(runtimeConfig.Hypervisor[DefaultHypervisor].DefaultVCPUs)
Expect(defaultVCPUs).To(BeNumerically(">", 0))
})

24 changes: 24 additions & 0 deletions integration/docker/main_test.go
Original file line number Diff line number Diff line change
@@ -5,6 +5,8 @@
package docker

import (
"os"
"strings"
"testing"

. "github.com/kata-containers/tests"
@@ -17,11 +19,33 @@ const (
shouldNotFail = false
)

var runtimeConfig RuntimeConfig

func randomDockerName() string {
return RandID(30)
}

func TestIntegration(t *testing.T) {
var err error
runtimeConfigPath := DefaultRuntimeConfigPath

args := []string{"--kata-show-default-config-paths"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

cmd := NewCommand(Runtime, args...)
stdout, _, exitCode := cmd.Run()
if exitCode == 0 && stdout != "" {
for _, c := range strings.Split(stdout, "\n") {
if _, err = os.Stat(c); err == nil {
runtimeConfigPath = c
break
}
}
}

runtimeConfig, err = LoadRuntimeConfiguration(runtimeConfigPath)
if err != nil {
t.Fatalf("failed to load runtime configuration: %v\n", err)
}

// before start we have to download the docker images
images := []string{
Image,
21 changes: 21 additions & 0 deletions vendor/github.com/BurntSushi/toml/COPYING

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions vendor/github.com/BurntSushi/toml/cmd/toml-test-decoder/COPYING

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions vendor/github.com/BurntSushi/toml/cmd/toml-test-encoder/COPYING

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions vendor/github.com/BurntSushi/toml/cmd/tomlv/COPYING

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

509 changes: 509 additions & 0 deletions vendor/github.com/BurntSushi/toml/decode.go

Large diffs are not rendered by default.

121 changes: 121 additions & 0 deletions vendor/github.com/BurntSushi/toml/decode_meta.go
27 changes: 27 additions & 0 deletions vendor/github.com/BurntSushi/toml/doc.go
568 changes: 568 additions & 0 deletions vendor/github.com/BurntSushi/toml/encode.go

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions vendor/github.com/BurntSushi/toml/encoding_types.go
18 changes: 18 additions & 0 deletions vendor/github.com/BurntSushi/toml/encoding_types_1.1.go
953 changes: 953 additions & 0 deletions vendor/github.com/BurntSushi/toml/lex.go

Large diffs are not rendered by default.

592 changes: 592 additions & 0 deletions vendor/github.com/BurntSushi/toml/parse.go

Large diffs are not rendered by default.

91 changes: 91 additions & 0 deletions vendor/github.com/BurntSushi/toml/type_check.go
242 changes: 242 additions & 0 deletions vendor/github.com/BurntSushi/toml/type_fields.go