linux_admin 1.2.4 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/linux_admin.rb +0 -8
- data/lib/linux_admin/disk.rb +12 -5
- data/lib/linux_admin/registration_system.rb +8 -4
- data/lib/linux_admin/scap.rb +1 -1
- data/lib/linux_admin/service/sys_v_init_service.rb +2 -1
- data/lib/linux_admin/service/systemd_service.rb +6 -2
- data/lib/linux_admin/version.rb +1 -1
- metadata +8 -100
- data/lib/linux_admin/registration_system/rhn.rb +0 -111
- data/spec/chrony_spec.rb +0 -64
- data/spec/common_spec.rb +0 -37
- data/spec/data/rhn/output_rhn-channel_list +0 -2
- data/spec/data/rhn/output_rhn-channel_list_available +0 -4
- data/spec/data/rhn/systemid +0 -57
- data/spec/data/rhn/systemid.missing_system_id +0 -57
- data/spec/data/rpm/cmd_output_for_list_installed +0 -20
- data/spec/data/subscription_manager/output_list_all_available +0 -42
- data/spec/data/subscription_manager/output_list_installed_not_subscribed +0 -19
- data/spec/data/subscription_manager/output_list_installed_subscribed +0 -19
- data/spec/data/subscription_manager/output_orgs +0 -6
- data/spec/data/subscription_manager/output_repos +0 -18
- data/spec/data/time_date/timedatectl_output +0 -14
- data/spec/data/yum/first.repo +0 -19
- data/spec/data/yum/output_repo_list +0 -13
- data/spec/data/yum/output_repoquery_multiple +0 -3
- data/spec/data/yum/output_repoquery_single +0 -1
- data/spec/data/yum/second.repo +0 -9
- data/spec/deb_spec.rb +0 -52
- data/spec/disk_spec.rb +0 -307
- data/spec/distro_spec.rb +0 -77
- data/spec/dns_spec.rb +0 -105
- data/spec/etc_issue_spec.rb +0 -37
- data/spec/fstab_spec.rb +0 -132
- data/spec/hardware_spec.rb +0 -46
- data/spec/hosts_spec.rb +0 -150
- data/spec/ip_address_spec.rb +0 -148
- data/spec/logical_volume_spec.rb +0 -166
- data/spec/mountable_spec.rb +0 -182
- data/spec/network_interface/network_interface_rh_spec.rb +0 -291
- data/spec/network_interface_spec.rb +0 -284
- data/spec/partition_spec.rb +0 -24
- data/spec/physical_volume_spec.rb +0 -101
- data/spec/registration_system_spec.rb +0 -85
- data/spec/rhn_spec.rb +0 -144
- data/spec/rpm_spec.rb +0 -85
- data/spec/scap_spec.rb +0 -48
- data/spec/service/sys_v_init_service_spec.rb +0 -127
- data/spec/service/systemd_service_spec.rb +0 -133
- data/spec/service_spec.rb +0 -54
- data/spec/spec_helper.rb +0 -116
- data/spec/ssh_spec.rb +0 -53
- data/spec/subscription_manager_spec.rb +0 -228
- data/spec/system_spec.rb +0 -15
- data/spec/time_date_spec.rb +0 -106
- data/spec/volume_group_spec.rb +0 -99
- data/spec/yum_spec.rb +0 -155
@@ -1,291 +0,0 @@
|
|
1
|
-
describe LinuxAdmin::NetworkInterfaceRH do
|
2
|
-
let(:device_name) { "eth0" }
|
3
|
-
let(:ifcfg_file_dhcp) do
|
4
|
-
<<-EOF
|
5
|
-
#A comment is here
|
6
|
-
DEVICE=eth0
|
7
|
-
BOOTPROTO=dhcp
|
8
|
-
UUID=3a48a5b5-b80b-4712-82f7-e517e4088999
|
9
|
-
ONBOOT=yes
|
10
|
-
TYPE=Ethernet
|
11
|
-
NAME="System eth0"
|
12
|
-
EOF
|
13
|
-
end
|
14
|
-
|
15
|
-
let(:ifcfg_file_static) do
|
16
|
-
<<-EOF
|
17
|
-
#A comment is here
|
18
|
-
DEVICE=eth0
|
19
|
-
BOOTPROTO=static
|
20
|
-
UUID=3a48a5b5-b80b-4712-82f7-e517e4088999
|
21
|
-
ONBOOT=yes
|
22
|
-
TYPE=Ethernet
|
23
|
-
NAME="System eth0"
|
24
|
-
IPADDR=192.168.1.100
|
25
|
-
NETMASK=255.255.255.0
|
26
|
-
GATEWAY=192.168.1.1
|
27
|
-
EOF
|
28
|
-
end
|
29
|
-
|
30
|
-
def stub_foreach_to_string(string)
|
31
|
-
allow(File).to receive(:foreach) do |&block|
|
32
|
-
string.each_line { |l| block.call(l) }
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def result(output, exit_status)
|
37
|
-
AwesomeSpawn::CommandResult.new("", output, "", exit_status)
|
38
|
-
end
|
39
|
-
|
40
|
-
subject(:dhcp_interface) do
|
41
|
-
allow(File).to receive(:exist?).and_return(true)
|
42
|
-
stub_path = described_class.path_to_interface_config_file(device_name)
|
43
|
-
allow(Pathname).to receive(:new).and_return(stub_path)
|
44
|
-
allow(stub_path).to receive(:file?).and_return(true)
|
45
|
-
stub_foreach_to_string(ifcfg_file_dhcp)
|
46
|
-
allow(AwesomeSpawn).to receive(:run!).exactly(6).times.and_return(result("", 0))
|
47
|
-
described_class.new(device_name)
|
48
|
-
end
|
49
|
-
|
50
|
-
subject(:static_interface) do
|
51
|
-
allow(File).to receive(:exist?).and_return(true)
|
52
|
-
stub_foreach_to_string(ifcfg_file_static)
|
53
|
-
allow(AwesomeSpawn).to receive(:run!).exactly(4).times.and_return(result("", 0))
|
54
|
-
described_class.new(device_name)
|
55
|
-
end
|
56
|
-
|
57
|
-
describe ".new" do
|
58
|
-
it "loads the configuration" do
|
59
|
-
conf = dhcp_interface.interface_config
|
60
|
-
expect(conf["NM_CONTROLLED"]).to eq("no")
|
61
|
-
expect(conf["DEVICE"]).to eq("eth0")
|
62
|
-
expect(conf["BOOTPROTO"]).to eq("dhcp")
|
63
|
-
expect(conf["UUID"]).to eq("3a48a5b5-b80b-4712-82f7-e517e4088999")
|
64
|
-
expect(conf["ONBOOT"]).to eq("yes")
|
65
|
-
expect(conf["TYPE"]).to eq("Ethernet")
|
66
|
-
expect(conf["NAME"]).to eq('"System eth0"')
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe "#parse_conf" do
|
71
|
-
it "reloads the interface configuration" do
|
72
|
-
interface = dhcp_interface
|
73
|
-
stub_foreach_to_string(ifcfg_file_static)
|
74
|
-
interface.parse_conf
|
75
|
-
|
76
|
-
conf = interface.interface_config
|
77
|
-
expect(conf["NM_CONTROLLED"]).to eq("no")
|
78
|
-
expect(conf["DEVICE"]).to eq("eth0")
|
79
|
-
expect(conf["BOOTPROTO"]).to eq("static")
|
80
|
-
expect(conf["UUID"]).to eq("3a48a5b5-b80b-4712-82f7-e517e4088999")
|
81
|
-
expect(conf["ONBOOT"]).to eq("yes")
|
82
|
-
expect(conf["TYPE"]).to eq("Ethernet")
|
83
|
-
expect(conf["NAME"]).to eq('"System eth0"')
|
84
|
-
expect(conf["IPADDR"]).to eq("192.168.1.100")
|
85
|
-
expect(conf["NETMASK"]).to eq("255.255.255.0")
|
86
|
-
expect(conf["GATEWAY"]).to eq("192.168.1.1")
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
describe "#address=" do
|
91
|
-
it "sets the address" do
|
92
|
-
address = "192.168.1.100"
|
93
|
-
|
94
|
-
dhcp_interface.address = address
|
95
|
-
|
96
|
-
conf = dhcp_interface.interface_config
|
97
|
-
expect(conf["IPADDR"]).to eq(address)
|
98
|
-
expect(conf["BOOTPROTO"]).to eq("static")
|
99
|
-
end
|
100
|
-
|
101
|
-
it "raises argument error when given a bad address" do
|
102
|
-
expect { dhcp_interface.address = "garbage" }.to raise_error(ArgumentError)
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
describe '#address6=' do
|
107
|
-
it 'sets the ipv6 address' do
|
108
|
-
address = 'fe80::1/64'
|
109
|
-
dhcp_interface.address6 = address
|
110
|
-
conf = dhcp_interface.interface_config
|
111
|
-
expect(conf['IPV6ADDR']).to eq(address)
|
112
|
-
expect(conf['IPV6INIT']).to eq('yes')
|
113
|
-
expect(conf['DHCPV6C']).to eq('no')
|
114
|
-
end
|
115
|
-
|
116
|
-
it 'raises error when given a bad address' do
|
117
|
-
expect { dhcp_interface.address6 = '1::1::1' }.to raise_error(ArgumentError)
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
describe "#gateway=" do
|
122
|
-
it "sets the gateway address" do
|
123
|
-
address = "192.168.1.1"
|
124
|
-
dhcp_interface.gateway = address
|
125
|
-
expect(dhcp_interface.interface_config["GATEWAY"]).to eq(address)
|
126
|
-
end
|
127
|
-
|
128
|
-
it "raises argument error when given a bad address" do
|
129
|
-
expect { dhcp_interface.gateway = "garbage" }.to raise_error(ArgumentError)
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
describe '#gateway6=' do
|
134
|
-
it 'sets the default gateway for IPv6' do
|
135
|
-
address = 'fe80::1/64'
|
136
|
-
dhcp_interface.gateway6 = address
|
137
|
-
expect(dhcp_interface.interface_config['IPV6_DEFAULTGW']).to eq(address)
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
describe "#netmask=" do
|
142
|
-
it "sets the sub-net mask" do
|
143
|
-
mask = "255.255.255.0"
|
144
|
-
dhcp_interface.netmask = mask
|
145
|
-
expect(dhcp_interface.interface_config["NETMASK"]).to eq(mask)
|
146
|
-
end
|
147
|
-
|
148
|
-
it "raises argument error when given a bad address" do
|
149
|
-
expect { dhcp_interface.netmask = "garbage" }.to raise_error(ArgumentError)
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
describe "#dns=" do
|
154
|
-
it "sets the correct configuration" do
|
155
|
-
dns1 = "192.168.1.1"
|
156
|
-
dns2 = "192.168.1.10"
|
157
|
-
|
158
|
-
static_interface.dns = dns1, dns2
|
159
|
-
|
160
|
-
conf = static_interface.interface_config
|
161
|
-
expect(conf["DNS1"]).to eq(dns1)
|
162
|
-
expect(conf["DNS2"]).to eq(dns2)
|
163
|
-
end
|
164
|
-
|
165
|
-
it "sets the correct configuration when given an array" do
|
166
|
-
dns = %w(192.168.1.1 192.168.1.10)
|
167
|
-
|
168
|
-
static_interface.dns = dns
|
169
|
-
|
170
|
-
conf = static_interface.interface_config
|
171
|
-
expect(conf["DNS1"]).to eq(dns[0])
|
172
|
-
expect(conf["DNS2"]).to eq(dns[1])
|
173
|
-
end
|
174
|
-
|
175
|
-
it "sets only DNS1 if given one value" do
|
176
|
-
dns = "192.168.1.1"
|
177
|
-
|
178
|
-
static_interface.dns = dns
|
179
|
-
|
180
|
-
conf = static_interface.interface_config
|
181
|
-
expect(conf["DNS1"]).to eq(dns)
|
182
|
-
expect(conf["DNS2"]).to be_nil
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
describe "#search_order=" do
|
187
|
-
it "sets the search domain list" do
|
188
|
-
search1 = "localhost"
|
189
|
-
search2 = "test.example.com"
|
190
|
-
search3 = "example.com"
|
191
|
-
static_interface.search_order = search1, search2, search3
|
192
|
-
expect(static_interface.interface_config["DOMAIN"]).to eq("\"#{search1} #{search2} #{search3}\"")
|
193
|
-
end
|
194
|
-
|
195
|
-
it "sets the search domain list when given an array" do
|
196
|
-
search_list = %w(localhost test.example.com example.com)
|
197
|
-
static_interface.search_order = search_list
|
198
|
-
expect(static_interface.interface_config["DOMAIN"]).to eq("\"#{search_list.join(' ')}\"")
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
describe "#enable_dhcp" do
|
203
|
-
it "sets the correct configuration" do
|
204
|
-
static_interface.enable_dhcp
|
205
|
-
conf = static_interface.interface_config
|
206
|
-
expect(conf["BOOTPROTO"]).to eq("dhcp")
|
207
|
-
expect(conf["IPADDR"]).to be_nil
|
208
|
-
expect(conf["NETMASK"]).to be_nil
|
209
|
-
expect(conf["GATEWAY"]).to be_nil
|
210
|
-
expect(conf["PREFIX"]).to be_nil
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
describe '#enable_dhcp6' do
|
215
|
-
it 'sets the correct configuration' do
|
216
|
-
[static_interface, dhcp_interface].each do |interface|
|
217
|
-
interface.enable_dhcp6
|
218
|
-
conf = interface.interface_config
|
219
|
-
expect(conf).to include('IPV6INIT' => 'yes', 'DHCPV6C' => 'yes')
|
220
|
-
expect(conf.keys).not_to include('IPV6ADDR', 'IPV6_DEFAULTGW')
|
221
|
-
end
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
describe "#apply_static" do
|
226
|
-
it "sets the correct configuration" do
|
227
|
-
expect(dhcp_interface).to receive(:save)
|
228
|
-
dhcp_interface.apply_static("192.168.1.12", "255.255.255.0", "192.168.1.1", ["192.168.1.1", nil], ["localhost"])
|
229
|
-
|
230
|
-
conf = dhcp_interface.interface_config
|
231
|
-
expect(conf["BOOTPROTO"]).to eq("static")
|
232
|
-
expect(conf["IPADDR"]).to eq("192.168.1.12")
|
233
|
-
expect(conf["NETMASK"]).to eq("255.255.255.0")
|
234
|
-
expect(conf["GATEWAY"]).to eq("192.168.1.1")
|
235
|
-
expect(conf["DNS1"]).to eq("192.168.1.1")
|
236
|
-
expect(conf["DNS2"]).to be_nil
|
237
|
-
expect(conf["DOMAIN"]).to eq("\"localhost\"")
|
238
|
-
end
|
239
|
-
end
|
240
|
-
|
241
|
-
describe '#apply_static6' do
|
242
|
-
it 'sets the static IPv6 configuration' do
|
243
|
-
expect(dhcp_interface).to receive(:save)
|
244
|
-
dhcp_interface.apply_static6('d:e:a:d:b:e:e:f', 127, 'd:e:a:d::/64', ['d:e:a:d::'])
|
245
|
-
conf = dhcp_interface.interface_config
|
246
|
-
expect(conf).to include('IPV6INIT' => 'yes', 'DHCPV6C' => 'no', 'IPV6ADDR' => 'd:e:a:d:b:e:e:f/127', 'IPV6_DEFAULTGW' => 'd:e:a:d::/64')
|
247
|
-
end
|
248
|
-
end
|
249
|
-
|
250
|
-
describe "#save" do
|
251
|
-
let(:iface_file) { Pathname.new("/etc/sysconfig/network-scripts/ifcfg-#{device_name}") }
|
252
|
-
|
253
|
-
def expect_old_contents
|
254
|
-
expect(File).to receive(:write) do |file, contents|
|
255
|
-
expect(file).to eq(iface_file)
|
256
|
-
expect(contents).to include("DEVICE=eth0")
|
257
|
-
expect(contents).to include("BOOTPROTO=dhcp")
|
258
|
-
expect(contents).to include("UUID=3a48a5b5-b80b-4712-82f7-e517e4088999")
|
259
|
-
expect(contents).to include("ONBOOT=yes")
|
260
|
-
expect(contents).to include("TYPE=Ethernet")
|
261
|
-
expect(contents).to include('NAME="System eth0"')
|
262
|
-
end
|
263
|
-
end
|
264
|
-
|
265
|
-
it "writes the configuration" do
|
266
|
-
expect(File).to receive(:read).with(iface_file)
|
267
|
-
expect(dhcp_interface).to receive(:stop).and_return(true)
|
268
|
-
expect(dhcp_interface).to receive(:start).and_return(true)
|
269
|
-
expect_old_contents
|
270
|
-
expect(dhcp_interface.save).to be true
|
271
|
-
end
|
272
|
-
|
273
|
-
it "returns false when the interface cannot be brought down" do
|
274
|
-
expect(File).to receive(:read).with(iface_file)
|
275
|
-
expect(dhcp_interface).to receive(:stop).twice.and_return(false)
|
276
|
-
expect(File).not_to receive(:write)
|
277
|
-
expect(dhcp_interface.save).to be false
|
278
|
-
end
|
279
|
-
|
280
|
-
it "returns false and writes the old contents when the interface fails to come back up" do
|
281
|
-
dhcp_interface # evaluate the subject first so the expectations stub the right calls
|
282
|
-
expect(File).to receive(:read).with(iface_file).and_return("old stuff")
|
283
|
-
expect(dhcp_interface).to receive(:stop).and_return(true)
|
284
|
-
expect_old_contents
|
285
|
-
expect(dhcp_interface).to receive(:start).and_return(false)
|
286
|
-
expect(File).to receive(:write).with(iface_file, "old stuff")
|
287
|
-
expect(dhcp_interface).to receive(:start)
|
288
|
-
expect(dhcp_interface.save).to be false
|
289
|
-
end
|
290
|
-
end
|
291
|
-
end
|
@@ -1,284 +0,0 @@
|
|
1
|
-
describe LinuxAdmin::NetworkInterface do
|
2
|
-
let(:device_name) { "eth0" }
|
3
|
-
let(:config_file_path) { LinuxAdmin::NetworkInterfaceRH.path_to_interface_config_file(device_name) }
|
4
|
-
context "on redhat systems" do
|
5
|
-
describe ".dist_class" do
|
6
|
-
it "returns NetworkInterfaceRH" do
|
7
|
-
allow(LinuxAdmin::Distros).to receive(:local).and_return(LinuxAdmin::Distros.rhel)
|
8
|
-
expect(described_class.dist_class(true)).to eq(LinuxAdmin::NetworkInterfaceRH)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
describe ".new" do
|
13
|
-
before do
|
14
|
-
allow_any_instance_of(described_class).to receive(:ip_show).and_raise(LinuxAdmin::NetworkInterfaceError.new(nil, nil))
|
15
|
-
allow(LinuxAdmin::Distros).to receive(:local).and_return(LinuxAdmin::Distros.rhel)
|
16
|
-
described_class.dist_class(true)
|
17
|
-
allow(Pathname).to receive(:new).and_return(config_file_path)
|
18
|
-
end
|
19
|
-
|
20
|
-
it "creates a NetworkInterfaceRH instance if the config file does exist" do
|
21
|
-
expect(config_file_path).to receive(:file?).and_return(true)
|
22
|
-
expect(File).to receive(:foreach).and_return("")
|
23
|
-
|
24
|
-
expect(described_class.new(device_name)).to be_an_instance_of(LinuxAdmin::NetworkInterfaceRH)
|
25
|
-
end
|
26
|
-
|
27
|
-
it "creates a NetworkInterfaceRH instance if the config file does not exist" do
|
28
|
-
expect(config_file_path).to receive(:file?).and_return(false)
|
29
|
-
|
30
|
-
expect(described_class.new(device_name)).to be_an_instance_of(LinuxAdmin::NetworkInterfaceRH)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context "on other linux systems" do
|
36
|
-
describe ".dist_class" do
|
37
|
-
it "returns NetworkInterfaceGeneric" do
|
38
|
-
allow(LinuxAdmin::Distros).to receive(:local).and_return(LinuxAdmin::Distros.generic)
|
39
|
-
expect(described_class.dist_class(true)).to eq(LinuxAdmin::NetworkInterfaceGeneric)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe ".new" do
|
44
|
-
subject do
|
45
|
-
allow_any_instance_of(described_class).to receive(:ip_show).and_raise(LinuxAdmin::NetworkInterfaceError.new(nil, nil))
|
46
|
-
allow(LinuxAdmin::Distros).to receive(:local).and_return(LinuxAdmin::Distros.generic)
|
47
|
-
described_class.dist_class(true)
|
48
|
-
described_class.new(device_name)
|
49
|
-
end
|
50
|
-
|
51
|
-
it "creates a NetworkInterfaceGeneric instance" do
|
52
|
-
expect(subject).to be_an_instance_of(LinuxAdmin::NetworkInterfaceGeneric)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
context "on all systems" do
|
58
|
-
IP_SHOW_ARGS = [
|
59
|
-
LinuxAdmin::Common.cmd("ip"),
|
60
|
-
:params => %w(addr show eth0)
|
61
|
-
]
|
62
|
-
|
63
|
-
IP_ROUTE_ARGS = [
|
64
|
-
LinuxAdmin::Common.cmd("ip"),
|
65
|
-
:params => ['-4', 'route']
|
66
|
-
]
|
67
|
-
|
68
|
-
IP6_ROUTE_ARGS = [
|
69
|
-
LinuxAdmin::Common.cmd("ip"),
|
70
|
-
:params => ['-6', 'route']
|
71
|
-
]
|
72
|
-
|
73
|
-
IFUP_ARGS = [
|
74
|
-
LinuxAdmin::Common.cmd("ifup"),
|
75
|
-
:params => ["eth0"]
|
76
|
-
]
|
77
|
-
|
78
|
-
IFDOWN_ARGS = [
|
79
|
-
LinuxAdmin::Common.cmd("ifdown"),
|
80
|
-
:params => ["eth0"]
|
81
|
-
]
|
82
|
-
|
83
|
-
IP_ADDR_OUT = <<-IP_OUT
|
84
|
-
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
|
85
|
-
link/ether 00:0c:29:ed:0e:8b brd ff:ff:ff:ff:ff:ff
|
86
|
-
inet 192.168.1.9/24 brd 192.168.1.255 scope global dynamic eth0
|
87
|
-
valid_lft 1297sec preferred_lft 1297sec
|
88
|
-
inet6 fe80::20c:29ff:feed:e8b/64 scope link
|
89
|
-
valid_lft forever preferred_lft forever
|
90
|
-
inet6 fd12:3456:789a:1::1/96 scope global
|
91
|
-
valid_lft forever preferred_lft forever
|
92
|
-
IP_OUT
|
93
|
-
|
94
|
-
IP6_ADDR_OUT = <<-IP_OUT
|
95
|
-
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
|
96
|
-
link/ether 00:0c:29:ed:0e:8b brd ff:ff:ff:ff:ff:ff
|
97
|
-
inet6 fe80::20c:29ff:feed:e8b/64 scope link
|
98
|
-
valid_lft forever preferred_lft forever
|
99
|
-
inet6 fd12:3456:789a:1::1/96 scope global
|
100
|
-
valid_lft forever preferred_lft forever
|
101
|
-
IP_OUT
|
102
|
-
|
103
|
-
IP_ROUTE_OUT = <<-IP_OUT
|
104
|
-
default via 192.168.1.1 dev eth0 proto static metric 100
|
105
|
-
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.9 metric 100
|
106
|
-
IP_OUT
|
107
|
-
IP6_ROUTE_OUT = <<-IP_OUT
|
108
|
-
default via d:e:a:d:b:e:e:f dev eth0 proto static metric 100
|
109
|
-
fc00:dead:beef:a::/64 dev virbr1 proto kernel metric 256 linkdown pref medium
|
110
|
-
fe80::/64 dev eth0 proto kernel scope link metric 100
|
111
|
-
IP_OUT
|
112
|
-
|
113
|
-
IP_NONE_ADDR_OUT = <<-IP_OUT.freeze
|
114
|
-
2: eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc fq_codel master virbr1 state DOWN group default qlen 1000
|
115
|
-
link/ether 52:54:00:ce:b4:f4 brd ff:ff:ff:ff:ff:ff
|
116
|
-
IP_OUT
|
117
|
-
|
118
|
-
subject(:subj) do
|
119
|
-
allow(LinuxAdmin::Distros).to receive(:local).and_return(LinuxAdmin::Distros.generic)
|
120
|
-
described_class.dist_class(true)
|
121
|
-
|
122
|
-
allow(AwesomeSpawn).to receive(:run!).with(*IP_SHOW_ARGS).and_return(result(IP_ADDR_OUT, 0))
|
123
|
-
allow(AwesomeSpawn).to receive(:run!).with(*IP_ROUTE_ARGS).and_return(result(IP_ROUTE_OUT, 0))
|
124
|
-
allow(AwesomeSpawn).to receive(:run!).with(*IP6_ROUTE_ARGS).and_return(result(IP6_ROUTE_OUT, 0))
|
125
|
-
described_class.new(device_name)
|
126
|
-
end
|
127
|
-
|
128
|
-
subject(:subj6) do
|
129
|
-
allow(LinuxAdmin::Distros).to receive(:local).and_return(LinuxAdmin::Distros.generic)
|
130
|
-
described_class.dist_class(true)
|
131
|
-
|
132
|
-
allow(AwesomeSpawn).to receive(:run!).with(*IP_SHOW_ARGS).and_return(result(IP6_ADDR_OUT, 0))
|
133
|
-
allow(AwesomeSpawn).to receive(:run!).with(*IP_ROUTE_ARGS).and_return(result(IP_ROUTE_OUT, 0))
|
134
|
-
allow(AwesomeSpawn).to receive(:run!).with(*IP6_ROUTE_ARGS).and_return(result(IP6_ROUTE_OUT, 0))
|
135
|
-
described_class.new(device_name)
|
136
|
-
end
|
137
|
-
|
138
|
-
subject(:subj_no_net) do
|
139
|
-
allow(LinuxAdmin::Distros).to receive(:local).and_return(LinuxAdmin::Distros.generic)
|
140
|
-
described_class.dist_class(true)
|
141
|
-
|
142
|
-
allow(AwesomeSpawn).to receive(:run!).with(*IP_SHOW_ARGS).and_return(result(IP_NONE_ADDR_OUT, 0))
|
143
|
-
allow(AwesomeSpawn).to receive(:run!).with(*IP_ROUTE_ARGS).and_return(result(IP_ROUTE_OUT, 0))
|
144
|
-
allow(AwesomeSpawn).to receive(:run!).with(*IP6_ROUTE_ARGS).and_return(result(IP6_ROUTE_OUT, 0))
|
145
|
-
described_class.new(device_name)
|
146
|
-
end
|
147
|
-
|
148
|
-
def result(output, exit_status)
|
149
|
-
AwesomeSpawn::CommandResult.new("", output, "", exit_status)
|
150
|
-
end
|
151
|
-
|
152
|
-
describe "#reload" do
|
153
|
-
it "returns false when ip addr show fails" do
|
154
|
-
subj
|
155
|
-
awesome_error = AwesomeSpawn::CommandResultError.new("", nil)
|
156
|
-
allow(AwesomeSpawn).to receive(:run!).with(*IP_SHOW_ARGS).and_raise(awesome_error)
|
157
|
-
expect(subj.reload).to eq(false)
|
158
|
-
end
|
159
|
-
|
160
|
-
it "raises when ip route fails" do
|
161
|
-
subj
|
162
|
-
awesome_error = AwesomeSpawn::CommandResultError.new("", nil)
|
163
|
-
allow(AwesomeSpawn).to receive(:run!).with(*IP_SHOW_ARGS).and_return(result(IP_ADDR_OUT, 0))
|
164
|
-
allow(AwesomeSpawn).to receive(:run!).with(*IP_ROUTE_ARGS).and_raise(awesome_error)
|
165
|
-
allow(AwesomeSpawn).to receive(:run!).with(*IP6_ROUTE_ARGS).and_raise(awesome_error)
|
166
|
-
expect { subj.reload }.to raise_error(LinuxAdmin::NetworkInterfaceError)
|
167
|
-
end
|
168
|
-
|
169
|
-
it "doesn't blow up when given only ipv6 addresses" do
|
170
|
-
subj6
|
171
|
-
allow(AwesomeSpawn).to receive(:run!).with(*IP_SHOW_ARGS).and_return(result(IP6_ADDR_OUT, 0))
|
172
|
-
allow(AwesomeSpawn).to receive(:run!).with(*IP_ROUTE_ARGS).and_return(result(IP_ROUTE_OUT, 0))
|
173
|
-
allow(AwesomeSpawn).to receive(:run!).with(*IP6_ROUTE_ARGS).and_return(result(IP6_ROUTE_OUT, 0))
|
174
|
-
expect { subj.reload }.to_not raise_error
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
describe "#address" do
|
179
|
-
it "returns an address" do
|
180
|
-
expect(subj.address).to eq("192.168.1.9")
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
describe "#address6" do
|
185
|
-
it "returns the global address by default" do
|
186
|
-
expect(subj.address6).to eq("fd12:3456:789a:1::1")
|
187
|
-
end
|
188
|
-
|
189
|
-
it "returns the link local address" do
|
190
|
-
expect(subj.address6(:link)).to eq("fe80::20c:29ff:feed:e8b")
|
191
|
-
end
|
192
|
-
|
193
|
-
it "raises ArgumentError when given a bad scope" do
|
194
|
-
expect { subj.address6(:garbage) }.to raise_error(ArgumentError)
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
describe "#mac_address" do
|
199
|
-
it "returns the correct MAC address" do
|
200
|
-
expect(subj.mac_address).to eq("00:0c:29:ed:0e:8b")
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
describe "#netmask" do
|
205
|
-
it "returns the correct netmask" do
|
206
|
-
expect(subj.netmask).to eq("255.255.255.0")
|
207
|
-
end
|
208
|
-
|
209
|
-
it 'does not blow-up, when no ip assigned' do
|
210
|
-
expect(subj_no_net.netmask).to eq(nil)
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
describe "#netmask6" do
|
215
|
-
it "returns the correct global netmask" do
|
216
|
-
expect(subj.netmask6).to eq("ffff:ffff:ffff:ffff:ffff:ffff::")
|
217
|
-
end
|
218
|
-
|
219
|
-
it "returns the correct link local netmask" do
|
220
|
-
expect(subj.netmask6(:link)).to eq("ffff:ffff:ffff:ffff::")
|
221
|
-
end
|
222
|
-
|
223
|
-
it "raises ArgumentError when given a bad scope" do
|
224
|
-
expect { subj.netmask6(:garbage) }.to raise_error(ArgumentError)
|
225
|
-
end
|
226
|
-
end
|
227
|
-
|
228
|
-
describe '#prefix' do
|
229
|
-
it 'returns the correct prefix' do
|
230
|
-
expect(subj.prefix).to eq(24)
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
describe '#prefix6' do
|
235
|
-
it 'returns the correct global prefix length' do
|
236
|
-
expect(subj.prefix6).to eq(96)
|
237
|
-
end
|
238
|
-
|
239
|
-
it 'returns the correct link local prefix length' do
|
240
|
-
expect(subj.prefix6(:link)).to eq(64)
|
241
|
-
end
|
242
|
-
|
243
|
-
it 'raises ArgumentError when given a bad scope' do
|
244
|
-
expect { subj.prefix6(:garbage) }.to raise_error(ArgumentError)
|
245
|
-
end
|
246
|
-
end
|
247
|
-
|
248
|
-
describe "#gateway" do
|
249
|
-
it "returns the correct gateway address" do
|
250
|
-
expect(subj.gateway).to eq("192.168.1.1")
|
251
|
-
end
|
252
|
-
end
|
253
|
-
|
254
|
-
describe '#gateway6' do
|
255
|
-
it 'returns the correct default gateway for IPv6 routing' do
|
256
|
-
expect(subj.gateway6).to eq('d:e:a:d:b:e:e:f')
|
257
|
-
end
|
258
|
-
end
|
259
|
-
|
260
|
-
describe "#start" do
|
261
|
-
it "returns true on success" do
|
262
|
-
expect(AwesomeSpawn).to receive(:run).with(*IFUP_ARGS).and_return(result("", 0))
|
263
|
-
expect(subj.start).to be true
|
264
|
-
end
|
265
|
-
|
266
|
-
it "returns false on failure" do
|
267
|
-
expect(AwesomeSpawn).to receive(:run).with(*IFUP_ARGS).and_return(result("", 1))
|
268
|
-
expect(subj.start).to be false
|
269
|
-
end
|
270
|
-
end
|
271
|
-
|
272
|
-
describe "#stop" do
|
273
|
-
it "returns true on success" do
|
274
|
-
expect(AwesomeSpawn).to receive(:run).with(*IFDOWN_ARGS).and_return(result("", 0))
|
275
|
-
expect(subj.stop).to be true
|
276
|
-
end
|
277
|
-
|
278
|
-
it "returns false on failure" do
|
279
|
-
expect(AwesomeSpawn).to receive(:run).with(*IFDOWN_ARGS).and_return(result("", 1))
|
280
|
-
expect(subj.stop).to be false
|
281
|
-
end
|
282
|
-
end
|
283
|
-
end
|
284
|
-
end
|