Skip to content

Commit

Permalink
Merge branch 'master' into containerdexecfilterfix
Browse files Browse the repository at this point in the history
  • Loading branch information
hellt committed Jun 29, 2021
2 parents 30f90c8 + 8d12776 commit f31424f
Show file tree
Hide file tree
Showing 51 changed files with 549 additions and 592 deletions.
85 changes: 58 additions & 27 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
env:
GOVER: 1.16.5
CGO_ENABLED: 0
MKDOCS_MATERIAL_VER: 7.1.0
MKDOCS_MATERIAL_VER: 7.1.8

jobs:
file-changes:
Expand Down Expand Up @@ -48,43 +48,18 @@ jobs:
- uses: actions/setup-go@v2
with:
go-version: ${{ env.GOVER }}
# create fake default config of srl for tests to validate path
- run: sudo mkdir -p /etc/containerlab/templates/srl && sudo touch /etc/containerlab/templates/srl/srlconfig.tpl
- run: go test -cover ./...

staticcheck:
runs-on: ubuntu-20.04
needs: file-changes
if: needs.file-changes.outputs.code == 'true' || startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: ${{ env.GOVER }}
- name: Staticcheck
run: |
go install honnef.co/go/tools/cmd/staticcheck@latest
staticcheck ./...
docs-test:
runs-on: ubuntu-20.04
needs: file-changes
if: needs.file-changes.outputs.docs == 'true' || startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/docs-publish'
steps:
- uses: actions/checkout@v2
- run: docker run -v $(pwd):/docs --entrypoint mkdocs squidfunk/mkdocs-material:$MKDOCS_MATERIAL_VER build --clean --strict
- name: htmltest
run: |
curl https://htmltest.wjdp.uk | bash
./bin/htmltest -c docs/htmltest.yml
smoke-tests:
runs-on: ubuntu-20.04
strategy:
matrix:
runtime: ["docker", "containerd"]
needs:
- staticcheck
- unit-test
steps:
- name: Checkout
Expand All @@ -96,7 +71,7 @@ jobs:
with:
go-version: ${{ env.GOVER }}
- name: Build containerlab
run: sudo go build -o /usr/bin/containerlab
run: go build && sudo mv ./containerlab /usr/bin/containerlab
- uses: actions/setup-python@v2
with:
python-version: "3.8"
Expand All @@ -114,12 +89,68 @@ jobs:
name: 01-smoke-log
path: ./tests/out/*.html

ceos-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: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Pull ceos image
run: docker pull ghcr.io/srl-labs/ceos:4.25.0F && docker tag ghcr.io/srl-labs/ceos:4.25.0F ceos:4.25.0F
- name: Run ceos tests
run: |
bash ./tests/rf-run.sh ${{ matrix.runtime }} ./tests/03-basic-ceos
# upload test reports as a zip file
- uses: actions/upload-artifact@v2
if: always()
with:
name: 03-basic-ceos-log
path: ./tests/out/*.html

docs-test:
runs-on: ubuntu-20.04
needs: file-changes
if: needs.file-changes.outputs.docs == 'true' || startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/docs-publish'
steps:
- uses: actions/checkout@v2
- run: docker run -v $(pwd):/docs --entrypoint mkdocs squidfunk/mkdocs-material:$MKDOCS_MATERIAL_VER build --clean --strict
- name: htmltest
run: |
curl https://htmltest.wjdp.uk | bash
./bin/htmltest -c docs/htmltest.yml
build-and-release:
runs-on: ubuntu-20.04
if: startsWith(github.ref, 'refs/tags/v')
needs:
- docs-test
- smoke-tests
- ceos-basic-tests
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down
116 changes: 116 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
linters-settings:
depguard:
list-type: blacklist
dupl:
threshold: 100
funlen:
lines: 100
statements: 50
gci:
local-prefixes: github.com/golangci/golangci-lint
goconst:
min-len: 2
min-occurrences: 2
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- dupImport # https://github.com/go-critic/go-critic/issues/845
- ifElseChain
- octalLiteral
- whyNoLint
- wrapperFunc
gocyclo:
min-complexity: 15
goimports:
local-prefixes: github.com/golangci/golangci-lint
gomnd:
settings:
mnd:
# don't include the "operation" and "assign"
checks: [argument, case, condition, return]
govet:
check-shadowing: true
settings:
printf:
funcs:
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
lll:
line-length: 150
misspell:
locale: US
nolintlint:
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
allow-unused: false # report any unused nolint directives
require-explanation: false # don't require an explanation for nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
enable:
- bodyclose
- deadcode
- depguard
- dogsled
- dupl
- errcheck
- exhaustive
- funlen
- gochecknoinits
- goconst
- gocritic
- gocyclo
- gofmt
- goimports
- gomnd
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- lll
- misspell
- nakedret
- noctx
- nolintlint
- revive
- rowserrcheck
- exportloopref
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- varcheck
- whitespace
- asciicheck
- gochecknoglobals
- gocognit
- godot
- godox
- goerr113
- nestif
- prealloc
- testpackage
- wsl

issues:
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
- path: _test\.go
linters:
- gomnd

run:
skip-dirs:
- private
3 changes: 0 additions & 3 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ archives:
- replacements:
linux: Linux
files:
- templates/**/*
- lab-examples/**/*
checksum:
name_template: checksums.txt
Expand Down Expand Up @@ -54,8 +53,6 @@ nfpms:
contents:
- src: ./lab-examples
dst: /etc/containerlab/lab-examples
- src: ./templates
dst: /etc/containerlab/templates
# - src: ./tools
# dst: /etc/containerlab/tools
- src: /usr/bin/containerlab
Expand Down
10 changes: 3 additions & 7 deletions clab/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,6 @@ var kinds = []string{
"host",
}

