knife-essentials 0.7.6 → 0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -2
- data/lib/chef/knife/{delete.rb → delete_essentials.rb} +10 -2
- data/lib/chef/knife/dependencies_essentials.rb +117 -0
- data/lib/chef/knife/{diff.rb → diff_essentials.rb} +3 -1
- data/lib/chef/knife/{download.rb → download_essentials.rb} +9 -4
- data/lib/chef/knife/{list.rb → list_essentials.rb} +8 -2
- data/lib/chef/knife/{raw.rb → raw_essentials.rb} +2 -0
- data/lib/chef/knife/{show.rb → show_essentials.rb} +3 -1
- data/lib/chef/knife/{upload.rb → upload_essentials.rb} +9 -4
- data/lib/chef_fs/command_line.rb +18 -0
- data/lib/chef_fs/file_pattern.rb +18 -0
- data/lib/chef_fs/file_system.rb +18 -1
- data/lib/chef_fs/file_system/base_fs_dir.rb +18 -0
- data/lib/chef_fs/file_system/base_fs_object.rb +19 -1
- data/lib/chef_fs/file_system/chef_repository_file_system_entry.rb +49 -8
- data/lib/chef_fs/file_system/chef_repository_file_system_root_dir.rb +62 -3
- data/lib/chef_fs/file_system/chef_server_root_dir.rb +18 -0
- data/lib/chef_fs/file_system/cookbook_dir.rb +26 -0
- data/lib/chef_fs/file_system/cookbook_file.rb +18 -0
- data/lib/chef_fs/file_system/cookbook_subdir.rb +18 -0
- data/lib/chef_fs/file_system/cookbooks_dir.rb +18 -2
- data/lib/chef_fs/file_system/data_bag_dir.rb +18 -0
- data/lib/chef_fs/file_system/data_bag_item.rb +18 -0
- data/lib/chef_fs/file_system/data_bags_dir.rb +18 -0
- data/lib/chef_fs/file_system/file_system_entry.rb +18 -0
- data/lib/chef_fs/file_system/file_system_error.rb +18 -0
- data/lib/chef_fs/file_system/file_system_root_dir.rb +18 -0
- data/lib/chef_fs/file_system/multiplexed_dir.rb +46 -0
- data/lib/chef_fs/file_system/must_delete_recursively_error.rb +18 -0
- data/lib/chef_fs/file_system/nodes_dir.rb +18 -0
- data/lib/chef_fs/file_system/nonexistent_fs_object.rb +18 -0
- data/lib/chef_fs/file_system/not_found_error.rb +18 -0
- data/lib/chef_fs/file_system/rest_list_dir.rb +18 -0
- data/lib/chef_fs/file_system/rest_list_entry.rb +18 -0
- data/lib/chef_fs/knife.rb +128 -18
- data/lib/chef_fs/path_utils.rb +19 -1
- data/lib/chef_fs/version.rb +1 -1
- data/spec/chef_fs/diff_spec.rb +69 -44
- data/spec/chef_fs/file_pattern_spec.rb +497 -479
- data/spec/chef_fs/file_system/chef_server_root_dir_spec.rb +18 -0
- data/spec/chef_fs/file_system/cookbooks_dir_spec.rb +18 -0
- data/spec/chef_fs/file_system/data_bags_dir_spec.rb +18 -0
- data/spec/chef_fs/file_system_spec.rb +124 -106
- data/spec/support/file_system_support.rb +93 -75
- metadata +12 -11
- 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
|
-
|
24
|
+
include FileSystemSupport
|
7
25
|
|
8
|
-
|
9
|
-
|
26
|
+
context 'with empty filesystem' do
|
27
|
+
let(:fs) { memory_fs('', {}) }
|
10
28
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
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
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|
-
|
58
|
+
attr_reader :cannot_be_in_regex
|
41
59
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
60
|
+
def path_for_printing
|
61
|
+
@pretty_name
|
62
|
+
end
|
63
|
+
end
|
46
64
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
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
|
-
|
71
|
-
|
72
|
-
|
88
|
+
def pattern(p)
|
89
|
+
ChefFS::FilePattern.new(p)
|
90
|
+
end
|
73
91
|
|
74
|
-
|
75
|
-
|
76
|
-
|
92
|
+
def return_paths(*expected)
|
93
|
+
ReturnPaths.new(expected)
|
94
|
+
end
|
77
95
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
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
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
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
|
|