knife_cookbook_dependencies 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -2,6 +2,11 @@ require "bundler/gem_tasks"
2
2
  require 'rdoc/task'
3
3
  require 'rspec/core/rake_task'
4
4
 
5
+ desc "clean VCR cassettes"
6
+ task "vcr:clean" do
7
+ sh "rm -rf spec/fixtures/vcr_cassettes/*"
8
+ end
9
+
5
10
  desc "check documentation coverage"
6
11
  task "rdoc:check" do
7
12
  sh "rdoc -C " + Dir["lib/**/*.rb"].join(" ")
@@ -0,0 +1,29 @@
1
+ Feature: Clean
2
+ As a user
3
+ I want to be able to clean all the files downloaded/created by kcd
4
+ So that I can be sure previous runs are not messing up my current action
5
+ and so I can get rid of installations I don't want any more
6
+
7
+ Scenario: knife cookbook dependencies clean
8
+ Given I write to "Cookbookfile" with:
9
+ """
10
+ cookbook "mysql"
11
+ """
12
+ When I run `knife cookbook dependencies install`
13
+ And I run `knife cookbook dependencies clean`
14
+ Then the following directories should not exist:
15
+ | cookbooks |
16
+ And the file "Cookbookfile.lock" should not exist
17
+ And the temp directory should not exist
18
+
19
+ Scenario: knife cookbook deps clean
20
+ Given I write to "Cookbookfile" with:
21
+ """
22
+ cookbook "mysql"
23
+ """
24
+ When I run `knife cookbook deps install`
25
+ And I run `knife cookbook deps clean`
26
+ Then the following directories should not exist:
27
+ | cookbooks |
28
+ And the file "Cookbookfile.lock" should not exist
29
+ And the temp directory should not exist
@@ -0,0 +1,24 @@
1
+ Feature: install cookbooks from a Cookbookfile
2
+ As a user with a Cookbookfile
3
+ I want to be able to run knife cookbook dependencies install to install my cookbooks
4
+ So that I don't have to download my cookbooks and their dependencies manually
5
+
6
+ Scenario: install cookbooks
7
+ Given I write to "Cookbookfile" with:
8
+ """
9
+ cookbook "mysql"
10
+ """
11
+ When I run `knife cookbook dependencies install`
12
+ Then the following directories should exist:
13
+ | cookbooks/mysql |
14
+ | cookbooks/openssl |
15
+
16
+ Scenario: install cookbooks with the alias
17
+ Given I write to "Cookbookfile" with:
18
+ """
19
+ cookbook "mysql"
20
+ """
21
+ When I run `knife cookbook deps install`
22
+ Then the following directories should exist:
23
+ | cookbooks/mysql |
24
+ | cookbooks/openssl |
@@ -0,0 +1,38 @@
1
+ Feature: update
2
+ As a user
3
+ I want a way to update the versions without clearing out the files I've downloaded
4
+ So that I can update faster than a clean install
5
+
6
+ Scenario: knife cookbook dependencies update
7
+ Given I write to "Cookbookfile" with:
8
+ """
9
+ cookbook "mysql"
10
+ """
11
+ Given I write to "Cookbookfile.lock" with:
12
+ """
13
+ cookbook 'mysql', :locked_version => '0.0.1'
14
+ cookbook 'openssl', :locked_version => '0.0.1'
15
+ """
16
+ When I run `knife cookbook dependencies update`
17
+ Then the file "Cookbookfile.lock" should contain exactly:
18
+ """
19
+ cookbook 'mysql', :locked_version => '1.2.4'
20
+ cookbook 'openssl', :locked_version => '1.0.0'
21
+ """
22
+
23
+ Scenario: knife cookbook deps update
24
+ Given I write to "Cookbookfile" with:
25
+ """
26
+ cookbook "mysql"
27
+ """
28
+ Given I write to "Cookbookfile.lock" with:
29
+ """
30
+ cookbook 'mysql', :locked_version => '0.0.1'
31
+ cookbook 'openssl', :locked_version => '0.0.1'
32
+ """
33
+ When I run `knife cookbook deps update`
34
+ Then the file "Cookbookfile.lock" should contain exactly:
35
+ """
36
+ cookbook 'mysql', :locked_version => '1.2.4'
37
+ cookbook 'openssl', :locked_version => '1.0.0'
38
+ """
@@ -20,9 +20,15 @@ Spork.prefork do
20
20
  end
21
21
  end
22
22
 
23
- Before('@slow_process') do
23
+ Before do
24
24
  @aruba_io_wait_seconds = 5
25
25
  end
