linux_admin 1.2.1 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/linux_admin.rb +0 -8
  4. data/lib/linux_admin/chrony.rb +1 -0
  5. data/lib/linux_admin/disk.rb +31 -7
  6. data/lib/linux_admin/fstab.rb +29 -14
  7. data/lib/linux_admin/partition.rb +1 -1
  8. data/lib/linux_admin/registration_system.rb +8 -4
  9. data/lib/linux_admin/scap.rb +1 -1
  10. data/lib/linux_admin/service/sys_v_init_service.rb +2 -1
  11. data/lib/linux_admin/service/systemd_service.rb +6 -2
  12. data/lib/linux_admin/version.rb +1 -1
  13. metadata +36 -120
  14. data/lib/linux_admin/registration_system/rhn.rb +0 -111
  15. data/spec/chrony_spec.rb +0 -64
  16. data/spec/common_spec.rb +0 -37
  17. data/spec/data/rhn/output_rhn-channel_list +0 -2
  18. data/spec/data/rhn/output_rhn-channel_list_available +0 -4
  19. data/spec/data/rhn/systemid +0 -57
  20. data/spec/data/rhn/systemid.missing_system_id +0 -57
  21. data/spec/data/rpm/cmd_output_for_list_installed +0 -20
  22. data/spec/data/subscription_manager/output_list_all_available +0 -42
  23. data/spec/data/subscription_manager/output_list_installed_not_subscribed +0 -19
  24. data/spec/data/subscription_manager/output_list_installed_subscribed +0 -19
  25. data/spec/data/subscription_manager/output_orgs +0 -6
  26. data/spec/data/subscription_manager/output_repos +0 -18
  27. data/spec/data/time_date/timedatectl_output +0 -14
  28. data/spec/data/yum/first.repo +0 -19
  29. data/spec/data/yum/output_repo_list +0 -13
  30. data/spec/data/yum/output_repoquery_multiple +0 -3
  31. data/spec/data/yum/output_repoquery_single +0 -1
  32. data/spec/data/yum/second.repo +0 -9
  33. data/spec/deb_spec.rb +0 -52
  34. data/spec/disk_spec.rb +0 -244
  35. data/spec/distro_spec.rb +0 -77
  36. data/spec/dns_spec.rb +0 -105
  37. data/spec/etc_issue_spec.rb +0 -37
  38. data/spec/fstab_spec.rb +0 -66
  39. data/spec/hardware_spec.rb +0 -46
  40. data/spec/hosts_spec.rb +0 -150
  41. data/spec/ip_address_spec.rb +0 -148
  42. data/spec/logical_volume_spec.rb +0 -166
  43. data/spec/mountable_spec.rb +0 -182
  44. data/spec/network_interface/network_interface_rh_spec.rb +0 -291
  45. data/spec/network_interface_spec.rb +0 -284
  46. data/spec/partition_spec.rb +0 -24
  47. data/spec/physical_volume_spec.rb +0 -101
  48. data/spec/registration_system_spec.rb +0 -85
  49. data/spec/rhn_spec.rb +0 -144
  50. data/spec/rpm_spec.rb +0 -85
  51. data/spec/scap_spec.rb +0 -48
  52. data/spec/service/sys_v_init_service_spec.rb +0 -127
  53. data/spec/service/systemd_service_spec.rb +0 -133
  54. data/spec/service_spec.rb +0 -54
  55. data/spec/spec_helper.rb +0 -116
  56. data/spec/ssh_spec.rb +0 -53
  57. data/spec/subscription_manager_spec.rb +0 -228
  58. data/spec/system_spec.rb +0 -15
  59. data/spec/time_date_spec.rb +0 -106
  60. data/spec/volume_group_spec.rb +0 -99
  61. data/spec/yum_spec.rb +0 -155
