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

Helpers do not work with kitchen test as expected #92

Open
jakereps opened this issue Oct 16, 2020 · 3 comments
Open

Helpers do not work with kitchen test as expected #92

jakereps opened this issue Oct 16, 2020 · 3 comments

Comments

@jakereps
Copy link

I'm not proficient in Ruby, but It appears that the method being used in this fallback handling (vault?) raises an exception that isn't handled in this helper, so instead of ever going to the "databag_falback" case it instead just hard stops and errors. The chef output in my kitchen test shows that it is resolving "chef-vault (4.0.3)".

https://github.com/chef/chef-vault/blob/master/lib/chef-vault/item.rb#L320

================================================================================
Recipe Compile Error in /tmp/kitchen/cache/cookbooks/cookbook/recipes/default.rb
================================================================================

Net::HTTPServerException
------------------------
404 "Not Found"

Cookbook Trace:
---------------
/tmp/kitchen/cache/cookbooks/chef-vault/libraries/helpers.rb:37:in `chef_vault_item'
/tmp/kitchen/cache/cookbooks/cookbook/recipes/configuration.rb:36:in `block in
from_file'
/tmp/kitchen/cache/cookbooks/cookbook/recipes/configuration.rb:32:in `from_fil
e'
/tmp/kitchen/cache/cookbooks/cookbook/recipes/default.rb:13:in `from_file'

Relevant File Content:
----------------------
/tmp/kitchen/cache/cookbooks/chef-vault/libraries/helpers.rb:

30:    # +node['chef-vault']['databag_fallback']+.
31:    # @example
32:    # item = chef_vault_item('secrets', 'bacon')
33:    # log 'Yeah buddy!' if item['_default']['type']
34:    # @param [String] bag Name of the data bag to load from.
35:    # @param [String] id Identifier of the data bag item to load.
36:    def chef_vault_item(bag, id)
37>>     if ChefVault::Item.vault?(bag, id)
38:        ChefVault::Item.load(bag, id)
39:      elsif node['chef-vault']['databag_fallback']
40:        data_bag_item(bag, id)
41:      else
42:        raise "Trying to load a regular data bag item #{id} from #{bag}, and databag_fallback is disabl
ed"
43:      end
44:    end
45:
46:    # Helper method that allows for listing the ids of a vault in a recipe.

System Info:
------------
chef_version=15.10.12
platform=centos
platform_version=7.8.2003
ruby=ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-linux]
program_name=/opt/chef/bin/chef-client
executable=/opt/chef/bin/chef-client

Escalating from a comment in another issue to its own issue as it still presents on new chef versions (initially wondered if it was relevant to being on such an old release). #64 (comment)

@jakereps
Copy link
Author

I would also be willing to assist in any dev that may or may not be required to fix this, assuming it isn't user error 👍

@artem-aksenkin
Copy link

+1

       ================================================================================
       Recipe Compile Error in /tmp/kitchen/cache/cookbooks/tmg-splunk-client/recipes/default.rb
       ================================================================================

       ChefVault::Exceptions::ItemNotFound
       -----------------------------------
       vault/splunk__default not found

       Cookbook Trace: (most recent call first)
       ----------------------------------------
         /tmp/kitchen/cache/cookbooks/chef-vault/libraries/helpers.rb:37:in `chef_vault_item'
         /tmp/kitchen/cache/cookbooks/chef-splunk/recipes/default.rb:22:in `from_file'
         /tmp/kitchen/cache/cookbooks/tmg-splunk-client/recipes/default.rb:10:in `from_file'

       Relevant File Content:
       ----------------------
       /tmp/kitchen/cache/cookbooks/chef-vault/libraries/helpers.rb:

        30:    # +node['chef-vault']['databag_fallback']+.
        31:    # @example
        32:    # item = chef_vault_item('secrets', 'bacon')
        33:    # log 'Yeah buddy!' if item['_default']['type']
        34:    # @param [String] bag Name of the data bag to load from.
        35:    # @param [String] id Identifier of the data bag item to load.
        36:    def chef_vault_item(bag, id)
        37>>     if ChefVault::Item.vault?(bag, id)
        38:        ChefVault::Item.load(bag, id)
        39:      elsif node['chef-vault']['databag_fallback']
        40:        data_bag_item(bag, id)
        41:      else
        42:        raise "Trying to load a regular data bag item #{id} from #{bag}, and databag_fallback is disabled"
        43:      end
        44:    end
        45:
        46:    # Helper method that allows for listing the ids of a vault in a recipe.

       System Info:
       ------------
       chef_version=16.9.20
       platform=amazon
       platform_version=2
       ruby=ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
       program_name=/opt/chef/bin/chef-client
       executable=/opt/chef/bin/chef-client


       Running handlers:
       [2021-01-20T16:28:32+00:00] ERROR: Running exception handlers
       Running handlers complete
       [2021-01-20T16:28:32+00:00] ERROR: Exception handlers complete
       Chef Infra Client failed. 0 resources updated in 01 seconds
       [2021-01-20T16:28:32+00:00] FATAL: Stacktrace dumped to /tmp/kitchen/cache/chef-stacktrace.out
       [2021-01-20T16:28:32+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
       [2021-01-20T16:28:32+00:00] FATAL: ChefVault::Exceptions::ItemNotFound: vault/splunk__default not found

@artem-aksenkin
Copy link

If somebody is googling this.
Fixed by adding the line to the kitchen.yml provisioner section:

provisioner:
  data_bags_path: test/fixtures/data_bags

and placing the data_bag to test/fixtures/data_bags/vault/splunk__default.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants