保存不确定部署处置重新核查实现及测试检查点
This commit is contained in:
1 parent
7fa5e9b3d2
commit
f9cd19f631
29 files changed
+907
-49
No files matched your search
@@ -60,7 +60,7 @@ func runConnected(ctx context.Context, conn net.Conn, screen terminal) error {
|
||||
if client.RecoveryAvailable() {
|
||||
prompt := "本机管理:1 重置超级管理员密码;2 只读核查部署事务;其他输入退出"
|
||||
if client.DispositionAvailable() {
|
||||
prompt = "本机管理:1 重置超级管理员密码;2 只读核查部署事务;3 人工处置部署事务;4 查询人工处置结果;其他输入退出"
|
||||
prompt = "本机管理:1 重置超级管理员密码;2 只读核查部署事务;3 人工处置部署事务;4 查询人工处置结果;5 重新核查不确定处置;其他输入退出"
|
||||
}
|
||||
choice, err := screen.Read(ctx, prompt, false)
|
||||
if err != nil {
|
||||
@@ -74,13 +74,16 @@ func runConnected(ctx context.Context, conn net.Conn, screen terminal) error {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
case "3", "4":
|
||||
case "3", "4", "5":
|
||||
if !client.DispositionAvailable() {
|
||||
return localreset.ErrUnavailable
|
||||
}
|
||||
if strings.TrimSpace(choice) == "4" {
|
||||
return recoveryResultFlow(ctx, client, screen)
|
||||
}
|
||||
if strings.TrimSpace(choice) == "5" {
|
||||
return recoveryReconciliationFlow(ctx, client, screen)
|
||||
}
|
||||
return recoveryDispositionFlow(ctx, client, screen)
|
||||
default:
|
||||
return nil
|
||||
|
||||
@@ -130,12 +130,22 @@ func showRecoveryDisposition(screen terminal, result deployment.RecoveryDisposit
|
||||
message = "本次人工提交核验及结束审计完成;不代表项目全部生产验收通过。"
|
||||
case deployment.RecoveryActionRollback:
|
||||
message = "本次恢复基线核验及结束审计完成;不代表项目全部生产验收通过。"
|
||||
case deployment.RecoveryActionVerifyCommit, deployment.RecoveryActionVerifyRollback:
|
||||
message = "重新核查与新审计已完成,占用已安全释放;原不确定处置历史保留,本次未重放远端动作。"
|
||||
}
|
||||
case "rejected":
|
||||
message = "处置已拒绝,未执行本次远端变更;请重新核查拒绝原因。"
|
||||
if result.SourceDispositionID != "" {
|
||||
message = "重新核查未通过,原占用继续保留;本次未执行远端变更,不得手动删锁或重放原动作。"
|
||||
}
|
||||
case "uncertain":
|
||||
message = "处置结果不确定,可能已修改远端;占用继续保留,禁止重复执行或手动删锁。"
|
||||
}
|
||||
if result.SourceDispositionID != "" {
|
||||
if err := screen.Show("关联原处置:" + terminalValue(result.SourceDispositionID)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := screen.Show(fmt.Sprintf("处置:%s;事务:%s;服务器:%s;动作:%s", terminalValue(result.ID), terminalValue(result.TransactionID), terminalValue(result.ServerID), dispositionActionLabel(result.Action))); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -150,6 +160,10 @@ func dispositionActionLabel(action deployment.RecoveryAction) string {
|
||||
return "完成提交"
|
||||
case deployment.RecoveryActionRollback:
|
||||
return "恢复基线"
|
||||
case deployment.RecoveryActionVerifyCommit:
|
||||
return "重新核查提交结果"
|
||||
case deployment.RecoveryActionVerifyRollback:
|
||||
return "重新核查回滚结果"
|
||||
}
|
||||
return "未知动作"
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package adminconsole
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.pcux.cn/xuans/Scert/backend/internal/localreset"
|
||||
)
|
||||
|
||||
type recoveryReconciliationClient interface {
|
||||
recoveryDispositionClient
|
||||
PrepareRecoveryReconciliation(string) (localreset.RecoveryPreparation, error)
|
||||
}
|
||||
|
||||
func recoveryReconciliationFlow(ctx context.Context, client recoveryReconciliationClient, screen terminal) error {
|
||||
sourceID, err := screen.Read(ctx, "请输入结果不确定的原处置编号;本操作只重新核验,不重放文件修改或服务重载", false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sourceID = strings.TrimSpace(sourceID)
|
||||
if err := ctx.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
prepared, err := client.PrepareRecoveryReconciliation(sourceID)
|
||||
if err != nil {
|
||||
_ = screen.Show("无法准备重新核查:主服务可能尚未支持,或原处置未结束、历史证据不足、现场不满足收尾条件。占用仍保留。")
|
||||
return err
|
||||
}
|
||||
defer func() { prepared.Token = "" }()
|
||||
summary := prepared.Summary
|
||||
if summary.Validate() != nil || summary.SourceDispositionID != sourceID || !time.Now().Before(summary.ExpiresAt) {
|
||||
return localreset.ErrProtocol
|
||||
}
|
||||
for _, line := range []string{
|
||||
"原处置:" + terminalValue(sourceID),
|
||||
"新核查编号:" + terminalValue(prepared.DispositionID) + "(请保留,用于断连后查询)",
|
||||
fmt.Sprintf("事务:%s;服务器:%s;动作:%s", terminalValue(summary.TransactionID), terminalValue(summary.ServerID), dispositionActionLabel(summary.Action)),
|
||||
"本次只核验原方向,不能改选提交或回滚;不写远端文件、不删锁、不重载。文件、残留、严格 HTTPS 和关闭检查全部通过后,才以新审计结束原事务并释放占用。",
|
||||
"原不确定记录永久保留;任何核验或审计失败均不释放占用,运行中处置不会因等待超时被接管。",
|
||||
} {
|
||||
if err := screen.Show(line); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
expected := "确认重新核查 " + sourceID + " " + dispositionActionLabel(summary.Action)
|
||||
answer, err := screen.Read(ctx, "如确认,请完整输入:"+expected+";其他输入取消", false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if answer != expected || ctx.Err() != nil || !time.Now().Before(summary.ExpiresAt) {
|
||||
return screen.Show("已取消或确认过期,未提交重新核查。")
|
||||
}
|
||||
result, err := client.ExecuteRecovery(prepared.DispositionID, prepared.Token)
|
||||
prepared.Token = ""
|
||||
if err != nil || result.Validate() != nil || result.ID != prepared.DispositionID || result.SourceDispositionID != sourceID ||
|
||||
result.TransactionID != summary.TransactionID || result.ServerID != summary.ServerID || result.Action != summary.Action {
|
||||
_ = screen.Show("未取得可靠结果,请重新连接后按新核查编号查询;不要重复执行或直接删除占用。")
|
||||
return localreset.ErrUnavailable
|
||||
}
|
||||
return showRecoveryDisposition(screen, result)
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package adminconsole
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.pcux.cn/xuans/Scert/backend/internal/deployment"
|
||||
"git.pcux.cn/xuans/Scert/backend/internal/localreset"
|
||||
)
|
||||
|
||||
type reconciliationConsoleClient struct {
|
||||
dispositionConsoleClient
|
||||
sourceID string
|
||||
mismatch bool
|
||||
}
|
||||
|
||||
func (c *reconciliationConsoleClient) PrepareRecoveryReconciliation(sourceID string) (localreset.RecoveryPreparation, error) {
|
||||
c.sourceID = sourceID
|
||||
value, err := c.PrepareRecovery("tx-1", deployment.RecoveryActionVerifyCommit)
|
||||
value.Summary.SourceDispositionID = sourceID
|
||||
value.Summary.Phase = deployment.TransactionPhaseCommitVerified
|
||||
return value, err
|
||||
}
|
||||
func (c *reconciliationConsoleClient) ExecuteRecovery(id, token string) (deployment.RecoveryDispositionSummary, error) {
|
||||
value, err := c.dispositionConsoleClient.ExecuteRecovery(id, token)
|
||||
if err != nil { return value, err }
|
||||
value.SourceDispositionID = c.sourceID
|
||||
if value.Status == "succeeded" { value.ResultCode = "committed" }
|
||||
if c.mismatch { value.SourceDispositionID = strings.Repeat("d", 64) }
|
||||
return value, nil
|
||||
}
|
||||
|
||||
func TestRecoveryReconciliationConsoleConfirmation(t *testing.T) {
|
||||
for _, mode := range []string{"success", "rejected", "cancelled", "expired", "disconnect", "mismatch"} {
|
||||
t.Run(mode, func(t *testing.T) {
|
||||
sourceID := strings.Repeat("a", 64)
|
||||
client := &reconciliationConsoleClient{}
|
||||
answer := "确认重新核查 " + sourceID + " " + dispositionActionLabel(deployment.RecoveryActionVerifyCommit)
|
||||
switch mode {
|
||||
case "rejected": client.status = "rejected"
|
||||
case "cancelled": answer = "确认"
|
||||
case "expired": client.expired = true
|
||||
case "disconnect": client.executeError = true
|
||||
case "mismatch": client.mismatch = true
|
||||
}
|
||||
screen := &recoveryTestScreen{testTerminalInput: testTerminalInput{values: []string{sourceID, answer}}}
|
||||
err := recoveryReconciliationFlow(t.Context(), client, screen)
|
||||
output := strings.Join(screen.lines, "|")
|
||||
if client.prepares != 1 || client.queries != 0 || strings.Contains(output, strings.Repeat("c", 64)) { t.Fatal("终端重复调用或泄露令牌") }
|
||||
if mode == "cancelled" || mode == "expired" {
|
||||
if client.executes != 0 { t.Fatal("取消或过期仍执行核查") }
|
||||
return
|
||||
}
|
||||
if client.executes != 1 || !strings.Contains(output, "原不确定记录永久保留") { t.Fatal("缺少明确警告或重复执行") }
|
||||
if mode == "disconnect" || mode == "mismatch" {
|
||||
if err == nil || !strings.Contains(output, "新核查编号查询") { t.Fatal("失去可靠响应后误报成功") }
|
||||
} else if err != nil { t.Fatal(err) }
|
||||
if mode == "success" && !strings.Contains(output, "占用已安全释放") { t.Fatal("缺少完成结果") }
|
||||
if mode == "rejected" && !strings.Contains(output, "原占用继续保留") { t.Fatal("错误显示拒绝结果") }
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user