Skip to content

Commit

Permalink
Always use CLI command to load cRPD license (#2014)
Browse files Browse the repository at this point in the history
  • Loading branch information
mzagozen committed Apr 25, 2024
1 parent c5896ac commit 387114e
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions nodes/crpd/crpd.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"

log "github.com/sirupsen/logrus"
"github.com/srl-labs/containerlab/clab/exec"
Expand All @@ -19,7 +20,9 @@ import (
)

const (
licDir = "/config/license/safenet"
// licDir is the directory where Junos 22+ expects to find the license file
licDir = "/config/license"
licFile = "license.lic"
)

var (
Expand Down Expand Up @@ -61,7 +64,7 @@ func (s *crpd) Init(cfg *types.NodeConfig, opts ...nodes.NodeOption) error {
fmt.Sprint(filepath.Join(s.Cfg.LabDir, "config"), ":/config"),
fmt.Sprint(filepath.Join(s.Cfg.LabDir, "log"), ":/var/log"),
// mount sshd_config
fmt.Sprint(filepath.Join(s.Cfg.LabDir, "config/sshd_config"), ":/etc/ssh/sshd_config"),
fmt.Sprint(filepath.Join(s.Cfg.LabDir, "config", "sshd_config"), ":/etc/ssh/sshd_config"),
)

return nil
Expand All @@ -86,7 +89,27 @@ func (s *crpd) PostDeploy(ctx context.Context, _ *nodes.PostDeployParams) error
}

if len(execResult.GetStdErrString()) > 0 {
return fmt.Errorf("crpd post-deploy failed: %s", execResult.GetStdErrString())
// If "ssh: unrecognized service" appears in the output we are probably
// on Junos >=23.4, where the SSH daemon configuration is fully owned by
// the management interface
if strings.Contains(execResult.GetStdErrString(), "ssh: unrecognized service") {
log.Debug(`Caught "ssh: unrecognized service" error, ignoring`)
} else {
return fmt.Errorf("crpd post-deploy sshd restart failed: %s", execResult.GetStdErrString())
}
}

if s.Config().License != "" {
cmd, _ = exec.NewExecCmdFromString(fmt.Sprintf("cli request system license add %s", filepath.Join(licDir, licFile)))
execResult, err = s.RunExec(ctx, cmd)
if err != nil {
return err
}

if len(execResult.GetStdErrString()) > 0 {
return fmt.Errorf("crpd post-deploy license add failed: %s", execResult.GetStdErrString())
}
log.Debugf("crpd post-deploy license add result: %s", execResult.GetStdOutString())
}

return err
Expand Down Expand Up @@ -121,7 +144,7 @@ func createCRPDFiles(node nodes.Node) error {
utils.CreateDirectory(filepath.Join(nodeCfg.LabDir, "log"), 0777)

// copy crpd config from default template or user-provided conf file
cfg := filepath.Join(nodeCfg.LabDir, "/config/juniper.conf")
cfg := filepath.Join(nodeCfg.LabDir, "config", "juniper.conf")
var cfgTemplate string

if nodeCfg.StartupConfig != "" {
Expand All @@ -142,7 +165,7 @@ func createCRPDFiles(node nodes.Node) error {
}

// write crpd sshd conf file to crpd node dir
dst := filepath.Join(nodeCfg.LabDir, "/config/sshd_config")
dst := filepath.Join(nodeCfg.LabDir, "config", "sshd_config")
err = utils.CreateFile(dst, sshdCfg)
if err != nil {
return fmt.Errorf("failed to write sshd_config file %v", err)
Expand All @@ -152,7 +175,7 @@ func createCRPDFiles(node nodes.Node) error {
if nodeCfg.License != "" {
// copy license file to node specific lab directory
src := nodeCfg.License
dst = filepath.Join(nodeCfg.LabDir, licDir, "junos_sfnt.lic")
dst = filepath.Join(nodeCfg.LabDir, licDir, licFile)

if err := os.MkdirAll(filepath.Join(nodeCfg.LabDir, licDir), 0777); err != nil { // skipcq: GSC-G301
return err
Expand Down

0 comments on commit 387114e

Please sign in to comment.