knife-essentials 0.7.6 → 0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/Rakefile +2 -2
  2. data/lib/chef/knife/{delete.rb → delete_essentials.rb} +10 -2
  3. data/lib/chef/knife/dependencies_essentials.rb +117 -0
  4. data/lib/chef/knife/{diff.rb → diff_essentials.rb} +3 -1
  5. data/lib/chef/knife/{download.rb → download_essentials.rb} +9 -4
  6. data/lib/chef/knife/{list.rb → list_essentials.rb} +8 -2
  7. data/lib/chef/knife/{raw.rb → raw_essentials.rb} +2 -0
  8. data/lib/chef/knife/{show.rb → show_essentials.rb} +3 -1
  9. data/lib/chef/knife/{upload.rb → upload_essentials.rb} +9 -4
  10. data/lib/chef_fs/command_line.rb +18 -0
  11. data/lib/chef_fs/file_pattern.rb +18 -0
  12. data/lib/chef_fs/file_system.rb +18 -1
  13. data/lib/chef_fs/file_system/base_fs_dir.rb +18 -0
  14. data/lib/chef_fs/file_system/base_fs_object.rb +19 -1
  15. data/lib/chef_fs/file_system/chef_repository_file_system_entry.rb +49 -8
  16. data/lib/chef_fs/file_system/chef_repository_file_system_root_dir.rb +62 -3
  17. data/lib/chef_fs/file_system/chef_server_root_dir.rb +18 -0
  18. data/lib/chef_fs/file_system/cookbook_dir.rb +26 -0
  19. data/lib/chef_fs/file_system/cookbook_file.rb +18 -0
  20. data/lib/chef_fs/file_system/cookbook_subdir.rb +18 -0
  21. data/lib/chef_fs/file_system/cookbooks_dir.rb +18 -2
  22. data/lib/chef_fs/file_system/data_bag_dir.rb +18 -0
  23. data/lib/chef_fs/file_system/data_bag_item.rb +18 -0
  24. data/lib/chef_fs/file_system/data_bags_dir.rb +18 -0
  25. data/lib/chef_fs/file_system/file_system_entry.rb +18 -0
  26. data/lib/chef_fs/file_system/file_system_error.rb +18 -0
  27. data/lib/chef_fs/file_system/file_system_root_dir.rb +18 -0
  28. data/lib/chef_fs/file_system/multiplexed_dir.rb +46 -0
  29. data/lib/chef_fs/file_system/must_delete_recursively_error.rb +18 -0
  30. data/lib/chef_fs/file_system/nodes_dir.rb +18 -0
  31. data/lib/chef_fs/file_system/nonexistent_fs_object.rb +18 -0
  32. data/lib/chef_fs/file_system/not_found_error.rb +18 -0
  33. data/lib/chef_fs/file_system/rest_list_dir.rb +18 -0
  34. data/lib/chef_fs/file_system/rest_list_entry.rb +18 -0
  35. data/lib/chef_fs/knife.rb +128 -18
  36. data/lib/chef_fs/path_utils.rb +19 -1
  37. data/lib/chef_fs/version.rb +1 -1
  38. data/spec/chef_fs/diff_spec.rb +69 -44
  39. data/spec/chef_fs/file_pattern_spec.rb +497 -479
  40. data/spec/chef_fs/file_system/chef_server_root_dir_spec.rb +18 -0
  41. data/spec/chef_fs/file_system/cookbooks_dir_spec.rb +18 -0
  42. data/spec/chef_fs/file_system/data_bags_dir_spec.rb +18 -0
  43. data/spec/chef_fs/file_system_spec.rb +124 -106
  44. data/spec/support/file_system_support.rb +93 -75
  45. metadata +12 -11
  46. data/lib/chef/sandbox_uploader.rb +0 -208
@@ -1,3 +1,21 @@
1
+ #
2
+ # Author:: John Keiser (<jkeiser@opscode.com>)
3
+ # Copyright:: Copyright (c) 2012 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
1
19
  require 'support/spec_helper'
2
20
  require 'chef_fs/file_system/chef_server_root_dir'
3
21
 