@@ -1,105 +0,0 @@
1
- describe LinuxAdmin::Dns do
2
- RESOLV_CONF = <<DNS_END
3
- # Generated by NetworkManager
4
- search test.example.com test.two.example.com. example.com.
5
- nameserver 192.168.1.2
6
- nameserver 10.10.1.2
7
- nameserver 192.168.252.3
8
- DNS_END
9
-
10
- SEARCH_ORDER = %w(test.example.com test.two.example.com. example.com.)
11
- NAMESERVERS = %w(192.168.1.2 10.10.1.2 192.168.252.3)
12
-
13
- NEW_CONF = <<DNS_END
14
- search new.test.example.com other.test.example.com
15
- nameserver 192.168.3.4
16
- nameserver 10.10.11.12
17
- DNS_END
18
-
19
- NO_SEARCH = <<DNS_END
20
- nameserver 192.168.1.2
21
- nameserver 10.10.1.2
22
- nameserver 192.168.252.3
23
- DNS_END
24
-
25
- NO_NAMESERVER = <<DNS_END
26
- search test.example.com test.two.example.com. example.com.
27
- DNS_END
28
-
29
- NEW_ORDER = %w(new.test.example.com other.test.example.com)
30
- NEW_NS = %w(192.168.3.4 10.10.11.12)
31
-
32
- FILE = "/etc/dns_file"
33
-
34
- subject do
35
- allow(File).to receive(:read).and_return(RESOLV_CONF)
36
- described_class.new(FILE)
37
- end
38
-
39
- describe ".new" do
40
- it "sets the filename" do
41
- expect(subject.filename).to eq(FILE)
42
- end
43
-
44
- it "parses the nameservers" do
45
- expect(subject.nameservers).to eq(NAMESERVERS)
46
- end
47
-
48
- it "parses the search order" do
49
- expect(subject.search_order).to eq(SEARCH_ORDER)
50
- end
51
- end
52
-
53
- describe "#reload" do
54
- it "reloads the nameservers" do
55
- expect(subject.nameservers).to eq(NAMESERVERS)
56
-
57
- allow(File).to receive(:read).and_return(NEW_CONF)
58
- subject.reload
59
-
60
- expect(subject.nameservers).to eq(NEW_NS)
61
- end
62
-
63
- it "reloads the search order" do
64
- expect(subject.search_order).to eq(SEARCH_ORDER)
65
-
66
- allow(File).to receive(:read).and_return(NEW_CONF)
67
- subject.reload
68
-
69
- expect(subject.search_order).to eq(NEW_ORDER)
70
- end
71
- end
72
-
73
- describe "#save" do
74
- it "writes the correct contents" do
75
- expect(File).to receive(:write) do |file, contents|
76
- expect(file).to eq(subject.filename)
77
- expect(contents).to eq(NEW_CONF)
78
- end
79
-
80
- subject.search_order = NEW_ORDER
81
- subject.nameservers = NEW_NS
82
- subject.save
83
- end
84
-
85
- it "omits search if the list is empty" do
86
- expect(File).to receive(:write) do |file, contents|
87
- expect(file).to eq(subject.filename)
88
- expect(contents).to eq(NO_SEARCH)
89
- end
90
-
91
- subject.search_order = []
92
- subject.save
93
- end
94
-
95
- it "omits nameserver if the list is empty" do
96
- expect(File).to receive(:write) do |file, contents|
97
- expect(file).to eq(subject.filename)
98
- expect(contents).to eq(NO_NAMESERVER)
99
- end
100
-
101
- subject.nameservers = []
102
- subject.save
103
- end
104
- end
105
- end
@@ -1,37 +0,0 @@
1
- describe LinuxAdmin::EtcIssue do
2
- subject { described_class.instance }
3
- before do
4
- # Reset the singleton so subsequent tests get a new instance
5
- subject.refresh
6
- end
7
-
8
- it "should not find the phrase when the file is missing" do
9
- expect(File).to receive(:exist?).with('/etc/issue').at_least(:once).and_return(false)
10
- expect(subject).not_to include("phrase")
11
- end
12
-
13
- it "should not find phrase when the file is empty" do
14
- etc_issue_contains("")
15
- expect(subject).not_to include("phrase")
16
- end
17
-
18
- it "should not find phrase when the file has a different phrase" do
19
- etc_issue_contains("something\nelse")
20
- expect(subject).not_to include("phrase")
21
- end
22
-
23
- it "should find phrase in same case" do
24
- etc_issue_contains("phrase")
25
- expect(subject).to include("phrase")
26
- end
27
-
28
- it "should find upper phrase in file" do
29
- etc_issue_contains("PHRASE\nother")
30
- expect(subject).to include("phrase")
31
- end
32
-
33
- it "should find phrase when searching with upper" do
34
- etc_issue_contains("other\nphrase")
35
- expect(subject).to include("PHRASE")
36
- end
37
- end
@@ -1,66 +0,0 @@
1
- describe LinuxAdmin::FSTab do
2
- subject { described_class.dup }
3
-
4
- it "has newline, single spaces, tab" do
5
- fstab = <<eos
6
-
7
-
8
-
9
- eos
10
- expect(File).to receive(:read).with('/etc/fstab').and_return(fstab)
11
- expect(subject.instance.entries.size).to eq(3)
12
- expect(subject.instance.entries.any?(&:has_content?)).to be_falsey
13
- end
14
-
15
- it "creates FSTabEntry for each line in fstab" do
16
- fstab = <<eos
17
- # Comment, indented comment, comment with device information
18
- # /dev/sda1 / ext4 defaults 1 1
19
- # /dev/sda1 / ext4 defaults 1 1
20
-
21
- /dev/sda1 / ext4 defaults 1 1
22
- /dev/sda2 swap swap defaults 0 0
23
- eos
24
- expect(File).to receive(:read).with('/etc/fstab').and_return(fstab)
25
- entries = subject.instance.entries
26
- expect(entries.size).to eq(6)
27
-
28
- expect(entries[0].comment).to eq("# Comment, indented comment, comment with device information\n")
29
- expect(entries[1].comment).to eq("# /dev/sda1 / ext4 defaults 1 1\n")
30
- expect(entries[2].comment).to eq("# /dev/sda1 / ext4 defaults 1 1\n")
31
- expect(entries[3].comment).to eq(nil)
32
- expect(entries[4].device).to eq('/dev/sda1')
33
- expect(entries[4].mount_point).to eq('/')
34
- expect(entries[4].fs_type).to eq('ext4')
35
- expect(entries[4].mount_options).to eq('defaults')
36
- expect(entries[4].dumpable).to eq(1)
37
- expect(entries[4].fsck_order).to eq(1)
38
-
39
- expect(entries[5].device).to eq('/dev/sda2')
40
- expect(entries[5].mount_point).to eq('swap')
41
- expect(entries[5].fs_type).to eq('swap')
42
- expect(entries[5].mount_options).to eq('defaults')
43
- expect(entries[5].dumpable).to eq(0)
44
- expect(entries[5].fsck_order).to eq(0)
45
- end
46
-
47
- describe "#write!" do
48
- it "writes entries to /etc/fstab" do
49
- # maually set fstab
50
- entry = LinuxAdmin::FSTabEntry.new
51
- entry.device = '/dev/sda1'
52
- entry.mount_point = '/'
53
- entry.fs_type = 'ext4'
54
- entry.mount_options = 'defaults'
55
- entry.dumpable = 1
56
- entry.fsck_order = 1
57
- entry.comment = "# more"
58
- allow_any_instance_of(subject).to receive(:refresh) # in case this is the first time we reference .instance
59
- subject.instance.maximum_column_lengths = [9, 1, 4, 8, 1, 1, 1]
60
- subject.instance.entries = [entry]
61
-
62
- expect(File).to receive(:write).with('/etc/fstab', "/dev/sda1 / ext4 defaults 1 1 # more\n")
63
- subject.instance.write!
64
- end
65
- end
66
- end
@@ -1,46 +0,0 @@
1
- describe LinuxAdmin::Hardware do
2
- CONTENT = <<-EOF
3
- processor : 0
4
- vendor_id : GenuineIntel
5
- cpu family : 6
6
- model : 58
7
- model name : Intel(R) Core(TM) i7-3740QM CPU @ 2.70GHz
8
- stepping : 9
9
- microcode : 0x17
10
- cpu MHz : 2614.148
11
- cache size : 6144 KB
12
- physical id : 0
13
- siblings : 8
14
- core id : 0
15
- cpu cores : 4
16
- apicid : 0
17
- initial apicid : 0
18
- fpu : yes
19
- fpu_exception : yes
20
- cpuid level : 13
21
- wp : yes
22
- flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm ida arat epb pln pts dtherm tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms xsaveopt
23
- bugs :
24
- bogomips : 5387.35
25
- clflush size : 64
26
- cache_alignment : 64
27
- address sizes : 36 bits physical, 48 bits virtual
28
- power management:
29
-
30
- processor : 1
31
-
32
- processor : 2
33
-
34
- processor : 3
35
- processor : 4
36
- processor : 5
37
- processor : 6
38
- processor : 7
39
- EOF
40
-
41
- it "total_cores" do
42
- allow(File).to receive(:readlines).and_return(CONTENT.lines)
43
-
44
- expect(described_class.new.total_cores).to eq(8)
45
- end
46
- end
@@ -1,150 +0,0 @@
1
- describe LinuxAdmin::Hosts do
2
- TEST_HOSTNAME = "test-hostname"
3
- etc_hosts = "\n #Some Comment\n127.0.0.1\tlocalhost localhost.localdomain # with a comment\n127.0.1.1 my.domain.local"
4
- before do
5
- allow(File).to receive(:read).and_return(etc_hosts)
6
- @instance = LinuxAdmin::Hosts.new
7
- end
8
-
9
- describe "#reload" do
10
- it "sets raw_lines" do
11
- expected_array = ["", " #Some Comment", "127.0.0.1\tlocalhost localhost.localdomain # with a comment", "127.0.1.1 my.domain.local"]
12
- expect(@instance.raw_lines).to eq(expected_array)
13
- end
14
-
15
- it "sets parsed_file" do
16
- expected_hash = [{:blank=>true}, {:comment=>"Some Comment"}, {:address=>"127.0.0.1", :hosts=>["localhost", "localhost.localdomain"], :comment=>"with a comment"}, {:address=>"127.0.1.1", :hosts=>["my.domain.local"]}]
17
- expect(@instance.parsed_file).to eq(expected_hash)
18
- end
19
- end
20
-
21
- describe "#update_entry" do
22
- it "removes an existing entry and creates a new one" do
23
- expected_hash = [{:blank=>true}, {:comment=>"Some Comment"}, {:address=>"127.0.0.1", :hosts=>["localhost", "localhost.localdomain"], :comment=>"with a comment"}, {:address=>"127.0.1.1", :hosts=>[]}, {:address=>"1.2.3.4", :hosts=>["my.domain.local"], :comment=>nil}]
24
- @instance.update_entry("1.2.3.4", "my.domain.local")
25
- expect(@instance.parsed_file).to eq(expected_hash)
26
- end
27
-
28
- it "updates an existing entry" do
29
- expected_hash = [{:blank=>true}, {:comment=>"Some Comment"}, {:address=>"127.0.0.1", :hosts=>["localhost", "localhost.localdomain", "new.domain.local"], :comment=>"with a comment"}, {:address=>"127.0.1.1", :hosts=>["my.domain.local"]}]
30
- @instance.update_entry("127.0.0.1", "new.domain.local")
31
- expect(@instance.parsed_file).to eq(expected_hash)
32
- end
33
- end
34
-
35
- describe "#set_loopback_hostname" do
36
- etc_hosts_v6_loopback = <<-EOT
37
-
38
- #Some Comment
39
- ::1\tlocalhost localhost.localdomain # with a comment
40
- 127.0.0.1\tlocalhost localhost.localdomain # with a comment
41
- 127.0.1.1 my.domain.local
42
- EOT
43
-
44
- before do
45
- allow(File).to receive(:read).and_return(etc_hosts_v6_loopback)
46
- @instance_v6_loopback = LinuxAdmin::Hosts.new
47
- end
48
-
49
- it "adds the hostname to the start of the hosts list for the loopback addresses" do
50
- expected_hash = [{:blank => true},
51
- {:comment => "Some Comment"},
52
- {:address => "::1",
53
- :hosts => ["examplehost.example.com", "localhost", "localhost.localdomain"],
54
- :comment => "with a comment"},
55
- {:address => "127.0.0.1",
56
- :hosts => ["examplehost.example.com", "localhost", "localhost.localdomain"],
57
- :comment => "with a comment"},
58
- {:address => "127.0.1.1", :hosts => ["my.domain.local"]}]
59
- @instance_v6_loopback.set_loopback_hostname("examplehost.example.com")
60
- expect(@instance_v6_loopback.parsed_file).to eq(expected_hash)
61
- end
62
- end
63
-
64
- describe "#set_canonical_hostname" do
65
- it "removes an existing entry and creates a new one" do
66
- expected_hash = [{:blank => true},
67
- {:comment => "Some Comment"},
68
- {:address => "127.0.0.1", :hosts => ["localhost", "localhost.localdomain"], :comment => "with a comment"},
69
- {:address => "127.0.1.1", :hosts => []},
70
- {:address => "1.2.3.4", :hosts => ["my.domain.local"], :comment => nil}]
71
- @instance.set_canonical_hostname("1.2.3.4", "my.domain.local")
72
- expect(@instance.parsed_file).to eq(expected_hash)
73
- end
74
-
75
- it "adds the hostname to the start of the hosts list" do
76
- expected_hash = [{:blank => true},
77
- {:comment => "Some Comment"},
78
- {:address => "127.0.0.1", :hosts => ["examplehost.example.com", "localhost", "localhost.localdomain"], :comment => "with a comment"},
79
- {:address => "127.0.1.1", :hosts => ["my.domain.local"]}]
80
- @instance.set_canonical_hostname("127.0.0.1", "examplehost.example.com")
81
- expect(@instance.parsed_file).to eq(expected_hash)
82
- end
83
- end
84
-
85
- describe "#save" do
86
- it "properly generates file with new content" do
87
- allow(File).to receive(:write)
88
- expected_array = ["", "#Some Comment", "127.0.0.1 localhost localhost.localdomain #with a comment", "127.0.1.1 my.domain.local", "1.2.3.4 test"]
89
- @instance.update_entry("1.2.3.4", "test")
90
- @instance.save
91
- expect(@instance.raw_lines).to eq(expected_array)
92
- end
93
-
94
- it "properly generates file with removed content" do
95
- allow(File).to receive(:write)
96
- expected_array = ["", "#Some Comment", "127.0.0.1 localhost localhost.localdomain my.domain.local #with a comment"]
97
- @instance.update_entry("127.0.0.1", "my.domain.local")
98
- @instance.save
99
- expect(@instance.raw_lines).to eq(expected_array)
100
- end
101
-
102
- it "ends the file with a new line" do
103
- expect(File).to receive(:write) do |_file, contents|
104
- expect(contents).to end_with("\n")
105
- end
106
- @instance.save
107
- end
108
- end
109
-
110
- describe "#hostname=" do
111
- it "sets the hostname using hostnamectl when the command exists" do
112
- spawn_args = [
113
- LinuxAdmin::Common.cmd('hostnamectl'),
114
- :params => ['set-hostname', TEST_HOSTNAME]
115
- ]
116
- expect(LinuxAdmin::Common).to receive(:cmd?).with("hostnamectl").and_return(true)
117
- expect(AwesomeSpawn).to receive(:run!).with(*spawn_args)
118
- @instance.hostname = TEST_HOSTNAME
119
- end
120
-
121
- it "sets the hostname with hostname when hostnamectl does not exist" do
122
- spawn_args = [
123
- LinuxAdmin::Common.cmd('hostname'),
124
- :params => {:file => "/etc/hostname"}
125
- ]
126
- expect(LinuxAdmin::Common).to receive(:cmd?).with("hostnamectl").and_return(false)
127
- expect(File).to receive(:write).with("/etc/hostname", TEST_HOSTNAME)
128
- expect(AwesomeSpawn).to receive(:run!).with(*spawn_args)
129
- @instance.hostname = TEST_HOSTNAME
130
- end
131
- end
132
-
133
- describe "#hostname" do
134
- let(:spawn_args) do
135
- [LinuxAdmin::Common.cmd('hostname'), {}]
136
- end
137
-
138
- it "returns the hostname" do
139
- result = AwesomeSpawn::CommandResult.new("", TEST_HOSTNAME, nil, 0)
140
- expect(AwesomeSpawn).to receive(:run).with(*spawn_args).and_return(result)
141
- expect(@instance.hostname).to eq(TEST_HOSTNAME)
142
- end
143
-
144
- it "returns nil when the command fails" do
145
- result = AwesomeSpawn::CommandResult.new("", "", "An error has happened", 1)
146
- expect(AwesomeSpawn).to receive(:run).with(*spawn_args).and_return(result)
147
- expect(@instance.hostname).to be_nil
148
- end
149
- end
150
- end
@@ -1,148 +0,0 @@
1
- describe LinuxAdmin::IpAddress do
2
- let(:ip) { described_class.new }
3
-
4
- ADDR_SPAWN_ARGS = [
5
- LinuxAdmin::Common.cmd("hostname"),
6
- :params => ["-I"]
7
- ]
8
-
9
- MAC_SPAWN_ARGS = [
10
- LinuxAdmin::Common.cmd("ip"),
11
- :params => %w(addr show eth0)
12
- ]
13
-
14
- MASK_SPAWN_ARGS = [
15
- LinuxAdmin::Common.cmd("ifconfig"),
16
- :params => %w(eth0)
17
- ]
18
-
19
- GW_SPAWN_ARGS = [
20
- LinuxAdmin::Common.cmd("ip"),
21
- :params => %w(route)
22
- ]
23
-
24
- IP_ADDR_SHOW_ETH0 = <<-IP_OUT
25
- 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
26
- link/ether 00:0c:29:ed:0e:8b brd ff:ff:ff:ff:ff:ff
27
- inet 192.168.1.9/24 brd 192.168.1.255 scope global dynamic eth0
28
- valid_lft 1297sec preferred_lft 1297sec
29
- inet6 fe80::20c:29ff:feed:e8b/64 scope link
30
- valid_lft forever preferred_lft forever
31
-
32
- IP_OUT
33
-
34
- IFCFG = <<-IP_OUT
35
- eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
36
- inet 192.168.1.9 netmask 255.255.255.0 broadcast 192.168.1.255
37
- inet6 fe80::20c:29ff:feed:e8b prefixlen 64 scopeid 0x20<link>
38
- ether 00:0c:29:ed:0e:8b txqueuelen 1000 (Ethernet)
39
- RX packets 10171 bytes 8163955 (7.7 MiB)
40
- RX errors 0 dropped 0 overruns 0 frame 0
41
- TX packets 2871 bytes 321915 (314.3 KiB)
42
- TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
43
-
44
- IP_OUT
45
-
46
- IP_ROUTE = <<-IP_OUT
47
- default via 192.168.1.1 dev eth0 proto static metric 100
48
- 192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.9 metric 100
49
- IP_OUT
50
-
51
- def result(output, exit_status)
52
- AwesomeSpawn::CommandResult.new("", output, "", exit_status)
53
- end
54
-
55
- describe "#address" do
56
- it "returns an address" do
57
- ip_addr = "192.168.1.2"
58
- expect(AwesomeSpawn).to receive(:run).with(*ADDR_SPAWN_ARGS).and_return(result(ip_addr, 0))
59
- expect(ip.address).to eq(ip_addr)
60
- end
61
-
62
- it "returns nil when no address is found" do
63
- ip_addr = ""
64
- expect(AwesomeSpawn).to receive(:run).at_least(5).times.with(*ADDR_SPAWN_ARGS).and_return(result(ip_addr, 1))
65
- expect(ip.address).to be_nil
66
- end
67
-
68
- it "returns only IPv4 addresses" do
69
- ip_addr = "fd12:3456:789a:1::1 192.168.1.2"
70
- expect(AwesomeSpawn).to receive(:run).with(*ADDR_SPAWN_ARGS).and_return(result(ip_addr, 0))
71
- expect(ip.address).to eq("192.168.1.2")
72
- end
73
- end
74
-
75
- describe "#address6" do
76
- it "returns an address" do
77
- ip_addr = "fd12:3456:789a:1::1"
78
- expect(AwesomeSpawn).to receive(:run).with(*ADDR_SPAWN_ARGS).and_return(result(ip_addr, 0))
79
- expect(ip.address6).to eq(ip_addr)
80
- end
81
-
82
- it "returns nil when no address is found" do
83
- ip_addr = ""
84
- expect(AwesomeSpawn).to receive(:run).at_least(5).times.with(*ADDR_SPAWN_ARGS).and_return(result(ip_addr, 1))
85
- expect(ip.address6).to be_nil
86
- end
87
-
88
- it "returns only IPv6 addresses" do
89
- ip_addr = "192.168.1.2 fd12:3456:789a:1::1"
90
- expect(AwesomeSpawn).to receive(:run).with(*ADDR_SPAWN_ARGS).and_return(result(ip_addr, 0))
91
- expect(ip.address6).to eq("fd12:3456:789a:1::1")
92
- end
93
- end
94
-
95
- describe "#mac_address" do
96
- it "returns the correct MAC address" do
97
- expect(AwesomeSpawn).to receive(:run).with(*MAC_SPAWN_ARGS).and_return(result(IP_ADDR_SHOW_ETH0, 0))
98
- expect(ip.mac_address("eth0")).to eq("00:0c:29:ed:0e:8b")
99
- end
100
-
101
- it "returns nil when the command fails" do
102
- expect(AwesomeSpawn).to receive(:run).with(*MAC_SPAWN_ARGS).and_return(result("", 1))
103
- expect(ip.mac_address("eth0")).to be_nil
104
- end
105
-
106
- it "returns nil if the link/ether line is not present" do
107
- bad_output = IP_ADDR_SHOW_ETH0.gsub(%r{link/ether}, "")
108
- expect(AwesomeSpawn).to receive(:run).with(*MAC_SPAWN_ARGS).and_return(result(bad_output, 0))
109
- expect(ip.mac_address("eth0")).to be_nil
110
- end
111
- end
112
-
113
- describe "#netmask" do
114
- it "returns the correct netmask" do
115
- expect(AwesomeSpawn).to receive(:run).with(*MASK_SPAWN_ARGS).and_return(result(IFCFG, 0))
116
- expect(ip.netmask("eth0")).to eq("255.255.255.0")
117
- end
118
-
119
- it "returns nil when the command fails" do
120
- expect(AwesomeSpawn).to receive(:run).with(*MASK_SPAWN_ARGS).and_return(result("", 1))
121
- expect(ip.netmask("eth0")).to be_nil
122
- end
123
-
124
- it "returns nil if the netmask line is not present" do
125
- bad_output = IFCFG.gsub(/netmask/, "")
126
- expect(AwesomeSpawn).to receive(:run).with(*MASK_SPAWN_ARGS).and_return(result(bad_output, 0))
127
- expect(ip.netmask("eth0")).to be_nil
128
- end
129
- end
130
-
131
- describe "#gateway" do
132
- it "returns the correct gateway address" do
133
- expect(AwesomeSpawn).to receive(:run).with(*GW_SPAWN_ARGS).and_return(result(IP_ROUTE, 0))
134
- expect(ip.gateway).to eq("192.168.1.1")
135
- end
136
-
137
- it "returns nil when the command fails" do
138
- expect(AwesomeSpawn).to receive(:run).with(*GW_SPAWN_ARGS).and_return(result("", 1))
139
- expect(ip.gateway).to be_nil
140
- end
141
-
142
- it "returns nil if the default line is not present" do
143
- bad_output = IP_ROUTE.gsub(/default/, "")
144
- expect(AwesomeSpawn).to receive(:run).with(*GW_SPAWN_ARGS).and_return(result(bad_output, 0))
145
- expect(ip.gateway).to be_nil
146
- end
147
- end
148
- end