26
+
27
+ Before('@slow_process') do
28
+ @aruba_io_wait_seconds = 10
29
+ end
30
+
31
+
26
32
  end
27
33
 
28
34
  Spork.each_run do
@@ -20,3 +20,7 @@ Then /^the file "(.*?)" should contain in the current directory:$/ do |filename,
20
20
  File.read(filename).should match(Regexp.new(string))
21
21
  end
22
22
  end
23
+
24
+ Then /^the temp directory should not exist$/ do
25
+ File.exists?(KCD::TMP_DIRECTORY).should be_false
26
+ end
@@ -0,0 +1,19 @@
1
+ require 'chef/knife'
2
+ require 'kcd'
3
+
4
+ module KnifeCookbookDependencies
5
+ class CookbookDependenciesClean < Chef::Knife
6
+ banner "knife cookbook dependencies clean"
7
+
8
+ def run
9
+ ui.info 'Cleaning up...'
10
+ ::KCD.ui = ui
11
+
12
+ ::KCD.clean
13
+ end
14
+ end
15
+
16
+ class CookbookDepsClean < CookbookDependenciesClean
17
+ banner "knife cookbook deps clean"
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ require 'chef/knife'
2
+ require 'kcd'
3
+
4
+ module KnifeCookbookDependencies
5
+ class CookbookDependenciesUpdate < CookbookDependenciesInstall
6
+ banner "knife cookbook dependencies update"
7
+
8
+ alias :install_run :run
9
+
10
+ def run
11
+ ::KCD.ui = ui
12
+
13
+ Lockfile.remove!
14
+ install_run
15
+ end
16
+ end
17
+
18
+ class CookbookDepsUpdate < CookbookDependenciesUpdate
19
+ banner "knife cookbook deps update"
20
+ end
21
+ end
data/lib/kcd/cookbook.rb CHANGED
@@ -7,7 +7,7 @@ module KnifeCookbookDependencies
7
7
  attr_reader :name, :version_constraints, :groups
8
8
  attr_accessor :locked_version
9
9
 
10
- DOWNLOAD_LOCATION = ENV["TMPDIR"] || '/tmp'
10
+ DOWNLOAD_LOCATION = ::KCD::TMP_DIRECTORY || '/tmp'
11
11
 
12
12
  def initialize(*args)
13
13
  @options = args.last.is_a?(Hash) ? args.pop : {}
@@ -47,7 +47,10 @@ module KnifeCookbookDependencies
47
47
  @git.checkout(@options[:ref]) if @options[:ref]
48
48
  @options[:path] ||= @git.directory
49
49
  else
50
+ FileUtils.mkdir_p KCD::TMP_DIRECTORY
50
51
  csd = Chef::Knife::CookbookSiteDownload.new([name, latest_constrained_version.to_s, "--file", download_filename])
52
+
53
+ output = ''
51
54
  rescue_404 do
52
55
  output = KCD::KnifeUtils.capture_knife_output(csd)
53
56
  end
data/lib/kcd/lockfile.rb CHANGED
@@ -1,14 +1,16 @@
1
1
  module KnifeCookbookDependencies
2
2
  class Lockfile
3
+ DEFAULT_FILENAME = "#{KCD::DEFAULT_FILENAME}.lock"
4
+
3
5
  def initialize(cookbooks)
4
6
  @cookbooks = cookbooks
5
7
  end
6
8
 
7
- def write(filename = KCD::DEFAULT_FILENAME)
9
+ def write(filename = DEFAULT_FILENAME)
8
10
  content = @cookbooks.map do |cookbook|
9
11
  get_cookbook_definition(cookbook)
10
12
  end.join("\n")
11
- File::open("#{filename}.lock", "wb") { |f| f.write content }
13
+ File::open(DEFAULT_FILENAME, "wb") { |f| f.write content }
12
14
  end
13
15
 
14
16
  def get_cookbook_definition(cookbook)
@@ -24,5 +26,15 @@ module KnifeCookbookDependencies
24
26
 
25
27
  return definition
26
28
  end
29
+
30
+ def remove!
31
+ self.class.remove!
32
+ end
33
+
34
+ class << self
35
+ def remove!
36
+ FileUtils.rm_f DEFAULT_FILENAME
37
+ end
38
+ end
27
39
  end
28
40
  end
data/lib/kcd/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module KnifeCookbookDependencies
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -1,20 +1,8 @@
1
- require 'dep_selector'
2
- require 'zlib'
3
- require 'archive/tar/minitar'
4
-
5
- require 'kcd/version'
6
- require 'kcd/shelf'
7
- require 'kcd/cookbook'
8
- require 'kcd/metacookbook'
9
- require 'kcd/dsl'
10
- require 'kcd/cookbookfile'
11
- require 'kcd/lockfile'
12
- require 'kcd/git'
13
- require 'kcd/error_messages'
14
-
15
1
  module KnifeCookbookDependencies