@@ -1,3 +1,21 @@
1
+ #
2
+ # Author:: John Keiser (<jkeiser@opscode.com>)
3
+ # Copyright:: Copyright (c) 2012 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
1
19
  require 'support/spec_helper'
2
20
  require 'chef_fs/file_system/chef_server_root_dir'
3
21
  require 'chef_fs/file_system'
@@ -1,3 +1,21 @@
1
+ #
2
+ # Author:: John Keiser (<jkeiser@opscode.com>)
3
+ # Copyright:: Copyright (c) 2012 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
1
19
  require 'support/spec_helper'
2
20
  require 'chef_fs/file_system/chef_server_root_dir'
3
21
 
@@ -1,117 +1,135 @@
1
+ #
2
+ # Author:: John Keiser (<jkeiser@opscode.com>)
3
+ # Copyright:: Copyright (c) 2012 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
1
19
  require 'support/spec_helper'
2
20
  require 'chef_fs/file_system'
3
21
  require 'chef_fs/file_pattern'
4
22
 
5
23
  describe ChefFS::FileSystem do
6
- include FileSystemSupport
24
+ include FileSystemSupport
7
25
 
8
- context 'with empty filesystem' do
9
- let(:fs) { memory_fs('', {}) }
26
+ context 'with empty filesystem' do
27
+ let(:fs) { memory_fs('', {}) }
10
28
 
11
- context 'list' do
12
- it '/' do
13
- list_should_yield_paths(fs, '/', '/')
14
- end
15
- it '/a' do
16
- list_should_yield_paths(fs, '/a', '/a')
17
- end
18
- it '/a/b' do
19
- list_should_yield_paths(fs, '/a/b')
20
- end
21
- it '/*' do
22
- list_should_yield_paths(fs, '/*', '/')
23
- end
24
- end
29
+ context 'list' do
30
+ it '/' do
31
+ list_should_yield_paths(fs, '/', '/')
32
+ end
33
+ it '/a' do
34
+ list_should_yield_paths(fs, '/a', '/a')
35
+ end
36
+ it '/a/b' do
37
+ list_should_yield_paths(fs, '/a/b')
38
+ end
39
+ it '/*' do
40
+ list_should_yield_paths(fs, '/*', '/')
41
+ end
42
+ end
25
43
 
26
- context 'resolve_path' do
27
- it '/' do
28
- ChefFS::FileSystem.resolve_path(fs, '/').path.should == '/'
29
- end
30
- it 'nonexistent /a' do
31
- ChefFS::FileSystem.resolve_path(fs, '/a').path.should == '/a'
32
- end
33
- it 'nonexistent /a/b' do
34
- ChefFS::FileSystem.resolve_path(fs, '/a/b').path.should == '/a/b'
35
- end
36
- end
37
- end
44
+ context 'resolve_path' do
45
+ it '/' do
46
+ ChefFS::FileSystem.resolve_path(fs, '/').path.should == '/'
47
+ end
48
+ it 'nonexistent /a' do
49
+ ChefFS::FileSystem.resolve_path(fs, '/a').path.should == '/a'
50
+ end
51
+ it 'nonexistent /a/b' do
52
+ ChefFS::FileSystem.resolve_path(fs, '/a/b').path.should == '/a/b'
53
+ end
54
+ end
55
+ end
38
56
 
39
- context 'with a populated filesystem' do
40
- let(:fs) {
41
- memory_fs('', {
42
- :a => {
43
- :aa => {
44
- :c => '',
45
- :zz => ''
46
- },
47
- :ab => {
48
- :c => '',
49
- }
50
- },
51
- :x => ''
52
- })
53
- }
54
- context 'list' do
55
- it '/**' do
56
- list_should_yield_paths(fs, '/**', '/', '/a', '/x', '/a/aa', '/a/aa/c', '/a/aa/zz', '/a/ab', '/a/ab/c')
57
- end
58
- it '/' do
59
- list_should_yield_paths(fs, '/', '/')
60
- end
61
- it '/*' do
62
- list_should_yield_paths(fs, '/*', '/', '/a', '/x')
63
- end
64
- it '/*/*' do
65
- list_should_yield_paths(fs, '/*/*', '/a/aa', '/a/ab')
66
- end
67
- it '/*/*/*' do
68
- list_should_yield_paths(fs, '/*/*/*', '/a/aa/c', '/a/aa/zz', '/a/ab/c')
69
- end
70
- it '/*/*/?' do
71
- list_should_yield_paths(fs, '/*/*/?', '/a/aa/c', '/a/ab/c')
72
- end
73
- it '/a/*/c' do
74
- list_should_yield_paths(fs, '/a/*/c', '/a/aa/c', '/a/ab/c')
75
- end
76
- it '/**b/c' do
77
- list_should_yield_paths(fs, '/**b/c', '/a/ab/c')
78
- end
79
- it '/a/ab/c' do
80
- no_blocking_calls_allowed
81
- list_should_yield_paths(fs, '/a/ab/c', '/a/ab/c')
82
- end
83
- it 'nonexistent /a/ab/blah' do
84
- no_blocking_calls_allowed
85
- list_should_yield_paths(fs, '/a/ab/blah', '/a/ab/blah')
86
- end
87
- it 'nonexistent /a/ab/blah/bjork' do
88
- no_blocking_calls_allowed
89
- list_should_yield_paths(fs, '/a/ab/blah/bjork')
90
- end
91
- end
57
+ context 'with a populated filesystem' do
58
+ let(:fs) {
59
+ memory_fs('', {
60
+ :a => {
61
+ :aa => {
62
+ :c => '',
63
+ :zz => ''
64
+ },
65
+ :ab => {
66
+ :c => '',
67
+ }
68
+ },
69
+ :x => ''
70
+ })
71
+ }
72
+ context 'list' do
73
+ it '/**' do
74
+ list_should_yield_paths(fs, '/**', '/', '/a', '/x', '/a/aa', '/a/aa/c', '/a/aa/zz', '/a/ab', '/a/ab/c')
75
+ end
76
+ it '/' do
77
+ list_should_yield_paths(fs, '/', '/')
78
+ end
79
+ it '/*' do
80
+ list_should_yield_paths(fs, '/*', '/', '/a', '/x')
81
+ end
82
+ it '/*/*' do
83
+ list_should_yield_paths(fs, '/*/*', '/a/aa', '/a/ab')
84
+ end
85
+ it '/*/*/*' do
86
+ list_should_yield_paths(fs, '/*/*/*', '/a/aa/c', '/a/aa/zz', '/a/ab/c')
87
+ end
88
+ it '/*/*/?' do
89
+ list_should_yield_paths(fs, '/*/*/?', '/a/aa/c', '/a/ab/c')
90
+ end
91
+ it '/a/*/c' do
92
+ list_should_yield_paths(fs, '/a/*/c', '/a/aa/c', '/a/ab/c')
93
+ end
94
+ it '/**b/c' do
95
+ list_should_yield_paths(fs, '/**b/c', '/a/ab/c')
96
+ end
97
+ it '/a/ab/c' do
98
+ no_blocking_calls_allowed
99
+ list_should_yield_paths(fs, '/a/ab/c', '/a/ab/c')
100
+ end
101
+ it 'nonexistent /a/ab/blah' do
102
+ no_blocking_calls_allowed
103
+ list_should_yield_paths(fs, '/a/ab/blah', '/a/ab/blah')
104
+ end
105
+ it 'nonexistent /a/ab/blah/bjork' do
106
+ no_blocking_calls_allowed
107
+ list_should_yield_paths(fs, '/a/ab/blah/bjork')
108
+ end
109
+ end
92
110
 
93
- context 'resolve_path' do
94
- before(:each) do
95
- no_blocking_calls_allowed
96
- end
97
- it 'resolves /' do
98
- ChefFS::FileSystem.resolve_path(fs, '/').path.should == '/'
99
- end
100
- it 'resolves /x' do
101
- ChefFS::FileSystem.resolve_path(fs, '/x').path.should == '/x'
102
- end
103
- it 'resolves /a' do
104
- ChefFS::FileSystem.resolve_path(fs, '/a').path.should == '/a'
105
- end
106
- it 'resolves /a/aa' do
107
- ChefFS::FileSystem.resolve_path(fs, '/a/aa').path.should == '/a/aa'
108
- end
109
- it 'resolves /a/aa/zz' do
110
- ChefFS::FileSystem.resolve_path(fs, '/a/aa/zz').path.should == '/a/aa/zz'
111
- end
112
- it 'resolves nonexistent /y/x/w' do
113
- ChefFS::FileSystem.resolve_path(fs, '/y/x/w').path.should == '/y/x/w'
114
- end
115
- end
116
- end
111
+ context 'resolve_path' do
112
+ before(:each) do
113
+ no_blocking_calls_allowed
114
+ end
115
+ it 'resolves /' do
116
+ ChefFS::FileSystem.resolve_path(fs, '/').path.should == '/'
117
+ end
118
+ it 'resolves /x' do
119
+ ChefFS::FileSystem.resolve_path(fs, '/x').path.should == '/x'
120
+ end
121
+ it 'resolves /a' do
122
+ ChefFS::FileSystem.resolve_path(fs, '/a').path.should == '/a'
123
+ end
124
+ it 'resolves /a/aa' do
125
+ ChefFS::FileSystem.resolve_path(fs, '/a/aa').path.should == '/a/aa'
126
+ end
127
+ it 'resolves /a/aa/zz' do
128
+ ChefFS::FileSystem.resolve_path(fs, '/a/aa/zz').path.should == '/a/aa/zz'
129
+ end
130
+ it 'resolves nonexistent /y/x/w' do
131
+ ChefFS::FileSystem.resolve_path(fs, '/y/x/w').path.should == '/y/x/w'
132
+ end
133
+ end
134
+ end
117
135
  end
@@ -1,92 +1,110 @@
1
+ #
2
+ # Author:: John Keiser (<jkeiser@opscode.com>)
3
+ # Copyright:: Copyright (c) 2012 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
1
19
  require 'chef_fs/file_system'
2
20
  require 'chef_fs/file_system/base_fs_dir'
3
21
  require 'chef_fs/file_system/base_fs_object'
4
22
 
5
23
  module FileSystemSupport
6
- class MemoryFile < ChefFS::FileSystem::BaseFSObject
7
- def initialize(name, parent, value)
8
- super(name, parent)
9
- @value = value
10
- end
11
- def read
12
- return @value
13
- end
14
- end
24
+ class MemoryFile < ChefFS::FileSystem::BaseFSObject
25
+ def initialize(name, parent, value)
26
+ super(name, parent)
27
+ @value = value
28
+ end
29
+ def read
30
+ return @value
31
+ end
32
+ end
15
33
 
16
- class MemoryDir < ChefFS::FileSystem::BaseFSDir
17
- def initialize(name, parent)
18
- super(name, parent)
19
- @children = []
20
- end
21
- attr_reader :children
22
- def child(name)
23
- @children.select { |child| child.name == name }.first || ChefFS::FileSystem::NonexistentFSObject.new(name, self)
24
- end
25
- def add_child(child)
26
- @children.push(child)
27
- end
28
- def can_have_child?(name, is_dir)
29
- root.cannot_be_in_regex ? (name !~ root.cannot_be_in_regex) : true
30
- end
31
- end
34
+ class MemoryDir < ChefFS::FileSystem::BaseFSDir
35
+ def initialize(name, parent)
36
+ super(name, parent)
37
+ @children = []
38
+ end
39
+ attr_reader :children
40
+ def child(name)
41
+ @children.select { |child| child.name == name }.first || ChefFS::FileSystem::NonexistentFSObject.new(name, self)
42
+ end
43
+ def add_child(child)
44
+ @children.push(child)
45
+ end
46
+ def can_have_child?(name, is_dir)
47
+ root.cannot_be_in_regex ? (name !~ root.cannot_be_in_regex) : true
48
+ end
49
+ end
32
50
 