// DefaultCredentials holds default username and password per each kind
var DefaultCredentials = map[string][]string{
"vr-sros": {"admin", "admin"},
"vr-vmx": {"admin", "admin@123"},
"vr-xrv9k": {"clab", "clab@123"},
}

// Config defines lab configuration as it is provided in the YAML file
type Config struct {
Name string `json:"name,omitempty"`
Expand Down Expand Up @@ -119,6 +112,7 @@ func (c *CLab) NewNode(nodeName string, nodeDef *types.NodeDefinition, idx int)
if err != nil {
return err
}

// Init
nodeInitializer, ok := nodes.Nodes[nodeCfg.Kind]
if !ok {
Expand All @@ -131,6 +125,7 @@ func (c *CLab) NewNode(nodeName string, nodeDef *types.NodeDefinition, idx int)
log.Errorf("failed to initialize node %q: %v", nodeCfg.ShortName, err)
return fmt.Errorf("failed to initialize node %q: %v", nodeCfg.ShortName, err)
}

n.Config().Labels = utils.MergeStringMaps(n.Config().Labels, map[string]string{
"containerlab": c.Config.Name,
"clab-node-name": n.Config().ShortName,
Expand All @@ -141,6 +136,7 @@ func (c *CLab) NewNode(nodeName string, nodeDef *types.NodeDefinition, idx int)
"clab-topo-file": c.TopoFile.path,
})
c.Nodes[nodeName] = n

return nil
}

Expand Down
File renamed without changes.
28 changes: 18 additions & 10 deletions cmd/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package cmd

import (
"context"
_ "embed"
"encoding/json"
"fmt"
"html/template"
Expand All @@ -19,14 +20,15 @@ import (
"github.com/srl-labs/containerlab/types"
)

const (
defaultTemplatePath = "/etc/containerlab/templates/graph/index.html"
)
var (
srv string
tmpl string
offline bool
dot bool

var srv string
var tmpl string
var offline bool
var dot bool
//go:embed graph-template.html
graphTemplate string
)

type graphTopo struct {
Nodes []containerDetails `json:"nodes,omitempty"`
Expand Down Expand Up @@ -117,9 +119,15 @@ var graphCmd = &cobra.Command{
Name: c.Config.Name,
Data: template.JS(string(b)),
}
tmpl := template.Must(template.ParseFiles(tmpl))
var t *template.Template
if tmpl != "" {
t = template.Must(template.ParseFiles(tmpl))
} else {
t = template.Must(template.New("graph").Parse(graphTemplate))
}

http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
_ = tmpl.Execute(w, topoD)
_ = t.Execute(w, topoD)
})

log.Infof("Listening on %s...", srv)
Expand Down Expand Up @@ -173,5 +181,5 @@ func init() {
graphCmd.Flags().StringVarP(&srv, "srv", "s", ":50080", "HTTP server address to view, customize and export your topology")
graphCmd.Flags().BoolVarP(&offline, "offline", "o", false, "use only information from topo file when building graph")
graphCmd.Flags().BoolVarP(&dot, "dot", "", false, "generate dot file instead of launching the web server")
graphCmd.Flags().StringVarP(&tmpl, "template", "", defaultTemplatePath, "Go html template used to generate the graph")
graphCmd.Flags().StringVarP(&tmpl, "template", "", "", "Go html template used to generate the graph")
}
Loading

0 comments on commit f31424f

Please sign in to comment.