Skip to content

Commit

Permalink
add checklist for v5 for opensearch and postgres
Browse files Browse the repository at this point in the history
Signed-off-by: Sahiba3108 <[email protected]>
  • Loading branch information
Sahiba3108 committed Dec 18, 2024
1 parent aa19964 commit f5d5ca3
Show file tree
Hide file tree
Showing 25 changed files with 2,263 additions and 0 deletions.
7 changes: 7 additions & 0 deletions components/automate-cli/cmd/chef-automate/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/chef/automate/components/automate-deployment/pkg/cli"
"github.com/chef/automate/components/automate-deployment/pkg/client"
"github.com/chef/automate/components/automate-deployment/pkg/inspector/upgradeinspectorv4"
"github.com/chef/automate/components/automate-deployment/pkg/inspector/upgradeinspectorv5"
"github.com/chef/automate/components/automate-deployment/pkg/majorupgradechecklist"
"github.com/chef/automate/components/automate-deployment/pkg/manifest"
"github.com/chef/automate/components/automate-deployment/pkg/toml"
Expand Down Expand Up @@ -224,6 +225,12 @@ func runUpgradeCmd(cmd *cobra.Command, args []string) error {
if isError {
return nil
}
case "5":
upgradeInspector := upgradeinspectorv5.NewUpgradeInspectorV5(writer, upgradeinspectorv5.NewUpgradeV5Utils(), &fileutils.FileSystemUtils{}, configCmdFlags.timeout)
isError := upgradeInspector.RunUpgradeInspector(upgradeRunCmdFlags.osDestDataDir, upgradeRunCmdFlags.skipStorageCheck)
if isError {
return nil
}
default:
return status.Errorf(status.UpgradeError, "invalid major version")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package upgradeinspectorv5

import (
"fmt"
"strings"

"github.com/chef/automate/components/automate-deployment/pkg/cli"
"github.com/chef/automate/components/automate-deployment/pkg/inspector"
"github.com/fatih/color"
"github.com/pkg/errors"
)

const (
OS_URL = "http://localhost:10144/_cluster/settings"
)

type DisableShardingInspection struct {
writer *cli.Writer
upgradeUtils UpgradeV5Utils
isExecuted bool
exitError error
exitedWithError bool
}

func NewDisableShardingInspection(w *cli.Writer, utls UpgradeV5Utils) *DisableShardingInspection {
return &DisableShardingInspection{
writer: w,
upgradeUtils: utls,
}
}

func (ds *DisableShardingInspection) ShowInfo(index *int) error {
return nil
}
func (ds *DisableShardingInspection) Skip() {
}
func (ds *DisableShardingInspection) GetShortInfo() []string {
return nil
}

func (ds *DisableShardingInspection) Inspect() (err error) {
disableShardingPayload := strings.NewReader(`{
"persistent": {
"cluster.routing.allocation.enable": "primaries"
}
}`)
_, err = ds.upgradeUtils.ExecRequest(OS_URL, "PUT", disableShardingPayload)
if err != nil {
err = errors.Wrap(err, "Failed to disable sharding")
ds.setExitError(err)
return err
}
ds.setExecuted()
return nil
}

func (ds *DisableShardingInspection) setExitError(err error) {
ds.exitError = err
ds.exitedWithError = true
}

func (ds *DisableShardingInspection) setExecuted() {
ds.isExecuted = true
}

func (ds *DisableShardingInspection) RollBackHandler() (err error) {
if !ds.isExecuted {
return nil
}
enableShardingPayload := strings.NewReader(`{
"persistent": {
"cluster.routing.allocation.enable": null
}
}`)
_, err = ds.upgradeUtils.ExecRequest(OS_URL, "PUT", enableShardingPayload)
if err != nil {
return errors.Wrap(err, "Failed to enable sharding")
}
return nil
}

func (ds *DisableShardingInspection) GetInstallationType() inspector.InstallationType {
return inspector.EMBEDDED
}

func (ds *DisableShardingInspection) ExitHandler() error {
if ds.exitedWithError {
ds.writer.Println(fmt.Errorf("["+color.New(color.FgRed).Sprint("Error")+"] %w", ds.exitError).Error())
}
return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package upgradeinspectorv5

import (
"errors"
"io"
"testing"

"github.com/chef/automate/lib/majorupgrade_utils"
"github.com/stretchr/testify/assert"
)

func TestDisableSharding(t *testing.T) {
tw := majorupgrade_utils.NewCustomWriter()
ds := NewDisableShardingInspection(tw.CliWriter, &MockUpgradeV5UtilsImp{
ExecRequestFunc: func(url, methodType string, requestBody io.Reader) ([]byte, error) {
return []byte{}, nil
},
})
err := ds.Inspect()
assert.NoError(t, err)
}

func TestDisableShardingError(t *testing.T) {
tw := majorupgrade_utils.NewCustomWriter()
ds := NewDisableShardingInspection(tw.CliWriter, &MockUpgradeV5UtilsImp{
ExecRequestFunc: func(url, methodType string, requestBody io.Reader) ([]byte, error) {
return nil, errors.New("Unreachable")
},
})
err := ds.Inspect()
assert.Error(t, err)
}

func TestDisableShardingErrorExitHandlerMessage(t *testing.T) {
tw := majorupgrade_utils.NewCustomWriter()
ds := NewDisableShardingInspection(tw.CliWriter, &MockUpgradeV5UtilsImp{
ExecRequestFunc: func(url, methodType string, requestBody io.Reader) ([]byte, error) {
return nil, errors.New("Unreachable")
},
})
err := ds.Inspect()
assert.Error(t, err)
err = ds.ExitHandler()
assert.NoError(t, err)
expected := `[Error] Failed to disable sharding: Unreachable`
assert.Contains(t, tw.Output(), expected)
}
Loading

0 comments on commit f5d5ca3

Please sign in to comment.