Skip to content
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
24 changes: 22 additions & 2 deletions pkg/agent/clsp/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"fmt"
"os"
"os/exec"

agentapi "go.githedgehog.com/fabric/api/agent/v1beta1"
"go.githedgehog.com/fabric/pkg/agent/dozer"
Expand All @@ -33,9 +34,16 @@ func (c *CelesticaPlusProcessor) Reinstall(ctx context.Context) error {
return bcm.Processor().Reinstall(ctx) //nolint:wrapcheck
}

// TODO
func (c *CelesticaPlusProcessor) FactoryReset(ctx context.Context) error {
return fmt.Errorf("not implemented") //nolint:err113
cmd := exec.CommandContext(ctx, "sonic-cli", "-c", "\"write erase\"")
Comment thread
edipascale marked this conversation as resolved.
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

if err := cmd.Run(); err != nil {
return fmt.Errorf("failed to reset config: %w", err)
}

return c.Reboot(ctx, true)
}

// TODO
Expand Down Expand Up @@ -109,3 +117,15 @@ func (c *CelesticaPlusProcessor) ApplyActions(ctx context.Context, actions []doz
func (c *CelesticaPlusProcessor) CalculateActions(ctx context.Context, actual *dozer.Spec, desired *dozer.Spec) ([]dozer.Action, error) {
return nil, fmt.Errorf("unsupported operation") //nolint:err113
}

func (c *CelesticaPlusProcessor) SaveConfig(ctx context.Context) error {
cmd := exec.CommandContext(ctx, "sonic-cli", "-c", "\"copy running-config startup-config\"")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

if err := cmd.Run(); err != nil {
return fmt.Errorf("failed to save config: %w", err)
}

return nil
}
5 changes: 5 additions & 0 deletions pkg/agent/cmls/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,8 @@ func (c *CumulusProcessor) ApplyActions(ctx context.Context, actions []dozer.Act
func (c *CumulusProcessor) CalculateActions(ctx context.Context, actual *dozer.Spec, desired *dozer.Spec) ([]dozer.Action, error) {
return nil, fmt.Errorf("unsupported operation") //nolint:err113
}

// TODO
func (c *CumulusProcessor) SaveConfig(ctx context.Context) error {
return fmt.Errorf("unsupported operation") //nolint:err113
}
36 changes: 22 additions & 14 deletions pkg/agent/dozer/bcm/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,22 +154,22 @@ func (p *BroadcomProcessor) Reinstall(ctx context.Context) error {
return p.Reboot(ctx, true)
}

func (p *BroadcomProcessor) FactoryReset(_ context.Context) error {
// TODO use sonic-cli for it and then switch to GNOI
// write erase boot

// stdin, err := cmd.StdinPipe()
// if err != nil {
// log.Fatal(err)
// }
func (p *BroadcomProcessor) FactoryReset(ctx context.Context) error {
// "write erase boot" prompts for confirmation ("...continue? [y/N]:") and
// reads the answer from the controlling TTY, not stdin, so a plain stdin
// pipe is ignored and the command defaults to N. Wrap it in `script`, which
// allocates a pty; `script` forwards its own stdin into the pty, so feeding
// "y\n" here reaches the prompt.
cmd := exec.CommandContext(ctx, "script", "-qec", `sonic-cli -c "write erase boot"`, "/dev/null")
cmd.Stdin = strings.NewReader("y\n")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

// go func() {
// defer stdin.Close()
// // todo test it
// io.WriteString(stdin, "y\n")
// }()
if err := cmd.Run(); err != nil {
return fmt.Errorf("failed to reset config: %w", err)
}

return fmt.Errorf("not supported") //nolint:err113
return p.Reboot(ctx, true)
}

func (p *BroadcomProcessor) LoadActualState(ctx context.Context, agent *agentapi.Agent) (*dozer.Spec, error) {
Expand Down Expand Up @@ -413,3 +413,11 @@ func (p *BroadcomProcessor) SetRoCE(ctx context.Context, val bool) error {

return nil
}

func (p *BroadcomProcessor) SaveConfig(ctx context.Context) error {
cmd := exec.CommandContext(ctx, "sonic-cli", "-c", "\"write memory\"")
Comment thread
edipascale marked this conversation as resolved.
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

return errors.Wrap(cmd.Run(), "failed to save config")
}
1 change: 1 addition & 0 deletions pkg/agent/dozer/dozer.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Processor interface {
FactoryReset(ctx context.Context) error
GetRoCE(ctx context.Context) (bool, error)
SetRoCE(ctx context.Context, enable bool) error
SaveConfig(ctx context.Context) error
}

type Action interface {
Expand Down
Loading