runtime: Do not error if only initrd/rootfs image installed

If only initrd or rootfs image is installed,
allow to start Kata Containers without erroring
out.

Fixes:  #1174

Signed-off-by: Nitesh Konkar niteshkonkar@in.ibm.com
This commit is contained in:
Nitesh Konkar 2019-02-04 18:01:00 +05:30
parent 6f2c036601
commit be0726ce50
2 changed files with 10 additions and 14 deletions

View File

@ -166,7 +166,7 @@ func (h hypervisor) initrd() (string, error) {
p := h.Initrd
if p == "" {
return "", nil
return "", errors.New("initrd is not set")
}
return ResolvePath(p)
@ -176,7 +176,7 @@ func (h hypervisor) image() (string, error) {
p := h.Image
if p == "" {
return "", nil
return "", errors.New("image is not set")
}
return ResolvePath(p)
@ -340,20 +340,16 @@ func (h hypervisor) guestHookPath() string {
}
func (h hypervisor) getInitrdAndImage() (initrd string, image string, err error) {
if initrd, err = h.initrd(); err != nil {
return
}
initrd, errInitrd := h.initrd()
if image, err = h.image(); err != nil {
return
}
image, errImage := h.image()
if image != "" && initrd != "" {
return "", "", errors.New("having both an image and an initrd defined in the configuration file is not supported")
}
if image == "" && initrd == "" {
return "", "", errors.New("either image or initrd must be defined in the configuration file")
if errInitrd != nil && errImage != nil {
return "", "", fmt.Errorf("Either initrd or image must be set to a valid path (initrd: %v) (image: %v)", errInitrd, errImage)
}
return

View File

@ -1046,14 +1046,14 @@ func TestHypervisorDefaultsInitrd(t *testing.T) {
defaultInitrdPath = testInitrdPath
h := hypervisor{}
p, err := h.initrd()
assert.NoError(err)
assert.Error(err)
assert.Equal(p, "", "default Image path wrong")
// test path resolution
defaultInitrdPath = testInitrdLinkPath
h = hypervisor{}
p, err = h.initrd()
assert.NoError(err)
assert.Error(err)
assert.Equal(p, "")
}
@ -1083,14 +1083,14 @@ func TestHypervisorDefaultsImage(t *testing.T) {
defaultImagePath = testImagePath
h := hypervisor{}
p, err := h.image()
assert.NoError(err)
assert.Error(err)
assert.Equal(p, "", "default Image path wrong")
// test path resolution
defaultImagePath = testImageLinkPath
h = hypervisor{}
p, err = h.image()
assert.NoError(err)
assert.Error(err)
assert.Equal(p, "")
}