Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/linux_admin/network_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def ip_show
#
# @param ip_output [String] The command output
def parse_ip4(ip_output)
cidr_ip = parse_ip_output(ip_output, /inet/, 1)
cidr_ip = parse_ip_output(ip_output, /inet /, 1)
return unless cidr_ip

@network_conf[:address] = cidr_ip.split('/')[0]
Expand Down
25 changes: 25 additions & 0 deletions spec/network_interface_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@
valid_lft forever preferred_lft forever
IP_OUT

IP6_ADDR_OUT = <<-IP_OUT
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:ed:0e:8b brd ff:ff:ff:ff:ff:ff
inet6 fe80::20c:29ff:feed:e8b/64 scope link
valid_lft forever preferred_lft forever
inet6 fd12:3456:789a:1::1/96 scope global
valid_lft forever preferred_lft forever
IP_OUT

IP_ROUTE_OUT = <<-IP_OUT
default via 192.168.1.1 dev eth0 proto static metric 100
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.9 metric 100
Expand All @@ -105,6 +114,15 @@
described_class.new("eth0")
end

subject(:subj6) do
allow(LinuxAdmin::Distros).to receive(:local).and_return(LinuxAdmin::Distros.generic)
described_class.dist_class(true)

allow(AwesomeSpawn).to receive(:run!).with(*IP_SHOW_ARGS).and_return(result(IP6_ADDR_OUT, 0))
allow(AwesomeSpawn).to receive(:run!).with(*IP_ROUTE_ARGS).and_return(result(IP_ROUTE_OUT, 0))
described_class.new("eth0")
end

def result(output, exit_status)
AwesomeSpawn::CommandResult.new("", output, "", exit_status)
end
Expand All @@ -124,6 +142,13 @@ def result(output, exit_status)
allow(AwesomeSpawn).to receive(:run!).with(*IP_ROUTE_ARGS).and_raise(awesome_error)
expect { subj.reload }.to raise_error(LinuxAdmin::NetworkInterfaceError)
end

it "doesn't blow up when given only ipv6 addresses" do
subj6
allow(AwesomeSpawn).to receive(:run!).with(*IP_SHOW_ARGS).and_return(result(IP6_ADDR_OUT, 0))
allow(AwesomeSpawn).to receive(:run!).with(*IP_ROUTE_ARGS).and_return(result(IP_ROUTE_OUT, 0))
expect { subj.reload }.to_not raise_error
end
end

describe "#address" do
Expand Down