Skip to content

Commit

Permalink
Merge commit '7927c39da90dae3f5be79e36ad9df3b4ad834ac1'
Browse files Browse the repository at this point in the history
* commit '7927c39da90dae3f5be79e36ad9df3b4ad834ac1':
  Update CHANGELOG
  Fixes hashicorp#10585: Properly set DHCP for systemd-networkd ips
  • Loading branch information
jojohans committed Jan 14, 2019
2 parents 6f0e83e + 7927c39 commit f442c2f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ IMPROVEMENTS:

BUG FIXES:

- guest/debian: Properly set DHCP for systemd-networkd ips [GH-10586]

## 2.2.3 (January 9, 2019)

FEATURES:
Expand Down
6 changes: 3 additions & 3 deletions plugins/guests/debian/cap/configure_networks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ def self.configure_networkd(machine, interfaces, comm, networks)
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
Expand All @@ -102,8 +104,6 @@ def self.configure_networkd(machine, interfaces, comm, networks)
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"))
Expand Down
16 changes: 16 additions & 0 deletions test/unit/plugins/guests/debian/cap/configure_networks_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@
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
Expand All @@ -113,6 +116,19 @@
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
Expand Down

0 comments on commit f442c2f

Please sign in to comment.