Skip to content
This repository was archived by the owner on May 6, 2020. It is now read-only.
Closed
Show file tree
Hide file tree
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
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,20 @@ PKGLIBEXECDIR := $(LIBEXECDIR)/$(CCDIR)

KERNELPATH := $(PKGDATADIR)/vmlinuz.container
IMAGEPATH := $(PKGDATADIR)/clear-containers.img
FIRMWAREPATH :=
MACHINEACCELERATORS :=

KERNELPARAMS :=

# The CentOS/RHEL hypervisor binary is not called qemu-lite
ifeq (,$(filter-out centos rhel,$(distro)))
QEMUCMD := qemu-system-x86_64
else
QEMUCMD := qemu-lite-system-x86_64
QEMUCMD := qemu-cc-system-x86_64
endif

QEMUPATH := $(QEMUBINDIR)/$(QEMUCMD)
MACHINETYPE := pc
MACHINETYPE := q35

SHIMCMD := cc-shim
SHIMPATH := $(PKGLIBEXECDIR)/$(SHIMCMD)
Expand Down Expand Up @@ -156,6 +158,8 @@ USER_VARS += DESTTARGET
USER_VARS += IMAGEPATH
USER_VARS += MACHINETYPE
USER_VARS += KERNELPATH
USER_VARS += FIRMWAREPATH
USER_VARS += MACHINEACCELERATORS
USER_VARS += KERNELPARAMS
USER_VARS += LIBEXECDIR
USER_VARS += LOCALSTATEDIR
Expand Down Expand Up @@ -215,6 +219,8 @@ var version = "$(VERSION)"
var defaultHypervisorPath = "$(QEMUPATH)"
var defaultImagePath = "$(IMAGEPATH)"
var defaultKernelPath = "$(KERNELPATH)"
var defaultFirmwarePath = "$(FIRMWAREPATH)"
var defaultMachineAccelerators = "$(MACHINEACCELERATORS)"
var defaultShimPath = "$(SHIMPATH)"

const defaultKernelParams = "$(KERNELPARAMS)"
Expand Down Expand Up @@ -285,6 +291,8 @@ $(GENERATED_FILES): %: %.in Makefile VERSION
-e "s|@CONFIG_IN@|$(CONFIG_IN)|g" \
-e "s|@IMAGEPATH@|$(IMAGEPATH)|g" \
-e "s|@KERNELPATH@|$(KERNELPATH)|g" \
-e "s|@FIRMWAREPATH@|$(FIRMWAREPATH)|g" \
-e "s|@MACHINEACCELERATORS@|$(MACHINEACCELERATORS)|g" \
-e "s|@KERNELPARAMS@|$(KERNELPARAMS)|g" \
-e "s|@LOCALSTATEDIR@|$(LOCALSTATEDIR)|g" \
-e "s|@PKGLIBEXECDIR@|$(PKGLIBEXECDIR)|g" \
Expand Down
29 changes: 29 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ type hypervisor struct {
Path string `toml:"path"`
Kernel string `toml:"kernel"`
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"`
Expand Down Expand Up @@ -134,6 +136,23 @@ func (h hypervisor) image() (string, error) {
return resolvePath(p)
}

func (h hypervisor) firmware() (string, error) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This needs a test.

p := h.Firmware

if p == "" {
if defaultFirmwarePath == "" {
return "", nil
}
p = defaultFirmwarePath
}

return resolvePath(p)
}

func (h hypervisor) machineAccelerators() string {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Another one that needs a very basic test.

return h.MachineAccelerators
}

func (h hypervisor) kernelParams() string {
if h.KernelParams == "" {
return defaultKernelParams
Expand Down Expand Up @@ -210,13 +229,21 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
return vc.HypervisorConfig{}, err
}

firmware, err := h.firmware()
if err != nil {
return vc.HypervisorConfig{}, err
}

machineAccelerators := h.machineAccelerators()
kernelParams := h.kernelParams()
machineType := h.machineType()

return vc.HypervisorConfig{
HypervisorPath: hypervisor,
KernelPath: kernel,
ImagePath: image,
FirmwarePath: firmware,
MachineAccelerators: machineAccelerators,
KernelParams: vc.DeserializeParams(strings.Fields(kernelParams)),
HypervisorMachineType: machineType,
DefaultVCPUs: h.defaultVCPUs(),
Expand Down Expand Up @@ -320,6 +347,8 @@ func loadConfiguration(configPath string, ignoreLogging bool) (resolvedConfigPat
HypervisorPath: defaultHypervisorPath,
KernelPath: defaultKernelPath,
ImagePath: defaultImagePath,
FirmwarePath: defaultFirmwarePath,
MachineAccelerators: defaultMachineAccelerators,
HypervisorMachineType: defaultMachineType,
DefaultVCPUs: defaultVCPUCount,
DefaultMemSz: defaultMemSize,
Expand Down
7 changes: 7 additions & 0 deletions config/configuration.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ machine_type = "@MACHINETYPE@"
# trouble running pre-2.15 glibc
kernel_params = "@KERNELPARAMS@"

# Path to the firmware.
# If you want that qemu uses the default firmware leave this option empty
firmware = "@FIRMWAREPATH@"

# Machine accelerators
machine_accelerators="@MACHINEACCELERATORS@"

# Default number of vCPUs per POD/VM:
# unspecified or 0 --> will be set to @DEFVCPUS@
# < 0 --> will be set to the actual number of physical cores
Expand Down
29 changes: 29 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -899,3 +899,32 @@ func TestGetDefaultConfigFile(t *testing.T) {
_, err = getDefaultConfigFile()
assert.Error(err)
}

func TestDefaultFirmware(t *testing.T) {
assert := assert.New(t)

f, err := ioutil.TempFile(os.TempDir(), "qboot.bin")
assert.NoError(err)
assert.NoError(f.Close())
defer os.RemoveAll(f.Name())

h := hypervisor{}
defaultFirmwarePath = ""
p, err := h.firmware()
assert.NoError(err)
assert.Empty(p)

defaultFirmwarePath = f.Name()
p, err = h.firmware()
assert.NoError(err)
assert.NotEmpty(p)
}

func TestDefaultMachineAccelerators(t *testing.T) {
assert := assert.New(t)
const machineAccelerators = "abc,123,rgb"

h := hypervisor{MachineAccelerators: machineAccelerators}

assert.Equal(machineAccelerators, h.machineAccelerators())
}