|
68 | 68 | allow(File).to receive(:readable?).with('/var/lib/NetworkManager/').and_return(false) |
69 | 69 | allow(File).to receive(:readable?).with('/var/db/').and_return(false) |
70 | 70 |
|
| 71 | + allow(Dir).to receive(:glob).with('{/run,/var/run}/dhcpcd{,*,/}*.pid').and_return(['/run/dhcpcd.pid']) |
| 72 | + allow(File).to receive(:file?).with('/run/dhcpcd.pid').and_return(true) |
| 73 | + allow(Facter::Util::FileHelper).to receive(:safe_read).with('/run/dhcpcd.pid', '').and_return('1234') |
| 74 | + allow(Process).to receive(:kill).with(0, 1234).and_return(true) |
| 75 | + allow(Facter::Util::FileHelper).to receive(:safe_read).with('/proc/1234/comm', nil).and_return('dhcpcd') |
| 76 | + |
71 | 77 | allow(Facter::Core::Execution).to receive(:which) |
72 | 78 | .with('dhcpcd').and_return('/usr/bin/dhcpcd') |
73 | 79 | allow(Facter::Core::Execution).to receive(:execute) |
|
100 | 106 | expect(dhcp_search.dhcp('ens160', 1, log_spy)).to eq(nil) |
101 | 107 | end |
102 | 108 | end |
| 109 | + |
| 110 | + context 'when the dhcpcd command is available, but not running' do |
| 111 | + before do |
| 112 | + allow(Facter::Util::FileHelper).to receive(:safe_read).with('/run/systemd/netif/leases/1', nil).and_return(nil) |
| 113 | + allow(File).to receive(:readable?).with('/var/lib/dhclient/').and_return(false) |
| 114 | + allow(File).to receive(:readable?).with('/var/lib/dhcp/').and_return(false) |
| 115 | + allow(File).to receive(:readable?).with('/var/lib/dhcp3/').and_return(false) |
| 116 | + allow(File).to receive(:readable?).with('/var/lib/NetworkManager/').and_return(false) |
| 117 | + allow(File).to receive(:readable?).with('/var/db/').and_return(false) |
| 118 | + allow(Dir).to receive(:glob).with('{/run,/var/run}/dhcpcd{,*,/}*.pid').and_return([]) |
| 119 | + allow(Dir).to receive(:glob).with('/proc/[0-9]*/comm').and_return([]) |
| 120 | + |
| 121 | + allow(Facter::Core::Execution).to receive(:which) |
| 122 | + .with('dhcpcd').and_return('/usr/bin/dhcpcd') |
| 123 | + |
| 124 | + dhcp_search.instance_eval { @dhcpcd_command = nil } |
| 125 | + end |
| 126 | + |
| 127 | + it 'returns nil' do |
| 128 | + expect(dhcp_search.dhcp('ens160', 1, log_spy)).to eq(nil) |
| 129 | + end |
| 130 | + end |
103 | 131 | end |
104 | 132 | end |
0 commit comments