Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ All notable changes to this project will be documented in this file.

- **CLI / Web UI**: Display the release version or source branch alongside the commit hash and build timestamp in the version output and footer.

### Fixed

- **vrouter**: Set VyOS and Vyatta router hostnames exactly as written in the topology instead of lowercasing them and replacing `.` and `_` with `-`, so the guest hostname matches the minimega VM name. Firewall nodes already behaved this way.

## [1.0.0]

### Changed
Expand Down
48 changes: 48 additions & 0 deletions src/go/app/vrouter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package app_test

import (
"bytes"
"strings"
"testing"

"phenix/tmpl"
v1 "phenix/types/version/v1"
)

// TestVyattaTemplateHostnameVerbatim verifies that vyatta.tmpl sets the router's
// system host-name to the topology hostname exactly as written, so the guest
// hostname matches the minimega VM name used by cc filters and tag matching.
func TestVyattaTemplateHostnameVerbatim(t *testing.T) {
const hostname = "Branch-Router-01"

tests := []struct {
name string
vyos bool
want string
}{
{name: "vyos script", vyos: true, want: "set system host-name " + hostname + "\n"},
{name: "vyatta config.boot", vyos: false, want: "host-name " + hostname + "\n"},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
node := &v1.Node{
TypeF: "Router",
GeneralF: &v1.General{HostnameF: hostname},
NetworkF: &v1.Network{},
}

data := map[string]any{"node": node, "vyos": tt.vyos}

var buf bytes.Buffer

if err := tmpl.GenerateFromTemplate("vyatta.tmpl", data, &buf); err != nil {
t.Fatal(err)
}

if !strings.Contains(buf.String(), tt.want) {
t.Fatalf("expected %q in rendered config:\n%s", tt.want, buf.String())
}
})
}
}
4 changes: 2 additions & 2 deletions src/go/tmpl/templates/vyatta.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ set service snmp trap-target {{ $target }} community '{{ $community.Name }}'
{{- end }}
{{- end }}
# --------------------------------- System --------------------------------
set system host-name {{ $node.RouterName }}
set system host-name {{ $node.General.Hostname }}
{{- range $idx, $iface := $node.Network.Interfaces }}
{{- range $dnsServer := $iface.DNS }}
set system name-server {{ $dnsServer }}
Expand Down Expand Up @@ -629,7 +629,7 @@ service {
{{- end }}

system {
host-name {{ $node.RouterName }}
host-name {{ $node.General.Hostname }}
{{- if $ntpAddr }}
ntp {
server {{ $ntpAddr }} {
Expand Down
12 changes: 0 additions & 12 deletions src/go/types/version/v0/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,18 +478,6 @@ func (n Node) FileDeletions() string {
return strings.Join(deletions, ",")
}

func (n Node) RouterName() string {
if !strings.EqualFold(n.TypeF, "router") {
return n.GeneralF.HostnameF
}

name := strings.ToLower(n.GeneralF.HostnameF)
name = strings.ReplaceAll(name, ".", "-")
name = strings.ReplaceAll(name, "_", "-")

return name
}

func (h Hardware) DiskConfig(snapshot string) string {
configs := make([]string, len(h.DrivesF))

Expand Down
12 changes: 0 additions & 12 deletions src/go/types/version/v1/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -762,18 +762,6 @@ func (n Node) FileDeletions() string {
return strings.Join(deletions, ",")
}

func (n Node) RouterName() string {
if !strings.EqualFold(n.TypeF, "router") {
return n.GeneralF.HostnameF
}

name := strings.ToLower(n.GeneralF.HostnameF)
name = strings.ReplaceAll(name, ".", "-")
name = strings.ReplaceAll(name, "_", "-")

return name
}

func (h Hardware) DiskConfig(snapshot string) string {
configs := make([]string, len(h.DrivesF))

Expand Down
Loading