diff --git a/plugins/guests/debian/cap/configure_networks.rb b/plugins/guests/debian/cap/configure_networks.rb index dfec32ccb..bb1ff69f9 100644 --- a/plugins/guests/debian/cap/configure_networks.rb +++ b/plugins/guests/debian/cap/configure_networks.rb @@ -8,6 +8,7 @@ module VagrantPlugins class ConfigureNetworks include Vagrant::Util extend Vagrant::Util::GuestInspection::Linux + extend Vagrant::Util::Retryable NETPLAN_DEFAULT_VERSION = 2 NETPLAN_DIRECTORY = "/etc/netplan".freeze @@ -166,11 +167,16 @@ module VagrantPlugins rm -f /tmp/vagrant-network-interfaces.post EOH + comm.sudo(commands.join("\n")) + network_up_commands = [] + # Bring back up each network interface, reconfigured. networks.each do |network| - commands << "/sbin/ifup '#{network[:device]}'" + network_up_commands << "/sbin/ifup '#{network[:device]}'" + end + retryable(on: Vagrant::Errors::VagrantError, sleep: 2, tries: 2) do + comm.sudo(network_up_commands.join("\n")) end - comm.sudo(commands.join("\n")) end # Simple helper to upload content to guest temporary file 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 8081de6fc..1898e3940 100644 --- a/test/unit/plugins/guests/debian/cap/configure_networks_test.rb +++ b/test/unit/plugins/guests/debian/cap/configure_networks_test.rb @@ -79,8 +79,9 @@ describe "VagrantPlugins::GuestDebian::Cap::ConfigureNetworks" do 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'") + expect(comm.received_commands[1]).to match("/sbin/ifup 'eth1'") + expect(comm.received_commands[1]).to match("/sbin/ifup 'eth2'") + end context "with systemd" do @@ -96,8 +97,8 @@ describe "VagrantPlugins::GuestDebian::Cap::ConfigureNetworks" do 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'") + expect(comm.received_commands[1]).to match("/sbin/ifup 'eth1'") + expect(comm.received_commands[1]).to match("/sbin/ifup 'eth2'") end context "with systemd-networkd" do