Skip to content
Snippets Groups Projects
Commit 544e2a69 authored by Lars Seipel's avatar Lars Seipel
Browse files

runner/libvirt: use topology.HasFunction where appropriate

parent aae00a2f
Branches
No related tags found
No related merge requests found
......@@ -70,7 +70,7 @@ func customizeDomain(ctx context.Context, uri string, d *device, extraCommands i
func commandsForFunction(d *device) []byte {
var buf bytes.Buffer
if f := d.topoDev.Function(); isCumulusFunction(f) {
if hasCumulusFunction(d) {
// These eat enough memory to summon the OOM killer in 512MiB
// VMs.
buf.WriteString("run-command systemctl disable netq-agent.service\n")
......@@ -89,7 +89,7 @@ func commandsForFunction(d *device) []byte {
// hostnames for CL. Work around by directly writing to
// /etc/hostname.
fmt.Fprintf(&buf, "write /etc/hostname:%s\\\n\n", d.topoDev.Name)
if f == topology.OOBSwitch {
if d.topoDev.Function() == topology.OOBSwitch {
writeExtraMgmtSwitchCommands(&buf, d)
}
return buf.Bytes()
......
......@@ -262,15 +262,16 @@ func isASCIIDigit(c rune) bool {
return '0' <= c && c <= '9'
}
// Returns whether the device function f defaults to Cumulus Linux.
func isCumulusFunction(f topology.DeviceFunction) bool {
switch f {
case topology.OOBSwitch, topology.Exit,
topology.SuperSpine, topology.Spine,
topology.Leaf, topology.TOR:
return true
}
return false
// Returns whether d defaults to Cumulus Linux.
func hasCumulusFunction(d *device) bool {
return topology.HasFunction(&d.topoDev,
topology.OOBSwitch,
topology.Exit,
topology.SuperSpine,
topology.Spine,
topology.Leaf,
topology.TOR,
)
}
// Waits until d received a DHCP lease from a libvirt network and return its
......
......@@ -66,9 +66,8 @@ func TestDnsmasqHostsFile(t *testing.T) {
if d.Attr("no_mgmt") != "" {
continue
}
if f := d.Function(); f == topology.OOBServer ||
f == topology.OOBSwitch ||
f == topology.Fake {
if topology.HasFunction(&d, topology.OOBServer,
topology.OOBSwitch, topology.Fake) {
continue
}
ndevices++
......
......@@ -686,7 +686,7 @@ func (r *Runner) customizeDomains(ctx context.Context, t *topology.T) (err error
defer cancel()
for _, d := range r.devices {
user := "root"
if isCumulusFunction(d.topoDev.Function()) {
if hasCumulusFunction(d) {
user = "cumulus"
fmt.Fprintf(&buf, "write /etc/ptm.d/topology.dot:%s\n",
bytes.Replace(t.DOT(), []byte("\n"),
......@@ -786,12 +786,11 @@ func (r *Runner) writeSSHConfig(ctx context.Context, t *topology.T) (err error)
`, ip)
for _, d := range t.Devices() {
if d.Function() == topology.OOBServer ||
d.Function() == topology.OOBSwitch {
if topology.HasFunction(&d, topology.OOBServer, topology.OOBSwitch) {
continue
}
user := "root"
if isCumulusFunction(d.Function()) {
if hasCumulusFunction(&device{topoDev: d}) {
user = "cumulus"
}
fmt.Fprintf(w, `Host %s
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment