Merge pull request #12421 from soapy1/retry-networks-setup-debian

Retry network setup on debain
This commit is contained in:
Sophia Castellarin 2021-06-21 09:11:50 -05:00 committed by GitHub
commit 750c95272d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 6 deletions

View File

@ -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

View File

@ -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