Merge pull request #10586 from briancain/debian-systemd-networkd-dhcp-static-ips

Fixes #10585: Properly set DHCP for systemd-networkd ips
This commit is contained in:
Brian Cain 2019-01-11 16:22:09 -08:00 committed by GitHub
commit b2ae361329
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 3 deletions

View File

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

View File

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