Feature #10238

Add support for identifying block devices to Facter

Added by Jason Gill 7 months ago. Updated 5 days ago.

Status:Closed Start date:10/23/2011
Priority:Low Due date:
Assignee:Adrien Thebo % Done:

0%

Category:library
Target version:2.0.0
Keywords: Affected Facter version:
Branch:
Votes: 0

Description

I’ve written a simple fact for Facter which parses /sys/block/ on Linux to identify block devices attached to the machine. This fact is serving as a good base for a hardware RAID querying fact that I’m working on, so I hoped to get it added to a future release of Facter. Additionally, users of the Puppet Inventory Service could find this quite handy for identifying the disks attached to machines (we have hundreds of servers with a large number of different disks and we’re trying to identify machines that have older or slower drives still in use).

You can find my code over at github

Example output from a machine with 2x Dell PowerEdge RAID Controller arrays and a CD drive:

blockdevice_sda => DELL PERC H700
blockdevice_sdb => DELL PERC H700
blockdevice_sr0 => TEAC DVD-ROM DV-28SW
blockdevices => sda,sdb,sr0    

Example output from a machine with two Western Digital SATA disks:

blockdevice_sda => ATA WDC WD5000AAKS-0
blockdevice_sdb => ATA WDC WD5000AAKS-0
blockdevices => sda,sdb

I’m open to feedback (or please close this if I’m out of line suggesting a new fact that I wrote) – this is my first real Ruby work!

History

Updated by James Turnbull 7 months ago

  • Category set to library
  • Status changed from Unreviewed to Needs Decision
  • Assignee set to Adrien Thebo

Updated by Adrien Thebo 7 months ago

This is actually a pretty cool fact, and I can see the utility. However, the concern that I have is that all the actual evaluation of the block devices happens outside of the setcode blocks, which means that this will only be evaluated at load time. If someone were to hot swap a hard drive and facter was running in a long running ruby process, it would not pick up the change. I’ll run this by a dev and see what they think, but again, this would definitely be good to have inside facter.

Updated by Jason Gill 7 months ago

Adrien, thanks for the feedback! I hadn’t considered the situation you describe (although I can see where that would happen) – if you guys have any suggestions on how to improve the code I am happy to listen. This was my first real crack at Ruby so I’m sure it needs a lot of work.

Thanks again and let me know what else I can do if anything to try to help!

Updated by Jason Gill 7 months ago

I’ve just pushed a minor update to the github repo for this fact which prevents a small bug in the rare case that a device has a /sys/block/*/device/ directory but no vendor and model files.

Additionally I’ve reviewed some of the other core facts and the situation you describe appears in many of them (for example network interfaces – these could change on demand especially in a virtualized environment, or in cases where removal (USB) network interfaces were used). If there is a recommended workaround I can try to update any fact that might be impacted by changes during a long running facter process but otherwise I think it may just be an occupational hazard of having a long running process :)

Updated by Adrien Thebo 6 months ago

  • Status changed from Needs Decision to Tests Insufficient

The more that I’ve thought about it the more I’ve realized that facter isn’t designed to update dynamically generated facts like this, and trying to shim that behavior would be too hard. As it stands this fact is great though. Would you be willing to write some tests to verify the behavior of this fact?

Updated by Jason Gill 6 months ago

  • Assignee changed from Adrien Thebo to Jason Gill

Adrien, no problem at all – I’ll write some tests now!

Updated by Jason Gill 6 months ago

  • Assignee changed from Jason Gill to Adrien Thebo

I have written tests that should handle all of the cases I could think of and submitted a GitHub pull request which references this ticket.

https://github.com/puppetlabs/facter/pull/98

Let me know your thoughts and if there is more that needs to be added. Thanks for your help and insight on Facter so far!

Updated by Ken Barber 6 months ago

So I love the idea of tracking this. By I wanted to add my 2p just for good luck.

Do we expect other metadata to be gleaned about a block device? Here we are assuming that ‘vendor model’ is the main piece of information a user wants about a device. What about other properties such as size, type?

An approach might be to break this out somehow. For example:

blockdevice_sda_vendor
blockdevice_sda_model
blockdevice_sda_size
blockdevice_sda_type

(Which would look much nicer if we had structured data support).

Updated by Jason Gill 6 months ago

Ken I totally agree, having the size and other details (like SCSI LUN, etc) would be really great. However in this initial version I just went with what was most important to me – the names of the devices (sda sdb sdc) and the make/model (which has been really handy to find which machines have what type of drives, locate old drives, etc, with puppet inventory service).

That being said, adding even more facts probably isn’t the solution – on some of my boxes that have 500+ IP’s up on them, it takes facter about 20 seconds to run and generate all ~1600 facts that come “out of the box” with 1.6.2.

Would it be better to just add more in to the existing blockdevice_sda fact (like a comma separated list of values or some other ugliness)? Or is it possible that a future version of facter could support this sort of “advanced” fact in a hash style or similar?

Updated by Ken Barber 6 months ago

Jason Gill wrote:

Ken I totally agree, having the size and other details (like SCSI LUN, etc) would be really great. However in this initial version I just went with what was most important to me – the names of the devices (sda sdb sdc) and the make/model (which has been really handy to find which machines have what type of drives, locate old drives, etc, with puppet inventory service).

Lol. The driving force behind most facter submissions :–). We have the problem of trying to please everyone though :–).

That being said, adding even more facts probably isn’t the solution – on some of my boxes that have 500+ IP’s up on them, it takes facter about 20 seconds to run and generate all ~1600 facts that come “out of the box” with 1.6.2.

Sounds like you need caching really :–). This particular fact you’ve written to read files is very light.

Would it be better to just add more in to the existing blockdevice_sda fact (like a comma separated list of values or some other ugliness)?

Possible – do you have a proposed format?

Or is it possible that a future version of facter could support this sort of “advanced” fact in a hash style or similar?

Yes – but in the future. There is a ticket about it somewhere.

Updated by Jason Gill 6 months ago

I think the only other information that can be reliably retrieved is size (it’s the value of /sys/block/*/size multiplied by 512 to get bytes). Other details like SCSI LUN, if the device is removable, etc, may be harder to detect and are more edge cases than it may be worth finding.

That being said, it’s easy to get the size = I could just update the fact to report:

blockdevice_sda => WDC WD5000AAKS-0,465.76 GB
blockdevice_sdb => DELL PERC H700,4.09 TB
blockdevices => sda,sdb

The memory fact already has a nice util class which can shift numbers from bytes to the appropriate scale (ie, GB, TB) which could be stolen and used here.

Thoughts? This should be real easy to add and add tests for

Updated by Ken Barber 6 months ago

Jason Gill wrote:

I think the only other information that can be reliably retrieved is size (it’s the value of /sys/block/*/size multiplied by 512 to get bytes). Other details like SCSI LUN, if the device is removable, etc, may be harder to detect and are more edge cases than it may be worth finding.

That being said, it’s easy to get the size = I could just update the fact to report:

blockdevice_sda => WDC WD5000AAKS-0,465.76 GB
blockdevice_sdb => DELL PERC H700,4.09 TB
blockdevices => sda,sdb

The memory fact already has a nice util class which can shift numbers from bytes to the appropriate scale (ie, GB, TB) which could be stolen and used here.

Funny – but most consumers of facts don’t like this shortening … as you can’t just go and use arithmetic with it :–). If I could go back and fix all the other numbers around facter to not use this I probably would :–).

Thoughts? This should be real easy to add and add tests for

I’m not sure I really like comma separated values for this. Its a fixed column index which isn’t very flexible when someone wants to add something later on. Also – what is the behaviour when a column is empty for whatever reason.

Also – wouldn’t model and vendor be comma separated?

Updated by Jason Gill 6 months ago

Hmm good points. I can easily change to the format you suggested:

blockdevice_sda_model
blockdevice_sda_vendor
blockdevice_sda_size (and just leave this in bytes)

and we can add more facts in the future if needed. Sound acceptable?

Updated by Ken Barber 6 months ago

Fine by me. Anyone else?

Updated by Jason Gill 6 months ago

Done; I’ve replaced the commit in the pull request (https://github.com/puppetlabs/facter/pull/98) and I’ve also included updated tests that check for the new output. Tested on my machines without any issues; here is some example output:

blockdevice_sda_model => WDC WD5000AAKS-0
blockdevice_sda_size => 500107862016
blockdevice_sda_vendor => ATA
blockdevice_sdb_model => WDC WD5000AAKS-0
blockdevice_sdb_size => 500107862016
blockdevice_sdb_vendor => ATA
blockdevices => sda,sdb

Thanks guys!

Updated by Adrien Thebo 6 months ago

  • Status changed from Tests Insufficient to In Topic Branch Pending Review

I’m happy with this. Ken, what are your thoughts?

Updated by Ken Barber 6 months ago

  • Status changed from In Topic Branch Pending Review to Merged - Pending Release
  • Target version set to 2.0.0

I’ve tested this myself and it looks okay to me. Merged into master.

Updated by Matthaus Litteken 5 days ago

  • Status changed from Merged - Pending Release to Closed

Released in facter 2.0.0rc1

Also available in: Atom PDF