butcher 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +13 -0
- data/Gemfile +1 -0
- data/README.md +15 -0
- data/features/step_definitions/chef_steps.rb +6 -6
- data/features/support/aruba.rb +1 -0
- data/lib/butcher/cache.rb +7 -3
- data/lib/butcher/stab/cli.rb +7 -5
- data/lib/butcher/version.rb +1 -1
- data/spec/lib/cache_spec.rb +11 -11
- data/spec/support/test_cache.rb +4 -1
- metadata +15 -14
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -3,6 +3,16 @@
|
|
3
3
|
Butcher is a set of command line tools intended to ease the use of Chef with a managed
|
4
4
|
Opscode account.
|
5
5
|
|
6
|
+
### Installation
|
7
|
+
|
8
|
+
gem install "butcher"
|
9
|
+
|
10
|
+
Or stick this in your Gemfile
|
11
|
+
|
12
|
+
gem "butcher"
|
13
|
+
# or
|
14
|
+
gem "butcher", "~>0.0.1"
|
15
|
+
|
6
16
|
## Commands
|
7
17
|
|
8
18
|
The following commands are currently available. All commands should be run from the top
|
@@ -39,6 +49,11 @@ by looking at the chef_server_url in your knife.rb. For this reason, stab can on
|
|
39
49
|
from the top level of a chef repo.
|
40
50
|
|
41
51
|
|
52
|
+
## Build Status
|
53
|
+
|
54
|
+
[![Build status](https://secure.travis-ci.org/modcloth/butcher.png)](http://travis-ci.org/modcloth/butcher)
|
55
|
+
|
56
|
+
|
42
57
|
## License
|
43
58
|
|
44
59
|
Copyright 2012 ModCloth
|
@@ -1,11 +1,11 @@
|
|
1
1
|
Given /I (don't|) ?have a knife configuration file/ do |expectation|
|
2
2
|
if expectation == "don't"
|
3
|
-
steps %
|
4
|
-
When I remove the file "
|
3
|
+
steps %Q{
|
4
|
+
When I remove the file "#{ENV["PWD"]}/.chef/knife.rb"
|
5
5
|
}
|
6
6
|
else
|
7
|
-
steps %
|
8
|
-
Given a file named "
|
7
|
+
steps %Q{
|
8
|
+
Given a file named "#{ENV["PWD"]}/.chef/knife.rb" with:
|
9
9
|
"""
|
10
10
|
chef_server_url "https://opscode.url/organizations/my_organization"
|
11
11
|
"""
|
@@ -14,8 +14,8 @@ Given /I (don't|) ?have a knife configuration file/ do |expectation|
|
|
14
14
|
end
|
15
15
|
|
16
16
|
Given /I have an invalid knife configuration file/ do
|
17
|
-
steps %
|
18
|
-
Given a file named "
|
17
|
+
steps %Q{
|
18
|
+
Given a file named "#{ENV["PWD"]}/.chef/knife.rb" with:
|
19
19
|
"""
|
20
20
|
some invalid content
|
21
21
|
"""
|
data/features/support/aruba.rb
CHANGED
data/lib/butcher/cache.rb
CHANGED
@@ -27,7 +27,7 @@ class Butcher::Cache
|
|
27
27
|
|
28
28
|
def self.format_nodes_for_stderr(nodes)
|
29
29
|
nodes.map do |key, value|
|
30
|
-
%Q{#{value} => #{key}}
|
30
|
+
%Q{#{value.inspect} => #{key}}
|
31
31
|
end.sort.join("\n")
|
32
32
|
end
|
33
33
|
|
@@ -38,14 +38,18 @@ class Butcher::Cache
|
|
38
38
|
private
|
39
39
|
|
40
40
|
def organization
|
41
|
-
raise Butcher::NoKnifeRB unless(File.exists?(
|
42
|
-
if m = File.read(
|
41
|
+
raise Butcher::NoKnifeRB unless(File.exists?(knife_file))
|
42
|
+
if m = File.read(knife_file).match(/chef_server_url\s+".+organizations\/([^\/"]+)"/)
|
43
43
|
m[1]
|
44
44
|
else
|
45
45
|
raise Butcher::NoKnifeOrganization
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
+
def knife_file
|
50
|
+
File.expand_path(KNIFE_FILE, ENV["PWD"])
|
51
|
+
end
|
52
|
+
|
49
53
|
def create_node_cachefile
|
50
54
|
File.open(nodes_file, "w") do |file|
|
51
55
|
file.puts %x[knife status]
|
data/lib/butcher/stab/cli.rb
CHANGED
@@ -19,10 +19,6 @@ class Butcher::Stab::CLI
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def matching_node
|
22
|
-
nodes = Butcher::Cache.instance.nodes(options).select do |k, v|
|
23
|
-
String(v).include? self.node_matcher
|
24
|
-
end
|
25
|
-
|
26
22
|
raise(Butcher::UnmatchedNode) if nodes.size == 0
|
27
23
|
raise(Butcher::AmbiguousNode, Butcher::Cache.format_nodes_for_stderr(nodes)) if nodes.size > 1
|
28
24
|
nodes.keys.first
|
@@ -33,4 +29,10 @@ class Butcher::Stab::CLI
|
|
33
29
|
" -l #{options[:login]}"
|
34
30
|
end
|
35
31
|
end
|
36
|
-
|
32
|
+
|
33
|
+
def nodes
|
34
|
+
@nodes ||= Butcher::Cache.instance.nodes(options).reject do |k, v|
|
35
|
+
! String(v).include? self.node_matcher
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/butcher/version.rb
CHANGED
data/spec/lib/cache_spec.rb
CHANGED
@@ -2,20 +2,21 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Butcher::Cache, "initialization" do
|
4
4
|
## singletons do not reset after initialization, so we run tests against clones
|
5
|
-
let(:cache_class) { Butcher::Cache.clone }
|
6
5
|
|
6
|
+
class CacheSingletonForEnv < Butcher::Cache; end
|
7
7
|
it "should accept cache_dir from env" do
|
8
8
|
ENV["CACHE_DIR"] = "tmp/cache_from_options"
|
9
9
|
test(?d, "tmp/cache_from_options").should be_false
|
10
|
-
|
10
|
+
CacheSingletonForEnv.instance
|
11
11
|
ENV["CACHE_DIR"] = nil
|
12
12
|
test(?d, "tmp/cache_from_options").should be_true
|
13
13
|
end
|
14
14
|
|
15
|
+
class CacheSingleton < Butcher::Cache; end
|
15
16
|
it "should create cache directory" do
|
16
|
-
|
17
|
+
CacheSingleton.any_instance.stubs(:cache_dir).returns("tmp/cache_stub")
|
17
18
|
test(?d, "tmp/cache_stub").should be_false
|
18
|
-
|
19
|
+
CacheSingleton.instance
|
19
20
|
test(?d, "tmp/cache_stub").should be_true
|
20
21
|
end
|
21
22
|
end
|
@@ -23,7 +24,7 @@ end
|
|
23
24
|
describe Butcher::Cache, "#nodes_file" do
|
24
25
|
context "cannot find knife.rb" do
|
25
26
|
it "should raise an error" do
|
26
|
-
File.expects(:exists?).with("
|
27
|
+
File.expects(:exists?).with("#{ENV["PWD"]}/.chef/knife.rb").returns(false)
|
27
28
|
lambda {
|
28
29
|
Butcher::Cache.instance.nodes_file
|
29
30
|
}.should raise_error(Butcher::NoKnifeRB)
|
@@ -31,11 +32,11 @@ describe Butcher::Cache, "#nodes_file" do
|
|
31
32
|
end
|
32
33
|
|
33
34
|
context "sees a knife.rb" do
|
34
|
-
before { File.expects(:exists?).with("
|
35
|
+
before { File.expects(:exists?).with("#{ENV["PWD"]}/.chef/knife.rb").returns(true) }
|
35
36
|
|
36
37
|
context "without chef_server_url" do
|
37
38
|
it "should raise an error" do
|
38
|
-
File.expects(:read).with("
|
39
|
+
File.expects(:read).with("#{ENV["PWD"]}/.chef/knife.rb").returns(
|
39
40
|
'some random content'
|
40
41
|
)
|
41
42
|
lambda {
|
@@ -48,7 +49,7 @@ describe Butcher::Cache, "#nodes_file" do
|
|
48
49
|
let(:expected_file) { "#{Butcher::TestCache.cache_dir}/my_organization.cache" }
|
49
50
|
|
50
51
|
it "should set filename based on chef_server_url" do
|
51
|
-
File.expects(:read).with("
|
52
|
+
File.expects(:read).with("#{ENV["PWD"]}/.chef/knife.rb").returns(
|
52
53
|
'chef_server_url "https://api.opscode.com/organizations/my_organization"'
|
53
54
|
)
|
54
55
|
Butcher::Cache.instance.nodes_file.should == expected_file
|
@@ -58,11 +59,10 @@ describe Butcher::Cache, "#nodes_file" do
|
|
58
59
|
end
|
59
60
|
|
60
61
|
describe Butcher::Cache, "#nodes" do
|
61
|
-
|
62
|
+
let(:cache_file) { "#{Butcher::TestCache.cache_dir}/ops_org.cache" }
|
63
|
+
before { Butcher::Cache.any_instance.stubs(:nodes_file).returns(cache_file) }
|
62
64
|
|
63
65
|
context "cache file does not exist" do
|
64
|
-
let(:cache_file) { "#{Butcher::TestCache.cache_dir}/ops_org.cache" }
|
65
|
-
|
66
66
|
before do
|
67
67
|
File.exists?(cache_file).should be_false
|
68
68
|
Butcher::Cache.any_instance.stubs(:`).with("knife status").returns("knife return codes")
|
data/spec/support/test_cache.rb
CHANGED
@@ -20,6 +20,8 @@
|
|
20
20
|
# World(Butcher::TestCache::TestHelpers)
|
21
21
|
#
|
22
22
|
module Butcher::TestCache
|
23
|
+
PWD = ENV["PWD"]
|
24
|
+
|
23
25
|
def self.setup_rspec(config)
|
24
26
|
config.before(:each) do
|
25
27
|
Butcher::TestCache.reset
|
@@ -40,8 +42,8 @@ module Butcher::TestCache
|
|
40
42
|
|
41
43
|
def self.cleanup # :nodoc:
|
42
44
|
FileUtils.rm_rf("tmp")
|
43
|
-
FileUtils.rm_rf(".chef")
|
44
45
|
ENV.delete("CACHE_DIR")
|
46
|
+
ENV["PWD"] = PWD
|
45
47
|
end
|
46
48
|
|
47
49
|
def self.cache_dir # :nodoc:
|
@@ -51,6 +53,7 @@ module Butcher::TestCache
|
|
51
53
|
private
|
52
54
|
|
53
55
|
def self.setup
|
56
|
+
ENV["PWD"] = "#{PWD}/tmp"
|
54
57
|
stub_cache
|
55
58
|
FileUtils.mkdir_p("tmp/test")
|
56
59
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: butcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-03-
|
13
|
+
date: 2012-03-19 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
17
|
-
requirement: &
|
17
|
+
requirement: &70173155128740 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>'
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '2'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70173155128740
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: aruba
|
28
|
-
requirement: &
|
28
|
+
requirement: &70173155128120 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70173155128120
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: aruba-doubles
|
39
|
-
requirement: &
|
39
|
+
requirement: &70173155127520 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70173155127520
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: guard-rspec
|
50
|
-
requirement: &
|
50
|
+
requirement: &70173155126960 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *70173155126960
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: guard-cucumber
|
61
|
-
requirement: &
|
61
|
+
requirement: &70173155126360 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ! '>='
|
@@ -66,10 +66,10 @@ dependencies:
|
|
66
66
|
version: '0'
|
67
67
|
type: :development
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *70173155126360
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: mocha
|
72
|
-
requirement: &
|
72
|
+
requirement: &70173155125600 !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
75
|
- - ! '>='
|
@@ -77,7 +77,7 @@ dependencies:
|
|
77
77
|
version: '0'
|
78
78
|
type: :development
|
79
79
|
prerelease: false
|
80
|
-
version_requirements: *
|
80
|
+
version_requirements: *70173155125600
|
81
81
|
description: Chef is a tool for managing server automation. A good butcher makes for
|
82
82
|
a good chef.
|
83
83
|
email:
|
@@ -90,6 +90,7 @@ files:
|
|
90
90
|
- .gitignore
|
91
91
|
- .rbenv-version
|
92
92
|
- .rspec
|
93
|
+
- .travis.yml
|
93
94
|
- Gemfile
|
94
95
|
- Guardfile
|
95
96
|
- README.md
|