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

Copy /tmp/kitchen/nodes back to workstation nodes dir after converge #36

Open
atheiman opened this issue Oct 22, 2017 · 6 comments
Open

Comments

@atheiman
Copy link
Contributor

atheiman commented Oct 22, 2017

Right now this doesnt seem to bring back the converged node attributes to the nodes directory on the workstation. For example, if you converge a node with an environment, environment attributes are written to the node json file on the instance (/tmp/kitchen/nodes/my-node.json). But the attributes are not written back to the node json file on the workstation (test/fixtures/nodes/my-node.json). The purpose of this would be to then search for the nodes that have attributes from an environment or that were set during a chef-client converge.

Is there a way to copy /tmp/kitchen/nodes from the instance back to the workstation nodes dir after converge?

Seems this could be done with data bags as well, some recipes create data bag items for recipes on other nodes to consume.

@mwrock
Copy link
Owner

mwrock commented Oct 23, 2017

I have not been using test-kitchen and chef lately and have not been actively developing this plugin. One weakness with this plugin is that it captures the state of a node prior to converge but as you have noted, does not persist state post converge. Definitely open to PRs if you wanted to investigate ea solution.

@atheiman
Copy link
Contributor Author

it looks like the way to do this would be:

  1. add a #download(remotes, local) method to Kitchen::Transport::Base::Connection
  2. patch conn.download('/tmp/kitchen/nodes', 'test/fixtures/nodes) onto the end of this block on Kitchen::Provisioner::Base#call

I might give this a try if I get time.

@atheiman
Copy link
Contributor Author

test-kitchen/test-kitchen#1306 will make this work. if that gets merged I think there could be some updates to kitchen-nodes:

  • kitchen nodes needs some changes to work with concurrency (-c 2), it currently:

    • deletes the node file of the converging node at the start of each converge
    • writes the bare node definition (ip, fqdn, recipes, platform, run list) to the local node file

    I think it needs to update to:

    • never delete node files unless kitchen destroy is run
    • either:
      • deep_merge in its bare node definition to existing local node definition files
      • do not write to local node definition files if they already exist
  • default provisioner[:downloads] to ['/tmp/kitchen/data_bags', '/tmp/kitchen/nodes'] => 'test/integration' so that data bags and nodes are downloaded from nodes by default and then ready to be uploaded to the next converged node

@mortee
Copy link

mortee commented Jan 24, 2018

What's the status of this suggestion? I'm having the same issue with kitchen-nodes: normal attributes of the nodes always get overwritten. It would be nice to have those preserved.

@atheiman
Copy link
Contributor Author

atheiman commented Jan 24, 2018

if youre running into the same issue I was - that the node file is deleted and recreated with only a few attributes at the start of the node's converge - then this patch will fix your problem:

require 'kitchen'
require 'kitchen/provisioner/chef_zero'

module Kitchen
  module Provisioner
    # Patch kitchen-nodes to not delete node files before converge. This
    # ensures all node files will be uploaded during concurrent provisions.
    # https://github.com/mwrock/kitchen-nodes/blob/master/lib/kitchen/provisioner/nodes.rb
    class Nodes < ChefZero
      def create_sandbox
        create_node
      ensure
        super
      end
    end
  end
end

That needs to be loaded when you run kitchen commands - I required it from a Rakefile which I use to kick off test-kitchen actions. Not ideal.

It would be a good idea to make this change in this gem - but I have not submitted a pr for it. it probably needs to be configurable whether or not the node file is deleted at the start of the node's converge.

@mortee
Copy link

mortee commented Jan 24, 2018

FWIW, #node_template should merge the normal attributes from the already existing node file, if anything. This would make sure that other, updated nodes' info also get their way into the index.

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

No branches or pull requests

3 participants