mwrock / kitchen-nodes

A Test Kitchen Provisioner that generates searchable Nodes.
Other
37 stars 24 forks source link

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

Open atheiman opened 7 years ago

atheiman commented 7 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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

mortee commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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.