From 483b9eaf6f0d3ee834cb86da281cca034aeb005b Mon Sep 17 00:00:00 2001 From: Samantha Jayasinghe Date: Wed, 12 Jul 2023 21:18:37 +1200 Subject: [PATCH] OSD-17374: Fixed backplane error overwriting issue when the proxy is not available --- cmd/ocm-backplane/login/login_test.go | 22 ++-------------------- pkg/cli/config/config.go | 10 ---------- 2 files changed, 2 insertions(+), 30 deletions(-) diff --git a/cmd/ocm-backplane/login/login_test.go b/cmd/ocm-backplane/login/login_test.go index 3963eee1..719b226e 100644 --- a/cmd/ocm-backplane/login/login_test.go +++ b/cmd/ocm-backplane/login/login_test.go @@ -291,7 +291,7 @@ 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()) @@ -299,29 +299,11 @@ var _ = Describe("Login command", func() { 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")) }) diff --git a/pkg/cli/config/config.go b/pkg/cli/config/config.go index bf647e03..4b3e7251 100644 --- a/pkg/cli/config/config.go +++ b/pkg/cli/config/config.go @@ -1,7 +1,6 @@ package config import ( - "errors" "net/http" "net/url" "os" @@ -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()