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:
commit
b2ae361329
|
@ -89,7 +89,9 @@ module VagrantPlugins
|
||||||
net_conf << "[Match]"
|
net_conf << "[Match]"
|
||||||
net_conf << "Name=#{dev_name}"
|
net_conf << "Name=#{dev_name}"
|
||||||
net_conf << "[Network]"
|
net_conf << "[Network]"
|
||||||
if network[:ip]
|
if network[:type].to_s == "dhcp"
|
||||||
|
net_conf << "DHCP=yes"
|
||||||
|
else
|
||||||
mask = network[:netmask]
|
mask = network[:netmask]
|
||||||
if mask && IPAddr.new(network[:ip]).ipv4?
|
if mask && IPAddr.new(network[:ip]).ipv4?
|
||||||
begin
|
begin
|
||||||
|
@ -102,8 +104,6 @@ module VagrantPlugins
|
||||||
net_conf << "DHCP=no"
|
net_conf << "DHCP=no"
|
||||||
net_conf << "Address=#{address}"
|
net_conf << "Address=#{address}"
|
||||||
net_conf << "Gateway=#{network[:gateway]}" if network[:gateway]
|
net_conf << "Gateway=#{network[:gateway]}" if network[:gateway]
|
||||||
else
|
|
||||||
net_conf << "DHCP=yes"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
remote_path = upload_tmp_file(comm, net_conf.join("\n"))
|
remote_path = upload_tmp_file(comm, net_conf.join("\n"))
|
||||||
|
|
|
@ -101,6 +101,9 @@ describe "VagrantPlugins::GuestDebian::Cap::ConfigureNetworks" do
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with systemd-networkd" do
|
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
|
before do
|
||||||
expect(comm).to receive(:test).with("systemctl -q is-active systemd-networkd.service", anything).and_return(true)
|
expect(comm).to receive(:test).with("systemctl -q is-active systemd-networkd.service", anything).and_return(true)
|
||||||
end
|
end
|
||||||
|
@ -113,6 +116,19 @@ describe "VagrantPlugins::GuestDebian::Cap::ConfigureNetworks" do
|
||||||
expect(comm.received_commands[0]).to match("chmod")
|
expect(comm.received_commands[0]).to match("chmod")
|
||||||
expect(comm.received_commands[2]).to match("systemctl restart")
|
expect(comm.received_commands[2]).to match("systemctl restart")
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context "with netplan" do
|
context "with netplan" do
|
||||||
|
|
Loading…
Reference in New Issue