foreman_maintain 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dbfb7def5819c4fdf0ca51b125a0834d27ceebd2
4
- data.tar.gz: 5fcb3a45ac4c4cd35c2b0321e1f870dc87367658
3
+ metadata.gz: fe40b2c9fdd4999acc0a0b764a916815e51c9c4a
4
+ data.tar.gz: cf9939ee27a333b61665f3eee0277005bfdd0167
5
5
  SHA512:
6
- metadata.gz: 5dad56ec28607fb9ece29c8a4de091a1a7ead1723c7808fd957bee0ad4369f61fc53288b204b97d775826e912bd7370e862f0305ec12cc7789bc5484ab2eb9c5
7
- data.tar.gz: f238b221d8fd8062b15080085e21459a773d574cb6d27d1db3d883c9b3dae84661ee93fd8fd9a9bdc57120a52c96afa8904d23b672801687b546a001df534044
6
+ metadata.gz: c3297df9601ce8f75dae19f2539b9563434d523d2f3eec602f4562bb6ce98ff29a3622f5c07c859a4da29c6f2cd38f2d90cd8d9d3531dee6b6f08bc49fdecefc
7
+ data.tar.gz: 67e607579907ad237d497692781c7e226352f87b9494f3cbe51aa167e67298ef500884b2099b386a002a9604432a4afa41da8c74a0b51bcf64721a5fa9a421e8
data/README.md CHANGED
@@ -10,10 +10,11 @@ enough to provide the right tools for the specific version.
10
10
  ```
11
11
  Subcommands:
12
12
  health Health related commands
13
- list-checks List the checks based on criteria
13
+ list List the checks based on criteria
14
14
  list-tags List the tags to use for filtering checks
15
15
  check Run the health checks against the system
16
- --tags tags Limit only for specific set of tags
16
+ --label label Run only a specific check
17
+ --tags tags Limit only for specific set of tags
17
18
 
18
19
  upgrade Upgrade related commands
19
20
  list-versions List versions this system is upgradable to
@@ -0,0 +1,41 @@
1
+ class Checks::DiskSpeedMinimal < ForemanMaintain::Check
2
+ EXPECTED_IO = 80
3
+ DEFAULT_UNIT = 'MB/sec'.freeze
4
+ DEFAULT_DIRS = ['/var/lib/pulp', '/var/lib/mongodb', '/var/lib/pgsql'].freeze
5
+
6
+ label :disk_io
7
+ description 'Check for recommended disk speed of pulp, mongodb, pgsql dir.'
8
+ tags :basic
9
+
10
+ confine do
11
+ execute?('which hdparm') && execute?('which fio')
12
+ end
13
+
14
+ def run
15
+ success = true
16
+ io_obj = ForemanMaintain::Utils::Disk::NilDevice.new
17
+
18
+ dirs_to_check.each do |dir|
19
+ io_obj = ForemanMaintain::Utils::Disk::Device.new(dir)
20
+
21
+ next if io_obj.read_speed >= EXPECTED_IO
22
+
23
+ success = false
24
+ logger.info "\n Slow disk detected for #{dir} - #{io_obj.read_speed} #{io_obj.unit}."
25
+ break
26
+ end
27
+
28
+ assert(success, io_obj.slow_disk_error_msg)
29
+ end
30
+
31
+ def check_only_single_device?
32
+ DEFAULT_DIRS.map do |dir|
33
+ ForemanMaintain::Utils::Disk::Device.new(dir).name
34
+ end.uniq.length <= 1
35
+ end
36
+
37
+ def dirs_to_check
38
+ return DEFAULT_DIRS.first(1) if check_only_single_device?
39
+ DEFAULT_DIRS
40
+ end
41
+ end
@@ -6,7 +6,7 @@ class Features::ForemanDatabase < ForemanMaintain::Feature
6
6
  end
7
7
 
8
8
  def query(sql)
9
- parse_csv(psql(%{COPY (#{sql}) TO STDOUT WITH CSV HEADER)}))
9
+ parse_csv(psql(%{COPY (#{sql}) TO STDOUT WITH CSV HEADER}))
10
10
  end
11
11
 
12
12
  def psql(query)
@@ -4,10 +4,10 @@ class Procedures::ForemanTasksResume < ForemanMaintain::Procedure
4
4
 
5
5
  def run
6
6
  say 'resuming paused tasks'
7
- sleep 2
7
+ sleep 1
8
8
  say 'hold on'
9
- sleep 2
9
+ sleep 1
10
10
  say 'almost there'
11
- sleep 2
11
+ sleep 1
12
12
  end
13
13
  end
@@ -37,8 +37,20 @@ module ForemanMaintain
37
37
  collection.inject([]) { |array, check| array.concat(check.tags).uniq }.sort_by(&:to_s)
38
38
  end
39
39
 
40
+ def self.label_option
41
+ option '--label', 'label',
42
+ 'Limit only for a specific label. ' \
43
+ '(Use "list" command to see available labels)' do |label|
44
+ raise ArgumentError, 'value not specified' if label.nil? || label.empty?
45
+ underscorize(label).to_sym
46
+ end
47
+ end
48
+
40
49
  def self.tags_option
41
- option '--tags', 'tags', 'Limit only for specific set of tags' do |tags|
50
+ option '--tags', 'tags',
51
+ 'Limit only for specific set of labels. ' \
52
+ '(Use list-tags command to see available tags)' do |tags|
53
+ raise ArgumentError, 'value not specified' if tags.nil? || tags.empty?
42
54
  tags.split(',').map(&:strip).map { |tag| underscorize(tag).to_sym }
43
55
  end
44
56
  end
@@ -1,7 +1,7 @@
1
1
  module ForemanMaintain
2
2
  module Cli
3
3
  class HealthCommand < Base
4
- subcommand 'list-checks', 'List the checks based on criteria' do
4
+ subcommand 'list', 'List the checks based on criteria' do
5
5
  tags_option
6
6
 
7
7
  def execute
@@ -28,10 +28,33 @@ module ForemanMaintain
28
28
  end
29
29
 
30
30
  subcommand 'check', 'Run the health checks against the system' do
31
+ label_option
31
32
  tags_option
32
33
 
33
34
  def execute
34
- run_scenario(Scenario::ChecksScenario.new(tags || [:basic]))
35
+ scenario = Scenario::FilteredScenario.new(filter)
36
+ if scenario.steps.empty?
37
+ puts "No scenario matching #{humanized_filter}"
38
+ exit 1
39
+ else
40
+ run_scenario(scenario)
41
+ end
42
+ end
43
+
44
+ def filter
45
+ if label
46
+ { :label => label }
47
+ else
48
+ { :tags => tags || [:basic] }
49
+ end
50
+ end
51
+
52
+ def humanized_filter
53
+ if label
54
+ "label #{label_string(filter[:label])}"
55
+ else
56
+ "tags #{filter[:tags].map { |tag| tag_string(tag) }.join}"
57
+ end
35
58
  end
36
59
  end
37
60
  end
@@ -85,7 +85,7 @@ module ForemanMaintain
85
85
  end
86
86
  output = f.read
87
87
  logger.debug("output of the command:\n #{output}")
88
- output
88
+ output.strip
89
89
  end
90
90
  end
91
91
  end
@@ -7,23 +7,32 @@ module ForemanMaintain
7
7
 
8
8
  attr_reader :steps
9
9
 
10
- class ChecksScenario < Scenario
10
+ class FilteredScenario < Scenario
11
11
  manual_detection
12
- attr_reader :filter_tags
12
+ attr_reader :filter_label, :filter_tags
13
13
 
14
- def initialize(filter_tags)
15
- @filter_tags = filter_tags
16
- @steps = ForemanMaintain.available_checks(:tags => filter_tags)
14
+ def initialize(filter)
15
+ @filter_tags = filter[:tags]
16
+ @filter_label = filter[:label]
17
+ @steps = ForemanMaintain.available_checks(filter)
17
18
  end
18
19
 
19
20
  def description
20
- "checks with tags #{tag_string(@filter_tags)}"
21
+ if @filter_label
22
+ "check with label [#{dashize(@filter_label)}]"
23
+ else
24
+ "checks with tags #{tag_string(@filter_tags)}"
25
+ end
21
26
  end
22
27
 
23
28
  private
24
29
 
25
30
  def tag_string(tags)
26
- tags.map { |tag| "[#{tag}]" }.join(' ')
31
+ tags.map { |tag| dashize("[#{tag}]") }.join(' ')
32
+ end
33
+
34
+ def dashize(string)
35
+ string.to_s.tr('_', '-')
27
36
  end
28
37
  end
29
38
 
@@ -0,0 +1,62 @@
1
+ module ForemanMaintain
2
+ module Utils
3
+ module Disk
4
+ class Device
5
+ include ForemanMaintain::Concerns::SystemHelpers
6
+
7
+ EXTERNAL_MOUNT_TYPE = %w(fuseblk nfs).freeze
8
+
9
+ attr_accessor :dir, :name, :unit, :read_speed
10
+
11
+ attr_reader :io_device
12
+
13
+ def initialize(dir)
14
+ @dir = dir
15
+ @name = find_device
16
+ @io_device = init_io_device
17
+ end
18
+
19
+ def unit
20
+ @unit ||= io_device.unit
21
+ end
22
+
23
+ def read_speed
24
+ @read_speed ||= io_device.read_speed
25
+ end
26
+
27
+ def slow_disk_error_msg
28
+ "Slow disk detected #{dir} mounted on #{name}.
29
+ Actual disk speed: #{read_speed} #{default_unit}
30
+ Expected disk speed: #{expected_io} #{default_unit}."
31
+ end
32
+
33
+ private
34
+
35
+ def init_io_device
36
+ if externally_mounted?
37
+ IO::FileSystem
38
+ else
39
+ IO::BlockDevice
40
+ end.new(dir, name)
41
+ end
42
+
43
+ def externally_mounted?
44
+ device_type = execute("stat -f -c %T #{dir}")
45
+ EXTERNAL_MOUNT_TYPE.include?(device_type)
46
+ end
47
+
48
+ def find_device
49
+ execute("df -h #{dir} | sed -n '2p' | awk '{print $1}'")
50
+ end
51
+
52
+ def default_unit
53
+ Checks::DiskSpeedMinimal::DEFAULT_UNIT
54
+ end
55
+
56
+ def expected_io
57
+ Checks::DiskSpeedMinimal::EXPECTED_IO
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,40 @@
1
+ module ForemanMaintain
2
+ module Utils
3
+ module Disk
4
+ module IO
5
+ class BlockDevice
6
+ include ForemanMaintain::Concerns::SystemHelpers
7
+
8
+ attr_accessor :dir, :unit, :read_speed, :name
9
+
10
+ def initialize(dir, name = Disk::Device.new('/var').name)
11
+ @dir = dir
12
+ @name = name
13
+ end
14
+
15
+ def read_speed
16
+ @read_speed ||= extract_speed(hdparm)
17
+ end
18
+
19
+ def unit
20
+ @unit ||= extract_unit(hdparm)
21
+ end
22
+
23
+ private
24
+
25
+ def hdparm
26
+ @stdout ||= execute("hdparm -t #{name} | awk 'NF'")
27
+ end
28
+
29
+ def extract_unit(stdout)
30
+ stdout.split(' ').last
31
+ end
32
+
33
+ def extract_speed(stdout)
34
+ stdout.split(' ').reverse[1].to_i
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,41 @@
1
+ module ForemanMaintain
2
+ module Utils
3
+ module Disk
4
+ module IO
5
+ class FileSystem
6
+ include ForemanMaintain::Concerns::SystemHelpers
7
+
8
+ attr_accessor :dir, :unit, :read_speed, :name
9
+
10
+ def initialize(dir, name = '')
11
+ @dir = dir
12
+ @name = name
13
+ end
14
+
15
+ def read_speed
16
+ @read_speed ||= convert_kb_to_mb(fio)
17
+ end
18
+
19
+ def unit
20
+ @unit ||= 'MB/sec'
21
+ end
22
+
23
+ private
24
+
25
+ # In fio command, --direct option bypass the cache page
26
+ def fio
27
+ cmd = "fio --name=job1 --rw=read --size=1g --output-format=json\
28
+ --directory=#{dir} --direct=1"
29
+ stdout = execute(cmd)
30
+ output = JSON.parse(stdout)
31
+ @fio ||= output['jobs'].first['read']['bw'].to_i
32
+ end
33
+
34
+ def convert_kb_to_mb(val)
35
+ val / 1024
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,2 @@
1
+ require 'foreman_maintain/utils/disk/io/block_device'
2
+ require 'foreman_maintain/utils/disk/io/file_system'
@@ -0,0 +1,18 @@
1
+ module ForemanMaintain
2
+ module Utils
3
+ module Disk
4
+ class NilDevice
5
+ NULL = 'NULL'.freeze
6
+
7
+ attr_accessor :dir, :name, :unit, :read_speed
8
+
9
+ def initialize
10
+ @dir = NULL
11
+ @name = NULL
12
+ @unit = NULL
13
+ @read_speed = NULL
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ require 'foreman_maintain/utils/disk/io'
2
+ require 'foreman_maintain/utils/disk/device'
3
+ require 'foreman_maintain/utils/disk/nil_device'
@@ -0,0 +1 @@
1
+ require 'foreman_maintain/utils/disk'
@@ -1,3 +1,3 @@
1
1
  module ForemanMaintain
2
- VERSION = '0.0.1'.freeze
2
+ VERSION = '0.0.2'.freeze
3
3
  end
@@ -1,3 +1,9 @@
1
+ if RUBY_VERSION <= '1.8.7'
2
+ require 'rubygems'
3
+ end
4
+
5
+ require 'json'
6
+
1
7
  module ForemanMaintain
2
8
  require 'foreman_maintain/concerns/logger'
3
9
  require 'foreman_maintain/concerns/metadata'
@@ -13,6 +19,7 @@ module ForemanMaintain
13
19
  require 'foreman_maintain/scenario'
14
20
  require 'foreman_maintain/runner'
15
21
  require 'foreman_maintain/reporter'
22
+ require 'foreman_maintain/utils'
16
23
 
17
24
  class << self
18
25
  attr_accessor :config
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_maintain
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Nečas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-02 00:00:00.000000000 Z
11
+ date: 2017-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clamp
@@ -98,7 +98,8 @@ description: |
98
98
  Provides various features that helps keeping the Foreman/Satellite up and
99
99
  running.
100
100
  email: inecas@redhat.com
101
- executables: []
101
+ executables:
102
+ - foreman-maintain
102
103
  extensions: []
103
104
  extra_rdoc_files:
104
105
  - LICENSE
@@ -107,6 +108,7 @@ files:
107
108
  - LICENSE
108
109
  - README.md
109
110
  - bin/foreman-maintain
111
+ - definitions/checks/disk_speed_minimal.rb
110
112
  - definitions/checks/foreman_tasks_not_paused.rb
111
113
  - definitions/checks/foreman_tasks_not_running.rb
112
114
  - definitions/features/downstream.rb
@@ -145,6 +147,13 @@ files:
145
147
  - lib/foreman_maintain/runner/execution.rb
146
148
  - lib/foreman_maintain/scenario.rb
147
149
  - lib/foreman_maintain/top_level_modules.rb
150
+ - lib/foreman_maintain/utils.rb
151
+ - lib/foreman_maintain/utils/disk.rb
152
+ - lib/foreman_maintain/utils/disk/device.rb
153
+ - lib/foreman_maintain/utils/disk/io.rb
154
+ - lib/foreman_maintain/utils/disk/io/block_device.rb
155
+ - lib/foreman_maintain/utils/disk/io/file_system.rb
156
+ - lib/foreman_maintain/utils/disk/nil_device.rb
148
157
  - lib/foreman_maintain/version.rb
149
158
  homepage: https://github.com/theforeman/foreman_maintain
150
159
  licenses: