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

Catching exception when running stat on non-existent volume #14

Merged
merged 2 commits into from
Feb 17, 2016

Conversation

arielsalvo
Copy link

No description provided.

@@ -31,7 +31,7 @@ def volume_to_attributes(vol)
:format_type => format_type,
:allocation => bytes_to_gb(vol.info.allocation),
:capacity => bytes_to_gb(vol.info.capacity),
}
} rescue nil # If there are issues during stat of volume file
Copy link
Member

Choose a reason for hiding this comment

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

Could you define an exception instead of rescue everything?
Otherwise this code will just swallow any other issues in that code.

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps Libvirt::RetrieveError ?

Copy link
Author

Choose a reason for hiding this comment

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

This is related to issue #13 .
I don't know that much Ruby to pinpoint the exception that's being raised.
If you can name the exception, I can change the code easily to comply.

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 say to define it like:

def volume_to_attributes(vol)
  format_type = xml_element(vol.xml_desc, "/volume/target/format", "type") rescue nil # not all volumes have types, e.g. LVM
  return nil if format_type == "dir"

  {
    :pool_name   => vol.pool.name,
    :key         => vol.key,
    :id          => vol.key,
    :path        => vol.path,
    :name        => vol.name,
    :format_type => format_type,
    :allocation  => bytes_to_gb(vol.info.allocation),
    :capacity    => bytes_to_gb(vol.info.capacity),
  }
rescue Libvirt::RetrieveError
  nil
end

@arielsalvo
Copy link
Author

How about this new version?
Or do you prefer I omit the "begin-end" block?

@plribeiro3000
Copy link
Member

Seems good to me. Can you confirm it is working with this change?

@arielsalvo
Copy link
Author

I tested it by allowing jenkins to run multiple configurations and multiple projects in parallel.
It seems to have done the trick regarding volumes. Basically, this change ignores volumes that are not ready yet, so it should be OK.

I got a similar error from the list_domains.rb file (I added the comment in the issue) but it was rare. I think vagrant/libvirt takes a lot more time time bringing up a volume than a domain, so it makes a lot of sense that list_volumes should fail a lot more often than list_domains.

@plribeiro3000
Copy link
Member

👍

plribeiro3000 added a commit that referenced this pull request Feb 17, 2016
Catching exception when running stat on non-existent volume
@plribeiro3000 plribeiro3000 merged commit 31a6b1d into fog:master Feb 17, 2016
@plribeiro3000
Copy link
Member

Thank you for your time working on this!

@arielsalvo
Copy link
Author

Remember to bump the version.... I don't know how you handle that in this project

@plribeiro3000
Copy link
Member

@arielsalvo Yeah. I'm actually part of the fog core team and help review stuff but regarding fog-libvirt i don't have permission on rubygem so i can't do a release.

@strzibny is your man here. =)

@strzibny
Copy link
Member

Yeah, I can do a release with this included. Edit: And we should inctroduce CHANGELOG.

@plribeiro3000
Copy link
Member

Awesome. Thx. Let US know when The realeas is out please. Thanks!

Em sex, 19 de fev de 2016 03:54, Josef Strzibny notifications@github.com
escreveu:

Yeah, I can do a release with this included.


Reply to this email directly or view it on GitHub
#14 (comment).

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.

None yet

3 participants