Skip to content

Commit

Permalink
functests, multus: refactor configInterface to allow sudo
Browse files Browse the repository at this point in the history
VMs based on Cirros images require sudo to configure the IP
address.

A follow up patch will reuse this function for cirros based VMs.

Signed-off-by: Miguel Duarte Barroso <mdbarroso@redhat.com>
  • Loading branch information
maiqueb committed Oct 22, 2020
1 parent 4e53de1 commit 4f7ec88
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions tests/vmi_multus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -938,23 +938,27 @@ func cidrToIP(cidr string) string {
return ip.String()
}

func configInterface(vmi *v1.VirtualMachineInstance, interfaceName, interfaceAddress string) {
cmdCheck := fmt.Sprintf("ip addr add %s dev %s\n", interfaceAddress, interfaceName)
func configVMIInterfaceWithSudo(vmi *v1.VirtualMachineInstance, interfaceName, interfaceAddress string) {
configInterface(vmi, interfaceName, interfaceAddress, "sudo ")
}

func configInterface(vmi *v1.VirtualMachineInstance, interfaceName, interfaceAddress string, userModifierPrefix ...string) {
setStaticIpCmd := fmt.Sprintf("%sip addr add %s dev %s\n", strings.Join(userModifierPrefix, " "), interfaceAddress, interfaceName)
err := console.SafeExpectBatch(vmi, []expect.Batcher{
&expect.BSnd{S: "\n"},
&expect.BExp{R: console.PromptExpression},
&expect.BSnd{S: cmdCheck},
&expect.BSnd{S: setStaticIpCmd},
&expect.BExp{R: console.PromptExpression},
&expect.BSnd{S: "echo $?\n"},
&expect.BExp{R: console.RetValue("0")},
}, 15)
Expect(err).ToNot(HaveOccurred(), "Failed to configure address %s for interface %s on VMI %s", interfaceAddress, interfaceName, vmi.Name)

cmdCheck = fmt.Sprintf("ip link set %s up\n", interfaceName)
setIfaceUpCmd := fmt.Sprintf("ip link set %s up\n", interfaceName)
err = console.SafeExpectBatch(vmi, []expect.Batcher{
&expect.BSnd{S: "\n"},
&expect.BExp{R: console.PromptExpression},
&expect.BSnd{S: cmdCheck},
&expect.BSnd{S: setIfaceUpCmd},
&expect.BExp{R: console.PromptExpression},
&expect.BSnd{S: "echo $?\n"},
&expect.BExp{R: console.RetValue("0")},
Expand Down

0 comments on commit 4f7ec88

Please sign in to comment.