capistrano-chef 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 57a52005f690eda3d555057201e0c5cd3def02f3
4
- data.tar.gz: 4f65681040d5d9f1ed2b0b263a85f67745ff93ee
3
+ metadata.gz: 7571f68315d2d0494837cb799924dca18b9a5a8d
4
+ data.tar.gz: 17a7eb5ae130a13338fbd69280d6d1cb5523419c
5
5
  SHA512:
6
- metadata.gz: 29c2c573ec777ad496e4085a3d2768ddff257f94df0cab462ec9b75933a4f7280c363fd7c5e384d1d0d839de416af80c9d15ce4cd49a519cf98af905f47e7864
7
- data.tar.gz: 40680056c8c6288e678f4a9bee248027fdc0e1795b8c44e1d1313ed71ad053cc94fba2ade2dedb6f988b5f40d1e31200b313b5c174ec6d8e357c3abb48272afc
6
+ metadata.gz: 576a03bac46dd012e23f9325887c4acbd159dc2bb5f5fc6cdd03b0ae40d7225f6d0aafa3805020c7288732fa8c1be9353800fe0888385631c9f96a973a64fe54
7
+ data.tar.gz: 70318dfea600847ae7104c18570c1e8e7e8b685afa55a44dacf7ac9c2df4e2831d8cdaab10cc47cd18334034620f2489c9b2bfe70d36a0d35fa770e18d551f0a
@@ -1,5 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - ree
4
- - 1.9.2
5
3
  - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.0
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
- # Capistrano Chef [![Build Status](https://secure.travis-ci.org/cramerdev/capistrano-chef.png?branch=master)](http://travis-ci.org/cramerdev/capistrano-chef)
1
+ # Chef For Capistrano 3
2
2
 
