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

[filesystem] Convert windows to filesystem2 #1267

Merged
merged 1 commit into from
Dec 6, 2019
Merged

Conversation

jaymzh
Copy link
Collaborator

@jaymzh jaymzh commented Oct 6, 2018

Description

Windows doesn't follow quite the same paradigms as Unix, but there's
enough in common that we can still map most things.

Signed-off-by: Phil Dibowitz phil@ipom.com

Check List

@jaymzh jaymzh requested a review from a team October 6, 2018 16:51
@jaymzh
Copy link
Collaborator Author

jaymzh commented Oct 6, 2018

[moving this comment over from the other PR, I'll delete it from there]

OK, I need help from @tas50 or someone. I sorta figured out what's up with the windows crap... It seems like sometimes logical_properties returns an array, but it very clearly creates a Mash and returns it.. and in other tests, it actually does.

The lack of my debug output in the failing tests made me think it was failing to create a Mash, but after running down that rabbit hole for a while, that doesn't seem to be the case.

On my windows VM I cannot repro it using the exact same data:

irb(main):001:0> disks = [{"caption"=>"C:", "deviceid"=>"C:", "size"=>"10000000", "filesystem"=>"NTFS", "freespace"=>"100000", "name"=>"C:", "volumename "=>""}, {"caption"=>"D:", "deviceid"=>"D:", "size"=>"10000000", "filesystem"=>"FAT32", "freespace"=>"100000", "name"=>"D:"}]
 => [{"caption"=>"C:", "deviceid"=>"C:", "size"=>"10000000", "filesystem"=>"NTFS", "freespace"=>"100000", "name"=>"C:", "volumename "=>""}, {"caption"=>"D:", "deviceid"=>"D:", "size"=>"10000000", "filesystem"=>"FAT32", "freespace"=>"100000", "name"=>"D:"}]
irb(main):001:0> x = logical_properties(disks)
PHILD: in logical_properties, got disks: [{"caption"=>"C:", "deviceid"=>"C:", "size"=>"10000000", "filesystem"=>"NTFS", "freespace"=>"100000", "name"=>"C:", "volumename "=>""}, {"caption"=>"D:", "deviceid"=>"D:", "size"=>"10000000", "filesystem"=>"FAT32", "freespace"=>"100000", "name"=>"D:"}]
PHILD: initialized properties: {}
PHILD: adding key ,C:
PHILD: adding key ,D:
PHILD: returning {",C:"=>{"kb_size"=>10000, "kb_available"=>100, "kb_used"=>9900, "percent_used"=>99, "mount"=>"C:", "fs_type"=>"ntfs", "volume_name"=>"", "device"=>""}, ",D:"=>{"kb_size"=>10000, "kb_available"=>100, "kb_used"=>9900, "percent_used"=>99, "mount"=>"D:", "fs_type"=>"fat32", "volume_name"=>"", "device"=>""}}
 => {",C:"=>{"kb_size"=>10000, "kb_available"=>100, "kb_used"=>9900, "percent_used"=>99, "mount"=>"C:", "fs_type"=>"ntfs", "volume_name"=>"", "device"=>""}, ",D:"=>{"kb_size"=>10000, "kb_available"=>100, "kb_used"=>9900, "percent_used"=>99, "mount"=>"D:", "fs_type"=>"fat32", "volume_name"=>"", "device"=>""}}
irb(main):001:0> x
 => {",C:"=>{"kb_size"=>10000, "kb_available"=>100, "kb_used"=>9900, "percent_used"=>99, "mount"=>"C:", "fs_type"=>"ntfs", "volume_name"=>"", "device"=>""}, ",D:"=>{"kb_size"=>10000, "kb_available"=>100, "kb_used"=>9900, "percent_used"=>99, "mount"=>"D:", "fs_type"=>"fat32", "volume_name"=>"", "device"=>""}}

But as you can see from the appveyer output:

  1) Ohai::System Windows Filesystem Plugin #logical_properties Returns a mash
     Failure/Error: expect(plugin.logical_properties(disks)).to be_a(Mash)
       expected [{"caption"=>"C:", "deviceid"=>"C:", "filesystem"=>"NTFS", "freespace"=>"100000", "name"=>"C:", "size..., "deviceid"=>"D:", "filesystem"=>"FAT32", "freespace"=>"100000", "name"=>"D:", "size"=>"10000000"}] to be a kind of Mash
     # ./spec/unit/plugins/windows/filesystem_spec.rb:82:in `block (3 levels) in <top (required)>'

and:

Ohai::System Windows Filesystem Plugin
  #logical_properties
PHILD: test disks is [{"caption"=>"C:", "deviceid"=>"C:", "size"=>"10000000", "filesystem"=>"NTFS", "freespace"=>"100000", "name"=>"C:", "volumename "=>""}, {"caption"=>"D:", "deviceid"=>"D:", "size"=>"10000000", "filesystem"=>"FAT32", "freespace"=>"100000", "name"=>"D:"}]
PHILD: x is [{"caption"=>"C:", "deviceid"=>"C:", "size"=>"10000000", "filesystem"=>"NTFS", "freespace"=>"100000", "name"=>"C:", "volumename "=>""}, {"caption"=>"D:", "deviceid"=>"D:", "size"=>"10000000", "filesystem"=>"FAT32", "freespace"=>"100000", "name"=>"D:"}]
PHILD: x class is Array
    Returns a mash (FAILED - 1)

But then LATER:

PHILD: in logical_properties, got disks: [#<WmiLite::Wmi::Instance:0x0421d028 @wmi_ole_object=#<WIN32OLE:0x0421d148>, @property_map={"access"=>0, "availability"=>nil, "blocksize"=>nil, "caption"=>"C:", "compressed"=>false, "configmanagererrorcode"=>nil, "configmanageruserconfig"=>nil, "creationclassname"=>"Win32_LogicalDisk", "description"=>"Local Fixed Disk", "deviceid"=>"C:", "drivetype"=>3, "errorcleared"=>nil, "errordescription"=>nil, "errormethodology"=>nil, "filesystem"=>"NTFS", "freespace"=>"56576516096", "installdate"=>nil, "lasterrorcode"=>nil, "maximumcomponentlength"=>255, "mediatype"=>12, "name"=>"C:", "numberofblocks"=>nil, "pnpdeviceid"=>nil, "powermanagementcapabilities"=>nil, "powermanagementsupported"=>nil, "providername"=>nil, "purpose"=>nil, "quotasdisabled"=>true, "quotasincomplete"=>false, "quotasrebuilding"=>false, "size"=>"214745214976", "status"=>nil, "statusinfo"=>nil, "supportsdiskquotas"=>true, "supportsfilebasedcompression"=>true, "systemcreationclassname"=>"Win32_ComputerSystem", "systemname"=>"APPVEYOR-VM", "volumedirty"=>false, "volumename"=>"", "volumeserialnumber"=>"1ACC0658"}>]
PHILD: initialized properties: {}
PHILD: adding key ,C:
PHILD: returning {",C:"=>{"kb_size"=>214745214, "kb_available"=>56576516, "kb_used"=>158168698, "percent_used"=>73, "mount"=>"C:", "fs_type"=>"ntfs", "volume_name"=>"", "device"=>""}}

So it works here. WUT?

@jaymzh jaymzh force-pushed the windows_fs2 branch 2 times, most recently from 31ba78b to bc9ba5c Compare October 10, 2018 17:52
@tas50
Copy link
Contributor

tas50 commented Oct 10, 2018

@jaymzh You can rebase this now

@jaymzh
Copy link
Collaborator Author

jaymzh commented Oct 10, 2018

rebased.

@jaymzh
Copy link
Collaborator Author

jaymzh commented Oct 31, 2018

CC @tas50

@jaymzh
Copy link
Collaborator Author

jaymzh commented Dec 19, 2018

OK I think I found the problem. Fix coming that generates this:

  "filesystem": {
    "C:": {
      "kb_size": 137070882,
      "kb_available": 53637890,
      "kb_used": 83432992,
      "percent_used": 60,
      "fs_type": "ntfs",
      "volume_name": "windows 10",
      "encryption_status": "FullyDecrypted",
      "device": "windows 10"
    },
    "D:": {
      "kb_size": 0,
      "kb_available": 0,
      "kb_used": 0,
      "percent_used": 0,
      "fs_type": "",
      "volume_name": "",
      "device": ""
    }
  },
  "filesystem2": {
    "by_device": {
      "windows 10": {
        "kb_size": 137070882,
        "kb_available": 53637890,
        "kb_used": 83432992,
        "percent_used": 60,
        "fs_type": "ntfs",
        "volume_name": "windows 10",
        "encryption_status": "FullyDecrypted",
        "mounts": [
          "C:"
        ]
      },
      "": {
        "kb_size": 0,
        "kb_available": 0,
        "kb_used": 0,
        "percent_used": 0,
        "fs_type": "",
        "volume_name": "",
        "mounts": [
          "D:"
        ]
      }
    },
    "by_mountpoint": {
      "C:": {
        "kb_size": 137070882,
        "kb_available": 53637890,
        "kb_used": 83432992,
        "percent_used": 60,
        "fs_type": "ntfs",
        "volume_name": "windows 10",
        "encryption_status": "FullyDecrypted",
        "devices": [
          "windows 10"
        ]
      },
      "D:": {
        "kb_size": 0,
        "kb_available": 0,
        "kb_used": 0,
        "percent_used": 0,
        "fs_type": "",
        "volume_name": "",
        "devices": [
          ""
        ]
      }
    },
    "by_pair": {
      "windows 10,C:": {
        "kb_size": 137070882,
        "kb_available": 53637890,
        "kb_used": 83432992,
        "percent_used": 60,
        "mount": "C:",
        "fs_type": "ntfs",
        "volume_name": "windows 10",
        "device": "windows 10",
        "encryption_status": "FullyDecrypted"
      },
      ",D:": {
        "kb_size": 0,
        "kb_available": 0,
        "kb_used": 0,
        "percent_used": 0,
        "mount": "D:",
        "fs_type": "",
        "volume_name": "",
        "device": ""
      }
    }
  },

@jaymzh jaymzh force-pushed the windows_fs2 branch 2 times, most recently from 1b6ef24 to 9a3ffe6 Compare December 19, 2018 23:40
@jaymzh
Copy link
Collaborator Author

jaymzh commented Dec 19, 2018

OK @tas50 - so I hadn't looked at the backcompat data and it was broke, but is now fixed.

However, I still ahve the same problem wiht the specs, I could use your help with.

@tas50
Copy link
Contributor

tas50 commented Jul 19, 2019

@jaymzh can you rebase this on master. We killed off appveyor.

@jaymzh
Copy link
Collaborator Author

jaymzh commented Jul 20, 2019

Yes, but it's going to be merge hell since the file was moved and I have to manually add changes that went in since then. So if I do the work, please review it in a timely manner this time around? :)

@jaymzh
Copy link
Collaborator Author

jaymzh commented Jul 20, 2019

OK that actually wasn't bad, only 2 minor changes from you. :)

Unfortunately I no longer have easy access to windows VMs... but the code, as I showed, works (assuming rebase didn't break it), the tests, on the other hand I still don't know why they're being odd.

@jaymzh
Copy link
Collaborator Author

jaymzh commented Nov 4, 2019

@tas50 going on almost 4 months since I rebased so you could review this and 11 months since I updated this to work right on all windows boxes I could find.

@Nimesh-Msys
Copy link
Contributor

@jaymzh , I see a few things to failing these test cases. First and foremost those methods needs to be extracted out from collect(:windows) block. And we need to add "device" property in test cases. Additionally some code changes ("key" selection in different properties) are also required.
For testing, I tried these changes which you could cherry pick from this commit: f93f3e5.

Concern is for few devices, "volumename" is coming as empty ! And due to which we are getting some inappropriate results. Could you please re-check this logic once. Output:

PS> bundle exec ohai filesystem
{
  "": {
    "kb_size": 105981550,
    "kb_available": 76303601,
    "kb_used": 29677949,
    "percent_used": 28,
    "fs_type": "ntfs",
    "volume_name": "",
    "encryption_status": "FullyDecrypted",
    "mount": "C:"
  },
  "vbox_gas_6.0.14": {
    "kb_size": 77195,
    "kb_available": 0,
    "kb_used": 77195,
    "percent_used": 100,
    "fs_type": "cdfs",
    "volume_name": "vbox_gas_6.0.14",
    "mount": "D:"
  }
}

@jaymzh
Copy link
Collaborator Author

jaymzh commented Nov 16, 2019

@Nimesh-Msys - Thanks for looking at this. I... will need to track down a windows machine somewhere to develop this on again. I don't suppose you know of a windows shell service that's cheap or free?

I don't quite understand why you moving those methods out might change the logical_properties from sometimes inexplicably returning an array in tests to returning a Mash as expected. What am I missing?

Also, for the example you give yeah, it's a typo, line 256 is:

device = disk["volumename"].to_s.downcase

but should be:

device = disk["volume_name"].to_s.downcase

I'll fix that.

@jaymzh
Copy link
Collaborator Author

jaymzh commented Nov 16, 2019

Oh... also, is there a reason MsysTechnologiesllc@f93f3e5 isn't upstream?

@jaymzh
Copy link
Collaborator Author

jaymzh commented Nov 16, 2019

@Nimesh-Msys I pulled in your patch as well as fixed that bug you found, and also rebased

@jaymzh jaymzh force-pushed the windows_fs2 branch 8 times, most recently from 2e2f58d to d8ae0b2 Compare November 17, 2019 00:29
Copy link
Contributor

@Nimesh-Msys Nimesh-Msys left a comment

Choose a reason for hiding this comment

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

Oh... also, is there a reason MsysTechnologiesllc@f93f3e5 isn't upstream?

It's a forked repo for internal purpose, Single direct upstream is chef/ohai.

I don't quite understand why you moving those methods out might change the logical_properties from sometimes inexplicably returning an array in tests to returning a Mash as expected.

In case of any failure, or cases where we are unable to retrieve some information(Exceptions), we have managed to continuing working with Mash. So that there won't be any dependency on multiple utilities that we are using to extract core information and then merging that in our results. When that method was within "collect_data(:windows)" block, it was actually not present for plugin's class of our test cases. This leads to an exception, and we were getting Mash as a result. One workaround for testing in this condition is by executing plugin.run.

Could you please cover some test cases. Few expected ones are mentioned below, and then we are good.

expect(data[nil].symbolize_keys.keys).to eq(logical_props)
expect(data[nil]["kb_used"]).to eq(0)
expect(data[nil]["fs_type"]).to be_empty
expect(data[","].symbolize_keys.keys).to eq(logical_props)
Copy link
Contributor

Choose a reason for hiding this comment

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

If I'm right, these test cases I believe are for :filesystem2["by_pair"] ? The way its been done for other OS in PR#1266.
If yes, then could you please add the cases for both "filesystem" and "filesystem2" as the output which is not expected "by_pair" is not captured here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorta - we're not testing the output of the plugin here, but instead logical_properties... but yes I will the appropriate tests

end

it "Refines required logical properties out of given instance" do
data = plugin.logical_properties(disks)
expect(data["C:"].symbolize_keys.keys).to eq(logical_props)
expect(data["D:"].symbolize_keys.keys).to eq(logical_props)
expect(data[",C:"].symbolize_keys.keys).to eq(logical_props)
Copy link
Contributor

Choose a reason for hiding this comment

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

And we can have multiple contexts, wherein when we have volume_name then That information is also present in this key, and this is the case when volume_name is not present.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sure

expect(plugin.merge_info([])).to be_empty
end
let(:logical_info2) { { ",drive1" => { "mount" => "drive1", "o" => 10, "p" => "test1" } } }
let(:encryption_info2) { { "drive2" => { "q" => 10, "r" => "test1" } } }
Copy link
Contributor

Choose a reason for hiding this comment

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

A small concern here, for filesystem, & filesystem2, the nature of keys for logical and encryption should be maintained. Like for fs: "drive1", "drive2" and for fs2: ",drive1", ",drive2", and so on. These methods are processing the core information and then we are merging this info to display the ohai mannered output. Symmetry maintenance would be helpful for further extension.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think so... that doesn't work anymore, which is why I broke that apart. AIUI, encryption_info only returns information on the mountpoint (i.e. drive letter), not volume. So imagine that you had:

MyCoolVolume mounted ad E:
EncryptionInfo doesn't know what MyCoolVolume is because the encryption commands don't return it, they only return the drive letter (E:)

So in order to safely build data we build by pair, so we build a key like MyCoolVolume,E:. However, if we were to try to pretend the encryption_info could be the same, then we'd build ,E:... and that doesn't match. Pretending it does is a lie. To "merge" these, we'd always ignore the first, part, look at the second part and then do exactly what I do above, look at anything that has a mount of E:.

Meanwhile if we don't have a VolumeName then logical_info can of course return ,E:, which has a specific meaning. It means a null-named volume is mounted at E:. But thats not what encryption_info has ever been able to tell you - all it can tell you is some encryption info about whatever happens to be mounted at E:.

Therefore trying to make the keys the same is impossible, and making them look the same is misleading and confusing, so I very specifically made it clear they were saying different things.

property[:mount] = mount
property[:fs_type] = disk["filesystem"].to_s.downcase
property[:volume_name] = device
property[:device] = device
Copy link
Contributor

Choose a reason for hiding this comment

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

The property :device should be added in Yard formatted comments above the method.

@jaymzh jaymzh force-pushed the windows_fs2 branch 2 times, most recently from 28b861b to 5d59e13 Compare November 21, 2019 05:26
@jaymzh
Copy link
Collaborator Author

jaymzh commented Nov 21, 2019

OK @Nimesh-Msys - yard docs updated, tons of tests added.

@jaymzh
Copy link
Collaborator Author

jaymzh commented Nov 21, 2019

@Nimesh-Msys Removed debug. Update commit message to remove comments about tests not passing and other silly stuff. Updated PR description accordingly.

BTW - why are there the two buildkite tests that don't do anything and report failure? :(

@Nimesh-Msys
Copy link
Contributor

BTW - why are there the two buildkite tests that don't do anything and report failure? :(

@tas50 might be able to help you out on this.

@jaymzh
Copy link
Collaborator Author

jaymzh commented Nov 21, 2019

@Nimesh-Msys - I'll bug @tas50 about it during the community meeting in the morning. I'm sure he'll be happy, I've been bugging him about this PR for 13 months.:) In the meantime, if you're happy with it, wanna approve it?

@jaymzh
Copy link
Collaborator Author

jaymzh commented Nov 21, 2019

According to today's Developer Meeting:

tas50 9:22 AM: I’ll fix it
it’d take longer to disable them

So @tas50 is on it ... modulo some driving today. Hopefully we can get this merged this week and finally be done with this PR.

Windows doesn't follow quite the same paradigms as Unix, but there's
enough in common that we can still map most things.

Signed-off-by: Phil Dibowitz <phil@ipom.com>
@jaymzh
Copy link
Collaborator Author

jaymzh commented Nov 26, 2019

@Nimesh-Msys / @tas50 - anything left here? Would really like to get this wrapped up.

@jaymzh
Copy link
Collaborator Author

jaymzh commented Dec 4, 2019

@tas50 post-thanksgiving friendly i-think-everyone-is-happy-and-the-tests-pass-and-it's-been-14-months ping :)

@tas50
Copy link
Contributor

tas50 commented Dec 6, 2019

So this seems fine as an additional option in filesystem2, but I wouldn't support making this the default on Windows systems. It's going to require a lot of folks to rework their cookbooks and I'm not sure the benefit is enough for that.

We've introduced a lot of artificial roadblocks to upgrades over the years that have resulted in many users just sticking with older releases like Chef 12 to avoid upgrade pains. I'd really like to avoid those sort of backwards compatibility breaks unless we need to. filesystem2 is there for anyone that wants drives by pair or label.

@tas50 tas50 merged commit 1d9343d into chef:master Dec 6, 2019
@jaymzh
Copy link
Collaborator Author

jaymzh commented Dec 6, 2019

I think it's far, far, far, far worse to have filesystem on different platforms be different. It's trivial for anyone to use ['filesystem']['by_mountpoint'] if they want. We have to do the filesystem->filesystem2->filesystem dane with bsd and hpux and solaris bla bla bla ANYWAY. It's do it with ALL these platforms once and for all and be done with the confusion.

@NaomiReeves
Copy link

I'll echo what @jaymzh is saying. In many of our API cookbooks we reference filesystem and trying to maintain these two separate APIs and definitions of filesystem on a platform by platform basis is going to be much more work and a headache moving forward than it is for us to convert.

We already had to do the conversion for linux and darwin but not having bsd and the other unixes on the new API definition changed assumptions about the functionality of the API and caused breakage for us, raised in issue #1180. The community now has to do the filesystem => filesystem2 => filesystem conversion again (as outlined in issue #1271) for bsd(due to #1181) and the remaining unixes (due to #1266).

Continuing to have a split brain definition for one remaining OS makes the API fragile and more prone to causing problems. We should be able to trust that the filesystem API means the same thing across all platforms. Please add windows to the list of OS's that are converting in issue #1271 so we don't have to do this again.

@tas50
Copy link
Contributor

tas50 commented Dec 10, 2019

While it's trivial to use the new mountpoint logic now it's a hurdle to upgrades and historically changing logic in Ohai has prevented users from upgrading to the latest version of Chef Infra. A very large percentage of our userbase is still on Chef 12 due to the difficulty in upgrading Chef versions. A "trivial" change to ohai attributes means that a customer needs to build logic into their cookbooks that checks Chef versions and uses different attributes based on the client they're running. That becomes a non-trivial change for complex Chef installations. In the end, we're doing this to provide the ability to sort of labels, which is somewhat meaningless in Windows as anyone can change them to anything. I get standardizing attributes, but here we've bent Windows to match *nix in a way that provides limited utility at best. In doing so we're requiring a large number of users to untake an attribute migration. I don't see that as benefiting our userbase. Different operating systems are always going to present data in Ohai differently and that's by design. We aim to standardize attributes where it makes sense, but standardizing attributes on differing operating systems often results in a less than ideal API.

@jaymzh
Copy link
Collaborator Author

jaymzh commented Dec 11, 2019

I understand what you're saying. @NaomiReeves and I went through a LOT of work getting Facebook off of Chef 12 (and her way more than I). I sympathize, I do... but this is part of the reason I'm urging you to do Windows along with the others as you plan on doing in #1271. Because people WILL have to migrate and it becomes the difference between something like this to get to the intermediate version of chef:

option 1 - when all things convert

device = node.windows? ? "E:\" : "/dev/magic"
if node['filelsystem2']
  node['filesystem2']['by_device'][device]['bytes_free']
else
  # old format
  node['filesystem'][device]['bytes_free']
fi

And then this once you're there:

device = node.windows? ? "E:\" : "/dev/magic"
if node['filelsystem2']
  node['filesystem2']['by_device'][device]['bytes_free']
else
  # we're done, this platform is fully converted!
  node['filesystem']['by_device'][device]['bytes_free']
fi

and eventually:

device = node.windows? ? "E:\" : "/dev/magic"
node['filesystem']['by_device'][device]['bytes_free']

option 2 - when they don't

ORRRRR I have to crazytown like this:

device = node.windows? ? "E:\" : "/dev/magic"
if node.linux?
  # linux/mac was converted already, so the new API is under FS
  node['filesystem']['by_device'][device]['bytes_free']
elsif node.bsd?  || node.macosx?
  # bsd and mac was done next, and is in conversion, depending on what version we're on
  # we could have either, but if we don't have fs2 its' because we're DONE converting instead
  # of not-yet converted
  if node['filelsystem2']
    node['filesystem2']['by_device'][device]['bytes_free']
  else
    node['filesystem']]'by_device'][device]['bytes_free']
  end
elsif node.windows?
  # Windows was never fully converted. what? why?
  node['filesystem2']['by_device'][device]['bytes_free']
else
  # the rest of platforms have STARTED converting, so if we don' thave filesystem2 we're
  # on the old API.
  # TODO: CHEF 16!!! Once we are on a version that has the new filesystem2 everywhere we need
  # to change this `else` to look like the bsd/mac one above
  if node['filelsystem2']
    node['filesystem2']['by_device'][device]['bytes_free']
  else
    node['filesystem'][device]['bytes_free']
  end
end

And then eventually:

device = node.windows? ? "E:\" : "/dev/magic"
if node.linux? || node.bsd?  || node.macosx?
  # linux/mac was converted already, so the new API is under FS
  node['filesystem']['by_device'][device]['bytes_free']
elsif node.windows?
  # Windows was never fully converted. what? why?
  node['filesystem2']['by_device'][device]['bytes_free']
else
  if node['filelsystem2']
    node['filesystem2']['by_device'][device]['bytes_free']
  else
    node['filesystem']['by_device'][device]['bytes_free']
  end
end

and then eventually:

device = node.windows? ? "E:\" : "/dev/magic"
if node.windows?
  # Windows was never fully converted. what? why?
  node['filesystem']['device']['bytes_free']
else
  # Windows was never fully converted. what? why?
  node['filesystem2']['by_device'][device]['bytes_free']
end

and never getting past that ugliness?

I understanding that "hey $customer your code will never ever have to change" is really attractive, but you're making everyone's code (and your own uglier), you're increasing support costs significantly, you're making the documentation much harder to generate, you're making expectations much less obvious. Leaving them separate trades a small amount of short-term gain for a much much bigger long-term loss.

facebook-github-bot pushed a commit to facebook/chef-cookbooks that referenced this pull request Jan 20, 2020
Summary:
Converting the `fb_systemd` cookbook over to the `ohai_fs_ver` node method.

In chef 13, the filesystem ohai plugin was replaced with the filesystem2 plugin, and the `filesystem2` data is written to both the `filesystem2` and `filesystem` apis. All uses of the old `filesystem` api were converted to the `filesystem2` api before I upgraded the fleet to chef 13 (tracked in T28228267). In order to upgrade to Chef 14+, we need to remove the references to the `filesystem2` api. However, there are some outlier operating systems that missed the conversion and so we're going to use a node method to detect what api is available and use that one so we can continue to support this transition for those other platforms.

official deprecation: https://docs.chef.io/deprecations_ohai_filesystem.html

PR to covert BSD: chef/ohai#1181
PR to convert the rest of Unix (solaris, aix): chef/ohai#1266
PR to convert Windows: chef/ohai#1267

Reviewed By: davide125

Differential Revision: D19466401

fbshipit-source-id: 9c9a1e7838e8a9e969c00ef611dce03f3dd9249d
facebook-github-bot pushed a commit to facebook/chef-cookbooks that referenced this pull request Jan 20, 2020
Summary: Well, until chef/ohai#1267 and I'm not backporting that just yet, so we'll actually test for the existence of `node['whatever_filesystem_ohai_version']['by_mountpoint']` and if it exists... continue

Reviewed By: davide125

Differential Revision: D19467985

fbshipit-source-id: a6df657de74d3e2eae653624aa422550c4ef26b8
facebook-github-bot pushed a commit to facebook/chef-cookbooks that referenced this pull request Mar 24, 2020
Summary:
Converting the `fb_swap` cookbook over to the `filesystem_data` node method.

In chef 13, the filesystem ohai plugin was replaced with the filesystem2 plugin, and the `filesystem2` data is written to both the `filesystem2` and `filesystem` apis. All uses of the old `filesystem` api were converted to the `filesystem2` api before I upgraded the fleet to chef 13 (tracked in T28228267). In order to upgrade to Chef 14+, we need to remove the references to the `filesystem2` api. However, there are some outlier operating systems that missed the conversion and so we're going to use a node method to detect what api is available and use that one so we can continue to support this transition for those other platforms.

official deprecation: https://docs.chef.io/deprecations_ohai_filesystem.html

PR to covert BSD: chef/ohai#1181
PR to convert the rest of Unix (solaris, aix): chef/ohai#1266
PR to convert Windows: chef/ohai#1267

Reviewed By: davide125

Differential Revision: D20610482

fbshipit-source-id: 01e9eb9073c226d18683ec0b0c806472f7e27c49
facebook-github-bot pushed a commit to facebook/chef-cookbooks that referenced this pull request Mar 25, 2020
Summary:
Converting the `fb_storage` cookbook over to the `filesystem_data` node method.

In chef 13, the `filesystem` ohai plugin was replaced with the `filesystem2` plugin, and the `filesystem2` data is written to both the `filesystem2` and `filesystem` apis. All uses of the old `filesystem` api were converted to the `filesystem2` api before I upgraded the fleet to chef 13 (tracked in T28228267). In order to upgrade to Chef 14+, we need to remove the references to the `filesystem2` api. However, there are some outlier operating systems that missed the conversion and so we're going to use a node method to detect what api is available and use that one so we can continue to support this transition for those other platforms.

official deprecation: https://docs.chef.io/deprecations_ohai_filesystem.html

PR to covert BSD: chef/ohai#1181
PR to convert the rest of Unix (solaris, aix): chef/ohai#1266
PR to convert Windows: chef/ohai#1267

Reviewed By: davide125

Differential Revision: D20634208

fbshipit-source-id: 90d3d3a00763d4e74fbda648c57a0abd6b649656
facebook-github-bot pushed a commit to facebook/chef-cookbooks that referenced this pull request Apr 29, 2020
Summary:
Converting the `fb_helpers` cookbook over to the `filesystem_data` node method.

In chef 13, the `filesystem` ohai plugin was replaced with the `filesystem2` plugin, and the `filesystem2` data is written to both the `filesystem2` and `filesystem` apis. All uses of the old `filesystem` api were converted to the `filesystem2` api before I upgraded the fleet to chef 13 (tracked in T28228267). In order to upgrade to Chef 14+, we need to remove the references to the `filesystem2` api. However, there are some outlier operating systems that missed the conversion and so we're going to use a node method to detect what api is available and use that one so we can continue to support this transition for those other platforms.

I'm also adding in some checks to validate that the various keys we are using in some of these methods actually exist so we don't end up with the `#<NoMethodError: undefined method `[]' for nil:NilClass>` issues

official deprecation: https://docs.chef.io/deprecations_ohai_filesystem.html
PR to covert BSD: chef/ohai#1181
PR to convert the rest of Unix (solaris, aix): chef/ohai#1266
PR to convert Windows: chef/ohai#1267

Reviewed By: joshuamiller01

Differential Revision: D21030821

fbshipit-source-id: 5457a9cdc35c55a33f43413ad7f5cf20b8ea593d
facebook-github-bot pushed a commit to facebook/IT-CPE that referenced this pull request Apr 29, 2020
Summary:
Converting the `fb_helpers` cookbook over to the `filesystem_data` node method.

In chef 13, the `filesystem` ohai plugin was replaced with the `filesystem2` plugin, and the `filesystem2` data is written to both the `filesystem2` and `filesystem` apis. All uses of the old `filesystem` api were converted to the `filesystem2` api before I upgraded the fleet to chef 13 (tracked in T28228267). In order to upgrade to Chef 14+, we need to remove the references to the `filesystem2` api. However, there are some outlier operating systems that missed the conversion and so we're going to use a node method to detect what api is available and use that one so we can continue to support this transition for those other platforms.

I'm also adding in some checks to validate that the various keys we are using in some of these methods actually exist so we don't end up with the `#<NoMethodError: undefined method `[]' for nil:NilClass>` issues

official deprecation: https://docs.chef.io/deprecations_ohai_filesystem.html
PR to covert BSD: chef/ohai#1181
PR to convert the rest of Unix (solaris, aix): chef/ohai#1266
PR to convert Windows: chef/ohai#1267

Reviewed By: joshuamiller01

Differential Revision: D21030821

fbshipit-source-id: 5457a9cdc35c55a33f43413ad7f5cf20b8ea593d
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

4 participants