16
2
  DEFAULT_FILENAME = 'Cookbookfile'
17
3
  COOKBOOKS_DIRECTORY = 'cookbooks'
4
+ TMP_DIRECTORY = File.join(ENV['TMPDIR'], 'knife_cookbook_dependencies')
5
+ FileUtils.mkdir_p TMP_DIRECTORY
18
6
 
19
7
  autoload :KnifeUtils, 'kcd/knife_utils'
20
8
 
@@ -39,10 +27,26 @@ module KnifeCookbookDependencies
39
27
 
40
28
  def clean
41
29
  clear_shelf!
30
+ Lockfile.remove!
42
31
  FileUtils.rm_rf COOKBOOKS_DIRECTORY
32
+ FileUtils.rm_rf TMP_DIRECTORY
43
33
  end
44
34
  end
45
35
  end
46
36
 
47
37
  # Alias for {KnifeCookbookDependencies}
48
38
  KCD = KnifeCookbookDependencies
39
+
40
+ require 'dep_selector'
41
+ require 'zlib'
42
+ require 'archive/tar/minitar'
43
+
44
+ require 'kcd/version'
45
+ require 'kcd/shelf'
46
+ require 'kcd/cookbook'
47
+ require 'kcd/metacookbook'
48
+ require 'kcd/dsl'
49
+ require 'kcd/cookbookfile'
50
+ require 'kcd/lockfile'
51
+ require 'kcd/git'
52
+ require 'kcd/error_messages'
@@ -20,7 +20,7 @@ module KnifeCookbookDependencies
20
20
 
21
21
  describe '#unpacked_cookbook_path' do
22
22
  it "should give the path to the directory where the archive should get unpacked" do
23
- subject.unpacked_cookbook_path.should == File.join(ENV['TMPDIR'], 'ntp-1.1.8')
23
+ subject.unpacked_cookbook_path.should == File.join(KCD::TMP_DIRECTORY, 'ntp-1.1.8')
24
24
  end
25
25
  end
26
26
 
data/spec/spec_helper.rb CHANGED
@@ -64,7 +64,7 @@ Spork.prefork do
64
64
  end
65
65
 
66
66
  def with_cookbookfile content
67
- Dir.chdir(ENV['TMPDIR']) do
67
+ Dir.chdir(KCD::TMP_DIRECTORY) do
68
68
  File.open('Cookbookfile', 'w') do |f|
69
69
  f.write content
70
70
  end
@@ -76,4 +76,5 @@ end
76
76
 
77
77
  Spork.each_run do
78
78
  require 'kcd'
79
+ FileUtils.mkdir_p KCD::TMP_DIRECTORY
79
80
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife_cookbook_dependencies
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,11 +11,11 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-05-16 00:00:00.000000000 Z
14
+ date: 2012-05-17 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: dep_selector
18
- requirement: &70354856923060 !ruby/object:Gem::Requirement
18
+ requirement: &70254336887000 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ! '>='
@@ -23,10 +23,10 @@ dependencies:
23
23
  version: '0'
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *70354856923060
26
+ version_requirements: *70254336887000
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: chef
29
- requirement: &70354856921900 !ruby/object:Gem::Requirement
29
+ requirement: &70254336886500 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - ~>
@@ -34,10 +34,10 @@ dependencies:
34
34
  version: 0.10.0
35
35
  type: :runtime
36
36
  prerelease: false
37
- version_requirements: *70354856921900
37
+ version_requirements: *70254336886500
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: minitar
40
- requirement: &70354856921300 !ruby/object:Gem::Requirement
40
+ requirement: &70254336886080 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
43
  - - ! '>='
@@ -45,10 +45,10 @@ dependencies:
45
45
  version: '0'
46
46
  type: :runtime
47
47
  prerelease: false
48
- version_requirements: *70354856921300
48
+ version_requirements: *70254336886080
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: cucumber
51
- requirement: &70354856920560 !ruby/object:Gem::Requirement
51
+ requirement: &70254336885620 !ruby/object:Gem::Requirement
52
52
  none: false
53
53
  requirements:
54
54
  - - ! '>='
@@ -56,10 +56,10 @@ dependencies:
56
56
  version: '0'
57
57
  type: :development
58
58
  prerelease: false
59
- version_requirements: *70354856920560
59
+ version_requirements: *70254336885620
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: vcr
62
- requirement: &70354856919900 !ruby/object:Gem::Requirement
62
+ requirement: &70254336885200 !ruby/object:Gem::Requirement
63
63
  none: false
64
64
  requirements:
65
65
  - - ! '>='
@@ -67,10 +67,10 @@ dependencies:
67
67
  version: '0'
68
68
  type: :development
69
69
  prerelease: false
70
- version_requirements: *70354856919900
70
+ version_requirements: *70254336885200
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: webmock
73
- requirement: &70354856919200 !ruby/object:Gem::Requirement
73
+ requirement: &70254336884780 !ruby/object:Gem::Requirement
74
74
  none: false
75
75
  requirements:
76
76
  - - ! '>='
@@ -78,10 +78,10 @@ dependencies:
78
78
  version: '0'
79
79
  type: :development
80
80
  prerelease: false
81
- version_requirements: *70354856919200
81
+ version_requirements: *70254336884780
82
82
  - !ruby/object:Gem::Dependency
83
83
  name: aruba
84
- requirement: &70354856918540 !ruby/object:Gem::Requirement
84
+ requirement: &70254336884360 !ruby/object:Gem::Requirement
85
85
  none: false
86
86
  requirements:
87
87
  - - ! '>='
@@ -89,10 +89,10 @@ dependencies:
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
- version_requirements: *70354856918540
92
+ version_requirements: *70254336884360
93
93
  - !ruby/object:Gem::Dependency
94
94
  name: rake
95
- requirement: &70354856916880 !ruby/object:Gem::Requirement
95
+ requirement: &70254336883860 !ruby/object:Gem::Requirement
96
96
  none: false
97
97
  requirements:
98
98
  - - ~>
@@ -100,10 +100,10 @@ dependencies:
100
100
  version: 0.9.0
101
101
  type: :development
102
102
  prerelease: false
103
- version_requirements: *70354856916880
103
+ version_requirements: *70254336883860
104
104
  - !ruby/object:Gem::Dependency
105
105
  name: rdoc
106
- requirement: &70354856913320 !ruby/object:Gem::Requirement
106
+ requirement: &70254336883360 !ruby/object:Gem::Requirement
107
107
  none: false
108
108
  requirements:
109
109
  - - ~>
@@ -111,10 +111,10 @@ dependencies:
111
111
  version: '3.0'
112
112
  type: :development
113
113
  prerelease: false
114
- version_requirements: *70354856913320
114
+ version_requirements: *70254336883360
115
115
  - !ruby/object:Gem::Dependency
116
116
  name: rspec
117
- requirement: &70354856906100 !ruby/object:Gem::Requirement
117
+ requirement: &70254336712200 !ruby/object:Gem::Requirement
118
118
  none: false
119
119
  requirements:
120
120
  - - ! '>='
@@ -122,10 +122,10 @@ dependencies:
122
122
  version: '0'
123
123
  type: :development
124
124
  prerelease: false
125
- version_requirements: *70354856906100
125
+ version_requirements: *70254336712200
126
126
  - !ruby/object:Gem::Dependency
127
127
  name: simplecov
128
- requirement: &70354856902180 !ruby/object:Gem::Requirement
128
+ requirement: &70254336711140 !ruby/object:Gem::Requirement
129
129
  none: false
130
130
  requirements:
131
131
  - - ! '>='
@@ -133,10 +133,10 @@ dependencies:
133
133
  version: '0'
134
134
  type: :development
135
135
  prerelease: false
136
- version_requirements: *70354856902180
136
+ version_requirements: *70254336711140
137
137
  - !ruby/object:Gem::Dependency
138
138
  name: fuubar
139
- requirement: &70354856895800 !ruby/object:Gem::Requirement
139
+ requirement: &70254336709980 !ruby/object:Gem::Requirement
140
140
  none: false
141
141
  requirements:
142
142
  - - ! '>='
@@ -144,10 +144,10 @@ dependencies:
144
144
  version: '0'
145
145
  type: :development
146
146
  prerelease: false
147
- version_requirements: *70354856895800
147
+ version_requirements: *70254336709980
148
148
  - !ruby/object:Gem::Dependency
149
149
  name: spork
150
- requirement: &70354857701020 !ruby/object:Gem::Requirement
150
+ requirement: &70254336709240 !ruby/object:Gem::Requirement
151
151
  none: false
152
152
  requirements:
153
153
  - - ! '>='
@@ -155,10 +155,10 @@ dependencies:
155
155
  version: '0'
156
156
  type: :development
157
157
  prerelease: false
