Skip to content

Commit

Permalink
Merge pull request #579 from srl-labs/srl-mounts
Browse files Browse the repository at this point in the history
directory based srlinux mounts
  • Loading branch information
hellt authored Aug 11, 2021
2 parents 869cda0 + 9f70a0e commit 2022cf0
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 23 deletions.
41 changes: 40 additions & 1 deletion .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ jobs:
runs-on: ubuntu-20.04
strategy:
matrix:
runtime: ["docker", "containerd"]
runtime:
- "docker"
# - "containerd"
needs:
- unit-test
steps:
Expand Down Expand Up @@ -135,6 +137,43 @@ jobs:
name: 03-basic-ceos-log
path: ./tests/out/*.html

srlinux-basic-tests:
runs-on: ubuntu-20.04
strategy:
matrix:
runtime:
- "docker"
# - "containerd"
needs:
- unit-test
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ${{ env.GOVER }}
- name: Build containerlab
run: go build && sudo mv ./containerlab /usr/bin/containerlab
- uses: actions/setup-python@v2
with:
python-version: "3.8"
- name: Install robotframework
run: |
python -m pip install --upgrade pip
pip install -r tests/requirements.txt
- name: Run srlinux tests
run: |
bash ./tests/rf-run.sh ${{ matrix.runtime }} ./tests/02-basic-srl
# upload test reports as a zip file
- uses: actions/upload-artifact@v2
if: always()
with:
name: 02-basic-srl-log
path: ./tests/out/*.html

docs-test:
runs-on: ubuntu-20.04
needs: file-changes
Expand Down
25 changes: 15 additions & 10 deletions docs/manual/kinds/srl.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ By default, `ixrd2` type will be used by containerlab.

Based on the provided type, containerlab will generate the topology file that will be mounted to SR Linux container and make it boot in a chosen HW variant.
### Node configuration
SR Linux nodes have a `config.json` file that is used to persist the configuration of the node. It is possible to launch nodes of `srl` kind with a basic "default" config or to provide a custom config file that will be used as a startup config instead.
SR Linux uses a `/etc/opt/srlinux/config.json` file to persist its configuration. By default containerlab starts nodes of `srl` kind with a basic "default" config, and with the `startup-config` parameter it is possible to provide a custom config file that will be used as a startup one.
#### Default node configuration
When a node is defined without `config` statement present, containerlab will generate an empty config from [this template](https://github.com/srl-labs/containerlab/blob/master/nodes/srl/srl.cfg) and put it in that directory.
When a node is defined without the `startup-config` statement present, containerlab will generate an basic config from [this template](https://github.com/srl-labs/containerlab/blob/master/nodes/srl/srl.cfg):

```yaml
# example of a topo file that does not define a custom config
# example of a topo file that does not define a custom startup-config
# as a result, the config will be generated from a template
# and used by this node
name: srl_lab
Expand All @@ -61,7 +61,7 @@ topology:
The generated config will be saved by the path `clab-<lab_name>/<node-name>/config/config.json`. Using the example topology presented above, the exact path to the config will be `clab-srl_lab/srl1/config/config.json`.

#### User defined startup config
It is possible to make SR Linux nodes to boot up with a user-defined config instead of a built-in one. With a [`startup-config`](../nodes.md#startup-config) property of the node/kind a user sets the path to the config file that will be mounted to a container:
It is possible to make SR Linux nodes to boot up with a user-defined config instead of a built-in one. With a [`startup-config`](../nodes.md#startup-config) property of the node/kind a user sets the path to the local config file that will be mounted to a container:

```yaml
name: srl_lab
Expand All @@ -71,17 +71,17 @@ topology:
kind: srl
type: ixr6
image: ghcr.io/nokia/srlinux
startup-config: myconfig.json
startup-config: myconfig.json # a path relative to the current working directory
```

With such topology file containerlab is instructed to take a file `myconfig.json` from the current working directory, copy it to the lab directory for that specific node under the `config.json` name and mount that file to the container. This will result in this config to act as a startup config for the node.
With such topology file containerlab is instructed to take a file `myconfig.json` from the current working directory, copy it to the lab directory for that specific node under the `config.json` name and mount that directory to the container. This will result in this config to act as a startup config for the node.

#### Saving configuration
As was explained in the [Node configuration](#node-configuration) section, SR Linux containers can make their config persistent, because config files are provided to the containers from the host via the bind mount.

When a user configures SR Linux node the changes are saved into the running configuration stored in memory. To save the running configuration as a startup configuration the user needs to execute the `tools system configuration save` CLI command. This will write the config to the `/etc/opt/srlinux/config.json` file that holds the startup config and is exposed to the host.

SR Linux node also support the [`containerlab save -t <topo-file>`](../../cmd/save.md) command which will execute the command to save the running config on all the lab nodes. For SR Linux node the `tools system configuration save` will be executed:
SR Linux node also supports the [`containerlab save -t <topo-file>`](../../cmd/save.md) command which will execute the command to save the running config on all the lab nodes. For SR Linux node the `tools system configuration save` will be executed:

```
❯ containerlab save -t quickstart.clab.yml
Expand Down Expand Up @@ -138,10 +138,15 @@ When a user starts a lab, containerlab creates a lab directory for storing [conf
```
~/clab/clab-srl02
❯ ls -lah srl1
-rwxrwxrwx+ 1 1002 1002 36169 Aug 2 17:31 config.json
-rw-r--r-- 1 root root 233 Dec 1 22:11 topology.yml
drwxrwxrwx+ 6 1002 1002 87 Dec 1 22:11 config
-rw-r--r-- 1 root root 233 Dec 1 22:11 topology.clab.yml
```
The `config.json` file is mounted to container's `/etc/opt/srlinux/config.json` in `rw` mode and will effectively contain the node's configuration that SR Linux runs:
The `config` directory is mounted to container's `/etc/opt/srlinux/` path in `rw` mode and will effectively contain configuration that SR Linux runs of as well as the files that SR Linux keeps in its `/etc/opt/srlinux/` directory:
```
❯ ls srl1/config
banner cli config.json devices tls ztp
```
The topology file that defines the emulated hardware type is driven by the value of the kinds `type` parameter. Depending on a specified `type` the appropriate content will be populated into the `topology.yml` file that will get mounted to `/tmp/topology.yml` directory inside the container in `ro` mode.
9 changes: 5 additions & 4 deletions nodes/srl/srl.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ func (s *srl) Init(cfg *types.NodeConfig, opts ...nodes.NodeOption) error {
s.cfg.Binds = append(s.cfg.Binds, fmt.Sprint(filepath.Join(s.cfg.LabDir, "license.key"), ":/opt/srlinux/etc/license.key:ro"))
}

// mount config file
cfgPath := filepath.Join(s.cfg.LabDir, "config.json")
s.cfg.Binds = append(s.cfg.Binds, fmt.Sprint(cfgPath, ":/etc/opt/srlinux/config.json:rw"))
// mount config directory
cfgPath := filepath.Join(s.cfg.LabDir, "config")
s.cfg.Binds = append(s.cfg.Binds, fmt.Sprint(cfgPath, ":/etc/opt/srlinux/:rw"))

// mount srlinux topology
topoPath := filepath.Join(s.cfg.LabDir, "topology.yml")
Expand Down Expand Up @@ -223,7 +223,8 @@ func createSRLFiles(nodeCfg *types.NodeConfig) error {
// generate a startup config file
// if the node has a `startup-config:` statement, the file specified in that section
// will be used as a template in GenerateConfig()
dst = path.Join(nodeCfg.LabDir, "config.json")
utils.CreateDirectory(path.Join(nodeCfg.LabDir, "config"), 0777)
dst = path.Join(nodeCfg.LabDir, "config", "config.json")
if nodeCfg.StartupConfig != "" {
c, err := os.ReadFile(nodeCfg.StartupConfig)
if err != nil {
Expand Down
20 changes: 14 additions & 6 deletions tests/02-basic-srl/01-two-srls.robot
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,41 @@ Suite Teardown Run Keyword Cleanup

*** Variables ***
${lab-name} 02-01-two-srls
${lab-file-name} 02-srl02.clab.yml
${runtime} docker

*** Test Cases ***
Deploy ${lab-name} lab
Log ${CURDIR}
${rc} ${output} = Run And Return Rc And Output
... sudo containerlab deploy -t ${CURDIR}/02-srl02.clab.yml
... sudo containerlab deploy -t ${CURDIR}/${lab-file-name}
Log ${output}
Should Be Equal As Integers ${rc} 0

Wait 5 seconds
Wait 5 seconds for srl to boot
Sleep 5s

Verify links in node srl1
${rc} ${output} = Run And Return Rc And Output
... sudo docker exec clab-${lab-name}-srl1 ip link show e1-1
... sudo containerlab --runtime ${runtime} exec -t ${CURDIR}/${lab-file-name} --label clab-node-name\=srl1 --cmd "ip link show e1-1"
Log ${output}
Should Be Equal As Integers ${rc} 0
Should Contain ${output} state UP

Verify links in node srl2
${rc} ${output} = Run And Return Rc And Output
... sudo docker exec clab-${lab-name}-srl2 ip link show e1-1
... sudo containerlab --runtime ${runtime} exec -t ${CURDIR}/${lab-file-name} --label clab-node-name\=srl2 --cmd "ip link show e1-1"
Log ${output}
Should Be Equal As Integers ${rc} 0
Should Contain ${output} state UP

Verify saving config
${rc} ${output} = Run And Return Rc And Output
... sudo containerlab --runtime ${runtime} save -t ${CURDIR}/${lab-file-name}
Log ${output}
Should Be Equal As Integers ${rc} 0
Should Not Contain ${output} ERRO

*** Keywords ***
Cleanup
Run sudo containerlab destroy -t ${CURDIR}/02-srl02.clab.yml --cleanup
Run rm -rf ${CURDIR}/${lab-name}
Run sudo containerlab destroy -t ${CURDIR}/${lab-file-name} --cleanup
3 changes: 1 addition & 2 deletions tests/02-basic-srl/02-srl02.clab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ name: 02-01-two-srls
topology:
kinds:
srl:
image: srlinux:21.3.1-410
license: /home/gitlab-runner/srl-lic.key
image: ghcr.io/nokia/srlinux
nodes:
srl1:
kind: srl
Expand Down

0 comments on commit 2022cf0

Please sign in to comment.