-
Notifications
You must be signed in to change notification settings - Fork 492
Add partial config file functionality to cEOS #3103
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
43f179d
8ba5abd
d52954c
2a83aa7
5bcf9b7
bdffc96
c95f445
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 |
|---|---|---|
|
|
@@ -34,5 +34,6 @@ management api http-commands | |
| vrf {{ .Env.CLAB_MGMT_VRF }} | ||
| no shutdown | ||
| {{end}} | ||
| {{ .PartialCfg }} | ||
| ! | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| package ceos | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "context" | ||
| _ "embed" | ||
| "encoding/json" | ||
|
|
@@ -16,6 +17,7 @@ import ( | |
| "path/filepath" | ||
| "regexp" | ||
| "strings" | ||
| "text/template" | ||
|
|
||
| "github.com/charmbracelet/log" | ||
| clabconstants "github.com/srl-labs/containerlab/constants" | ||
|
|
@@ -81,6 +83,7 @@ func Register(r *clabnodes.NodeRegistry) { | |
|
|
||
| type ceos struct { | ||
| clabnodes.DefaultNode | ||
| partialStartupCfg string | ||
| } | ||
|
|
||
| // intfMap represents interface mapping config file. | ||
|
|
@@ -217,7 +220,12 @@ func (n *ceos) createCEOSFiles(ctx context.Context) error { | |
| if err != nil { | ||
| return err | ||
| } | ||
| currentCfgTemplate = string(c) | ||
|
|
||
| if clabutils.IsPartialConfigFile(nodeCfg.StartupConfig) { | ||
| n.partialStartupCfg = string(c) | ||
| } else { | ||
| currentCfgTemplate = string(c) | ||
| } | ||
| } | ||
|
|
||
| err = n.GenerateConfig(nodeCfg.ResStartupConfig, currentCfgTemplate) | ||
|
|
@@ -402,3 +410,28 @@ func (n *ceos) CheckInterfaceName() error { | |
|
|
||
| return nil | ||
| } | ||
|
|
||
| type ceosTemplateData struct { | ||
|
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. According to a quick AI review for this PR new nodes/ceos/ceos.go logic no longer honors suppress-startup-config and enforce-startup-config. I was not checking the code in detail, but installed the Containerlab from you branch and tested following:
This is breaking and must be fixed. |
||
| *clabtypes.NodeConfig | ||
| PartialCfg string | ||
| } | ||
|
|
||
| func (n *ceos) GenerateConfig(dst, t string) error { | ||
| data := ceosTemplateData{ | ||
| NodeConfig: n.Cfg, | ||
| PartialCfg: n.partialStartupCfg, | ||
| } | ||
|
|
||
| ceosCfgTpl, err := template.New("ceos-config").Funcs(clabutils.CreateFuncs()).Parse(t) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to parse ceos cfg template for node %q: %w", n.Cfg.ShortName, err) | ||
| } | ||
|
|
||
| buf := new(bytes.Buffer) | ||
| err = ceosCfgTpl.Execute(buf, data) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to execute ceos cfg template for node %q: %w", n.Cfg.ShortName, err) | ||
| } | ||
|
|
||
| return clabutils.CreateFile(dst, buf.String()) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| *** Settings *** | ||
|
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. Thank you for adding the test.
Thank you! |
||
| Library OperatingSystem | ||
| Resource ../common.robot | ||
| Resource ../ssh.robot | ||
|
|
||
| Suite Teardown Run Keyword Cleanup | ||
|
|
||
|
|
||
| *** Variables *** | ||
| ${lab-name} ceos-partial-test | ||
| ${lab-file-name} partial-clab.yml | ||
| ${runtime} docker | ||
|
|
||
|
|
||
| *** Test Cases *** | ||
| Deploy ${lab-name} lab | ||
| Log ${CURDIR} | ||
| ${rc} ${output} = Run And Return Rc And Output | ||
| ... ${CLAB_BIN} deploy -t ${CURDIR}/${lab-file-name} | ||
| Log ${output} | ||
| Should Be Equal As Integers ${rc} 0 | ||
|
|
||
| Verify default configuration on ceos1 | ||
| ${f} = OperatingSystem.Get File ${CURDIR}/clab-${lab-name}/ceos1/flash/startup-config | ||
| Log ${f} | ||
| Should Contain ${f} hostname ceos1 | ||
| Should Contain ${f} username admin | ||
| Should Contain ${f} management api gnmi | ||
|
|
||
| Verify partial startup configuration on ceos2 | ||
| ${f} = OperatingSystem.Get File ${CURDIR}/clab-${lab-name}/ceos2/flash/startup-config | ||
| Log ${f} | ||
| Should Contain ${f} hostname ceos2 | ||
| Should Contain ${f} username admin | ||
| Should Contain ${f} management api gnmi | ||
| Should Contain ${f} description PARTIAL_CONFIG_TEST | ||
| Should Contain ${f} interface Ethernet1 | ||
|
|
||
| Verify full startup configuration on ceos3 | ||
| ${f} = OperatingSystem.Get File ${CURDIR}/clab-${lab-name}/ceos3/flash/startup-config | ||
| Log ${f} | ||
| Should Contain ${f} hostname ceos3-full | ||
| Should Not Contain ${f} management api gnmi | ||
|
|
||
| Destroy ${lab-name} lab | ||
| Log ${CURDIR} | ||
| ${rc} ${output} = Run And Return Rc And Output | ||
| ... ${CLAB_BIN} --runtime ${runtime} destroy -t ${CURDIR}/${lab-file-name} | ||
| Log ${output} | ||
| Should Be Equal As Integers ${rc} 0 | ||
|
|
||
|
|
||
| *** Keywords *** | ||
| Cleanup | ||
| Run ${CLAB_BIN} destroy -t ${CURDIR}/${lab-file-name} --cleanup | ||
| Run rm -rf ${CURDIR}/clab-${lab-name} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| hostname {{ .ShortName }}-full | ||
| ! |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| interface Ethernet1 | ||
| description PARTIAL_CONFIG_TEST | ||
| no shutdown | ||
| ! |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| name: ceos-partial-test | ||
|
|
||
| topology: | ||
| kinds: | ||
| arista_ceos: | ||
| image: ceos:4.32.0F | ||
| nodes: | ||
| ceos1: | ||
| kind: arista_ceos | ||
| ceos2: | ||
| kind: arista_ceos | ||
| startup-config: ./interface.partial.cfg | ||
| ceos3: | ||
| kind: arista_ceos | ||
| startup-config: ./full_config.cfg | ||
|
|
||
| links: | ||
| - endpoints: ["ceos1:eth1", "ceos2:eth1"] | ||
| - endpoints: ["ceos2:eth1", "ceos3:eth1"] |
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.
AI remark, not tested in the lab:
Full configs still get Go template rendering, but no longer pass through SubstituteEnvsAndTemplate, so ${VAR} expansion regresses. Partial configs are inserted as .PartialCfg, so a partial file containing {{ .ShortName }} would be emitted literally instead of rendered.
Please add a test case for env expansion.