158
- version_requirements: *70354857701020
158
+ version_requirements: *70254336709240
159
159
  - !ruby/object:Gem::Dependency
160
160
  name: guard
161
- requirement: &70354857700320 !ruby/object:Gem::Requirement
161
+ requirement: &70254336708580 !ruby/object:Gem::Requirement
162
162
  none: false
163
163
  requirements:
164
164
  - - ! '>='
@@ -166,10 +166,10 @@ dependencies:
166
166
  version: '0'
167
167
  type: :development
168
168
  prerelease: false
169
- version_requirements: *70354857700320
169
+ version_requirements: *70254336708580
170
170
  - !ruby/object:Gem::Dependency
171
171
  name: guard-rspec
172
- requirement: &70354857699120 !ruby/object:Gem::Requirement
172
+ requirement: &70254336707280 !ruby/object:Gem::Requirement
173
173
  none: false
174
174
  requirements:
175
175
  - - ! '>='
@@ -177,10 +177,10 @@ dependencies:
177
177
  version: '0'
178
178
  type: :development
179
179
  prerelease: false
180
- version_requirements: *70354857699120
180
+ version_requirements: *70254336707280
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: guard-spork
183
- requirement: &70354857698200 !ruby/object:Gem::Requirement
183
+ requirement: &70254336705560 !ruby/object:Gem::Requirement
184
184
  none: false
185
185
  requirements:
186
186
  - - ! '>='
@@ -188,7 +188,7 @@ dependencies:
188
188
  version: '0'
189
189
  type: :development
190
190
  prerelease: false
191
- version_requirements: *70354857698200
191
+ version_requirements: *70254336705560
192
192
  description: Resolves cookbook dependencies
193
193
  email:
194
194
  - josiah@skirmisher.net
@@ -205,13 +205,18 @@ files:
205
205
  - LICENSE
206
206
  - README.rdoc
207
207
  - Rakefile
208
+ - features/lib/chef/knife/clean.feature
208
209
  - features/lib/chef/knife/error_messages.feature
210
+ - features/lib/chef/knife/install.feature
209
211
  - features/lib/chef/knife/lockfile.feature
212
+ - features/lib/chef/knife/update.feature
210
213
  - features/lib/chef/knife/without.feature
211
214
  - features/support/env.rb
212
215
  - features/support/step_definitions.rb
213
216
  - knife_cookbook_dependencies.gemspec
217
+ - lib/chef/knife/cookbook_dependencies_clean.rb
214
218
  - lib/chef/knife/cookbook_dependencies_install.rb
219
+ - lib/chef/knife/cookbook_dependencies_update.rb
215
220
  - lib/kcd.rb
216
221
  - lib/kcd/cookbook.rb
217
222
  - lib/kcd/cookbookfile.rb
@@ -224,7 +229,6 @@ files:
224
229
  - lib/kcd/shelf.rb
225
230
  - lib/kcd/version.rb
226
231
  - lib/knife_cookbook_dependencies.rb
227
- - spec/acceptance/knife_cookbook_dependencies_spec.rb
228
232
  - spec/fixtures/cookbooks/example_cookbook/README.md
229
233
  - spec/fixtures/cookbooks/example_cookbook/metadata.rb
230
234
  - spec/fixtures/cookbooks/example_cookbook/recipes/default.rb
@@ -263,12 +267,14 @@ signing_key:
263
267
  specification_version: 3
264
268
  summary: Resolves cookbook dependencies
265
269
  test_files:
270
+ - features/lib/chef/knife/clean.feature
266
271
  - features/lib/chef/knife/error_messages.feature
272
+ - features/lib/chef/knife/install.feature
267
273
  - features/lib/chef/knife/lockfile.feature
274
+ - features/lib/chef/knife/update.feature
268
275
  - features/lib/chef/knife/without.feature
269
276
  - features/support/env.rb
270
277
  - features/support/step_definitions.rb
271
- - spec/acceptance/knife_cookbook_dependencies_spec.rb
272
278
  - spec/fixtures/cookbooks/example_cookbook/README.md
273
279
  - spec/fixtures/cookbooks/example_cookbook/metadata.rb
274
280
  - spec/fixtures/cookbooks/example_cookbook/recipes/default.rb
@@ -1,12 +0,0 @@
1
- require 'spec_helper'
2
- require 'chef/knife/cookbook_dependencies_install'
3
- require 'aruba/api'
4
-
5
-
6
- describe "knife cookbook dependencies install" do
7
- describe "should print a friendly error message" do
8
- include Aruba::Api
9
-
10
- it "for --without option"
11
- end
12
- end