sous-chefs / users

Development repository for the users cookbook
https://supermarket.chef.io/cookbooks/users
Apache License 2.0
138 stars 217 forks source link

Error executing action `remove` on resource 'users_manage[rebels]' - 404 #352

Closed cowgill closed 7 years ago

cowgill commented 8 years ago

Cookbook version

3.0.0

Chef-client version

12.13.37

Platform Details

MacBook Pro mid 2012. El Capitan 10.11.6. Kitchen Test Vagrant Ubuntu 16.04 Chef Development Kit Version: 0.17.17 berks version: 4.3.5 kitchen version: 1.11.1

$ kitchen list
Instance             Driver   Provisioner  Verifier  Transport  Last Action
default-ubuntu-1604  Vagrant  ChefZero     Inspec    Ssh        Created

Scenario:

Trying to build a test kitchen following this tutorial. I've got all the files setup correctly with users in the data_bags/users dir.

Steps to Reproduce:

$ cd ~/chef-repo/cookbooks/my_users/
$ kitchen create
$ kitchen converge

kitchen.yml


---
driver:
  name: vagrant

provisioner:
  name: chef_zero

verifier:
  name: inspec

platforms:
  - name: ubuntu-16.04

suites:
  - name: default
    run_list:
      - recipe[my_users::default]
    verifier:
      inspec_tests:
        - test/recipes
    attributes:

metadata.rb

name 'my_users'
version '0.1.0'

depends 'users'
depends 'sudo'

recipes/default.rb

users_manage "rebels" do
   group_id 1138
   action [ :remove, :create ]
 end

Expected Result:

The test kitchen to load without any errors and create the user and group.

Actual Result:

-----> Starting Kitchen (v1.11.1)
-----> Converging <default-ubuntu-1604>...
       Preparing files for transfer
       Preparing dna.json
       Resolving cookbook dependencies with Berkshelf 4.3.5...
       Removing non-cookbook files before transfer
       Preparing validation.pem
       Preparing client.rb
-----> Installing Chef Omnibus (install only if missing)
       Downloading https://omnitruck.chef.io/install.sh to file /tmp/install.sh
       Trying wget...
       Download complete.
       ubuntu 16.04 x86_64
       Getting information for chef stable  for ubuntu...
       downloading https://omnitruck.chef.io/stable/chef/metadata?v=&p=ubuntu&pv=16.04&m=x86_64
         to file /tmp/install.sh.6079/metadata.txt
       trying wget...
       sha1 72a0a10ba5684d1e51590c1bc022bcb2e99348c6
       sha256   973c2bc9a84822158ba7c0c360d0a25c97420f293ccbe5d8019615a411460785
       url  https://packages.chef.io/stable/ubuntu/14.04/chef_12.13.37-1_amd64.deb
       version  12.13.37
       downloaded metadata file looks valid...
       downloading https://packages.chef.io/stable/ubuntu/14.04/chef_12.13.37-1_amd64.deb
         to file /tmp/install.sh.6079/chef_12.13.37-1_amd64.deb
       trying wget...
       Comparing checksum with sha256sum...

       WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING

       You are installing an omnibus package without a version pin.  If you are installing
       on production servers via an automated process this is DANGEROUS and you will
       be upgraded without warning on new releases, even to new major releases.
       Letting the version float is only appropriate in desktop, test, development or
       CI/CD environments.

       WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING

       Installing chef 
       installing with dpkg...
       Selecting previously unselected package chef.
