smart_proxy_pulp 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 449eb101bce06ca7d526b94e2d5f1ac5c494cfcd
4
- data.tar.gz: e572ad1882b60f02d023a6fcabe7ec8500cedb0b
3
+ metadata.gz: 2cfca5cf9a70d4e21a551238e05bf7cfd7021bbd
4
+ data.tar.gz: 9f70189e1dac7544f34ddd7f7983106268333dd1
5
5
  SHA512:
6
- metadata.gz: a5dd127eb6ea63480e5ff35121f7a56159eb321db7ae55ce1cf2f50b0a42642d6adbced81e65285adb781a2065e1fddfa4c7620674ac8ba1673bda8feb2de4ad
7
- data.tar.gz: b8d31112946962ef098b5b899002b7200e5d6326d19137b2448624896e3f5baa4a606171fb3f3820635471ccfdf7ff892488fe94bfc7718474b57a1891afb597
6
+ metadata.gz: 573fd5cd53098343c9e6daa779c127562fd7017a461dedcac0692480203a3312300779f06cc249bcc56f5882350493ada62c98a02dc2e96d5cdc6d97d6732a66
7
+ data.tar.gz: af4aaee752664afe0394559852ec62ec76f55db52b9c79450c54e08762ef75babbe8680c3f3f92cb3cb2c1c95b387f4163c2eb1967e60678c05b445a8ee6c874
@@ -10,7 +10,8 @@ module PulpProxy
10
10
  raise(::Proxy::Error::ConfigurationError, 'Unable to continue - must provide a path.') if opts[:path].nil?
11
11
  @paths_hash = validate_path(path_hash(opts[:path]))
12
12
  @path = @paths_hash.values
13
- @size = SIZE[opts[:size]] || SIZE[:kilobyte]
13
+ @size_format = opts[:size] || :kilobyte
14
+ @size = SIZE[@size_format]
14
15
  @stat = {}
15
16
  find_df
16
17
  get_stat
@@ -32,22 +33,55 @@ module PulpProxy
32
33
  [command_path, "-B", "#{size}", *path]
33
34
  end
34
35
 
35
- def get_stat
36
- raw = Open3::popen3({"LC_ALL" => "C"}, *command) do |stdin, stdout, stderr, thread|
37
- unless stderr.read.empty?
38
- error_line = stderr.read
39
- logger.error "[#{command_path}] #{error_line}"
40
- raise(::Proxy::Error::ConfigurationError, "#{command_path} raised an error: #{error_line}")
36
+ # Inspired and copied from Facter
37
+ # @ https://github.com/puppetlabs/facter/blob/2.x/lib/facter/core/execution/base.rb
38
+ # @TODO: Refactor http://projects.theforeman.org/issues/15235 when removing support for 1.8.7
39
+ def with_env(values)
40
+ old = {}
41
+ values.each do |var, value|
42
+ # save the old value if it exists
43
+ if old_val = ENV[var]
44
+ old[var] = old_val
45
+ end
46
+ # set the new (temporary) value for the environment variable
47
+ ENV[var] = value
48
+ end
49
+ # execute the caller's block, capture the return value
50
+ rv = yield
51
+ # use an ensure block to make absolutely sure we restore the variables
52
+ ensure
53
+ # restore the old values
54
+ values.each do |var, value|
55
+ if old.include?(var)
56
+ ENV[var] = old[var]
57
+ else
58
+ # if there was no old value, delete the key from the current environment variables hash
59
+ ENV.delete(var)
41
60
  end
42
- stdout.read.split("\n")
43
61
  end
44
- logger.debug "[#{command_path}] #{raw.to_s}"
62
+ # return the captured return value
63
+ rv
64
+ end
65
+
66
+ def get_stat
67
+ with_env 'LC_ALL' => 'C' do
68
+ raw = Open3::popen3(*command) do |stdin, stdout, stderr, thread|
69
+ unless stderr.read.empty?
70
+ error_line = stderr.read
71
+ logger.error "[#{command_path}] #{error_line}"
72
+ raise(::Proxy::Error::ConfigurationError, "#{command_path} raised an error: #{error_line}")
73
+ end
74
+ stdout.read.split("\n")
75
+ end
76
+
77
+ logger.debug "[#{command_path}] #{raw.to_s}"
45
78
 
46
- titles = normalize_titles(raw)
47
- raw.each_with_index do |line, index|
48
- mount_path = path[index]
49
- values = normalize_values(line.split)
50
- @stat[@paths_hash.key(mount_path)] = Hash[titles.zip(values)].merge({:path => mount_path, :size => SIZE.key(size)})
79
+ titles = normalize_titles(raw)
80
+ raw.each_with_index do |line, index|
81
+ mount_path = path[index]
82
+ values = normalize_values(line.split)
83
+ @stat[hash_key_for(mount_path)] = Hash[titles.zip(values)].merge({:path => mount_path, :size => @size_format})
84
+ end
51
85
  end
52
86
  end
53
87
 
@@ -55,6 +89,11 @@ module PulpProxy
55
89
  path.is_a?(Hash) ? path : Hash[path, path]
56
90
  end
57
91
 
92
+ def hash_key_for(path)
93
+ @paths_hash.select { |k,v| v == path}.first[0]
94
+ end
95
+
96
+
58
97
  def normalize_titles(raw)
59
98
  replacers = {"mounted on" => :mounted, "use%" => :percent}
60
99
  raw.shift.downcase.gsub(/(use%|mounted on)/) { |m| replacers.fetch(m,m)}.split.map(&:to_sym)
@@ -21,7 +21,7 @@ module PulpProxy
21
21
 
22
22
  get '/status/disk_usage' do
23
23
  size = (params[:size] && DiskUsage::SIZE.keys.include?(params[:size].to_sym)) ? params[:size].to_sym : :kilobyte
24
- monitor_dirs = ::PulpProxy::Plugin.settings.to_h.select { |key, _| key == :pulp_dir || key == :pulp_content_dir || key == :mongodb_dir }
24
+ monitor_dirs = Hash[::PulpProxy::Plugin.settings.marshal_dump.select { |key, _| key == :pulp_dir || key == :pulp_content_dir || key == :mongodb_dir }]
25
25
  begin
26
26
  pulp_disk = DiskUsage.new({:path => monitor_dirs, :size => size})
27
27
  pulp_disk.to_json
@@ -1,3 +1,3 @@
1
1
  module PulpProxy
2
- VERSION = "1.2.0"
2
+ VERSION = "1.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_proxy_pulp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitri Dolguikh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-26 00:00:00.000000000 Z
11
+ date: 2016-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-unit