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

add checklist for v5 for opensearch and postgres #8706

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
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
Loading