33
- class MemoryRoot < MemoryDir
34
- def initialize(pretty_name, cannot_be_in_regex = nil)
35
- super('', nil)
36
- @pretty_name = pretty_name
37
- @cannot_be_in_regex = cannot_be_in_regex
38
- end
51
+ class MemoryRoot < MemoryDir
52
+ def initialize(pretty_name, cannot_be_in_regex = nil)
53
+ super('', nil)
54
+ @pretty_name = pretty_name
55
+ @cannot_be_in_regex = cannot_be_in_regex
56
+ end
39
57
 
40
- attr_reader :cannot_be_in_regex
58
+ attr_reader :cannot_be_in_regex
41
59
 
42
- def path_for_printing
43
- @pretty_name
44
- end
45
- end
60
+ def path_for_printing
61
+ @pretty_name
62
+ end
63
+ end
46
64
 
47
- def memory_fs(pretty_name, value, cannot_be_in_regex = nil)
48
- if !value.is_a?(Hash)
49
- raise "memory_fs() must take a Hash"
50
- end
51
- dir = MemoryRoot.new(pretty_name, cannot_be_in_regex)
52
- value.each do |key, child|
53
- dir.add_child(memory_fs_value(child, key.to_s, dir))
54
- end
55
- dir
56
- end
65
+ def memory_fs(pretty_name, value, cannot_be_in_regex = nil)
66
+ if !value.is_a?(Hash)
67
+ raise "memory_fs() must take a Hash"
68
+ end
69
+ dir = MemoryRoot.new(pretty_name, cannot_be_in_regex)
70
+ value.each do |key, child|
71
+ dir.add_child(memory_fs_value(child, key.to_s, dir))
72
+ end
73
+ dir
74
+ end
57
75
 
58
- def memory_fs_value(value, name = '', parent = nil)
59
- if value.is_a?(Hash)
60
- dir = MemoryDir.new(name, parent)
61
- value.each do |key, child|
62
- dir.add_child(memory_fs_value(child, key.to_s, dir))
63
- end
64
- dir
65
- else
66
- MemoryFile.new(name, parent, value || "#{name}\n")
67
- end
68
- end
76
+ def memory_fs_value(value, name = '', parent = nil)
77
+ if value.is_a?(Hash)
78
+ dir = MemoryDir.new(name, parent)
79
+ value.each do |key, child|
80
+ dir.add_child(memory_fs_value(child, key.to_s, dir))
81
+ end
82
+ dir
83
+ else
84
+ MemoryFile.new(name, parent, value || "#{name}\n")
85
+ end
86
+ end
69
87
 
70
- def pattern(p)
71
- ChefFS::FilePattern.new(p)
72
- end
88
+ def pattern(p)
89
+ ChefFS::FilePattern.new(p)
90
+ end
73
91
 
74
- def return_paths(*expected)
75
- ReturnPaths.new(expected)
76
- end
92
+ def return_paths(*expected)
93
+ ReturnPaths.new(expected)
94
+ end
77
95
 
78
- def no_blocking_calls_allowed
79
- [ MemoryFile, MemoryDir ].each do |c|
80
- [ :children, :exists?, :read ].each do |m|
81
- c.any_instance.stub(m).and_raise("#{m.to_s} should not be called")
82
- end
83
- end
84
- end
96
+ def no_blocking_calls_allowed
97
+ [ MemoryFile, MemoryDir ].each do |c|
98
+ [ :children, :exists?, :read ].each do |m|
99
+ c.any_instance.stub(m).and_raise("#{m.to_s} should not be called")
100
+ end
101
+ end
102
+ end
85
103
 
86
- def list_should_yield_paths(fs, pattern_str, *expected_paths)
87
- result_paths = []
88
- ChefFS::FileSystem.list(fs, pattern(pattern_str)) { |result| result_paths << result.path }
89
- result_paths.should =~ expected_paths
90
- end
104
+ def list_should_yield_paths(fs, pattern_str, *expected_paths)
105
+ result_paths = []
106
+ ChefFS::FileSystem.list(fs, pattern(pattern_str)) { |result| result_paths << result.path }
107
+ result_paths.should =~ expected_paths
108
+ end
91
109
  end
92
110