Skip to content
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

Add support for cli and json styled SR Linux configs #343

Merged
merged 17 commits into from
Apr 4, 2023

Conversation

n0shut
Copy link
Contributor

@n0shut n0shut commented Mar 28, 2023

This is a matching PR to support CLI and JSON-styled configs for SR Linux srl-labs/srl-controller#37

The idea is that KNE calculates how the config file should be named (config.cli or config.json) based on the extension provided to the startup config file.

Then srl-controller loads the appropriate startup config file.

Changes to resetter

Resetter now resets to startup config if it was provided, or to a default config (factory) if no startup config was provided (see inline comments)

Changes to ConfigPush

Config push now works with CLI snippets expressed both in set / flat syntax as well as multiline CLI-styled blobs.

Changes to examples

I have thus removed the JSON config example and used CLI format hereafter.

@coveralls
Copy link

coveralls commented Mar 29, 2023

Pull Request Test Coverage Report for Build 4612322046

  • 32 of 42 (76.19%) changed or added relevant lines in 1 file are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.03%) to 64.229%

Changes Missing Coverage Covered Lines Changed/Added Lines %
topo/node/srl/srl.go 32 42 76.19%
Files with Coverage Reduction New Missed Lines %
topo/node/srl/srl.go 2 54.68%
Totals Coverage Status
Change from base Build 4578300478: 0.03%
Covered Lines: 3144
Relevant Lines: 4895

💛 - Coveralls

@n0shut n0shut changed the title Add support for cli and json styled configs Add support for cli and json styled SR Linux configs Mar 29, 2023
@n0shut n0shut marked this pull request as ready for review March 30, 2023 10:04
@n0shut n0shut marked this pull request as draft March 30, 2023 10:18
Comment on lines -28 to +32
configResetCmd = "load factory auto-commit"
// srl-controller v0.6.0+ creates a named checkpoint "initial" on node startup
// configuration reset is therefore done by reverting to this checkpoint
configResetCmd = "/tools system configuration checkpoint initial revert"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resetting is now done by reverting to a checkpoint named initial.
This checkpoint is created by srl-controller:v0.6.0+ and will capture the config state of a node once it has booted and applied startup config (if present)

Comment on lines 241 to 247
err := n.ControllerClient.Delete(ctx, &srlinuxv1.Srlinux{ObjectMeta: metav1.ObjectMeta{Name: n.Name()}})
err := n.ControllerClient.Delete(ctx, &srlinuxv1.Srlinux{
ObjectMeta: metav1.ObjectMeta{
Namespace: n.GetNamespace(), Name: n.Name()}},
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Namespace info was missing before in a call to Delete

Comment on lines +293 to 333
// SR Linux default name for config file is either config.json or config.cli.
// This depends on the extension of the provided startup-config file.
if pb.Config.ConfigFile == "" {
pb.Config.ConfigFile = "config.json"
ext := filepath.Ext(pb.Config.GetFile())
if ext != ".json" {
ext = ".cli"
}

pb.Config.ConfigFile = "config" + ext
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default file name used to contain startup-config lines is derived from the file extension provided by a user in the topo.
This is done to let srl-controller know what format the config is provided with.

}
services:{
key: 22
value: {
name: "ssh"
inside: 22
outside: 22
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

outside ports were removed, as keys already convey this info

@n0shut n0shut marked this pull request as ready for review March 30, 2023 11:43
@alexmasi alexmasi requested a review from bormanp March 30, 2023 17:14
@alexmasi
Copy link
Contributor

I took a quick glance, the behavior is exactly what we would want to support (cli or json), simplified cfgs, reset to initial cfg commit.

Can you update the examples/multivendor/. topo + cfg as well as cloudbuild/vendors/. topo + cfg to match the new simplified cfgs?

Assigning to Paul to do an actual code review here

@n0shut n0shut force-pushed the srl-cli-startup-cfg branch from 6a599fe to 5804601 Compare March 30, 2023 19:40
@n0shut
Copy link
Contributor Author

n0shut commented Mar 30, 2023

Thanks @alexmasi
added CLI-styled configs for cloudbuild and multivendor

// srl-controller v0.6.0+ creates a named checkpoint "initial" on node startup
// configuration reset is therefore done by reverting to this checkpoint
configResetCmd = "/tools system configuration checkpoint initial revert"
pushCfgFile = "/home/admin/kne-push-config"
Copy link
Contributor

@hellt hellt Mar 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

configpush functionality now undergoes the following steps:

  1. config from a file is read into a string, and all double quotes are escaped
  2. the escaped config is then transferred to the srlinux node using pty transport opened with scrapligo over kubectl exec.
  3. the transfer happens via echo "<config lines>" > pushCfgFile command.
  4. then a candidate is opened and pushed config is sourced via source pushCfgFile
  5. It is then committed and persisted.

Comment on lines +13 to +14
A:pod1# file cat /etc/opt/srlinux/devices/app_ephemeral.mgmt_server.ready_for_config
loaded initial configuration
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in srlinux-scrapli package v0.6.0 we improved the way to check when the NOS is ready to accept configs. This is the new way

bormanp
bormanp previously approved these changes Mar 31, 2023
Copy link
Collaborator

@bormanp bormanp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Go changes are simply nits


log.V(1).Infof("config to push:\n%s", cfgs)
log.V(1).Infof("config to push:\n%s", cfg)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't these lines be after the check for err?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @bormanp
done in 4cb5267

err := n.ControllerClient.Delete(ctx, &srlinuxv1.Srlinux{
ObjectMeta: metav1.ObjectMeta{
Namespace: n.GetNamespace(), Name: n.Name()}},
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When breaking up the line you should match the {}'s.

        err := n.ControllerClient.Delete(ctx, &srlinuxv1.Srlinux{
                ObjectMeta: metav1.ObjectMeta{
                        Namespace: n.GetNamespace(), Name: n.Name(),
                },
        })

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks
Done in 9a561cd

@alexmasi
Copy link
Contributor

alexmasi commented Apr 3, 2023

Looks like one of those commits caused the go test to fail

@hellt
Copy link
Contributor

hellt commented Apr 3, 2023

@alexmasi it is a wild west in go test output there, I couldn't find which test was failing, I saw that some cluster tests failed, so maybe try to rerun to exclude flakiness?

@hellt
Copy link
Contributor

hellt commented Apr 3, 2023

@alexmasi looks like some metallb tests failed -- https://github.com/openconfig/kne/actions/runs/4582237788/jobs/8092328043?pr=343#step:4:643
I don't think this PR is related to it

@alexmasi
Copy link
Contributor

alexmasi commented Apr 4, 2023

I have no clue how that test could have failed, the context gets cancelled as expected. Anyway rerunning now to confirm its a flake. This PR doesn't directly modify that code so I'm even more confused, we haven't seen a flake like that before

@alexmasi
Copy link
Contributor

alexmasi commented Apr 4, 2023

/gcbrun

alexmasi
alexmasi previously approved these changes Apr 4, 2023
Copy link
Contributor

@alexmasi alexmasi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

carrying over borman's approval that was dismissed, assuming the presubmit passes I will merge

sorry for the hassle here

@alexmasi
Copy link
Contributor

alexmasi commented Apr 4, 2023

/gcbrun

@alexmasi alexmasi merged commit 97ecf79 into openconfig:main Apr 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants