-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add checklist for v5 for opensearch and postgres
Signed-off-by: Sahiba3108 <[email protected]>
- Loading branch information
1 parent
aa19964
commit f5d5ca3
Showing
25 changed files
with
2,263 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
components/automate-deployment/pkg/inspector/upgradeinspectorv5/disablesharding.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
47 changes: 47 additions & 0 deletions
47
components/automate-deployment/pkg/inspector/upgradeinspectorv5/disablesharding_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
Oops, something went wrong.