3
3
  A common use-case for applications is to have [Chef](http://www.opscode.com/chef/) configure your systems and use [Capistrano](http://capify.org/) to deploy the applications that run on them.
4
4
 
5
- Capistrano Chef is a Capistrano extension that makes Chef and Capistrano get along like best buds.
5
+ Capistrano Chef is a Capistrano 3 extension that makes Chef and Capistrano 3 get along like best buds.
6
+
7
+ Note: this latest version of this gem will not work for Capistrano versions prior to 3. Please use [version 0.1.0](http://rubygems.org/gems/capistrano-chef/versions/0.1.0) or earlier if you want to use Capistrano Chef with Capistrano 2.
6
8
 
7
9
  ## Roles
8
10
 
@@ -40,69 +42,21 @@ For a more deep and complex attribute search, use a Proc object:
40
42
 
41
43
  This defines the same roles using Chef's [search feature](http://wiki.opscode.com/display/chef/Search). Nodes are searched using the given query. The node's `ipaddress` attribute is used by default, but other attributes can be specified in the options as shown in the examples above. The rest of the options are the same as those used by Capistrano.
42
44
 
43
- The `limit` attribute of the options hash will make it so only that the given number of items will be returned from a search.
44
-
45
45
  You can also define multiple roles at the same time if the host list is identical. Instead of running multiple searches to the Chef server, you can pass an Array to `chef_role`:
46
46
 
47
47
  chef_role [:web, :app], 'roles:web'
48
48
 
49
- ## Data Bags
50
-
51
- Chef [Data Bags](http://wiki.opscode.com/display/chef/Data+Bags) let you store arbitrary JSON data. A common pattern is to use an _apps_ data bag to store data about an application for use in configuration and deployment.
52
-
53
- Chef also has a [Deploy Resource](http://wiki.opscode.com/display/chef/Deploy+Resource) described in one of their blog posts, [Data Driven Application Deployment with Chef](http://www.opscode.com/blog/2010/05/06/data-driven-application-deployment-with-chef/). This is one method of deploying, but, if you're reading this, you're probably interested in deploying with Capistrano.
54
-
55
- If you create an _apps_ data bag item (let's call it _myapp_), Capistrano Chef will let you use the data in your Capistrano recipes with the `set_from_data_bag` method.
56
-
57
- This will allow you to store all of your metadata about your app in one place.
58
-
59
- ### Example
60
-
61
- In normal Capistrano `deploy.rb`:
62
-
63
- set :application, 'myapp'
64
- set :user, 'myapp'
65
- set :deploy_to, '/var/apps/myapp'
66
- set :scm, :git
67
- ... # and so on
68
-
69
- With Capistrano Chef, an _apps_ data bag item:
70
-
71
- {
72
- "id": "myapp",
73
- "user": "myapp",
74
- "deploy_to": "/var/apps/myapp",
75
- "scm": "git",
76
- ... // and so on
77
- }
78
-
79
- And in the`deploy.rb`:
80
-
81
- set :application, 'myapp'
82
- set_from_data_bag
83
-
84
- If you want to use a data bag other than _apps_, you can do `set_from_data_bag :my_other_data_bag`.
85
-
86
49
  ## Chef Configuration
87
50
 
88
51
  A Chef server is expected to be available and [Knife](http://wiki.opscode.com/display/chef/Knife) is used to configure the extension, looking for knife.rb the keys needed in .chef in the current directory or one its parent directories.
89
52
 
90
53
  If you're using [Opscode Hosted Chef](http://www.opscode.com/hosted-chef/) these files will be provided for you. If not, the configuration can be generated with `knife configure -i`. See the [Chef Documentation](http://wiki.opscode.com/display/chef/Chef+Repository#ChefRepository-Configuration) for more details.
91
54
 
92
- ## Requirements
93
-
94
- Tested with Ruby Enterprise Edition 1.8.7, Ruby 1.9.2 and 1.9.3. Should work with Capistrano 2.
95
-
96
- ### Capistrano 3 Support
97
-
98
- Capistrano 3 is not supported at this time. Pull requests that add this support are welcome. Issues related to Capistrano 3 have a "Capistrano 3" label in the issues section on GitHub.
99
-
100
55
  ## License
101
56
 
102
- Copyright (c) 2011-2012 Cramer Development, Inc.
103
-
104
57
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
105
58
 
106
59
  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
107
60
 
108
61
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
62
+
@@ -7,18 +7,17 @@ Gem::Specification.new do |s|
7
7
  s.version = CapistranoChef::VERSION.dup
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.license = 'MIT'
10
- s.authors = ['Nathan L Smith']
11
- s.email = ['nlloyds@gmail.com']
12
- s.homepage = "https://github.com/cramerdev/capistrano-chef"
13
- s.summary = %q{Capistrano extensions for Chef integration}
14
- s.description = %q{Allows capistrano to use Chef data for deployment}
15
-
16
- s.rubyforge_project = "capistrano-chef"
10
+ s.authors = ['Ryan Oblak']
11
+ s.email = ['rroblak@gmail.com']
12
+ s.homepage = "https://github.com/rroblak/capistrano-chef"
13
+ s.summary = %q{Capistrano 3 extensions for Chef integration}
14
+ s.description = %q{Allows Capistrano to use Chef data for deployment}
17
15
 
18
16
  s.files = `git ls-files`.split("\n")
19
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
19
  s.require_paths = ["lib"]
22
- s.add_dependency 'capistrano', '< 3'
20
+ s.add_dependency 'capistrano', '>= 3'
23
21
  s.add_dependency 'chef', '>= 0.10.10'
24
22
  end
23
+
File without changes
data/chef.rb ADDED
@@ -0,0 +1,37 @@
1
+ module Capistrano
2
+ module DSL
3
+ module Chef
4
+ def chef_role(name, query = '*:*', options)
5
+ arg = options.delete(:attribute) || :ipaddress
6
+
7
+ search_proc = case arg
8
+ when Proc
9
+ arg
10
+ when Hash
11
+ iface, family = arg.keys.first.to_s, arg.values.first.to_s
12
+ Proc.new do |n|
13
+ addresses = n["network"]["interfaces"][iface]["addresses"]
14
+ addresses.select{|address, data| data["family"] == family }.to_a.first.first
15
+ end
16
+ when Symbol, String
17
+ Proc.new{|n| n[arg.to_s]}
18
+ else
19
+ raise ArgumentError, 'Search arguments must be Proc, Hash, Symbol, String.'
20
+ end
21
+
22
+ hosts = chef_search(query).map(&search_proc)
23
+
24
+ name = [name] unless name.is_a?(Array)
25
+
26
+ user = fetch(:user)
27
+
28
+ name.each { |n| role(name, hosts.map { |h| "#{user ? "#{user}@" : ''}#{h}" }) }
29
+ end
30
+
31
+ def chef_search(query)
32
+ Module.const_get(:Chef)::Search::Query.new.search(:node, query)[0].compact
33
+ end
34
+ end
35
+ end
36
+ end
37
+
@@ -1,83 +1,10 @@
1
- require 'capistrano'
2
1
  require 'chef/knife'
3
- require 'chef/data_bag_item'
4
2
  require 'chef/search/query'
3
+ require 'capistrano/dsl/chef'
5
4
 
6
- module Capistrano::Chef
7
- # Set up chef configuration
8
- def self.configure_chef
9
- knife = Chef::Knife.new
10
- # If you don't do this it gets thrown into debug mode
11
- Chef::Config[:verbosity] = 1 # :info
12
- knife.configure_chef
13
- end
5
+ knife = Chef::Knife.new
6
+ # If you don't do this it gets thrown into debug mode
7
+ knife.configure_chef
14
8
 
15
- # Do a search on the Chef server and return an attary of the requested
16
- # matching attributes
17
- def self.search_chef_nodes(query = '*:*', arg = :ipaddress, limit = 1000)
18
- search_proc = \
19
- case arg
20
- when Proc
21
- arg
22
- when Hash
23
- iface, family = arg.keys.first.to_s, arg.values.first.to_s
24
- Proc.new do |n|
25
- addresses = n["network"]["interfaces"][iface]["addresses"]
26
- addresses.select{|address, data| data["family"] == family }.to_a.first.first
27
- end
28
- when Symbol, String
29
- Proc.new{|n| n[arg.to_s]}
30
- else
31
- raise ArgumentError, 'Search arguments must be Proc, Hash, Symbol, String.'
32
- end
33
- Chef::Search::Query.new.search(:node, query, 'X_CHEF_id_CHEF_X asc', 0, limit)[0].compact.map(&search_proc)
34
- end
9
+ self.extend Capistrano::DSL::Chef
35
10
 
36
- def self.get_data_bag_item(id, data_bag = :apps)
37
- Chef::DataBagItem.load(data_bag, id).raw_data
38
- end
39
-
40
- def self.get_encrypted_data_bag_item(id, data_bag = :apps, secret = nil)
41
- Chef::EncryptedDataBagItem.load(data_bag, id, secret).to_hash
42
- end
43
-
44
- # Load into Capistrano
45
- def self.load_into(configuration)
46
- self.configure_chef
47
- configuration.set :capistrano_chef, self
48
- configuration.load do
49
- def chef_role(name, query = '*:*', options = {})
50
- options = {:attribute => :ipaddress, :limit => 1000}.merge(options)
51
- # Don't do the lookup if HOSTS is used.
52
- # Allows deployment from knifeless machine
53
- # to specific hosts (ie. developent, staging)
54
- unless ENV['HOSTS']
55
- hosts = capistrano_chef.search_chef_nodes(query, options.delete(:attribute), options.delete(:limit)) + [options]
56
- if name.is_a?(Array)
57
- name.each { |n| role n, *hosts }
58
- else
59
- role name, *hosts
60
- end
61
- end
62
- end
63
-
64
- def set_from_data_bag(data_bag = :apps)
65
- raise ':application must be set' if fetch(:application).nil?
66
- capistrano_chef.get_data_bag_item(application, data_bag).each do |k, v|
67
- set k, v
68
- end
69
- end
70
-
71
- def set_from_encrypted_data_bag(data_bag = :apps, secret = nil)
72
- raise ':application must be set' if fetch(:application).nil?
73
- capistrano_chef.get_encrypted_data_bag_item(application, data_bag, secret).each do |k, v|
74
- set k, v
75
- end
76
- end
77
- end
78
- end
79
- end
80
-
81
- if Capistrano::Configuration.instance
82
- Capistrano::Chef.load_into(Capistrano::Configuration.instance)
83
- end
@@ -1,3 +1,3 @@
1
1
  module CapistranoChef
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '1.0.0'.freeze
3
3
  end
@@ -0,0 +1,37 @@
1
+ module Capistrano
2
+ module DSL
3
+ module Chef
4
+ def chef_role(name, query = '*:*', options)
5
+ arg = options.delete(:attribute) || :ipaddress
6
+
7
+ search_proc = case arg
8
+ when Proc
9
+ arg
10
+ when Hash
11
+ iface, family = arg.keys.first.to_s, arg.values.first.to_s
12
+ Proc.new do |n|
13
+ addresses = n["network"]["interfaces"][iface]["addresses"]
14
+ addresses.select{|address, data| data["family"] == family }.to_a.first.first
15
+ end
16
+ when Symbol, String
17
+ Proc.new{|n| n[arg.to_s]}
18
+ else
19
+ raise ArgumentError, 'Search arguments must be Proc, Hash, Symbol, String.'
20
+ end
21
+
22
+ hosts = chef_search(query).map(&search_proc)
23
+
24
+ name = [name] unless name.is_a?(Array)
25
+
26
+ user = fetch(:user)
27
+
28
+ name.each { |n| role(name, hosts.map { |h| "#{user ? "#{user}@" : ''}#{h}" }) }
29
+ end
30
+
31
+ def chef_search(query)
32
+ Module.const_get(:Chef)::Search::Query.new.search(:node, query)[0].compact
33
+ end
34
+ end
35
+ end
36
+ end
37
+
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-chef
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
- - Nathan L Smith
7
+ - Ryan Oblak
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-08 00:00:00.000000000 Z
11
+ date: 2014-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - <
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - <
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3'
27
27
  - !ruby/object:Gem::Dependency
@@ -38,9 +38,9 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.10.10
41
- description: Allows capistrano to use Chef data for deployment
41
+ description: Allows Capistrano to use Chef data for deployment
42
42
  email:
43
- - nlloyds@gmail.com
43
+ - rroblak@gmail.com
44
44
  executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
@@ -48,16 +48,15 @@ files:
48
48
  - .gitignore
49
49
  - .rspec
50
50
  - .travis.yml
51
- - Gemfile
52
- - Guardfile
53
51
  - README.md
54
52
  - Rakefile
55
53
  - capistrano-chef.gemspec
54
+ - capistrano-chef.rb
55
+ - chef.rb
56
56
  - lib/capistrano/chef.rb
57
57
  - lib/capistrano/chef/version.rb
58
- - spec/capistrano/chef_spec.rb
59
- - spec/spec_helper.rb
60
- homepage: https://github.com/cramerdev/capistrano-chef
58
+ - lib/capistrano/dsl/chef.rb
59
+ homepage: https://github.com/rroblak/capistrano-chef
61
60
  licenses:
62
61
  - MIT
63
62
  metadata: {}
@@ -76,12 +75,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
75
  - !ruby/object:Gem::Version
77
76
  version: '0'
78
77
  requirements: []
79
- rubyforge_project: capistrano-chef
78
+ rubyforge_project:
80
79
  rubygems_version: 2.0.14
81
80
  signing_key:
82
81
  specification_version: 4
83
- summary: Capistrano extensions for Chef integration
84
- test_files:
85
- - spec/capistrano/chef_spec.rb
86
- - spec/spec_helper.rb
82
+ summary: Capistrano 3 extensions for Chef integration
83
+ test_files: []
87
84
  has_rdoc:
data/Gemfile DELETED
@@ -1,10 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- group :test do
4
- gem 'rake'
5
- gem 'rspec'
6
- gem 'capistrano-spec'
7
- gem 'guard-rspec'
8
- end
9
-
10
- gemspec
data/Guardfile DELETED
@@ -1,9 +0,0 @@
1
- # A sample Guardfile
2
- # More info at https://github.com/guard/guard#readme
3
-
4
- guard 'rspec', :version => 2 do
5
- watch(%r{^spec/.+_spec\.rb$})
6
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
- watch('spec/spec_helper.rb') { "spec" }
8
- end
9
-
@@ -1,173 +0,0 @@
1
- require 'spec_helper'
2
- require 'capistrano/chef'
3
-
4
- MOCK_NODE_DATA = [
5
- {
6
- "ipaddress" => '10.0.0.2',
7
- "fqdn" => 'localhost.localdomain',
8
- "hostname" => 'localhost',
9
- "network" => {
10
- "default_interface" => "eth0",
11
- "interfaces" => {
12
- "eth0" => {
13
- "addresses" => {
14
- "fe80::a00:27ff:feca:ab08" => {"scope" => "Link", "prefixlen" => "64", "family" => "inet6"},
15
- "10.0.0.2" => {"netmask" => "255.255.255.0", "broadcast" => "10.0.0.255", "family" => "inet"},
16
- "08:00:27:CA:AB:08" => {"family" => "lladdr"}
17
- },
18
- },
19
- "lo" => {
20
- "addresses" => {
21
- "::1" => {"scope" => "Node", "prefixlen" => "128", "family" => "inet6"},
22
- "127.0.0.1" => {"netmask" => "255.0.0.0", "family" => "inet"}
23
- },
24
- },
25
- "eth1" => {
26
- "addresses" => {
27
- "fe80::a00:27ff:fe79:83fc" => {"scope" => "Link", "prefixlen" => "64", "family" => "inet6"},
28
- "192.168.77.101" => {"netmask" => "255.255.255.0", "broadcast" => "192.168.77.255", "family" => "inet"},
29
- "08:00:27:79:83:FC" => {"family" => "lladdr"}
30
- },
31
- },
32
- },
33
- }
34
- },
35
- nil
36
- ]
37
-
38
- describe Capistrano::Chef do
39
- before do
40
- # Stub knife config
41
- @knife = mock('Chef::Knife')
42
- Chef::Knife.stub!(:new).and_return(@knife)
43
- @knife.stub!(:configure_chef)
44
-
45
- # Load into capistrano configuration
46
- @configuration = Capistrano::Configuration.new
47
- Capistrano::Chef.load_into(@configuration)
48
-
49
- # Data bag items
50
- @other_item = mock('Chef::DataBagItem')
51
- Chef::DataBagItem.stub(:load).with(:other_data_bag, 'other_test').and_return @other_item
52
- @other_item.stub(:raw_data).and_return Mash.new({
53
- :id => 'other_test',
54
- :deploy_to => '/dev/other_null'
55
- })
56
-
57
- @item = mock('Chef::DataBagItem')
58
- Chef::DataBagItem.stub(:load).with(:apps, 'test').and_return @item
59
- @item.stub(:raw_data).and_return Mash.new({
60
- :id => 'test',
61
- :deploy_to => '/dev/null'
62
- })
63
- end
64
-
65
- it 'should be a module' do
66
- expect { described_class.to be_a Module }
67
- end
68
-
69
- describe 'search_chef_nodes' do
70
- before(:each) do
71
- Chef::Knife.new.configure_chef
72
- @search = mock('Chef::Search::Query')
73
- Chef::Search::Query.stub!(:new).and_return(@search)
74
- @search.stub!(:search).and_return([::MOCK_NODE_DATA, 0, 1])
75
- end
76
-
77
- specify 'without argument (will get :ipaddress)' do
78
- Capistrano::Chef.search_chef_nodes('*:*').should eql ['10.0.0.2']
79
- end
80
-
81
- # with Symbol(or String) will search top-level attributes
82
- specify 'with Symbol argument' do
83
- Capistrano::Chef.search_chef_nodes('*:*', :fqdn).should eql ['localhost.localdomain']
84
- end
85
-
86
- # with Hash, can specify "interface" and "family" by key and value.
87
- specify 'with Hash argument' do
88
- Capistrano::Chef.search_chef_nodes('*:*', {:eth0 => :inet}).should eql ['10.0.0.2']
89
- end
90
-
91
- # use Proc for more deep, complex attributes search.
92
- specify 'with Proc argument' do
93
- search_proc = Proc.new do |n|
94
- n["network"]["interfaces"]["eth1"]["addresses"].select{|address, data| data["family"] == "inet" }.to_a.first.first
95
- end
96
- Capistrano::Chef.search_chef_nodes('*:*', search_proc).should eql ['192.168.77.101']
97
- end
98
- end
99
-
100
-
101
- specify 'get_data_bag_item' do
102
- Capistrano::Chef.get_data_bag_item('test').should === Mash.new({
103
- :id => 'test',
104
- :deploy_to => '/dev/null'
105
- })
106
- Capistrano::Chef.get_data_bag_item('other_test', :other_data_bag).should === Mash.new({
107
- :id => 'other_test',
108
- :deploy_to => '/dev/other_null'
109
- })
110
- end
111
-
112
- specify 'set_from_data_bag' do
113
- expect { @configuration.set_from_data_bag }.to raise_error
114
- @configuration.set(:application, 'test')
115
- @configuration.set_from_data_bag
116
- @configuration.fetch(:deploy_to).should === '/dev/null'
117
- @configuration.fetch(:id).should === 'test'
118
-
119
- @configuration.set(:application, 'other_test')
120
- @configuration.set_from_data_bag :other_data_bag
121
- @configuration.fetch(:deploy_to).should === '/dev/other_null'
122
- @configuration.fetch(:id).should === 'other_test'
123
- end
124
-
125
- describe '#chef_role' do
126
- context 'when adding nodes to the role' do
127
- before do
128
- Capistrano::Chef.stub!(:search_chef_nodes).and_return(['10.0.0.2'])
129
- @search = mock('Chef::Search::Query')
130
- end
131
-
132
- it 'add nodes to one role' do
133
- @configuration.should respond_to :chef_role
134
- @configuration.chef_role(:test)
135
- @configuration.roles.should have_key :test
136
- @configuration.roles[:test].to_a[0].host.should === '10.0.0.2'
137
- end
138
-
139
- it 'supports defining multiple roles in one go to avoid multiple searches' do
140
- @configuration.chef_role([:test, :test2])
141
- @configuration.roles.should have_key :test
142
- @configuration.roles.should have_key :test2
143
- @configuration.roles[:test].to_a[0].host.should === '10.0.0.2'
144
- @configuration.roles[:test2].to_a[0].host.should === '10.0.0.2'
145
- end
146
-
147
- it 'does not call search more than once when defining multiple Cap roles' do
148
- Capistrano::Chef.should_receive(:search_chef_nodes).once
149
- @configuration.chef_role([:test, :test2])
150
- end
151
- end
152
-
153
- it 'defaults to calling search with :ipaddress as the attribute and 1000 as the limit when giving a query' do
154
- query = "this is my chef query"
155
- Capistrano::Chef.should_receive(:search_chef_nodes).with(query, :ipaddress, 1000).and_return(['10.0.0.2'])
156
- @configuration.chef_role(:test, query)
157
- end
158
-
159
- it 'allows you to specify the attribute used in the query' do
160
- query = "this is my chef query"
161
- attribute = :my_attr
162
- Capistrano::Chef.should_receive(:search_chef_nodes).with(query, attribute, 1000).and_return(['10.0.0.2'])
163
- @configuration.chef_role(:test, query, :attribute => attribute)
164
- end
165
-
166
- it 'allows you to specify the limit used in the query' do
167
- query = "this is my chef query"
168
- limit = 55
169
- Capistrano::Chef.should_receive(:search_chef_nodes).with(query, :ipaddress, limit).and_return(['10.0.0.2'])
170
- @configuration.chef_role(:test, query, :limit => limit)
171
- end
172
- end
173
- end
@@ -1,11 +0,0 @@
1
- # This file was generated by the `rspec --init` command. Conventionally, all
2
- # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
- # Require this file using `require "spec_helper.rb"` to ensure that it is only
4
- # loaded once.
5
- #
6
- # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
- RSpec.configure do |config|
8
- config.treat_symbols_as_metadata_keys_with_true_values = true
9
- config.run_all_when_everything_filtered = true
10
- config.filter_run :focus
11
- end