Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #13013 - Adds API to display pulp dir status #3

Closed
wants to merge 1 commit into from

Conversation

shlomizadok
Copy link
Member

No description provided.

@@ -2,5 +2,5 @@ source 'https://rubygems.org'
gemspec

group :development do
gem 'smart_proxy', :git => "https://github.com/theforeman/smart-proxy"
gem 'smart_proxy', :git => 'https://github.com/theforeman/smart-proxy', :branch => 'develop'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, not. Since smart-proxy now have only develop branch (master was deleted), bundle will fail when trying to run. So need to point it to develop branch (which also makes sense in development).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@witlessbird your thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

module PulpProxy
class PulpDisk
def initialize(path = PulpProxy::Plugin.settings.pulp_dir)
@path = path
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add the properties to the class? e.g.

attr_accessor :free, :total, :block_device, :path 

@@ -0,0 +1,25 @@
module PulpProxy
class DiskUsage
attr_accessor :free, :total, :block_device, :path
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe consider accepting a unit argument, so you can decide if its bytes, kilo, mb, gb or human

@shlomizadok
Copy link
Member Author

Changed a little bit. let me know what u think

attr_reader :path, :stat, :size

def initialize(path = PulpProxy::Plugin.settings.pulp_dir, size = SIZE[:megabyte])
@path = path
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would pass opts = {} instead of hard coding the size as the second argument, e.g.

DiskUsage.new(:path => '..', :size_format ..)

@@ -25,6 +25,7 @@ Gem::Specification.new do |gem|
gem.add_development_dependency('webmock', '~> 1')
gem.add_development_dependency('rack-test', '~> 0')
gem.add_development_dependency('rake', '~> 10')
gem.add_dependency('sys-filesystem', '~> 1.1')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh are you sure? :-) You need to create packages for Red Hat and Debian... I was not insisting on this at all.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 df is simple enough instead of calling out to an external ffi gem.
granted it will not work on windows, but since the scope of pulp is only redhat family I think I'm fine with it.

#:pulp_dir: /var/lib/pulp
#:pulp_content: /var/lib/pulp/content
#:mongodb: /var/lib/mongodb
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The values are incorrect, you have renamed them.

@shlomizadok shlomizadok force-pushed the fix_13013 branch 2 times, most recently from b46deb2 to 1a519eb Compare January 12, 2016 08:50
@lzap
Copy link
Member

lzap commented Jan 12, 2016

Ok it works but convert to numbers what should be a number...

[lzap@lzapx smart-proxy-pulp]$ curl -sk http://localhost:8448/pulp/status/disk_usage?size=megabyte | json_reformat 
{
    "pulp_dir": {
        "filesystem": "tmpfs",
        "1m-blocks": "7875",
        "used": "1",
        "available": "7875",
        "percent": "1%",
        "mounted": "/tmp",
        "path": "/tmp",
        "size": "megabyte"
    }
}

@shlomizadok
Copy link
Member Author

Converted numbers to what should be a number.

@lzap
Copy link
Member

lzap commented Jan 12, 2016

There are test failures.

@lzap
Copy link
Member

lzap commented Jan 12, 2016

I have no push rights, @witlessbird RTM:

13 tests, 19 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed

stdout.read.split("\n")
end
raw.each do |line|
logger.debug "[#{command_path}] #{line}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think you can just dump raw instead of loop over it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks better on a loop, but I can switch to a raw dump

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dumping raw


get '/status/disk_usage' do
size = (params[:size] && DiskUsage::SIZE.keys.include?(params[:size].to_sym)) ? params[:size].to_sym : :kilobyte
monitor_dirs = ::PulpProxy::Plugin.settings.to_h.delete_if { |key, _| key == :pulp_url || key == :enabled }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not great, as this will have to change the moment an additional setting is added; Why not explicitly list settings you are interested in?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to select, with the keys I want

@dmitri-d
Copy link
Member

[test]

@shlomizadok
Copy link
Member Author

Changed according to your comments.
Don't think [test] plays here


def test_returns_pulp_disk_on_200
PulpProxy::Plugin.load_test_settings(:pulp_dir => ::Sinatra::Application.settings.root)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to define 'pulp_content_dir' and 'mongodb_dir' too, as otherwise default values are going to be used (and test will fail on my machine, as I don't have those dirs).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

def get_stat
raw = Open3::popen3({"LC_ALL" => "C"}, *command) do |stdin, stdout, stderr, thread|
unless stderr.read.empty?
error_line = stderr.read.join(" ")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an issue here: I'm getting "undefined method `join' for "":String": #read returns a single string, readlines returns an array.

@dmitri-d
Copy link
Member

merged at 7b4d074. Thanks, @shlomizadok!

@dmitri-d dmitri-d closed this Jan 12, 2016
shlomizadok referenced this pull request in shlomizadok/smart-proxy-pulp May 11, 2016
Add spool dir instructions for git users
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants