Skip to content

Commit

Permalink
Merge branch 'master' into config
Browse files Browse the repository at this point in the history
  • Loading branch information
hellt committed Jun 23, 2021
2 parents 16053d3 + ead63cf commit ce64479
Show file tree
Hide file tree
Showing 108 changed files with 4,333 additions and 1,899 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ jobs:
smoke-tests:
runs-on: ubuntu-20.04
strategy:
matrix:
runtime: ["docker", "containerd"]
needs:
- staticcheck
- unit-test
Expand All @@ -103,7 +106,7 @@ jobs:
pip install -r tests/requirements.txt
- name: Run smoke tests
run: |
bash ./tests/rf-run.sh ./tests/01-smoke
bash ./tests/rf-run.sh ${{ matrix.runtime }} ./tests/01-smoke
# upload test reports as a zip file
- uses: actions/upload-artifact@v2
if: always()
Expand Down
15 changes: 12 additions & 3 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,44 @@ build-containerlab:

smoke-tests:
stage: smoke-tests
parallel:
matrix:
- RUNTIME: [docker, containerd]
tags:
- containerlab
script:
- source ~/venvs/rf/bin/activate
- bash ./tests/rf-run.sh ./tests/01-smoke
- bash ./tests/rf-run.sh $RUNTIME ./tests/01-smoke
artifacts:
when: always
paths:
- "./tests/out/*.html"

srl-tests:
stage: integration-tests
parallel:
matrix:
- RUNTIME: [docker, containerd]
tags:
- containerlab
script:
- source ~/venvs/rf/bin/activate
- bash ./tests/rf-run.sh ./tests/02-basic-srl
- bash ./tests/rf-run.sh $RUNTIME ./tests/02-basic-srl
artifacts:
when: always
paths:
- "./tests/out/*.html"

ceos-tests:
stage: integration-tests
parallel:
matrix:
- RUNTIME: [docker, containerd]
tags:
- containerlab
script:
- source ~/venvs/rf/bin/activate
- bash ./tests/rf-run.sh ./tests/03-basic-ceos
- bash ./tests/rf-run.sh $RUNTIME ./tests/02-basic-srl
artifacts:
when: always
paths:
Expand Down
4 changes: 4 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Copyright 2020 Nokia
# Licensed under the BSD 3-Clause License.
# SPDX-License-Identifier: BSD-3-Clause

project_name: containerlab
builds:
- env:
Expand Down
4 changes: 1 addition & 3 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
BSD 3-Clause License
Copyright (c) 2021 Nokia. All rights reserved.

Copyright (c) 2021, SRL Labs
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Expand Down
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
BIN_DIR = $(shell pwd)/bin
BINARY = $(shell pwd)/bin/containerlab

all: build

build:
mkdir -p $(BIN_DIR)
go build -o $(BINARY) main.go

test:
go test -race ./... -v

lint:
golangci-lint run

clint:
docker run -it --rm -v $$(pwd):/app -w /app golangci/golangci-lint:v1.40.1 golangci-lint run -v
50 changes: 25 additions & 25 deletions clab/cert.go → cert/cert.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
package clab
// Copyright 2020 Nokia
// Licensed under the BSD 3-Clause License.
// SPDX-License-Identifier: BSD-3-Clause

package cert

import (
"bytes"
Expand All @@ -16,6 +20,7 @@ import (
"github.com/cloudflare/cfssl/signer"
"github.com/cloudflare/cfssl/signer/universal"
log "github.com/sirupsen/logrus"
"github.com/srl-labs/containerlab/nodes"
"github.com/srl-labs/containerlab/types"
"github.com/srl-labs/containerlab/utils"
)
Expand Down Expand Up @@ -75,7 +80,7 @@ var rootCACSRTempl string = `{
}
`

var nodeCSRTempl string = `{
var NodeCSRTempl string = `{
"CN": "{{.Name}}.{{.Prefix}}.io",
"key": {
"algo": "rsa",
Expand All @@ -93,15 +98,13 @@ var nodeCSRTempl string = `{
"{{.Fqdn}}"
]
}
`

// GenerateRootCa function
func (c *CLab) GenerateRootCa(csrRootJsonTpl *template.Template, input CaRootInput) (*Certificates, error) {
func GenerateRootCa(labCARoot string, csrRootJsonTpl *template.Template, input CaRootInput) (*Certificates, error) {
log.Info("Creating root CA")
// create root CA root directory
utils.CreateDirectory(c.Dir.LabCARoot, 0755)
utils.CreateDirectory(labCARoot, 0755)
var err error
csrBuff := new(bytes.Buffer)
err = csrRootJsonTpl.Execute(csrBuff, input)
Expand All @@ -126,16 +129,13 @@ func (c *CLab) GenerateRootCa(csrRootJsonTpl *template.Template, input CaRootInp
Csr: csrPEM,
Cert: cert,
}
c.writeCertFiles(certs, path.Join(c.Dir.LabCARoot, input.NamePrefix))
writeCertFiles(certs, path.Join(labCARoot, input.NamePrefix))
return certs, nil
}

// GenerateCert generates and signs a certificate passed as input and saves the certificate and generated private key by path
// CA used to sign the cert is passed as ca and caKey file paths
func (c *CLab) GenerateCert(ca string, caKey string, csrJSONTpl *template.Template, input CertInput, targetPath string) (*Certificates, error) {
c.m.RLock()
defer c.m.RUnlock()

func GenerateCert(ca, caKey string, csrJSONTpl *template.Template, input CertInput, targetPath string) (*Certificates, error) {
utils.CreateDirectory(targetPath, 0755)
var err error
csrBuff := new(bytes.Buffer)
Expand Down Expand Up @@ -192,14 +192,14 @@ func (c *CLab) GenerateCert(ca string, caKey string, csrJSONTpl *template.Templa
Cert: cert,
}

c.writeCertFiles(certs, path.Join(targetPath, input.Name))
writeCertFiles(certs, path.Join(targetPath, input.Name))
return certs, nil
}

// RetrieveNodeCertData reads the node private key and certificate by the well known paths
// if either of those files doesn't exist, an error is returned
func (c *CLab) RetrieveNodeCertData(n *types.Node) (*Certificates, error) {
var nodeCertFilesDir = path.Join(c.Dir.LabCA, n.ShortName)
func RetrieveNodeCertData(n *types.NodeConfig, labCADir string) (*Certificates, error) {
var nodeCertFilesDir = path.Join(labCADir, n.ShortName)
var nodeCertFile = path.Join(nodeCertFilesDir, n.ShortName+".pem")
var nodeKeyFile = path.Join(nodeCertFilesDir, n.ShortName+"-key.pem")

Expand All @@ -225,19 +225,19 @@ func (c *CLab) RetrieveNodeCertData(n *types.Node) (*Certificates, error) {
return certs, nil
}

func (c *CLab) writeCertFiles(certs *Certificates, filesPrefix string) {
createFile(filesPrefix+".pem", string(certs.Cert))
createFile(filesPrefix+"-key.pem", string(certs.Key))
createFile(filesPrefix+".csr", string(certs.Csr))
func writeCertFiles(certs *Certificates, filesPrefix string) {
utils.CreateFile(filesPrefix+".pem", string(certs.Cert))
utils.CreateFile(filesPrefix+"-key.pem", string(certs.Key))
utils.CreateFile(filesPrefix+".csr", string(certs.Csr))
}

//CreateRootCA creates RootCA key/certificate if it is needed by the topology
func (c *CLab) CreateRootCA() error {
func CreateRootCA(configName, labCARoot string, ns map[string]nodes.Node) error {
rootCANeeded := false
// check if srl kinds defined in topo
// for them we need to create rootCA and certs
for _, n := range c.Nodes {
if n.Kind == "srl" {
for _, n := range ns {
if n.Config().Kind == "srl" {
rootCANeeded = true
break
}
Expand All @@ -247,8 +247,8 @@ func (c *CLab) CreateRootCA() error {
return nil
}

var rootCaCertPath = path.Join(c.Dir.LabCARoot, "root-ca.pem")
var rootCaKeyPath = path.Join(c.Dir.LabCARoot, "root-ca-key.pem")
var rootCaCertPath = path.Join(labCARoot, "root-ca.pem")
var rootCaKeyPath = path.Join(labCARoot, "root-ca-key.pem")

var rootCaCertExists = false
var rootCaKeyExists = false
Expand All @@ -273,8 +273,8 @@ func (c *CLab) CreateRootCA() error {
if err != nil {
return fmt.Errorf("failed to parse Root CA CSR Template: %v", err)
}
rootCerts, err := c.GenerateRootCa(tpl, CaRootInput{
Prefix: c.Config.Name,
rootCerts, err := GenerateRootCa(labCARoot, tpl, CaRootInput{
Prefix: configName,
NamePrefix: "root-ca",
})
if err != nil {
Expand Down
116 changes: 0 additions & 116 deletions clab/ceos.go

This file was deleted.

Loading

0 comments on commit ce64479

Please sign in to comment.