From 95967650345c76a31c9e865f1de28700c7f052d4 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Wed, 3 Jan 2018 16:32:21 -0800 Subject: [PATCH] Update debian network configuration tests --- .../debian/cap/configure_networks_test.rb | 57 ++++++++++++++++--- 1 file changed, 48 insertions(+), 9 deletions(-) diff --git a/test/unit/plugins/guests/debian/cap/configure_networks_test.rb b/test/unit/plugins/guests/debian/cap/configure_networks_test.rb index f0d8ab9e3..121af75dc 100644 --- a/test/unit/plugins/guests/debian/cap/configure_networks_test.rb +++ b/test/unit/plugins/guests/debian/cap/configure_networks_test.rb @@ -71,11 +71,13 @@ describe "VagrantPlugins::GuestDebian::Cap::ConfigureNetworks" do } 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 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) + end + 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("/sbin/ifdown 'eth1' || true") @@ -86,15 +88,52 @@ describe "VagrantPlugins::GuestDebian::Cap::ConfigureNetworks" do expect(comm.received_commands[0]).to match("/sbin/ifup 'eth2'") end - it "creates and starts the networks for systemd with netplan" do - allow(comm).to receive(:test).with("systemctl | grep '^-.mount'").and_return(true) - allow(comm).to receive(:test).with("sudo systemctl status systemd-networkd.service").and_return(true) - allow(comm).to receive(:test).with("netplan -h").and_return(true) + context "with systemd" do + before do + expect(comm).to receive(:test).with("systemctl | grep '^-.mount'").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("sudo netplan apply") + expect(comm.received_commands[0]).to match("/sbin/ifdown 'eth1' || true") + 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