(Reading database ... 61588 files and directories currently installed.)
       Preparing to unpack .../chef_12.13.37-1_amd64.deb ...
       Unpacking chef (12.13.37-1) ...
       Setting up chef (12.13.37-1) ...
       Thank you for installing Chef!
       Transferring files to <default-ubuntu-1604>
       Starting Chef Client, version 12.13.37
       Creating a new client identity for default-ubuntu-1604 using the validator key.
       resolving cookbooks for run list: ["my_users::default"]
       Synchronizing Cookbooks:
         - my_users (0.1.0)
         - users (3.0.0)
         - sudo (2.11.0)
       Installing Cookbook Gems:
       Compiling Cookbooks...
       Converging 1 resources
       Recipe: my_users::default
         * users_manage[rebels] action remove

           ================================================================================
           Error executing action `remove` on resource 'users_manage[rebels]'
           ================================================================================

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

           Cookbook Trace:
           ---------------
           /tmp/kitchen/cache/cookbooks/users/providers/manage.rb:28:in `block in class_from_file'

           Resource Declaration:
           ---------------------
           # In /tmp/kitchen/cache/cookbooks/my_users/recipes/default.rb

             7: users_manage "rebels" do
             8:    group_id 1138
             9:    action [ :remove, :create ]
            10:  end

           Compiled Resource:
           ------------------
           # Declared in /tmp/kitchen/cache/cookbooks/my_users/recipes/default.rb:7:in `from_file'

           users_manage("rebels") do
             action [:remove, :create]
             retries 0
             retry_delay 2
             default_guard_interpreter :default
             declared_type :users_manage
             cookbook_name "my_users"
             recipe_name "default"
             group_id 1138
             data_bag "users"
             search_group "rebels"
           end

           Platform:
           ---------
           x86_64-linux

       Running handlers:
       [2016-09-06T01:59:30+00:00] ERROR: Running exception handlers
       Running handlers complete
       [2016-09-06T01:59:30+00:00] ERROR: Exception handlers complete
       Chef Client failed. 0 resources updated in 01 seconds
       [2016-09-06T01:59:30+00:00] FATAL: Stacktrace dumped to /tmp/kitchen/cache/chef-stacktrace.out
       [2016-09-06T01:59:30+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
       [2016-09-06T01:59:30+00:00] ERROR: users_manage[rebels] (my_users::default line 7) had an error: Net::HTTPServerException: 404 "Not Found"
       [2016-09-06T01:59:30+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
>>>>>> ------Exception-------
>>>>>> Class: Kitchen::ActionFailed
>>>>>> Message: 1 actions failed.
>>>>>>     Converge failed on instance <default-ubuntu-1604>.  Please see .kitchen/logs/default-ubuntu-1604.log for more details
>>>>>> ----------------------
>>>>>> Please see .kitchen/logs/kitchen.log for more details
>>>>>> Also try running `kitchen diagnose --all` for configuration
jcii commented 8 years ago

Howdy,

We've experienced similar behavior. For the 404, it helps to see what URL is returning the error. I ended up putting puts statements inside the chef code in the kitchen VM. There's probably a simpler way to do this, but I followed this gist: https://gist.github.com/mattjbarlow/242b66cdae6938d34419

which gets you to executing the recipe inside the VM that kitchen setup. The stacktrace is more informative in there, and I put some puts statements in the chef http.rb file right before the response error handler.

For my case, I found that one of the groups that was in the databag did not exist, so it was failing the databag search, and resulting in a 404.

HOWEVER, if you're using the chef-client cookbook to manage the client.rb of the node, you can also override the URL the the client uses to get to chef-zero, instead sending the client to your real Chef Server. If you do that, you'll probably see a 401 Unauthorized error.

tas50 commented 7 years ago

I'm not able to reproduce this with the 5.0 version of the cookbook. I've added 2 different tests for deletion of users: a user that exists on the system, and a user that does not exist. Both work just fine.

xianlin commented 7 years ago

@cowgill , because your kitchen.yml file didn't include the data bag directory.

If your data bag json file in inside your cookbook directory my_test_cookbook/data_bag/users/cowgill.json then you can add this to your kitchen yml file:

suites:
  - name: default
    data_bags_path: "data_bags"

the same as your test kitchen scripts, must tell the kitchen the path.