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

Add support for PE package inventory facts #229

Merged
merged 3 commits into from
Dec 18, 2020

Conversation

seanmil
Copy link
Contributor

@seanmil seanmil commented Dec 14, 2020

Overview

This pull request introduces functionality to feed the data from the
Puppet Enterprise package inventory feature back into the compile
process.

When an agent gathers facts in a Puppet Enterprise environment with
the PE-specific package inventory feature turned on, the package
inventory is returned as part of the fact upload and then that
package data is available in a PuppetDB endpoint independent of the
rest of the facter data.

You should not generally need to include the package inventory data
for Octocatalog-Diff testing, but if you have a specific reason to
want it included to more closely match what occurs in production
this addition allows it to be included.

Checklist

  • Make sure that all of the tests pass, and fix any that don't. Just run rake in your checkout directory, or review the CI job triggered whenever you push to a pull request.
  • Make sure that there is 100% test coverage by running rake coverage:spec or ignoring untestable sections of code with # :nocov comments. If you need help getting to 100% coverage please ask; however, don't just submit code with no tests.
  • If you have added a new command line option, we would greatly appreciate a corresponding integration test that exercises it from start to finish. This is optional but recommended.
  • If you have added any new gem dependencies, make sure those gems are licensed under the MIT or Apache 2.0 license. We cannot add any dependencies on gems licensed under GPL.
  • If you have added any new gem dependencies, make sure you've checked in a copy of the .gem file into the vendor/cache directory.

seanmil and others added 2 commits December 14, 2020 09:03
When an agent gathers facts in a Puppet Enterprise environment with
the PE-specific package inventory feature turned on, the package
inventory is returned as part of the fact upload and then that
package data is available in a PuppetDB endpoint independent of the
rest of the facter data.

You should not generally need to include the package inventory data
for Octocatalog-Diff testing, but if you have a specific reason to
want it included to more closely match what occurs in production
this addition allows it to be included.
Copy link
Contributor

@ahayworth ahayworth left a comment

Choose a reason for hiding this comment

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

This seems okay to me, in general. Since I don't have a way to test against PE at the moment, could you post a diff output when this feature is used?

@ahayworth ahayworth added this to the 2.0.0 milestone Dec 17, 2020
@seanmil
Copy link
Contributor Author

seanmil commented Dec 18, 2020

This seems okay to me, in general. Since I don't have a way to test against PE at the moment, could you post a diff output when this feature is used?

Let me see if I can come up with something simple but effective to show the behavior.

@seanmil
Copy link
Contributor Author

seanmil commented Dec 18, 2020

This seems okay to me, in general. Since I don't have a way to test against PE at the moment, could you post a diff output when this feature is used?

@ahayworth Given that the only difference when enabling this option is the addition of one extra fact in both the from and to compiles it wasn't quite as simple as doing notify on the fact and seeing the difference (because enabled or disabled the fact value should be the same), so I came up with the following:

$timestamp = Timestamp.new()
$pkgs = $facts.dig('_puppet_inventory_1', 'packages')

if $pkgs {
  $pkg_count = $pkgs.length
  $msg = "${String($timestamp)}: ${pkg_count} packages"
} else {
  $msg = "${String($timestamp)}: ${String($facts['_puppet_inventory_1'], '%p')}"
}

notify { 'package_inventory_count':
  message => $msg,
}

The idea is that the timestamp will differ, even if the actual fact does not. With the above code I get:

$ bundle exec octocatalog-diff <a bunch of options> --no-puppetdb-package-inventory
I, [2020-12-18T17:00:53.677306 #12217]  INFO -- : Catalogs compiled for mytestnode
I, [2020-12-18T17:00:53.678453 #12217]  INFO -- : Diffs computed for mytestnode
  Notify[package_inventory_count] =>
   parameters =>
     message =>
      - 2020-12-18T17:00:53.524052575 UTC: undef
      + 2020-12-18T17:00:53.601770732 UTC: undef
*******************************************

With the new option enabled:

$ bundle exec octocatalog-diff <a bunch of options> --puppetdb-package-inventory
I, [2020-12-18T17:01:56.641819 #12576]  INFO -- : Catalogs compiled for mytestnode
I, [2020-12-18T17:01:56.643138 #12576]  INFO -- : Diffs computed for mytestnode
  Notify[package_inventory_count] =>
   parameters =>
     message =>
      - 2020-12-18T17:01:56.529232507 UTC: 773 packages
      + 2020-12-18T17:01:56.560630729 UTC: 773 packages
*******************************************

Was that what you were looking for?

@ahayworth
Copy link
Contributor

@seanmil Yeah, that works! Seeing the puppet code is actually what made sense to me. In retrospect ... the change actually makes a lot more sense than I initially thought and I am not really sure what I was worried about. 😆

@ahayworth ahayworth merged commit 8550721 into github:master Dec 18, 2020
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

2 participants