From 88bb66063810f8e6c69f417826fba1c09bccbb44 Mon Sep 17 00:00:00 2001 From: joshivedant84 Date: Fri, 19 Jul 2024 04:38:10 +0000 Subject: [PATCH 1/5] Commenting out the auto upload of support bundle --- pkg/supportBundle/supportBundle.go | 52 ++++++++++++++++-------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/pkg/supportBundle/supportBundle.go b/pkg/supportBundle/supportBundle.go index 899f06f..aa9798f 100644 --- a/pkg/supportBundle/supportBundle.go +++ b/pkg/supportBundle/supportBundle.go @@ -112,36 +112,38 @@ func SupportBundleUpload(ctx objects.Config, allClients client.Client, isRemote FQDN = strings.Replace(FQDN, "https://", "", 1) } + // Commenting out the auto upload of the support bundle in favour of #incident351 + // S3 location to upload the file - S3_Location = S3_Loc + "/" + FQDN + "/" + hostIP + "/" + // S3_Location = S3_Loc + "/" + FQDN + "/" + hostIP + "/" // To upload the pf9cli log bundle to S3 bucket - errUpload := S3Upload(allClients.Executor) - if errUpload != nil { - zap.S().Debugf("Failed to upload pf9ctl supportBundle to %s bucket!! ", S3_BUCKET_NAME, errUpload) - - if err := allClients.Segment.SendEvent("supportBundle upload Failed", auth, "Failed", ""); err != nil { - zap.S().Debugf("Unable to send Segment event for supportBundle. Error: %s", err.Error()) - } - - } else { - zap.S().Debugf("Succesfully uploaded pf9ctl supportBundle to %s bucket at %s location \n", - S3_BUCKET_NAME, S3_Location) - if err := allClients.Segment.SendEvent("supportBundle upload Success", auth, "Success", ""); err != nil { - zap.S().Debugf("Unable to send Segment event for supportBundle. Error: %s", err.Error()) - } - } + // errUpload := S3Upload(allClients.Executor) + // if errUpload != nil { + // zap.S().Debugf("Failed to upload pf9ctl supportBundle to %s bucket!! ", S3_BUCKET_NAME, errUpload) + + // if err := allClients.Segment.SendEvent("supportBundle upload Failed", auth, "Failed", ""); err != nil { + // zap.S().Debugf("Unable to send Segment event for supportBundle. Error: %s", err.Error()) + // } + + // } else { + // zap.S().Debugf("Succesfully uploaded pf9ctl supportBundle to %s bucket at %s location \n", + // S3_BUCKET_NAME, S3_Location) + // if err := allClients.Segment.SendEvent("supportBundle upload Success", auth, "Success", ""); err != nil { + // zap.S().Debugf("Unable to send Segment event for supportBundle. Error: %s", err.Error()) + // } + // } // Remove the supportbundle after uploading to S3 - errremove := RemoveBundle(allClients.Executor) - if errremove != nil { - zap.S().Debug("Error removing generated bundle", errremove) - } + // errremove := RemoveBundle(allClients.Executor) + // if errremove != nil { + // zap.S().Debug("Error removing generated bundle", errremove) + // } return nil } -//To generate the targetfile name including the hostname and the timestamp +// To generate the targetfile name including the hostname and the timestamp func GenTargetFilename(timestamp time.Time, hostname string) string { //timestamp format for the archive file(Note:UTC Time is taken) @@ -157,7 +159,7 @@ func GenTargetFilename(timestamp time.Time, hostname string) string { return targetfile } -//To upload supportBundle to the S3 location +// To upload supportBundle to the S3 location func S3Upload(exec cmdexec.Executor) error { errUpload := exec.Run("bash", "-c", fmt.Sprintf("curl -T %s -H %s %s", fileloc, S3_ACL, S3_Location)) @@ -167,7 +169,7 @@ func S3Upload(exec cmdexec.Executor) error { return nil } -//To remove the supportBundle +// To remove the supportBundle func RemoveBundle(exec cmdexec.Executor) error { errremove := exec.Run("bash", "-c", fmt.Sprintf("rm -rf %s", fileloc)) if errremove != nil { @@ -189,8 +191,8 @@ func statPaths(exec cmdexec.Executor, paths ...string) bool { return couldStatAll } -//This function is used to generate the support bundles. -//It copies all the log files specified into a directory and archives that given directory. +// This function is used to generate the support bundles. +// It copies all the log files specified into a directory and archives that given directory. func GenSupportBundle(exec cmdexec.Executor, timestamp time.Time, isRemote bool) (string, error) { //Check whether the source directories exist in remote node. From 450ee86f2ab20c78f8160ffde1313039640b79af Mon Sep 17 00:00:00 2001 From: joshivedant84 Date: Fri, 19 Jul 2024 04:45:20 +0000 Subject: [PATCH 2/5] Commenting out unused variables --- pkg/supportBundle/supportBundle.go | 63 +++++++++++++++--------------- 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/pkg/supportBundle/supportBundle.go b/pkg/supportBundle/supportBundle.go index aa9798f..3305cd8 100644 --- a/pkg/supportBundle/supportBundle.go +++ b/pkg/supportBundle/supportBundle.go @@ -9,7 +9,6 @@ import ( "github.com/platform9/pf9ctl/pkg/client" "github.com/platform9/pf9ctl/pkg/cmdexec" "github.com/platform9/pf9ctl/pkg/color" - "github.com/platform9/pf9ctl/pkg/keystone" "github.com/platform9/pf9ctl/pkg/objects" "github.com/platform9/pf9ctl/pkg/pmk" "github.com/platform9/pf9ctl/pkg/util" @@ -33,11 +32,11 @@ var ( hostOS string //Errors returned from the functions - ErrHostIP = fmt.Errorf("Host IP not found") - ErrRemove = fmt.Errorf("Unable to remove bundle") - ErrGenBundle = fmt.Errorf("Unable to generate supportBundle in remote host") - ErrUpload = fmt.Errorf("Unable to upload supportBundle to S3") - ErrPartialBundle = fmt.Errorf("Failed to generate complete supportBundle, generated partial bundle") + ErrHostIP = fmt.Errorf("host IP not found") + ErrRemove = fmt.Errorf("unable to remove bundle") + ErrGenBundle = fmt.Errorf("unable to generate supportBundle in remote host") + ErrUpload = fmt.Errorf("unable to upload supportBundle to S3") + ErrPartialBundle = fmt.Errorf("failed to generate complete supportBundle, generated partial bundle") //Timestamp used for generating targetfile Timestamp = time.Now() @@ -54,7 +53,7 @@ func HostOS(exec cmdexec.Executor) { // To get the Host IP address func HostIP(exec cmdexec.Executor) (string, error) { zap.S().Debug("Fetching HostIP") - host, err := exec.RunWithStdout("bash", "-c", fmt.Sprintf("hostname -I")) + host, err := exec.RunWithStdout("bash", "-c", "hostname -I") if err != nil { zap.S().Error("Host IP Not found", err) return host, ErrHostIP @@ -79,38 +78,38 @@ func SupportBundleUpload(ctx objects.Config, allClients client.Client, isRemote } // To get the HostIP - hostIP, err := HostIP(allClients.Executor) - if err != nil { - zap.S().Debug("Unable to fetch Host IP") - } + // hostIP, err := HostIP(allClients.Executor) + // if err != nil { + // zap.S().Debug("Unable to fetch Host IP") + // } //To remove extra spaces and lines after the IP - hostIP = strings.TrimSpace(strings.Trim(hostIP, "\n")) + // hostIP = strings.TrimSpace(strings.Trim(hostIP, "\n")) // Fetch the keystone token. // This is used as a reference to the segment event. - auth, err := allClients.Keystone.GetAuth( - ctx.Username, - ctx.Password, - ctx.Tenant, - ctx.MfaToken, - ) - if err != nil { - zap.S().Debug("Unable to locate keystone credentials: %s\n", err.Error()) - return fmt.Errorf("Unable to locate keystone credentials: %s\n", err.Error()) - } + // auth, err := allClients.Keystone.GetAuth( + // ctx.Username, + // ctx.Password, + // ctx.Tenant, + // ctx.MfaToken, + // ) + // if err != nil { + // zap.S().Debug("Unable to locate keystone credentials: %s\n", err.Error()) + // return fmt.Errorf("Unable to locate keystone credentials: %s\n", err.Error()) + // } // To Fetch FQDN - FQDN, err := keystone.FetchRegionFQDN(ctx.Fqdn, ctx.Region, auth) - if err != nil { - zap.S().Debug("unable to fetch fqdn: %w") - return fmt.Errorf("unable to fetch fqdn: %w", err) - } + // FQDN, err := keystone.FetchRegionFQDN(ctx.Fqdn, ctx.Region, auth) + // if err != nil { + // zap.S().Debug("unable to fetch fqdn: %w") + // return fmt.Errorf("unable to fetch fqdn: %w", err) + // } //To fetch FQDN from config if region given is invalid - if FQDN == "" { - FQDN = ctx.Fqdn - FQDN = strings.Replace(FQDN, "https://", "", 1) - } + // if FQDN == "" { + // FQDN = ctx.Fqdn + // FQDN = strings.Replace(FQDN, "https://", "", 1) + // } // Commenting out the auto upload of the support bundle in favour of #incident351 @@ -217,7 +216,7 @@ func GenSupportBundle(exec cmdexec.Executor, timestamp time.Time, isRemote bool) statPaths(exec, util.DmesgLog, msgfile, lockfile) // To fetch the hostname of remote node - hostname, err := exec.RunWithStdout("bash", "-c", fmt.Sprintf("hostname")) + hostname, err := exec.RunWithStdout("bash", "-c", "hostname") if err != nil { zap.S().Debug("Failed to fetch hostname ", err) } From 1d7603eefc3341c2d2bdbae02efd40121650065d Mon Sep 17 00:00:00 2001 From: joshivedant84 Date: Mon, 22 Jul 2024 03:47:01 +0000 Subject: [PATCH 3/5] Remove support bundle upload to s3 --- pkg/supportBundle/supportBundle.go | 66 +----------------------------- 1 file changed, 2 insertions(+), 64 deletions(-) diff --git a/pkg/supportBundle/supportBundle.go b/pkg/supportBundle/supportBundle.go index 3305cd8..b2b6b95 100644 --- a/pkg/supportBundle/supportBundle.go +++ b/pkg/supportBundle/supportBundle.go @@ -63,10 +63,10 @@ func HostIP(exec cmdexec.Executor) (string, error) { return host, nil } -// To upload pf9ctl log bundle to S3 bucket +// Generate support bundle and not upload func SupportBundleUpload(ctx objects.Config, allClients client.Client, isRemote bool) error { - zap.S().Debugf("Received a call to upload pf9ctl supportBundle to %s bucket.\n", S3_BUCKET_NAME) + zap.S().Debugf("Received a call to generate pf9ctl supportBundle\n") HostOS(allClients.Executor) fileloc, err = GenSupportBundle(allClients.Executor, Timestamp, isRemote) if err != nil && err != ErrPartialBundle { @@ -77,68 +77,6 @@ func SupportBundleUpload(ctx objects.Config, allClients client.Client, isRemote zap.S().Debugf(color.Red("x ")+"Failed to generate supportBundle\n", err.Error()) } - // To get the HostIP - // hostIP, err := HostIP(allClients.Executor) - // if err != nil { - // zap.S().Debug("Unable to fetch Host IP") - // } - - //To remove extra spaces and lines after the IP - // hostIP = strings.TrimSpace(strings.Trim(hostIP, "\n")) - - // Fetch the keystone token. - // This is used as a reference to the segment event. - // auth, err := allClients.Keystone.GetAuth( - // ctx.Username, - // ctx.Password, - // ctx.Tenant, - // ctx.MfaToken, - // ) - // if err != nil { - // zap.S().Debug("Unable to locate keystone credentials: %s\n", err.Error()) - // return fmt.Errorf("Unable to locate keystone credentials: %s\n", err.Error()) - // } - - // To Fetch FQDN - // FQDN, err := keystone.FetchRegionFQDN(ctx.Fqdn, ctx.Region, auth) - // if err != nil { - // zap.S().Debug("unable to fetch fqdn: %w") - // return fmt.Errorf("unable to fetch fqdn: %w", err) - // } - //To fetch FQDN from config if region given is invalid - // if FQDN == "" { - // FQDN = ctx.Fqdn - // FQDN = strings.Replace(FQDN, "https://", "", 1) - // } - - // Commenting out the auto upload of the support bundle in favour of #incident351 - - // S3 location to upload the file - // S3_Location = S3_Loc + "/" + FQDN + "/" + hostIP + "/" - - // To upload the pf9cli log bundle to S3 bucket - // errUpload := S3Upload(allClients.Executor) - // if errUpload != nil { - // zap.S().Debugf("Failed to upload pf9ctl supportBundle to %s bucket!! ", S3_BUCKET_NAME, errUpload) - - // if err := allClients.Segment.SendEvent("supportBundle upload Failed", auth, "Failed", ""); err != nil { - // zap.S().Debugf("Unable to send Segment event for supportBundle. Error: %s", err.Error()) - // } - - // } else { - // zap.S().Debugf("Succesfully uploaded pf9ctl supportBundle to %s bucket at %s location \n", - // S3_BUCKET_NAME, S3_Location) - // if err := allClients.Segment.SendEvent("supportBundle upload Success", auth, "Success", ""); err != nil { - // zap.S().Debugf("Unable to send Segment event for supportBundle. Error: %s", err.Error()) - // } - // } - - // Remove the supportbundle after uploading to S3 - // errremove := RemoveBundle(allClients.Executor) - // if errremove != nil { - // zap.S().Debug("Error removing generated bundle", errremove) - // } - return nil } From 940fa562d22980ab9da4f2a17d27b4d7236a38ad Mon Sep 17 00:00:00 2001 From: joshivedant84 Date: Mon, 22 Jul 2024 23:51:15 +0000 Subject: [PATCH 4/5] Remove the s3 upload unit test --- cmd/supportBundle_test.go | 62 ++++----------------------------------- 1 file changed, 5 insertions(+), 57 deletions(-) diff --git a/cmd/supportBundle_test.go b/cmd/supportBundle_test.go index 67616b3..16456b8 100644 --- a/cmd/supportBundle_test.go +++ b/cmd/supportBundle_test.go @@ -12,13 +12,13 @@ import ( "github.com/platform9/pf9ctl/pkg/test_utils" ) -//Errors returned by the functions +// Errors returned by the functions var ErrHostIP = errors.New("Host IP not found") var ErrRemove = errors.New("Unable to remove bundle") var ErrUpload = errors.New("Unable to upload supportBundle to S3") var ErrPartialBundle = errors.New("Failed to generate complete supportBundle, generated partial bundle") -//HostIP test case +// HostIP test case func TestHostIP(t *testing.T) { type want struct { host string @@ -71,7 +71,7 @@ func TestHostIP(t *testing.T) { } -//GenSupportBundle test case(Only for Local Host) +// GenSupportBundle test case(Only for Local Host) func TestGenSupportBundle(t *testing.T) { //isRemote := false @@ -132,7 +132,7 @@ func TestGenSupportBundle(t *testing.T) { } -//GenTargetFilename test case +// GenTargetFilename test case func TestGenTargetFilename(t *testing.T) { type want struct { @@ -169,59 +169,7 @@ func TestGenTargetFilename(t *testing.T) { } -//S3Upload test case -func TestS3Upload(t *testing.T) { - type want struct { - err error - } - - type args struct { - exec cmdexec.Executor - } - - cases := map[string]struct { - args - want - }{ - //Success case.The S3Upload function returns nil error on successful execution - "CheckPass": { - args: args{ - exec: &cmdexec.MockExecutor{ - MockRun: func(name string, args ...string) error { - return nil - }, - }, - }, - want: want{ - err: nil, - }, - }, - //Failure case.The S3Upload function returns ErrUpload error on execution - "CheckFail": { - args: args{ - exec: &cmdexec.MockExecutor{ - MockRun: func(name string, args ...string) error { - return ErrUpload - }, - }, - }, - want: want{ - err: ErrUpload, - }, - }, - } - - for name, tc := range cases { - t.Run(name, func(t *testing.T) { - - err1 := supportBundle.S3Upload(tc.exec) - test_utils.Equals(t, tc.want.err, err1) - }) - } - -} - -//RemoveBundle test case +// RemoveBundle test case func TestRemoveBundle(t *testing.T) { type want struct { err error From dc9ef1b72c62855a223d556d7cf404d208e4571a Mon Sep 17 00:00:00 2001 From: joshivedant84 Date: Tue, 23 Jul 2024 00:01:40 +0000 Subject: [PATCH 5/5] Remove some unused vars --- cmd/supportBundle_test.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/cmd/supportBundle_test.go b/cmd/supportBundle_test.go index 16456b8..b4d442c 100644 --- a/cmd/supportBundle_test.go +++ b/cmd/supportBundle_test.go @@ -13,16 +13,16 @@ import ( ) // Errors returned by the functions -var ErrHostIP = errors.New("Host IP not found") -var ErrRemove = errors.New("Unable to remove bundle") -var ErrUpload = errors.New("Unable to upload supportBundle to S3") -var ErrPartialBundle = errors.New("Failed to generate complete supportBundle, generated partial bundle") +var ErrHostIP = errors.New("host IP not found") +var ErrRemove = errors.New("unable to remove bundle") +var ErrUpload = errors.New("unable to upload supportBundle to S3") +var ErrPartialBundle = errors.New("failed to generate complete supportBundle, generated partial bundle") // HostIP test case func TestHostIP(t *testing.T) { type want struct { - host string - err error + // host string + err error } type args struct { @@ -78,14 +78,14 @@ func TestGenSupportBundle(t *testing.T) { timestamp := time.Now() type want struct { - targetfile string - err error + // targetfile string + err error } type args struct { - exec cmdexec.Executor - timestamp time.Time - isRemote bool + exec cmdexec.Executor + // timestamp time.Time + // isRemote bool } cases := map[string]struct {