Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSD-17374: Fixed backplane error overwriting issue when the proxy is not available #151

Merged
Merged
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
22 changes: 2 additions & 20 deletions cmd/ocm-backplane/login/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,37 +291,19 @@ var _ = Describe("Login command", func() {
Expect(cfg.Contexts["default/test123/anonymous"].Namespace).To(Equal("default"))
})

It("should fail when BP API timeouts", func() {
It("should fail when a proxy or backplane url is unreachable", func() {

err := utils.CreateTempKubeConfig(nil)
Expect(err).To(BeNil())
mockOcmInterface.EXPECT().GetTargetCluster(testClusterId).Return(trueClusterId, testClusterId, nil)
mockOcmInterface.EXPECT().IsClusterHibernating(gomock.Eq(trueClusterId)).Return(false, nil).AnyTimes()
mockOcmInterface.EXPECT().GetOCMAccessToken().Return(&testToken, nil)
mockClientUtil.EXPECT().MakeRawBackplaneAPIClientWithAccessToken(backplaneAPIUri, testToken).Return(mockClient, nil)
mockClient.EXPECT().LoginCluster(gomock.Any(), gomock.Eq(trueClusterId)).Return(fakeResp, errors.New("dial tcp i/o timeout"))
mockClient.EXPECT().LoginCluster(gomock.Any(), gomock.Eq(trueClusterId)).Return(fakeResp, errors.New("dial tcp: lookup yourproxy.com: no such host"))

err = runLogin(nil, []string{testClusterId})

Expect(err).NotTo(BeNil())
Expect(err.Error()).Should(ContainSubstring("cannot connect to backplane API URL"))

})

It("should fail when proxy not avaliable", func() {

err := utils.CreateTempKubeConfig(nil)
Expect(err).To(BeNil())
mockOcmInterface.EXPECT().GetTargetCluster(testClusterId).Return(trueClusterId, testClusterId, nil)
mockOcmInterface.EXPECT().IsClusterHibernating(gomock.Eq(trueClusterId)).Return(false, nil).AnyTimes()
mockOcmInterface.EXPECT().GetOCMAccessToken().Return(&testToken, nil)
mockClientUtil.EXPECT().MakeRawBackplaneAPIClientWithAccessToken(backplaneAPIUri, testToken).Return(mockClient, nil)
mockClient.EXPECT().LoginCluster(gomock.Any(), gomock.Eq(trueClusterId)).Return(fakeResp, errors.New("proxyconnect tcp: dial tcp: lookup yourproxy.com: no such host "))

err = runLogin(nil, []string{testClusterId})

Expect(err).NotTo(BeNil())
Expect(err.Error()).Should(ContainSubstring("check if you need to use a proxy/VPN to access backplane"))

})

Expand Down
10 changes: 0 additions & 10 deletions pkg/cli/config/config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package config

import (
"errors"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -79,15 +78,6 @@ func GetBackplaneConfiguration() (bpConfig BackplaneConfiguration, err error) {
// CheckAPIConnection validate API connection via configured proxy and VPN
func (config BackplaneConfiguration) CheckAPIConnection() error {

// Check backplane Proxy URL
if config.ProxyURL == "" {
path, err := GetConfigFilePath()
if err != nil {
return err
}
return errors.New("empty proxy url - check your backplane-cli configuration in " + path)
}

// make test api connection
connectionOk, err := config.testHttpRequestToBackplaneAPI()

Expand Down