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.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/lib/linux_admin.rb +0 -8
  3. data/lib/linux_admin/disk.rb +12 -5
  4. data/lib/linux_admin/registration_system.rb +8 -4
  5. data/lib/linux_admin/scap.rb +1 -1
  6. data/lib/linux_admin/service/sys_v_init_service.rb +2 -1
  7. data/lib/linux_admin/service/systemd_service.rb +6 -2
  8. data/lib/linux_admin/version.rb +1 -1
  9. metadata +8 -100
  10. data/lib/linux_admin/registration_system/rhn.rb +0 -111
  11. data/spec/chrony_spec.rb +0 -64
  12. data/spec/common_spec.rb +0 -37
  13. data/spec/data/rhn/output_rhn-channel_list +0 -2
  14. data/spec/data/rhn/output_rhn-channel_list_available +0 -4
  15. data/spec/data/rhn/systemid +0 -57
  16. data/spec/data/rhn/systemid.missing_system_id +0 -57
  17. data/spec/data/rpm/cmd_output_for_list_installed +0 -20
  18. data/spec/data/subscription_manager/output_list_all_available +0 -42
  19. data/spec/data/subscription_manager/output_list_installed_not_subscribed +0 -19
  20. data/spec/data/subscription_manager/output_list_installed_subscribed +0 -19
  21. data/spec/data/subscription_manager/output_orgs +0 -6
  22. data/spec/data/subscription_manager/output_repos +0 -18
  23. data/spec/data/time_date/timedatectl_output +0 -14
  24. data/spec/data/yum/first.repo +0 -19
  25. data/spec/data/yum/output_repo_list +0 -13
  26. data/spec/data/yum/output_repoquery_multiple +0 -3
  27. data/spec/data/yum/output_repoquery_single +0 -1
  28. data/spec/data/yum/second.repo +0 -9
  29. data/spec/deb_spec.rb +0 -52
  30. data/spec/disk_spec.rb +0 -307
  31. data/spec/distro_spec.rb +0 -77
  32. data/spec/dns_spec.rb +0 -105
  33. data/spec/etc_issue_spec.rb +0 -37
  34. data/spec/fstab_spec.rb +0 -132
  35. data/spec/hardware_spec.rb +0 -46
  36. data/spec/hosts_spec.rb +0 -150
  37. data/spec/ip_address_spec.rb +0 -148
  38. data/spec/logical_volume_spec.rb +0 -166
  39. data/spec/mountable_spec.rb +0 -182
  40. data/spec/network_interface/network_interface_rh_spec.rb +0 -291
  41. data/spec/network_interface_spec.rb +0 -284
  42. data/spec/partition_spec.rb +0 -24
  43. data/spec/physical_volume_spec.rb +0 -101
  44. data/spec/registration_system_spec.rb +0 -85
  45. data/spec/rhn_spec.rb +0 -144
  46. data/spec/rpm_spec.rb +0 -85
  47. data/spec/scap_spec.rb +0 -48
  48. data/spec/service/sys_v_init_service_spec.rb +0 -127
  49. data/spec/service/systemd_service_spec.rb +0 -133
  50. data/spec/service_spec.rb +0 -54
  51. data/spec/spec_helper.rb +0 -116
  52. data/spec/ssh_spec.rb +0 -53
  53. data/spec/subscription_manager_spec.rb +0 -228
  54. data/spec/system_spec.rb +0 -15
  55. data/spec/time_date_spec.rb +0 -106
  56. data/spec/volume_group_spec.rb +0 -99
  57. data/spec/yum_spec.rb +0 -155
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b829f3cc2362f608bad95b43d9e3fe8b97a57bf027c84d16cd38c758dc841840
4
- data.tar.gz: 0f9741c5305f8dee09358f9c1c44edf12ad150fa11a79514c59a8110c8254094
3
+ metadata.gz: 5681d25983ab26caad539f8b7978090804ba734a45ed80fdf2107730d4c2cc42
4
+ data.tar.gz: 4e3879832bbd3e426d5440fa42d4eade9dbf0120d03aa410450cd53f64092da9
5
5
  SHA512:
6
- metadata.gz: e80cc3ce27b7b68d4d74947e81d8fa9451849aa0995a008874ec741ad30ff57a9c7306fca270299463a22785a490722aa55a0ffa036dd03903a6e79517beb755
7
- data.tar.gz: 6887b3343ea5220c23c86373e049d4ff497babdda16bc70b8d542d506641575392092a3ecf1b85ec42060d31fc6f263efe5e29cd3fcb9bc7e7696bf100ccce83
6
+ metadata.gz: 873010562e96308eb395441c06eda128e44cdf900e829b91e76d4927313f2971f3d55be28d96ef5af4c083f646993a8d06b6542fa01e5b423ec61f70f6a2c646
7
+ data.tar.gz: dfa21c10b2a0490606c3c28b29e6dc813dba9d3d3d92ac3d845f95b41fb39d927daf08491b1c058af65b3aa097894e50be7e0b62be22d86839acd7e34c81de3c
@@ -33,18 +33,10 @@ require 'linux_admin/ip_address'
33
33
  require 'linux_admin/dns'
34
34
  require 'linux_admin/network_interface'
35
35
  require 'linux_admin/chrony'
36
- require 'forwardable'
37
36
 
38
37
  module LinuxAdmin
39
38
  class << self
40
- extend Forwardable
41
- extend Gem::Deprecate
42
39
  attr_writer :logger
43
-
44
- def_delegators Common, :run
45
- def_delegators Common, :run!
46
- deprecate :run, "AwesomeSpawn.run", 2017, 6
47
- deprecate :run!, "AwesomeSpawn.run!", 2017, 6
48
40
  end
49
41
 
50
42
  def self.logger
@@ -8,16 +8,23 @@ module LinuxAdmin
8
8
 
9
9
  attr_accessor :path, :model
10
10
 
11
+ # Collect local disk information via the lsblk command. Only disks with a
12
+ # size greater than zero are returned.
13
+ #
11
14
  def self.local
12
- result = Common.run!(Common.cmd("lsblk"), :params => {:d => nil, :n => nil, :p => nil, :o => "NAME"})
13
- result.output.split.collect do |d|
14
- Disk.new :path => d
15
- end
15
+ result = Common.run!(Common.cmd("lsblk"), :params => {:b => nil, :d => nil, :n => nil, :p => nil, :o => "NAME,SIZE,TYPE,MODEL"})
16
+ result.output.split("\n").collect do |string|
17
+ path, size, type, *model = string.split
18
+ if type.casecmp?('disk') && size.to_i > 0
19
+ self.new(:path => path, :size => size.to_i, :model => model.join(' '))
20
+ end
21
+ end.compact
16
22
  end
17
23
 
18
24
  def initialize(args = {})
19
25
  @path = args[:path]
20
- @model = "unknown"
26
+ @model = args[:model] || "unknown"
27
+ @size = args[:size]
21
28
  end
22
29
 
23
30
  def size
@@ -3,6 +3,7 @@ module LinuxAdmin
3
3
  include Logging
4
4
 
5
5
  def self.registration_type(reload = false)
6
+ @registration_type ||= nil
6
7
  return @registration_type if @registration_type && !reload
7
8
  @registration_type = registration_type_uncached
8
9
  end
@@ -23,10 +24,13 @@ module LinuxAdmin
23
24
 
24
25
  private
25
26
 
27
+ def self.respond_to_missing?(method_name, _include_private = false)
28
+ white_list_methods.include?(method_name)
29
+ end
30
+ private_class_method :respond_to_missing?
31
+
26
32
  def self.registration_type_uncached
27
- if Rhn.new.registered?
28
- Rhn
29
- elsif SubscriptionManager.new.registered?
33
+ if SubscriptionManager.new.registered?
30
34
  SubscriptionManager
31
35
  else
32
36
  self
@@ -36,7 +40,7 @@ module LinuxAdmin
36
40
 
37
41
  def self.white_list_methods
38
42
  @white_list_methods ||= begin
39
- all_methods = RegistrationSystem.instance_methods(false) + Rhn.instance_methods(false) + SubscriptionManager.instance_methods(false)
43
+ all_methods = RegistrationSystem.instance_methods(false) + SubscriptionManager.instance_methods(false)
40
44
  all_methods.uniq
41
45
  end
42
46
  end
@@ -83,7 +83,7 @@ module LinuxAdmin
83
83
  end
84
84
 
85
85
  def model_xml_element(doc)
86
- doc.css("//nist_list|model", "nist_list" => "http://checklists.nist.gov/xccdf/1.2").detect { |model| model.namespace.prefix.nil? }
86
+ doc.xpath("//ns10:model").first
87
87
  end
88
88
  end
89
89
  end
@@ -17,9 +17,10 @@ module LinuxAdmin
17
17
  self
18
18
  end
19
19
 
20
- def start
20
+ def start(enable = false)
21
21
  Common.run!(Common.cmd(:service),
22
22
  :params => {nil => [name, "start"]})
23
+ self.enable if enable
23
24
  self
24
25
  end
25
26
 
@@ -14,8 +14,12 @@ module LinuxAdmin
14
14
  self
15
15
  end
16
16
 
17
- def start
18
- Common.run!(command_path, :params => ["start", name])
17
+ def start(enable = false)
18
+ if enable
19
+ Common.run!(command_path, :params => ["enable", "--now", name])
20
+ else
21
+ Common.run!(command_path, :params => ["start", name])
22
+ end
19
23
  self
20
24
  end
21
25
 
@@ -1,3 +1,3 @@
1
1
  module LinuxAdmin
2
- VERSION = "1.2.4".freeze
2
+ VERSION = "2.0.0".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linux_admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Dunne
@@ -21,10 +21,12 @@ authors:
21
21
  - DuskyPrawn
22
22
  - Petr Blaho
23
23
  - Nick LaMuro
24
+ - Daniel Berger
25
+ - Satoe Imaishi
24
26
  autorequire:
25
27
  bindir: bin
26
28
  cert_chain: []
27
- date: 2019-07-08 00:00:00.000000000 Z
29
+ date: 2019-12-12 00:00:00.000000000 Z
28
30
  dependencies:
29
31
  - !ruby/object:Gem::Dependency
30
32
  name: rake
@@ -213,6 +215,8 @@ email:
213
215
  - 32548790+DuskyPrawn@users.noreply.github.com
214
216
  - pblaho@redhat.com
215
217
  - nicklamuro@gmail.com
218
+ - djberg96@gmail.com
219
+ - simaishi@redhat.com
216
220
  executables: []
217
221
  extensions: []
218
222
  extra_rdoc_files: []
@@ -243,7 +247,6 @@ files:
243
247
  - lib/linux_admin/partition.rb
244
248
  - lib/linux_admin/physical_volume.rb
245
249
  - lib/linux_admin/registration_system.rb
246
- - lib/linux_admin/registration_system/rhn.rb
247
250
  - lib/linux_admin/registration_system/subscription_manager.rb
248
251
  - lib/linux_admin/rpm.rb
249
252
  - lib/linux_admin/scap.rb
@@ -259,53 +262,6 @@ files:
259
262
  - lib/linux_admin/volume_group.rb
260
263
  - lib/linux_admin/yum.rb
261
264
  - lib/linux_admin/yum/repo_file.rb
262
- - spec/chrony_spec.rb
263
- - spec/common_spec.rb
264
- - spec/data/rhn/output_rhn-channel_list
265
- - spec/data/rhn/output_rhn-channel_list_available
266
- - spec/data/rhn/systemid
267
- - spec/data/rhn/systemid.missing_system_id
268
- - spec/data/rpm/cmd_output_for_list_installed
269
- - spec/data/subscription_manager/output_list_all_available
270
- - spec/data/subscription_manager/output_list_installed_not_subscribed
271
- - spec/data/subscription_manager/output_list_installed_subscribed
272
- - spec/data/subscription_manager/output_orgs
273
- - spec/data/subscription_manager/output_repos
274
- - spec/data/time_date/timedatectl_output
275
- - spec/data/yum/first.repo
276
- - spec/data/yum/output_repo_list
277
- - spec/data/yum/output_repoquery_multiple
278
- - spec/data/yum/output_repoquery_single
279
- - spec/data/yum/second.repo
280
- - spec/deb_spec.rb
281
- - spec/disk_spec.rb
282
- - spec/distro_spec.rb
283
- - spec/dns_spec.rb
284
- - spec/etc_issue_spec.rb
285
- - spec/fstab_spec.rb
286
- - spec/hardware_spec.rb
287
- - spec/hosts_spec.rb
288
- - spec/ip_address_spec.rb
289
- - spec/logical_volume_spec.rb
290
- - spec/mountable_spec.rb
291
- - spec/network_interface/network_interface_rh_spec.rb
292
- - spec/network_interface_spec.rb
293
- - spec/partition_spec.rb
294
- - spec/physical_volume_spec.rb
295
- - spec/registration_system_spec.rb
296
- - spec/rhn_spec.rb
297
- - spec/rpm_spec.rb
298
- - spec/scap_spec.rb
299
- - spec/service/sys_v_init_service_spec.rb
300
- - spec/service/systemd_service_spec.rb
301
- - spec/service_spec.rb
302
- - spec/spec_helper.rb
303
- - spec/ssh_spec.rb
304
- - spec/subscription_manager_spec.rb
305
- - spec/system_spec.rb
306
- - spec/time_date_spec.rb
307
- - spec/volume_group_spec.rb
308
- - spec/yum_spec.rb
309
265
  homepage: http://github.com/ManageIQ/linux_admin
310
266
  licenses:
311
267
  - MIT
@@ -325,56 +281,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
325
281
  - !ruby/object:Gem::Version
326
282
  version: '0'
327
283
  requirements: []
328
- rubyforge_project:
329
- rubygems_version: 2.7.6.2
284
+ rubygems_version: 3.0.6
330
285
  signing_key:
331
286
  specification_version: 4
332
287
  summary: LinuxAdmin is a module to simplify management of linux systems.
