linux_admin 1.2.4 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/spec/distro_spec.rb
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
describe LinuxAdmin::Distros::Distro do
|
2
|
-
let(:subject) { LinuxAdmin::Distros.local }
|
3
|
-
describe "#local" do
|
4
|
-
before do
|
5
|
-
allow(LinuxAdmin::Distros).to receive(:local).and_call_original
|
6
|
-
end
|
7
|
-
|
8
|
-
[['ubuntu', :ubuntu],
|
9
|
-
['Fedora', :fedora],
|
10
|
-
['red hat', :rhel],
|
11
|
-
['CentOS', :rhel],
|
12
|
-
['centos', :rhel]].each do |i, d|
|
13
|
-
context "/etc/issue contains '#{i}'" do
|
14
|
-
before(:each) do
|
15
|
-
etc_issue_contains(i)
|
16
|
-
exists("/etc/fedora-release" => false, "/etc/redhat-release" => false)
|
17
|
-
end
|
18
|
-
|
19
|
-
it "returns Distros.#{d}" do
|
20
|
-
distro = LinuxAdmin::Distros.send(d)
|
21
|
-
expect(subject).to eq(distro)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context "/etc/issue did not match" do
|
27
|
-
before(:each) do
|
28
|
-
etc_issue_contains('')
|
29
|
-
end
|
30
|
-
|
31
|
-
context "/etc/redhat-release exists" do
|
32
|
-
it "returns Distros.rhel" do
|
33
|
-
exists("/etc/fedora-release" => false, "/etc/redhat-release" => true)
|
34
|
-
expect(subject).to eq(LinuxAdmin::Distros.rhel)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
context "/etc/fedora-release exists" do
|
39
|
-
it "returns Distros.fedora" do
|
40
|
-
exists("/etc/fedora-release" => true, "/etc/redhat-release" => false)
|
41
|
-
expect(subject).to eq(LinuxAdmin::Distros.fedora)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
it "returns Distros.generic" do
|
47
|
-
etc_issue_contains('')
|
48
|
-
exists("/etc/fedora-release" => false, "/etc/redhat-release" => false)
|
49
|
-
expect(subject).to eq(LinuxAdmin::Distros.generic)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe "#info" do
|
54
|
-
it "dispatches to redhat lookup mechanism" do
|
55
|
-
stub_distro(LinuxAdmin::Distros.rhel)
|
56
|
-
expect(LinuxAdmin::Rpm).to receive(:info).with('ruby')
|
57
|
-
LinuxAdmin::Distros.local.info 'ruby'
|
58
|
-
end
|
59
|
-
|
60
|
-
it "dispatches to ubuntu lookup mechanism" do
|
61
|
-
stub_distro(LinuxAdmin::Distros.ubuntu)
|
62
|
-
expect(LinuxAdmin::Deb).to receive(:info).with('ruby')
|
63
|
-
LinuxAdmin::Distros.local.info 'ruby'
|
64
|
-
end
|
65
|
-
|
66
|
-
it "dispatches to ubuntu lookup mechanism" do
|
67
|
-
stub_distro(LinuxAdmin::Distros.generic)
|
68
|
-
expect { LinuxAdmin::Distros.local.info 'ruby' }.not_to raise_error
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
private
|
73
|
-
|
74
|
-
def exists(files)
|
75
|
-
files.each_pair { |file, value| allow(File).to receive(:exist?).with(file).and_return(value) }
|
76
|
-
end
|
77
|
-
end
|
data/spec/dns_spec.rb
DELETED
@@ -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
|
data/spec/etc_issue_spec.rb
DELETED
@@ -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
|
data/spec/fstab_spec.rb
DELETED
@@ -1,132 +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
|
-
expect(File).to receive(:read).with("/etc/fstab").and_return("")
|
50
|
-
|
51
|
-
subject.instance.entries << LinuxAdmin::FSTabEntry.new(
|
52
|
-
:device => '/dev/sda1',
|
53
|
-
:mount_point => '/',
|
54
|
-
:fs_type => 'ext4',
|
55
|
-
:mount_options => 'defaults',
|
56
|
-
:dumpable => 1,
|
57
|
-
:fsck_order => 1,
|
58
|
-
:comment => "# more"
|
59
|
-
)
|
60
|
-
|
61
|
-
expect(File).to receive(:write).with('/etc/fstab', "/dev/sda1 / ext4 defaults 1 1 # more\n")
|
62
|
-
|
63
|
-
subject.instance.write!
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
describe "#entries" do
|
68
|
-
it "#<< updates maximum_column_lengths" do
|
69
|
-
expect(File).to receive(:read).with("/etc/fstab").and_return("")
|
70
|
-
|
71
|
-
subject.instance.entries << LinuxAdmin::FSTabEntry.new(
|
72
|
-
:device => '/dev/sda1',
|
73
|
-
:mount_point => '/',
|
74
|
-
:fs_type => 'ext4',
|
75
|
-
:mount_options => 'defaults',
|
76
|
-
:dumpable => 1,
|
77
|
-
:fsck_order => 1,
|
78
|
-
:comment => "# more"
|
79
|
-
)
|
80
|
-
|
81
|
-
expect(subject.instance.entries.maximum_column_lengths).to eq([9, 1, 4, 8, 1, 1, 6])
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
describe "integration test" do
|
86
|
-
it "input equals output, just alignment changed" do
|
87
|
-
original_fstab = <<~END_OF_FSTAB
|
88
|
-
|
89
|
-
#
|
90
|
-
# /etc/fstab
|
91
|
-
# Created by anaconda on Wed May 29 12:37:40 2019
|
92
|
-
#
|
93
|
-
# Accessible filesystems, by reference, are maintained under '/dev/disk'
|
94
|
-
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
|
95
|
-
#
|
96
|
-
/dev/mapper/VG--MIQ-lv_os / xfs defaults 0 0
|
97
|
-
UUID=02bf07b5-2404-4779-b93c-d8eb7f2eedea /boot xfs defaults 0 0
|
98
|
-
/dev/mapper/VG--MIQ-lv_home /home xfs defaults 0 0
|
99
|
-
/dev/mapper/VG--MIQ-lv_tmp /tmp xfs defaults 0 0
|
100
|
-
/dev/mapper/VG--MIQ-lv_var /var xfs defaults 0 0
|
101
|
-
/dev/mapper/VG--MIQ-lv_var_log /var/log xfs defaults 0 0
|
102
|
-
/dev/mapper/VG--MIQ-lv_var_log_audit /var/log/audit xfs defaults 0 0
|
103
|
-
/dev/mapper/VG--MIQ-lv_log /var/www/miq/vmdb/log xfs defaults 0 0
|
104
|
-
/dev/mapper/VG--MIQ-lv_swap swap swap defaults 0 0
|
105
|
-
END_OF_FSTAB
|
106
|
-
|
107
|
-
new_fstab = <<~END_OF_FSTAB
|
108
|
-
|
109
|
-
# /etc/fstab
|
110
|
-
# Created by anaconda on Wed May 29 12:37:40 2019
|
111
|
-
|
112
|
-
# Accessible filesystems, by reference, are maintained under '/dev/disk'
|
113
|
-
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
|
114
|
-
|
115
|
-
/dev/mapper/VG--MIQ-lv_os / xfs defaults 0 0
|
116
|
-
UUID=02bf07b5-2404-4779-b93c-d8eb7f2eedea /boot xfs defaults 0 0
|
117
|
-
/dev/mapper/VG--MIQ-lv_home /home xfs defaults 0 0
|
118
|
-
/dev/mapper/VG--MIQ-lv_tmp /tmp xfs defaults 0 0
|
119
|
-
/dev/mapper/VG--MIQ-lv_var /var xfs defaults 0 0
|
120
|
-
/dev/mapper/VG--MIQ-lv_var_log /var/log xfs defaults 0 0
|
121
|
-
/dev/mapper/VG--MIQ-lv_var_log_audit /var/log/audit xfs defaults 0 0
|
122
|
-
/dev/mapper/VG--MIQ-lv_log /var/www/miq/vmdb/log xfs defaults 0 0
|
123
|
-
/dev/mapper/VG--MIQ-lv_swap swap swap defaults 0 0
|
124
|
-
END_OF_FSTAB
|
125
|
-
|
126
|
-
expect(File).to receive(:read).with("/etc/fstab").and_return(original_fstab)
|
127
|
-
expect(File).to receive(:write).with("/etc/fstab", new_fstab)
|
128
|
-
|
129
|
-
subject.instance.write!
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
data/spec/hardware_spec.rb
DELETED
@@ -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
|
data/spec/hosts_spec.rb
DELETED
@@ -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
|