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

Commit

Permalink
Merge pull request #351 from devimc/docker/loadRuntimeConfig
Browse files Browse the repository at this point in the history
integration/docker: read default number of vCPUs from config file
  • Loading branch information
chavafg authored May 30, 2018
2 parents 07098a1 + cc7ba87 commit 2645701
Show file tree
Hide file tree
Showing 19 changed files with 3,335 additions and 21 deletions.
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
Expand Up @@ -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
Expand Up @@ -7,7 +7,6 @@ package docker
import (
"fmt"
"math"
"strconv"
"strings"

. "github.com/kata-containers/tests"
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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))
})

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

import (
"os"
"strings"
"testing"

. "github.com/kata-containers/tests"
Expand All @@ -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"}
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,
Expand Down
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.

Loading

0 comments on commit 2645701

Please sign in to comment.