333
- test_files:
334
- - spec/chrony_spec.rb
335
- - spec/common_spec.rb
336
- - spec/data/rhn/output_rhn-channel_list
337
- - spec/data/rhn/output_rhn-channel_list_available
338
- - spec/data/rhn/systemid
339
- - spec/data/rhn/systemid.missing_system_id
340
- - spec/data/rpm/cmd_output_for_list_installed
341
- - spec/data/subscription_manager/output_list_all_available
342
- - spec/data/subscription_manager/output_list_installed_not_subscribed
343
- - spec/data/subscription_manager/output_list_installed_subscribed
344
- - spec/data/subscription_manager/output_orgs
345
- - spec/data/subscription_manager/output_repos
346
- - spec/data/time_date/timedatectl_output
347
- - spec/data/yum/first.repo
348
- - spec/data/yum/output_repo_list
349
- - spec/data/yum/output_repoquery_multiple
350
- - spec/data/yum/output_repoquery_single
351
- - spec/data/yum/second.repo
352
- - spec/deb_spec.rb
353
- - spec/disk_spec.rb
354
- - spec/distro_spec.rb
355
- - spec/dns_spec.rb
356
- - spec/etc_issue_spec.rb
357
- - spec/fstab_spec.rb
358
- - spec/hardware_spec.rb
359
- - spec/hosts_spec.rb
360
- - spec/ip_address_spec.rb
361
- - spec/logical_volume_spec.rb
362
- - spec/mountable_spec.rb
363
- - spec/network_interface/network_interface_rh_spec.rb
364
- - spec/network_interface_spec.rb
365
- - spec/partition_spec.rb
366
- - spec/physical_volume_spec.rb
367
- - spec/registration_system_spec.rb
368
- - spec/rhn_spec.rb
369
- - spec/rpm_spec.rb
370
- - spec/scap_spec.rb
371
- - spec/service/sys_v_init_service_spec.rb
372
- - spec/service/systemd_service_spec.rb
373
- - spec/service_spec.rb
374
- - spec/spec_helper.rb
375
- - spec/ssh_spec.rb
376
- - spec/subscription_manager_spec.rb
377
- - spec/system_spec.rb
378
- - spec/time_date_spec.rb
379
- - spec/volume_group_spec.rb
380
- - spec/yum_spec.rb
288
+ test_files: []
@@ -1,111 +0,0 @@
1
- require 'nokogiri'
2
-
3
- module LinuxAdmin
4
- class Rhn < RegistrationSystem
5
- SATELLITE5_SERVER_CERT_PATH = "pub/rhn-org-trusted-ssl-cert-1.0-1.noarch.rpm"
6
- INSTALLED_SERVER_CERT_PATH = "/usr/share/rhn/RHN-ORG-TRUSTED-SSL-CERT"
7
-
8
- def initialize
9
- warn("[DEPRECATION] 'LinuxAdmin::Rhn' is deprecated. Please use 'LinuxAdmin::SubscriptionManager' instead.")
10
- end
11
-
12
- def registered?(_options = nil)
13
- id = ""
14
- if File.exist?(systemid_file)
15
- xml = Nokogiri.XML(File.read(systemid_file))
16
- id = xml.xpath('/params/param/value/struct/member[name="system_id"]/value/string').text
17
- end
18
- id.length > 0
19
- end
20
-
21
- def register(options)
22
- cmd = "rhnreg_ks"
23
- params = {}
24
-
25
- if options[:activationkey]
26
- params["--activationkey="] = options[:activationkey]
27
- elsif options[:username] && options[:password]
28
- params["--username="] = options[:username]
29
- params["--password="] = options[:password]
30
- else
31
- raise ArgumentError, "activation key or username and password are required"
32
- end
33
-
34
- install_server_certificate(options[:server_url], SATELLITE5_SERVER_CERT_PATH) if options[:server_url]
35
- certificate_installed = LinuxAdmin::Rpm.list_installed["rhn-org-trusted-ssl-cert"]
36
-
37
- params["--proxy="] = options[:proxy_address] if options[:proxy_address]
38
- params["--proxyUser="] = options[:proxy_username] if options[:proxy_username]
39
- params["--proxyPassword="] = options[:proxy_password] if options[:proxy_password]
40
- params["--serverUrl="] = options[:server_url] if options[:server_url]
41
- params["--systemorgid="] = options[:org] if options[:server_url] && options[:org]
42
- params["--sslCACert="] = INSTALLED_SERVER_CERT_PATH if certificate_installed
43
-
44
- Common.run!(cmd, :params => params)
45
- end
46
-
47
- def enable_channel(repo, options)
48
- cmd = "rhn-channel -a"
49
- params = user_pwd(options).merge("--channel=" => repo)
50
-
51
- logger.info("#{self.class.name}##{__method__} Enabling channel: #{repo}")
52
- Common.run!(cmd, :params => params)
53
- end
54
- alias_method :subscribe, :enable_channel
55
- alias_method :enable_repo, :enable_channel
56
-
57
- def disable_channel(repo, options)
58
- cmd = "rhn-channel -r"
59
- params = user_pwd(options).merge("--channel=" => repo)
60
-
61
- Common.run!(cmd, :params => params)
62
- end
63
- alias_method :disable_repo, :disable_channel
64
-
65
- def enabled_channels
66
- cmd = "rhn-channel -l"
67
-
68
- Common.run!(cmd).output.split("\n").compact
69
- end
70
- alias_method :enabled_repos, :enabled_channels
71
- alias_method :subscribed_products, :enabled_channels
72
-
73
- def available_channels(options)
74
- cmd = "rhn-channel -L"
75
- params = user_pwd(options)
76
-
77
- Common.run!(cmd, :params => params).output.chomp.split("\n").compact
78
- end
79
-
80
- def all_repos(options)
81
- available = available_channels_with_status(options)
82
- merge_enabled_channels_with_status(available)
83
- end
84
-
85
- private
86
-
87
- def available_channels_with_status(options)
88
- available_channels(options).collect { |ac| {:repo_id => ac, :enabled => false} }
89
- end
90
-
91
- def merge_enabled_channels_with_status(available)
92
- enabled_channels.each_with_object(available) do |enabled, all|
93
- if repo = all.detect { |i| i[:repo_id] == enabled }
94
- repo[:enabled] = true
95
- else
96
- all.push({:repo_id => enabled, :enabled => true})
97
- end
98
- end
99
- end
100
-
101
- def user_pwd(options)
102
- raise ArgumentError, "username and password are required" if options[:username].blank? || options[:password].blank?
103
-
104
- {"--user=" => options[:username], "--password=" => options[:password]}
105
- end
106
-
107
- def systemid_file
108
- "/etc/sysconfig/rhn/systemid"
109
- end
110
- end
111
- end
@@ -1,64 +0,0 @@
1
- describe LinuxAdmin::Chrony do
2
- CHRONY_CONF = <<-EOF
3
- # commented server baz.example.net
4
- server foo.example.net
5
- server bar.example.net iburst
6
- driftfile /var/lib/chrony/drift
7
- makestep 10 3
8
- rtcsync
9
- EOF
10
-
11
- subject do
12
- allow(File).to receive(:exist?).and_return(true)
13
- described_class.new
14
- end
15
-
16
- describe ".new" do
17
- it "raises when the given config file doesn't exist" do
18
- expect { described_class.new("nonsense/file") }.to raise_error(LinuxAdmin::MissingConfigurationFileError)
19
- end
20
- end
21
-
22
- describe "#clear_servers" do
23
- it "removes all the server lines from the conf file" do
24
- allow(File).to receive(:read).and_return(CHRONY_CONF.dup)
25
- expect(File).to receive(:write) do |_file, contents|
26
- expect(contents).to eq "# commented server baz.example.net\ndriftfile /var/lib/chrony/drift\nmakestep 10 3\nrtcsync\n"
27
- end
28
- subject.clear_servers
29
- end
30
- end
31
-
32
- describe "#add_servers" do
33
- it "adds server lines to the conf file" do
34
- allow(File).to receive(:read).and_return(CHRONY_CONF.dup)
35
- expect(File).to receive(:write) do |_file, contents|
36
- expect(contents).to eq(CHRONY_CONF + "server baz.example.net iburst\nserver foo.bar.example.com iburst\n")
37
- end
38
- allow(subject).to receive(:restart_service_if_running)
39
- subject.add_servers("baz.example.net", "foo.bar.example.com")
40
- end
41
-
42
- it "restarts the service if it is running" do
43
- allow(File).to receive(:read).and_return(CHRONY_CONF.dup)
44
- allow(File).to receive(:write)
45
-
46
- chronyd_service = double
47
- expect(LinuxAdmin::Service).to receive(:new).with("chronyd").and_return(chronyd_service)
48
- expect(chronyd_service).to receive(:running?).and_return true
49
- expect(chronyd_service).to receive(:restart)
50
- subject.add_servers("baz.example.net", "foo.bar.example.com")
51
- end
52
-
53
- it "doesn't restart the service if it is not running" do
54
- allow(File).to receive(:read).and_return(CHRONY_CONF.dup)
55
- allow(File).to receive(:write)
56
-
57
- chronyd_service = double
58
- expect(LinuxAdmin::Service).to receive(:new).with("chronyd").and_return(chronyd_service)
59
- expect(chronyd_service).to receive(:running?).and_return false
60
- expect(chronyd_service).not_to receive(:restart)
61
- subject.add_servers("baz.example.net", "foo.bar.example.com")
62
- end
63
- end
64
- end