Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
config: Check factory config
Browse files Browse the repository at this point in the history
If VM factory templating is enabled (`enable_template=true`), error if
the configured image is not an `initrd=` one.

Also add a note to the config file explaining that a normal image cannot
be used - only initrd images are supported.

Fixes #948.

Signed-off-by: James O. D. Hunt <[email protected]>
  • Loading branch information
jodh-intel committed Nov 29, 2018
1 parent fe784c1 commit 0bf29c8
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cli/config/configuration.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ enable_iothreads = @DEFENABLEIOTHREADS@
#
# When disabled, new VMs are created from scratch.
#
# Note: Requires "initrd=" to be set ("image=" is not supported).
#
# Default false
#enable_template = true

Expand Down
13 changes: 13 additions & 0 deletions pkg/katautils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,10 @@ func checkConfig(config oci.RuntimeConfig) error {
return err
}

if err := checkFactoryConfig(config); err != nil {
return err
}

return nil
}

Expand Down Expand Up @@ -710,6 +714,15 @@ func checkNetNsConfig(config oci.RuntimeConfig) error {
return nil
}

// checkFactoryConfig ensures the VM factory configuration is valid.
func checkFactoryConfig(config oci.RuntimeConfig) error {
if config.FactoryConfig.Template && config.HypervisorConfig.InitrdPath == "" {
return errors.New("Factory option enable_template requires an initrd image")
}

return nil
}

// checkHypervisorConfig performs basic "sanity checks" on the hypervisor
// config.
func checkHypervisorConfig(config vc.HypervisorConfig) error {
Expand Down
41 changes: 41 additions & 0 deletions pkg/katautils/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1497,3 +1497,44 @@ func TestCheckNetNsConfig(t *testing.T) {
err = checkNetNsConfig(config)
assert.Error(err)
}

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

type testData struct {
factoryEnabled bool
imagePath string
initrdPath string
expectError bool
}

data := []testData{
{false, "", "", false},
{false, "image", "", false},
{false, "", "initrd", false},

{true, "", "initrd", false},
{true, "image", "", true},
}

for i, d := range data {
config := oci.RuntimeConfig{
HypervisorConfig: vc.HypervisorConfig{
ImagePath: d.imagePath,
InitrdPath: d.initrdPath,
},

FactoryConfig: oci.FactoryConfig{
Template: d.factoryEnabled,
},
}

err := checkFactoryConfig(config)

if d.expectError {
assert.Error(err, "test %d (%+v)", i, d)
} else {
assert.NoError(err, "test %d (%+v)", i, d)
}
}
}

0 comments on commit 0bf29c8

Please sign in to comment.