Update debian network configuration tests

This commit is contained in:
Chris Roberts 2018-01-03 16:32:21 -08:00
parent a36a84c85a
commit 9596765034
1 changed files with 48 additions and 9 deletions

View File

@ -71,11 +71,13 @@ describe "VagrantPlugins::GuestDebian::Cap::ConfigureNetworks" do
} }
end end
it "creates and starts the networks for non systemd" do before do
allow(comm).to receive(:test).with("systemctl | grep '^-.mount'").and_return(false) allow(comm).to receive(:test).with("systemctl | grep '^-.mount'").and_return(false)
allow(comm).to receive(:test).with("systemctl status systemd-networkd.service").and_return(false) allow(comm).to receive(:test).with("sudo systemctl status systemd-networkd.service").and_return(false)
allow(comm).to receive(:test).with("netplan -h").and_return(false) allow(comm).to receive(:test).with("netplan -h").and_return(false)
end
it "creates and starts the networks using net-tools" do
cap.configure_networks(machine, [network_0, network_1]) cap.configure_networks(machine, [network_0, network_1])
expect(comm.received_commands[0]).to match("/sbin/ifdown 'eth1' || true") expect(comm.received_commands[0]).to match("/sbin/ifdown 'eth1' || true")
@ -86,15 +88,52 @@ describe "VagrantPlugins::GuestDebian::Cap::ConfigureNetworks" do
expect(comm.received_commands[0]).to match("/sbin/ifup 'eth2'") expect(comm.received_commands[0]).to match("/sbin/ifup 'eth2'")
end end
it "creates and starts the networks for systemd with netplan" do context "with systemd" do
allow(comm).to receive(:test).with("systemctl | grep '^-.mount'").and_return(true) before do
allow(comm).to receive(:test).with("sudo systemctl status systemd-networkd.service").and_return(true) expect(comm).to receive(:test).with("systemctl | grep '^-.mount'").and_return(true)
allow(comm).to receive(:test).with("netplan -h").and_return(true) allow(comm).to receive(:test).with("netplan -h").and_return(false)
end
cap.configure_networks(machine, [network_0, network_1]) it "creates and starts the networks using net-tools" do
cap.configure_networks(machine, [network_0, network_1])
expect(comm.received_commands[0]).to match("mv '/tmp/vagrant-network-entry' /etc/netplan/99-vagrant.yaml") expect(comm.received_commands[0]).to match("/sbin/ifdown 'eth1' || true")
expect(comm.received_commands[0]).to match("sudo netplan apply") expect(comm.received_commands[0]).to match("/sbin/ip addr flush dev 'eth1'")
expect(comm.received_commands[0]).to match("/sbin/ifdown 'eth2' || true")
expect(comm.received_commands[0]).to match("/sbin/ip addr flush dev 'eth2'")
expect(comm.received_commands[0]).to match("/sbin/ifup 'eth1'")
expect(comm.received_commands[0]).to match("/sbin/ifup 'eth2'")
end
context "with systemd-networkd" do
before do
expect(comm).to receive(:test).with("sudo systemctl status systemd-networkd.service").and_return(true)
end
it "creates and starts the networks using systemd-networkd" do
cap.configure_networks(machine, [network_0, network_1])
expect(comm.received_commands[0]).to match("mv -f '/tmp/vagrant-network-entry.*' '/etc/systemd/network/.*network'")
expect(comm.received_commands[0]).to match("chown")
expect(comm.received_commands[0]).to match("chmod")
expect(comm.received_commands[0]).to match("systemctl restart")
end
end
context "with netplan" do
before do
expect(comm).to receive(:test).with("netplan -h").and_return(true)
end
it "creates and starts the networks for systemd with netplan" do
cap.configure_networks(machine, [network_0, network_1])
expect(comm.received_commands[0]).to match("mv -f '/tmp/vagrant-network-entry.*' '/etc/netplan/.*.yaml'")
expect(comm.received_commands[0]).to match("chown")
expect(comm.received_commands[0]).to match("chmod")
expect(comm.received_commands[0]).to match("netplan apply")
end
end
end end
end end
end end