Fixes #10585: Properly set DHCP for systemd-networkd ips
Prior to this commit, if a debian system requested an DHCP address using systemd-network, Vagrant would ignore it and instead use the configured IP from the virtualbox network action. This commit fixes that by instead looking if DHCP was requested, and if so, use that option for an IP.
This commit is contained in:
parent
cdd3e7578b
commit
65a7261853
|
@ -89,7 +89,9 @@ module VagrantPlugins
|
|||
net_conf << "[Match]"
|
||||
net_conf << "Name=#{dev_name}"
|
||||
net_conf << "[Network]"
|
||||
if network[:ip]
|
||||
if network[:type].to_s == "dhcp"
|
||||
net_conf << "DHCP=yes"
|
||||
else
|
||||
mask = network[:netmask]
|
||||
if mask && IPAddr.new(network[:ip]).ipv4?
|
||||
begin
|
||||
|
@ -102,8 +104,6 @@ module VagrantPlugins
|
|||
net_conf << "DHCP=no"
|
||||
net_conf << "Address=#{address}"
|
||||
net_conf << "Gateway=#{network[:gateway]}" if network[:gateway]
|
||||
else
|
||||
net_conf << "DHCP=yes"
|
||||
end
|
||||
|
||||
remote_path = upload_tmp_file(comm, net_conf.join("\n"))
|
||||
|
|
|
@ -101,6 +101,9 @@ describe "VagrantPlugins::GuestDebian::Cap::ConfigureNetworks" do
|
|||
end
|
||||
|
||||
context "with systemd-networkd" do
|
||||
let(:net_conf_dhcp) { "[Match]\nName=eth1\n[Network]\nDHCP=yes" }
|
||||
let(:net_conf_static) { "[Match]\nName=eth2\n[Network]\nDHCP=no\nAddress=33.33.33.10/16\nGateway=33.33.0.1" }
|
||||
|
||||
before do
|
||||
expect(comm).to receive(:test).with("systemctl -q is-active systemd-networkd.service", anything).and_return(true)
|
||||
end
|
||||
|
@ -113,6 +116,19 @@ describe "VagrantPlugins::GuestDebian::Cap::ConfigureNetworks" do
|
|||
expect(comm.received_commands[0]).to match("chmod")
|
||||
expect(comm.received_commands[2]).to match("systemctl restart")
|
||||
end
|
||||
|
||||
it "properly configures DHCP and static IPs if defined" do
|
||||
expect(cap).to receive(:upload_tmp_file).with(comm, net_conf_dhcp)
|
||||
expect(cap).to receive(:upload_tmp_file).with(comm, net_conf_static)
|
||||
|
||||
cap.configure_networks(machine, [network_0, network_1])
|
||||
|
||||
expect(comm.received_commands[0]).to match("mkdir -p /etc/systemd/network")
|
||||
expect(comm.received_commands[0]).to match("mv -f '' '/etc/systemd/network/50-vagrant-eth1.network'")
|
||||
expect(comm.received_commands[0]).to match("chown root:root '/etc/systemd/network/50-vagrant-eth1.network'")
|
||||
expect(comm.received_commands[0]).to match("chmod 0644 '/etc/systemd/network/50-vagrant-eth1.network'")
|
||||
expect(comm.received_commands[2]).to match("systemctl restart")
|
||||
end
|
||||
end
|
||||
|
||||
context "with netplan" do
|
||||
|
|
Loading…
Reference in New Issue