-
Notifications
You must be signed in to change notification settings - Fork 490
Run cEOS postdeploy through container runtime #3280
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,14 +8,14 @@ import ( | |
| "context" | ||
| _ "embed" | ||
| "encoding/json" | ||
| "errors" | ||
| "fmt" | ||
| "net" | ||
| "os" | ||
| "path" | ||
| "path/filepath" | ||
| "regexp" | ||
| "strings" | ||
| "time" | ||
|
|
||
| "github.com/charmbracelet/log" | ||
| clabconstants "github.com/srl-labs/containerlab/constants" | ||
|
|
@@ -57,6 +57,15 @@ var ( | |
|
|
||
| saveCmd = "Cli -p 15 -c wr" | ||
|
|
||
| ceosPostDeployExec = func( | ||
| n *ceos, | ||
| ctx context.Context, | ||
| execCmd *clabexec.ExecCmd, | ||
| ) (*clabexec.ExecResult, error) { | ||
| return n.RunExec(ctx, execCmd) | ||
| } | ||
| ceosPostDeploySleep = time.Sleep | ||
|
|
||
| defaultCredentials = clabnodes.NewCredentials("admin", "admin") | ||
| ) | ||
|
|
||
|
|
@@ -347,16 +356,10 @@ func setMgmtInterface(node *clabtypes.NodeConfig) error { | |
| } | ||
|
|
||
| // ceosPostDeploy runs postdeploy actions which are required for ceos nodes. | ||
| func (n *ceos) ceosPostDeploy(_ context.Context) error { | ||
| func (n *ceos) ceosPostDeploy(ctx context.Context) error { | ||
| nodeCfg := n.Config() | ||
| d, err := clabutils.SpawnCLIviaExec("arista_eos", nodeCfg.LongName, n.Runtime.GetName()) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| defer d.Close() | ||
|
|
||
| cfgs := []string{ | ||
| "configure terminal", | ||
| "interface " + nodeCfg.MgmtIntf, | ||
| "no ip address", | ||
| "no ipv6 address", | ||
|
|
@@ -410,18 +413,40 @@ func (n *ceos) ceosPostDeploy(_ context.Context) error { | |
| } | ||
|
|
||
| // add save to startup cmd | ||
| cfgs = append(cfgs, "wr") | ||
| cfgs = append(cfgs, "end", "write memory") | ||
|
|
||
| log.Debugf("cEOS PostDeploy configuration for node %s: %v", n.Cfg.ShortName, cfgs) | ||
|
|
||
| resp, err := d.SendConfigs(cfgs) | ||
| if err != nil { | ||
| return err | ||
| } else if resp.Failed != nil { | ||
| return errors.New("failed CLI configuration") | ||
| var lastErr error | ||
| var lastResp *clabexec.ExecResult | ||
| cliCmd := "Cli -p 15 --abort-on-error -c $'" + strings.Join(cfgs, "\n") + "'" | ||
|
|
||
| for range 60 { | ||
| execCmd := clabexec.NewExecCmdFromSlice([]string{"/bin/bash", "-lc", cliCmd}) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we really involve bash here? Is there a specific use case for that? Is direct Cli call an option? clabexec.NewExecCmdFromSlice([]string{
"Cli",
"-p", "15",
"--abort-on-error",
"-c", strings.Join(cfgs, "\n"),
}) |
||
| resp, err := ceosPostDeployExec(n, ctx, execCmd) | ||
| if err == nil && resp.GetReturnCode() == 0 { | ||
| return nil | ||
| } | ||
|
|
||
| lastErr = err | ||
| lastResp = resp | ||
| log.Debugf("%s - Cli not ready (%v, %v) - waiting.", nodeCfg.LongName, err, resp) | ||
| ceosPostDeploySleep(2 * time.Second) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. have to test that in a live lab, but I suspect cancellation will not stop this loop. Please check and fix if it's the case. I'll run this fork in my lab during the final review. |
||
| } | ||
|
|
||
| return err | ||
| if lastErr != nil { | ||
| return lastErr | ||
| } | ||
| if lastResp != nil { | ||
| return fmt.Errorf( | ||
| "failed CLI configuration: rc=%d stdout=%q stderr=%q", | ||
| lastResp.GetReturnCode(), | ||
| lastResp.GetStdOutString(), | ||
| lastResp.GetStdErrString(), | ||
| ) | ||
| } | ||
|
|
||
| return fmt.Errorf("failed CLI configuration") | ||
| } | ||
|
|
||
| // CheckInterfaceName checks if a name of the interface referenced in the topology file correct. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If understand this correctly, this simply throws the whatever post deploy command at cEOS 60 times without any possibility to detect syntax errors, unsupported commands, etc. While I'd expect this line to be healthy in general and not have all of that, can we consider an alternative approach?