From 306d709e12a63b763d8d2b2f8df4e0c81d7d116e Mon Sep 17 00:00:00 2001 From: Drew Walters Date: Wed, 26 Feb 2020 10:24:29 -0600 Subject: [PATCH] [#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 --- pkg/remote/remote_direct.go | 7 ++++++- pkg/remote/remote_direct_test.go | 13 +++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/pkg/remote/remote_direct.go b/pkg/remote/remote_direct.go index 958be4d3f..ee6b126dc 100644 --- a/pkg/remote/remote_direct.go +++ b/pkg/remote/remote_direct.go @@ -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 diff --git a/pkg/remote/remote_direct_test.go b/pkg/remote/remote_direct_test.go index ea349f6dd..e2a557ddb 100644 --- a/pkg/remote/remote_direct_test.go +++ b/pkg/remote/remote_direct_test.go @@ -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) +}