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,15 +0,0 @@
1
- describe LinuxAdmin::System do
2
- describe "#reboot!" do
3
- it "reboots the system" do
4
- expect(LinuxAdmin::Common).to receive(:run!).with(LinuxAdmin::Common.cmd(:shutdown), :params => {'-r' => 'now'})
5
- LinuxAdmin::System.reboot!
6
- end
7
- end
8
-
9
- describe "#shutdown!" do
10
- it "shuts down the system" do
11
- expect(LinuxAdmin::Common).to receive(:run!).with(LinuxAdmin::Common.cmd(:shutdown), :params => {'-h' => '0'})
12
- LinuxAdmin::System.shutdown!
13
- end
14
- end
15
- end
@@ -1,106 +0,0 @@
1
- describe LinuxAdmin::TimeDate do
2
- RUN_COMMAND = LinuxAdmin::Common.cmd("timedatectl")
3
-
4
- def timedatectl_result
5
- output = File.read(Pathname.new(data_file_path("time_date/timedatectl_output")))
6
- AwesomeSpawn::CommandResult.new("", output, "", 0)
7
- end
8
-
9
- describe ".system_timezone_detailed" do
10
- it "returns the correct timezone" do
11
- awesome_spawn_args = [
12
- RUN_COMMAND,
13
- :params => ["status"]
14
- ]
15
- expect(AwesomeSpawn).to receive(:run).with(*awesome_spawn_args).and_return(timedatectl_result)
16
- tz = described_class.system_timezone_detailed
17
- expect(tz).to eq("America/New_York (EDT, -0400)")
18
- end
19
- end
20
-
21
- describe ".system_timezone" do
22
- it "returns the correct timezone" do
23
- awesome_spawn_args = [
24
- RUN_COMMAND,
25
- :params => ["status"]
26
- ]
27
- expect(AwesomeSpawn).to receive(:run).with(*awesome_spawn_args).and_return(timedatectl_result)
28
- tz = described_class.system_timezone
29
- expect(tz).to eq("America/New_York")
30
- end
31
- end
32
-
33
- describe ".timezones" do
34
- let(:timezones) do
35
- <<-EOS
36
- Africa/Bangui
37
- Africa/Banjul
38
- Africa/Bissau
39
- Africa/Blantyre
40
- Africa/Brazzaville
41
- Africa/Bujumbura
42
- Africa/Cairo
43
- America/Havana
44
- America/Hermosillo
45
- America/Indiana/Indianapolis
46
- America/Indiana/Knox
47
- America/Argentina/San_Juan
48
- America/Argentina/San_Luis
49
- America/Argentina/Tucuman
50
- America/Argentina/Ushuaia
51
- EOS
52
- end
53
-
54
- it "returns the correct list" do
55
- awesome_spawn_args = [
56
- RUN_COMMAND,
57
- :params => ["list-timezones"]
58
- ]
59
- result = AwesomeSpawn::CommandResult.new("", timezones, "", 0)
60
- expect(AwesomeSpawn).to receive(:run!).with(*awesome_spawn_args).and_return(result)
61
- expect(described_class.timezones).to eq(timezones.split("\n"))
62
- end
63
- end
64
-
65
- describe ".system_time=" do
66
- it "sets the time" do
67
- time = Time.new(2015, 1, 1, 1, 1, 1)
68
- awesome_spawn_args = [
69
- RUN_COMMAND,
70
- :params => ["set-time", "2015-01-01 01:01:01", :adjust_system_clock]
71
- ]
72
- expect(AwesomeSpawn).to receive(:run!).with(*awesome_spawn_args)
73
- described_class.system_time = time
74
- end
75
-
76
- it "raises when the command fails" do
77
- time = Time.new(2015, 1, 1, 1, 1, 1)
78
- err = AwesomeSpawn::CommandResultError.new("message", nil)
79
- allow(AwesomeSpawn).to receive(:run!).and_raise(err)
80
- expect do
81
- described_class.send(:system_time=, time)
82
- end.to raise_error(described_class::TimeCommandError, "message")
83
- end
84
- end
85
-
86
- describe ".system_timezone=" do
87
- it "sets the timezone" do
88
- zone = "Location/City"
89
- awesome_spawn_args = [
90
- RUN_COMMAND,
91
- :params => ["set-timezone", zone]
92
- ]
93
- expect(AwesomeSpawn).to receive(:run!).with(*awesome_spawn_args)
94
- described_class.system_timezone = zone
95
- end
96
-
97
- it "raises when the command fails" do
98
- zone = "Location/City"
99
- err = AwesomeSpawn::CommandResultError.new("message", nil)
100
- allow(AwesomeSpawn).to receive(:run!).and_raise(err)
101
- expect do
102
- described_class.send(:system_timezone=, zone)
103
- end.to raise_error(described_class::TimeCommandError, "message")
104
- end
105
- end
106
- end
@@ -1,99 +0,0 @@
1
- describe LinuxAdmin::VolumeGroup do
2
- before(:each) do
3
- @groups = <<eos
4
- vg_foobar:r/w:772:-1:0:2:2:-1:0:1:1:12058624:32768:368:368:0:tILZUF-IspH-H90I-pT5j-vVFl-b76L-zWx3CW
5
- eos
6
- end
7
-
8
- after(:each) do
9
- # reset local copies of volumes / groups
10
- LinuxAdmin::LogicalVolume.instance_variable_set(:@lvs, nil)
11
- LinuxAdmin::PhysicalVolume.instance_variable_set(:@pvs, nil)
12
- described_class.instance_variable_set(:@vgs, nil)
13
- end
14
-
15
- describe "#attach_to" do
16
- it "uses lvextend" do
17
- vg = described_class.new :name => 'vg'
18
- lv = LinuxAdmin::LogicalVolume.new :name => 'lv', :volume_group => vg
19
- expect(LinuxAdmin::Common).to receive(:run!)
20
- .with(LinuxAdmin::Common.cmd(:lvextend), :params => %w(lv vg))
21
- vg.attach_to(lv)
22
- end
23
-
24
- it "returns self" do
25
- vg = described_class.new :name => 'vg'
26
- lv = LinuxAdmin::LogicalVolume.new :name => 'lv', :volume_group => vg
27
- allow(LinuxAdmin::Common).to receive(:run!)
28
- expect(vg.attach_to(lv)).to eq(vg)
29
- end
30
- end
31
-
32
- describe "#extend_with" do
33
- it "uses vgextend" do
34
- vg = described_class.new :name => 'vg'
35
- pv = LinuxAdmin::PhysicalVolume.new :device_name => '/dev/hda'
36
- expect(LinuxAdmin::Common).to receive(:run!)
37
- .with(LinuxAdmin::Common.cmd(:vgextend), :params => ['vg', '/dev/hda'])
38
- vg.extend_with(pv)
39
- end
40
-
41
- it "assigns volume group to physical volume" do
42
- vg = described_class.new :name => 'vg'
43
- pv = LinuxAdmin::PhysicalVolume.new :device_name => '/dev/hda'
44
- allow(LinuxAdmin::Common).to receive(:run!)
45
- vg.extend_with(pv)
46
- expect(pv.volume_group).to eq(vg)
47
- end
48
-
49
- it "returns self" do
50
- vg = described_class.new :name => 'vg'
51
- pv = LinuxAdmin::PhysicalVolume.new :device_name => '/dev/hda'
52
- allow(LinuxAdmin::Common).to receive(:run!)
53
- expect(vg.extend_with(pv)).to eq(vg)
54
- end
55
- end
56
-
57
- describe "#create" do
58
- before(:each) do
59
- @pv = LinuxAdmin::PhysicalVolume.new :device_name => '/dev/hda'
60
- end
61
-
62
- it "uses vgcreate" do
63
- described_class.instance_variable_set(:@vgs, [])
64
- expect(LinuxAdmin::Common).to receive(:run!)
65
- .with(LinuxAdmin::Common.cmd(:vgcreate), :params => ['vg', '/dev/hda'])
66
- described_class.create 'vg', @pv
67
- end
68
-
69
- it "returns new volume group" do
70
- allow(LinuxAdmin::Common).to receive_messages(:run! => double(:output => ""))
71
- vg = described_class.create 'vg', @pv
72
- expect(vg).to be_an_instance_of(described_class)
73
- expect(vg.name).to eq('vg')
74
- end
75
-
76
- it "adds volume group to local registry" do
77
- allow(LinuxAdmin::Common).to receive_messages(:run! => double(:output => ""))
78
- vg = described_class.create 'vg', @pv
79
- expect(described_class.scan).to include(vg)
80
- end
81
- end
82
-
83
- describe "#scan" do
84
- it "uses vgdisplay" do
85
- expect(LinuxAdmin::Common).to receive(:run!)
86
- .with(LinuxAdmin::Common.cmd(:vgdisplay), :params => {'-c' => nil})
87
- .and_return(double(:output => @groups))
88
- described_class.scan
89
- end
90
-
91
- it "returns local volume groups" do
92
- expect(LinuxAdmin::Common).to receive(:run!).and_return(double(:output => @groups))
93
- vgs = described_class.scan
94
-
95
- expect(vgs[0]).to be_an_instance_of(described_class)
96
- expect(vgs[0].name).to eq('vg_foobar')
97
- end
98
- end
99
- end
@@ -1,155 +0,0 @@
1
- describe LinuxAdmin::Yum do
2
- before(:each) do
3
- allow(FileUtils).to receive_messages(:mkdir_p => true)
4
- end
5
-
6
- context ".create_repo" do
7
- it "default arguments" do
8
- expect(LinuxAdmin::Common).to receive(:run!).once
9
- .with("createrepo", :params => {nil => "some/path", "--database" => nil, "--unique-md-filenames" => nil})
10
- described_class.create_repo("some/path")
11
- end
12
-
13
- it "bare create" do
14
- expect(LinuxAdmin::Common).to receive(:run!).once.with("createrepo", :params => {nil => "some/path"})
15
- described_class.create_repo("some/path", :database => false, :unique_file_names => false)
16
- end
17
- end
18
-
19
- context ".download_packages" do
20
- it "with valid input" do
21
- expect(LinuxAdmin::Common).to receive(:run!).once
22
- .with("repotrack", :params => {"-p" => "some/path", nil => "pkg_a pkg_b"})
23
- described_class.download_packages("some/path", "pkg_a pkg_b")
24
- end
25
-
26
- it "without mirror type" do
27
- expect { described_class.download_packages("some/path", "pkg_a pkg_b", :mirror_type => nil) }.to raise_error(ArgumentError)
28
- end
29
- end
30
-
31
- it ".repo_settings" do
32
- expect(described_class).to receive(:parse_repo_dir).once.with("/etc/yum.repos.d").and_return(true)
33
- expect(described_class.repo_settings).to be_truthy
34
- end
35
-
36
- it ".parse_repo_dir" do
37
- expect(described_class.parse_repo_dir(data_file_path("yum"))).to eq({
38
- File.join(data_file_path("yum"), "first.repo") =>
39
- { "my-local-repo-a" =>
40
- { "name" =>"My Local Repo A",
41
- "baseurl" =>"https://mirror.example.com/a/content/os_ver",
42
- "enabled" =>0,
43
- "gpgcheck" =>1,
44
- "gpgkey" =>"file:///etc/pki/rpm-gpg/RPM-GPG-KEY-my-local-server",
45
- "sslverify" =>1,
46
- "sslcacert" =>"/etc/rhsm/ca/my-loacl-server.pem",
47
- "sslclientkey" =>"/etc/pki/entitlement/0123456789012345678-key.pem",
48
- "sslclientcert" =>"/etc/pki/entitlement/0123456789012345678.pem",
49
- "metadata_expire" =>86400},
50
- "my-local-repo-b" =>
51
- { "name" =>"My Local Repo B",
52
- "baseurl" =>"https://mirror.example.com/b/content/os_ver",
53
- "enabled" =>1,
54
- "gpgcheck" =>0,
55
- "sslverify" =>0,
56
- "metadata_expire" =>86400}},
57
- File.join(data_file_path("yum"), "second.repo") =>
58
- { "my-local-repo-c" =>
59
- { "name" =>"My Local Repo c",
60
- "baseurl" =>"https://mirror.example.com/c/content/os_ver",
61
- "enabled" =>0,
62
- "cost" =>100,
63
- "gpgcheck" =>1,
64
- "gpgkey" =>"file:///etc/pki/rpm-gpg/RPM-GPG-KEY-my-local-server",
65
- "sslverify" =>0,
66
- "metadata_expire" =>1}},})
67
- end
68
-
69
- context ".updates_available?" do
70
- it "check updates for a specific package" do
71
- expect(LinuxAdmin::Common).to receive(:run).once.with("yum check-update", :params => {nil => ["abc"]})
72
- .and_return(double(:exit_status => 100))
73
- expect(described_class.updates_available?("abc")).to be_truthy
74
- end
75
-
76
- it "updates are available" do
77
- allow(LinuxAdmin::Common).to receive_messages(:run => double(:exit_status => 100))
78
- expect(described_class.updates_available?).to be_truthy
79
- end
80
-
81
- it "updates not available" do
82
- allow(LinuxAdmin::Common).to receive_messages(:run => double(:exit_status => 0))
83
- expect(described_class.updates_available?).to be_falsey
84
- end
85
-
86
- it "other exit code" do
87
- allow(LinuxAdmin::Common).to receive_messages(:run => double(:exit_status => 255, :error => 'test'))
88
- expect { described_class.updates_available? }.to raise_error(RuntimeError)
89
- end
90
-
91
- it "other error" do
92
- allow(LinuxAdmin::Common).to receive(:run).and_raise(RuntimeError)
93
- expect { described_class.updates_available? }.to raise_error(RuntimeError)
94
- end
95
- end
96
-
97
- context ".update" do
98
- it "no arguments" do
99
- expect(LinuxAdmin::Common).to receive(:run!).once.with("yum -y update", :params => nil)
100
- .and_return(AwesomeSpawn::CommandResult.new("", "", "", 0))
101
- described_class.update
102
- end
103
-
104
- it "with arguments" do
105
- expect(LinuxAdmin::Common).to receive(:run!).once.with("yum -y update", :params => {nil => ["1 2", "3"]})
106
- .and_return(AwesomeSpawn::CommandResult.new("", "", "", 0))
107
- described_class.update("1 2", "3")
108
- end
109
-
110
- it "with bad arguments" do
111
- error = AwesomeSpawn::CommandResult.new("", "Loaded plugins: product-id\nNo Packages marked for Update\n", "Blah blah ...\nNo Match for argument: \n", 0)
112
- expect(LinuxAdmin::Common).to receive(:run!).once
113
- .with("yum -y update", :params => {nil => [""]}).and_return(error)
114
- expect { described_class.update("") }.to raise_error(AwesomeSpawn::CommandResultError)
115
- end
116
- end
117
-
118
- context ".version_available" do
119
- it "no packages" do
120
- expect { described_class.version_available }.to raise_error(ArgumentError)
121
- end
122
-
123
- it "with one package" do
124
- expect(LinuxAdmin::Common).to receive(:run!).once
125
- .with("repoquery --qf=\"%{name} %{version}\"", :params => {nil => ["subscription-manager"]})
126
- .and_return(double(:output => sample_output("yum/output_repoquery_single")))
127
- expect(described_class.version_available("subscription-manager")).to eq({"subscription-manager" => "1.1.23.1"})
128
- end
129
-
130
- it "with multiple packages" do
131
- expect(LinuxAdmin::Common).to receive(:run!).once
132
- .with("repoquery --qf=\"%{name} %{version}\"", :params => {nil => ["curl", "subscription-manager", "wget"]})
133
- .and_return(double(:output => sample_output("yum/output_repoquery_multiple")))
134
- expect(described_class.version_available("curl", "subscription-manager", "wget")).to eq({
135
- "curl" => "7.19.7",
136
- "subscription-manager" => "1.1.23.1",
137
- "wget" => "1.12"
138
- })
139
- end
140
- end
141
-
142
- context ".repo_list" do
143
- it "with no arguments" do
144
- expect(LinuxAdmin::Common).to receive(:run!).with("yum repolist", :params => {nil => "enabled"})
145
- .and_return(double(:output => sample_output("yum/output_repo_list")))
146
- expect(described_class.repo_list).to eq(["rhel-6-server-rpms", "rhel-ha-for-rhel-6-server-rpms", "rhel-lb-for-rhel-6-server-rpms"])
147
- end
148
-
149
- it "with argument" do
150
- expect(LinuxAdmin::Common).to receive(:run!).with("yum repolist", :params => {nil => "enabled"})
151
- .and_return(double(:output => sample_output("yum/output_repo_list")))
152
- expect(described_class.repo_list("enabled")).to eq(["rhel-6-server-rpms", "rhel-ha-for-rhel-6-server-rpms", "rhel-lb-for-rhel-6-server-rpms"])
153
- end
154
- end
155
- end