diff --git a/plugins/guests/redhat/cap/configure_networks.rb b/plugins/guests/redhat/cap/configure_networks.rb index 054801a62..c1b58b72d 100644 --- a/plugins/guests/redhat/cap/configure_networks.rb +++ b/plugins/guests/redhat/cap/configure_networks.rb @@ -14,7 +14,7 @@ module VagrantPlugins network_scripts_dir = machine.guest.capability(:network_scripts_dir) - commands = [] + commands = {:start => [], :middle => [], :end => []} interfaces = machine.guest.capability(:network_interfaces) # Check if NetworkManager is installed on the system @@ -64,21 +64,25 @@ module VagrantPlugins final_path = "#{network_scripts_dir}/ifcfg-#{network[:device]}" if nm_controlled - commands << "nmcli d disconnect '#{network[:device]}'" + if extra_opts[:nm_controlled] == "no" + commands[:start] << "nmcli d disconnect iface '#{network[:device]}'" + end else - commands << "/sbin/ifdown '#{network[:device]}'" - end - commands << "mv -f '#{remote_path}' '#{final_path}'" - if nmcli_installed - commands << "nmcli c reload" + commands[:start] << "/sbin/ifdown '#{network[:device]}'" end + commands[:middle] << "mv -f '#{remote_path}' '#{final_path}'" if extra_opts[:nm_controlled] == "no" - commands << "/sbin/ifup '#{network[:device]}'" - else - commands << "nmcli c up ifname '#{network[:device]}'" + commands[:end] << "/sbin/ifup '#{network[:device]}'" end end + if nmcli_installed + commands[:middle] << "((nmcli c help 2>&1 | grep reload) && nmcli c reload) || " \ + "(test -f /etc/init.d/NetworkManager && /etc/init.d/NetworkManager restart) || " \ + "((systemctl | grep NetworkManager.service) && systemctl NetworkManager restart)" + end + commands = commands[:start] + commands[:middle] + commands[:end] comm.sudo(commands.join("\n")) + comm.wait_for_ready(5) end end end diff --git a/test/unit/plugins/guests/redhat/cap/configure_networks_test.rb b/test/unit/plugins/guests/redhat/cap/configure_networks_test.rb index 9a64d258a..32625b607 100644 --- a/test/unit/plugins/guests/redhat/cap/configure_networks_test.rb +++ b/test/unit/plugins/guests/redhat/cap/configure_networks_test.rb @@ -104,7 +104,7 @@ describe "VagrantPlugins::GuestRedHat::Cap::ConfigureNetworks" do expect(comm.received_commands[0]).to match(/nmcli.*disconnect.*eth1/) expect(comm.received_commands[0]).to match(/nmcli c reload/) expect(comm.received_commands[0]).to match(/ifup.*eth1/) - expect(comm.received_commands[0]).to match(/nmcli.*up.*eth2/) + expect(comm.received_commands[0]).to match(/nmcli.*reload/) expect(comm.received_commands[0]).to_not match(/ifdown/) end end @@ -157,9 +157,8 @@ describe "VagrantPlugins::GuestRedHat::Cap::ConfigureNetworks" do cap.configure_networks(machine, [network_1, network_2]) expect(comm.received_commands[0]).to_not match(/nmcli.*disconnect/) expect(comm.received_commands[0]).to match(/ifdown/) - expect(comm.received_commands[0]).to match(/nmcli c reload/) expect(comm.received_commands[0]).to match(/ifup.*eth1/) - expect(comm.received_commands[0]).to match(/nmcli.*up.*eth2/) + expect(comm.received_commands[0]).to match(/nmcli.*reload/) end end end