GithubHelp home page GithubHelp logo

watkinsv-hp / kitchen-nodes Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mwrock/kitchen-nodes

0.0 1.0 0.0 75 KB

A Test Kitchen Provisioner that generates searchable Nodes.

License: Other

Ruby 100.00%

kitchen-nodes's Introduction

Kitchen::Nodes

A Test Kitchen Provisioner that generates searchable Nodes.

The nodes provisioner extends the chef-zero provisioner along with all of its functionality and configuration. chef-zero can support chef searches by querying against node data stored in json files inside of the kitchen nodes folder. The kitchen-nodes plugin automatically generates a node file when a test instance is provisioned by test-kitchen.

Example nodes:

{
  "id": "server-community-ubuntu-1204",
  "automatic": {
    "ipaddress": "172.17.0.8",
    "platform": "ubuntu",
    "recipes": [
      "apt::default",
      "couchbase-tests::ipaddress",
      "couchbase::server",
      "export-node"
    ]
  },
  "normal": {
    "attr1": "val1"
  }
  "run_list": [
    "recipe[apt]",
    "recipe[couchbase-tests::ipaddress]",
    "recipe[couchbase::server]",
    "recipe[export-node]"
  ]
}

{
  "id": "second-node-ubuntu-1204",
  "automatic": {
    "ipaddress": "172.17.0.9",
    "platform": "ubuntu",
    "recipes": [
      "apt::default",
      "couchbase-tests::ipaddress",
      "couchbase::server",
      "export-node"
    ]
  },
  "run_list": [
    "recipe[apt]",
    "recipe[couchbase-tests::ipaddress]",
    "recipe[couchbase-tests::default]",
    "recipe[export-node]"
  ]
}

The node data includes the node id based on the test-kitchen suite name, the run list assigned to the node, the normal attributes included in the .kitchen.yml file, the externally reachable ip address and the platform of the test instance os.

Installation

gem install kitchen-nodes

Configuration

Use nodes instead of chef-zero for the kitchen provisioner name.

provisioner:
  name: nodes

Usage

Using kitchen-nodes one can expect all previously converged nodes to be represented in a node file and be searchable. For example consider this scenario looking for a primary node in a cluster in order to add a node to join:

require 'timeout'

def search_for_nodes(query, timeout = 120)
  nodes = []
  Timeout::timeout(timeout) do
    nodes = search(:node, query)
    until  nodes.count > 0 && nodes[0].has_key?('ipaddress')
      sleep 5
      nodes = search(:node, query)
    end
  end

  if nodes.count == 0 || !nodes[0].has_key?('ipaddress')
    raise "Unable to find nodes!"
  end

  nodes
end

primary = search_for_nodes("run_list:*couchbase??server* AND platform:#{node['platform']}")
node.normal["couchbase-tests"]["primary_ip"] = primary[0]['ipaddress']

Using with Vagrant

When using kitchen-nodes with the vagrant driver, make sure you add the following to your driver_config:

network:
  - ["private_network", { type: "dhcp" }]

This will add an additional non-NAT NIC to your vagrant box with an IP reachable from the host and other test nodes.

Why is my ohai ipaddress different from my node ipaddress on vagrant with VirtualBox?

Ohai will pick up the localhost ipaddress on vagrant boxes using virtualbox. To reset the node["ipaddress"] to the reachable ip, add hurry-up-and-test::set_non_nat_vbox_ip to the top of your run_list.

suites:
  - name: my-suite
    run_list:
      - recipe[hurry-up-and-test::set_non_nat_vbox_ip]
      - recipe[cookbook-under-test]

You can add this even if you do not use virtualbox and the recipe will do nothing.

Development

Pull requests are very welcome! Make sure your patches are well tested. Ideally create a topic branch for every separate change you make. For example:

  1. Fork the repo
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Authors

Created and maintained by Matt Wrock ([email protected])

License

Apache 2.0 (see LICENSE)

kitchen-nodes's People

Contributors

eherot avatar faja avatar jcejohnson avatar joerocklin avatar mwrock avatar sam-martin avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.