[#65] Avoid panic on missing remoteDirect opts

Running "airshipctl bootstrap remotedirect" without remoteDirect options
in the bootstrap config causes a panic. This change adds checks to avoid
the aforementioned panic.

Change-Id: I72d360ede628750acb5a6b01c8ebea7819adf043
Signed-off-by: Drew Walters <andrew.walters@att.com>
This commit is contained in:
Drew Walters 2020-02-26 10:24:29 -06:00
parent 8cf0247086
commit 306d709e12
2 changed files with 19 additions and 1 deletions

View File

@ -77,6 +77,11 @@ func getRemoteDirectConfig(settings *environment.AirshipCTLSettings) (*config.Re
return nil, "", err
}
remoteConfig := bootstrapSettings.RemoteDirect
if remoteConfig == nil {
return nil, "", config.ErrMissingConfig{What: "RemoteDirect options not defined in bootstrap config"}
}
// TODO (dukov) replace with the appropriate function once it's available
// in document module
docBundle, err := document.NewBundle(fs.MakeRealFS(), manifest.TargetPath, "")
@ -106,7 +111,7 @@ func getRemoteDirectConfig(settings *environment.AirshipCTLSettings) (*config.Re
return nil, "", err
}
return bootstrapSettings.RemoteDirect, remoteURL, nil
return remoteConfig, remoteURL, nil
}
// Top level function to execute remote direct based on remote type

View File

@ -71,3 +71,16 @@ func TestRedfishRemoteDirectWithEmptyIsoPath(t *testing.T) {
_, ok := err.(redfish.ErrRedfishMissingConfig)
assert.True(t, ok)
}
func TestBootstrapRemoteDirectMissingConfigOpts(t *testing.T) {
s := initSettings(
t,
nil,
"base",
)
err := DoRemoteDirect(s)
_, ok := err.(config.ErrMissingConfig)
assert.True(t, ok)
}