chef 12.11.18 → 12.12.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -4
- data/Rakefile +3 -2
- data/VERSION +1 -1
- data/acceptance/Gemfile.lock +22 -23
- data/acceptance/data-collector/test/integration/default/serverspec/default_spec.rb +2 -41
- data/lib/chef/application/solo.rb +7 -0
- data/lib/chef/chef_fs/file_system/multiplexed_dir.rb +1 -1
- data/lib/chef/data_collector.rb +79 -43
- data/lib/chef/data_collector/messages.rb +4 -33
- data/lib/chef/data_collector/messages/helpers.rb +2 -2
- data/lib/chef/data_collector/resource_report.rb +21 -11
- data/lib/chef/decorator/unchain.rb +43 -0
- data/lib/chef/exceptions.rb +5 -0
- data/lib/chef/http.rb +5 -5
- data/lib/chef/knife/cookbook_create.rb +4 -0
- data/lib/chef/knife/cookbook_site_download.rb +8 -1
- data/lib/chef/knife/cookbook_site_install.rb +8 -0
- data/lib/chef/knife/cookbook_site_list.rb +8 -1
- data/lib/chef/knife/cookbook_site_search.rb +8 -1
- data/lib/chef/knife/cookbook_site_share.rb +8 -1
- data/lib/chef/knife/cookbook_site_show.rb +14 -3
- data/lib/chef/knife/cookbook_site_unshare.rb +8 -1
- data/lib/chef/knife/core/bootstrap_context.rb +1 -1
- data/lib/chef/knife/supermarket_download.rb +33 -0
- data/lib/chef/knife/supermarket_install.rb +33 -0
- data/lib/chef/knife/supermarket_list.rb +33 -0
- data/lib/chef/knife/supermarket_search.rb +33 -0
- data/lib/chef/knife/supermarket_share.rb +33 -0
- data/lib/chef/knife/supermarket_show.rb +33 -0
- data/lib/chef/knife/supermarket_unshare.rb +33 -0
- data/lib/chef/node.rb +13 -32
- data/lib/chef/node/attribute.rb +123 -70
- data/lib/chef/node/attribute_collections.rb +9 -130
- data/lib/chef/node/common_api.rb +124 -0
- data/lib/chef/node/immutable_collections.rb +27 -2
- data/lib/chef/property.rb +6 -2
- data/lib/chef/provider.rb +4 -5
- data/lib/chef/provider/batch.rb +1 -1
- data/lib/chef/provider/directory.rb +3 -1
- data/lib/chef/provider/package/openbsd.rb +1 -1
- data/lib/chef/provider/package/rubygems.rb +9 -3
- data/lib/chef/provider/package/windows/exe.rb +2 -5
- data/lib/chef/provider/powershell_script.rb +1 -1
- data/lib/chef/provider/remote_directory.rb +2 -0
- data/lib/chef/resource.rb +22 -17
- data/lib/chef/resource_builder.rb +9 -4
- data/lib/chef/shell.rb +1 -1
- data/lib/chef/version.rb +1 -1
- data/spec/data/run_context/cookbooks/circular-dep1/attributes/default.rb +2 -4
- data/spec/data/run_context/cookbooks/circular-dep2/attributes/default.rb +2 -3
- data/spec/data/run_context/cookbooks/dependency1/attributes/aa_first.rb +2 -2
- data/spec/data/run_context/cookbooks/dependency1/attributes/default.rb +2 -2
- data/spec/data/run_context/cookbooks/dependency1/attributes/zz_last.rb +2 -3
- data/spec/data/run_context/cookbooks/dependency2/attributes/default.rb +2 -3
- data/spec/data/run_context/cookbooks/no-default-attr/attributes/server.rb +2 -3
- data/spec/data/run_context/cookbooks/test-with-circular-deps/attributes/default.rb +2 -3
- data/spec/data/run_context/cookbooks/test-with-deps/attributes/default.rb +2 -3
- data/spec/functional/assets/chocolatey_feed/test-A.1.0.nupkg +0 -0
- data/spec/functional/assets/chocolatey_feed/test-A.1.5.nupkg +0 -0
- data/spec/functional/assets/chocolatey_feed/test-A.2.0.nupkg +0 -0
- data/spec/functional/assets/chocolatey_feed/test-B.1.0.nupkg +0 -0
- data/spec/functional/resource/dsc_script_spec.rb +1 -0
- data/spec/functional/resource/package_spec.rb +1 -1
- data/spec/functional/resource/template_spec.rb +3 -3
- data/spec/functional/shell_spec.rb +1 -1
- data/spec/integration/knife/client_bulk_delete_spec.rb +130 -0
- data/spec/integration/knife/client_create_spec.rb +69 -0
- data/spec/integration/knife/client_delete_spec.rb +63 -0
- data/spec/integration/knife/client_key_create_spec.rb +65 -0
- data/spec/integration/knife/client_key_delete_spec.rb +42 -0
- data/spec/integration/knife/client_key_list_spec.rb +60 -0
- data/spec/integration/knife/client_key_show_spec.rb +44 -0
- data/spec/integration/knife/client_list_spec.rb +48 -0
- data/spec/integration/knife/client_show_spec.rb +36 -0
- data/spec/integration/knife/cookbook_bulk_delete_spec.rb +64 -0
- data/spec/integration/knife/cookbook_download_spec.rb +95 -0
- data/spec/integration/knife/cookbook_list_spec.rb +54 -0
- data/spec/integration/knife/cookbook_show_spec.rb +159 -0
- data/spec/integration/knife/cookbook_upload_spec.rb +90 -0
- data/spec/integration/knife/data_bag_create_spec.rb +58 -0
- data/spec/integration/knife/data_bag_delete_spec.rb +58 -0
- data/spec/integration/knife/data_bag_from_file_spec.rb +115 -0
- data/spec/integration/knife/data_bag_list_spec.rb +43 -0
- data/spec/integration/knife/data_bag_show_spec.rb +53 -0
- data/spec/integration/knife/environment_compare_spec.rb +74 -0
- data/spec/integration/knife/environment_create_spec.rb +40 -0
- data/spec/integration/knife/environment_delete_spec.rb +36 -0
- data/spec/integration/knife/environment_from_file_spec.rb +115 -0
- data/spec/integration/knife/environment_list_spec.rb +41 -0
- data/spec/integration/knife/environment_show_spec.rb +56 -0
- data/spec/integration/knife/node_bulk_delete_spec.rb +51 -0
- data/spec/integration/knife/node_create_spec.rb +46 -0
- data/spec/integration/knife/node_delete_spec.rb +47 -0
- data/spec/integration/knife/node_environment_set_spec.rb +42 -0
- data/spec/integration/knife/node_from_file_spec.rb +58 -0
- data/spec/integration/knife/node_list_spec.rb +44 -0
- data/spec/integration/knife/node_run_list_add_spec.rb +53 -0
- data/spec/integration/knife/node_run_list_remove_spec.rb +35 -0
- data/spec/integration/knife/node_run_list_set_spec.rb +40 -0
- data/spec/integration/knife/node_show_spec.rb +35 -0
- data/spec/integration/knife/role_bulk_delete_spec.rb +51 -0
- data/spec/integration/knife/role_create_spec.rb +40 -0
- data/spec/integration/knife/role_delete_spec.rb +47 -0
- data/spec/integration/knife/role_from_file_spec.rb +95 -0
- data/spec/integration/knife/role_list_spec.rb +44 -0
- data/spec/integration/knife/role_show_spec.rb +50 -0
- data/spec/support/shared/integration/knife_support.rb +10 -3
- data/spec/unit/application/solo_spec.rb +7 -0
- data/spec/unit/cookbook_version_spec.rb +4 -4
- data/spec/unit/data_collector/messages/helpers_spec.rb +3 -7
- data/spec/unit/data_collector/messages_spec.rb +28 -45
- data/spec/unit/data_collector_spec.rb +40 -47
- data/spec/unit/knife/cookbook_create_spec.rb +1 -0
- data/spec/unit/knife/cookbook_site_download_spec.rb +1 -0
- data/spec/unit/knife/node_environment_set_spec.rb +0 -24
- data/spec/unit/knife/node_run_list_set_spec.rb +0 -25
- data/spec/unit/node/attribute_spec.rb +7 -9
- data/spec/unit/node/immutable_collections_spec.rb +4 -0
- data/spec/unit/node/vivid_mash_spec.rb +344 -0
- data/spec/unit/node_spec.rb +115 -26
- data/spec/unit/provider/directory_spec.rb +11 -1
- data/spec/unit/provider/package/windows/exe_spec.rb +14 -9
- data/spec/unit/provider/powershell_script_spec.rb +4 -4
- data/spec/unit/provider/remote_directory_spec.rb +15 -0
- data/spec/unit/recipe_spec.rb +31 -6
- data/spec/unit/run_context_spec.rb +2 -2
- data/spec/unit/shell/shell_session_spec.rb +1 -1
- data/tasks/dependencies.rb +0 -2
- metadata +55 -786
- data/acceptance/.bundle/config +0 -2
- data/acceptance/basics/.kitchen/logs/chef-current-install-ubuntu-1404.log +0 -2
- data/acceptance/basics/.kitchen/logs/kitchen.log +0 -3
- data/acceptance/fips/.kitchen/logs/fips-integration-centos-6.log +0 -3
- data/acceptance/fips/.kitchen/logs/fips-integration-windows-2012r2.log +0 -3
- data/acceptance/fips/.kitchen/logs/fips-unit-functional-centos-6.log +0 -3
- data/acceptance/fips/.kitchen/logs/fips-unit-functional-windows-2012r2.log +0 -3
- data/acceptance/fips/.kitchen/logs/kitchen.log +0 -6
- data/acceptance/trivial/.kitchen/logs/chef-current-install-windows-2012r2.log +0 -2
- data/acceptance/trivial/.kitchen/logs/kitchen.log +0 -3
- data/acceptance/windows-service/.kitchen/logs/chef-windows-service-windows-2012r2.log +0 -2
- data/acceptance/windows-service/.kitchen/logs/kitchen.log +0 -3
@@ -0,0 +1,51 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright 2013-2016, Chef Software Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require "support/shared/integration/integration_helper"
|
18
|
+
require "support/shared/context/config"
|
19
|
+
|
20
|
+
describe "knife role bulk delete", :workstation do
|
21
|
+
include IntegrationSupport
|
22
|
+
include KnifeSupport
|
23
|
+
|
24
|
+
include_context "default config options"
|
25
|
+
|
26
|
+
when_the_chef_server "has some roles" do
|
27
|
+
before do
|
28
|
+
role "cons", {}
|
29
|
+
role "car", {}
|
30
|
+
role "cdr", {}
|
31
|
+
role "cat", {}
|
32
|
+
end
|
33
|
+
|
34
|
+
it "deletes all matching roles" do
|
35
|
+
knife("role bulk delete ^ca.*", input: "Y").should_succeed <<EOM
|
36
|
+
The following roles will be deleted:
|
37
|
+
|
38
|
+
car cat
|
39
|
+
|
40
|
+
Are you sure you want to delete these roles? (Y/N) Deleted role car
|
41
|
+
Deleted role cat
|
42
|
+
EOM
|
43
|
+
|
44
|
+
knife("role list").should_succeed <<EOM
|
45
|
+
cdr
|
46
|
+
cons
|
47
|
+
EOM
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright 2013-2016, Chef Software Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require "support/shared/integration/integration_helper"
|
18
|
+
require "support/shared/context/config"
|
19
|
+
|
20
|
+
describe "knife role create", :workstation do
|
21
|
+
include IntegrationSupport
|
22
|
+
include KnifeSupport
|
23
|
+
|
24
|
+
include_context "default config options"
|
25
|
+
|
26
|
+
let(:out) { "Created role[bah]\n" }
|
27
|
+
|
28
|
+
when_the_chef_server "is empty" do
|
29
|
+
it "creates a new role" do
|
30
|
+
knife("role create bah").should_succeed out
|
31
|
+
end
|
32
|
+
|
33
|
+
it "refuses to add an existing role" do
|
34
|
+
pending "Knife role create must not blindly overwrite an existing role"
|
35
|
+
knife("role create bah").should_succeed out
|
36
|
+
expect { knife("role create bah") }.to raise_error(Net::HTTPServerException)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright 2013-2016, Chef Software Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require "support/shared/integration/integration_helper"
|
18
|
+
require "support/shared/context/config"
|
19
|
+
|
20
|
+
describe "knife role delete", :workstation do
|
21
|
+
include IntegrationSupport
|
22
|
+
include KnifeSupport
|
23
|
+
|
24
|
+
include_context "default config options"
|
25
|
+
|
26
|
+
when_the_chef_server "has some roles" do
|
27
|
+
before do
|
28
|
+
role "cons", {}
|
29
|
+
role "car", {}
|
30
|
+
role "cdr", {}
|
31
|
+
role "cat", {}
|
32
|
+
end
|
33
|
+
|
34
|
+
it "deletes a role" do
|
35
|
+
knife("role delete car", input: "Y").should_succeed <<EOM
|
36
|
+
Do you really want to delete car? (Y/N) Deleted role[car]
|
37
|
+
EOM
|
38
|
+
|
39
|
+
knife("role list").should_succeed <<EOM
|
40
|
+
cat
|
41
|
+
cdr
|
42
|
+
cons
|
43
|
+
EOM
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright 2013-2016, Chef Software Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require "support/shared/integration/integration_helper"
|
18
|
+
require "support/shared/context/config"
|
19
|
+
|
20
|
+
describe "knife role from file", :workstation do
|
21
|
+
include IntegrationSupport
|
22
|
+
include KnifeSupport
|
23
|
+
|
24
|
+
# include_context "default config options"
|
25
|
+
|
26
|
+
let (:role_dir) { "#{@repository_dir}/roles" }
|
27
|
+
|
28
|
+
when_the_chef_server "is empty" do
|
29
|
+
when_the_repository "has some roles" do
|
30
|
+
before do
|
31
|
+
|
32
|
+
file "roles/cons.json", <<EOM
|
33
|
+
{
|
34
|
+
"name": "cons",
|
35
|
+
"description": "An role",
|
36
|
+
"json_class": "Chef::role",
|
37
|
+
"chef_type": "role",
|
38
|
+
"default_attributes": {
|
39
|
+
"hola": "Amigos!"
|
40
|
+
},
|
41
|
+
"override_attributes": {
|
42
|
+
|
43
|
+
}
|
44
|
+
}
|
45
|
+
EOM
|
46
|
+
|
47
|
+
file "roles/car.json", <<EOM
|
48
|
+
{
|
49
|
+
"name": "car",
|
50
|
+
"description": "A role for list nodes",
|
51
|
+
"json_class": "Chef::Role",
|
52
|
+
"chef_type": "role",
|
53
|
+
"default_attributes": {
|
54
|
+
"hola": "Amigos!"
|
55
|
+
},
|
56
|
+
"override_attributes": {
|
57
|
+
|
58
|
+
}
|
59
|
+
}
|
60
|
+
EOM
|
61
|
+
|
62
|
+
file "roles/cdr.json", <<EOM
|
63
|
+
{
|
64
|
+
"name": "cdr",
|
65
|
+
"description": "A role for last nodes",
|
66
|
+
"json_class": "Chef::Role",
|
67
|
+
"chef_type": "role",
|
68
|
+
"default_attributes": {
|
69
|
+
"hola": "Amigos!"
|
70
|
+
},
|
71
|
+
"override_attributes": {
|
72
|
+
|
73
|
+
}
|
74
|
+
}
|
75
|
+
EOM
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
it "uploads a single file" do
|
80
|
+
knife("role from file #{role_dir}/cons.json").should_succeed stderr: <<EOM
|
81
|
+
Updated Role cons
|
82
|
+
EOM
|
83
|
+
end
|
84
|
+
|
85
|
+
it "uploads many files" do
|
86
|
+
knife("role from file #{role_dir}/cons.json #{role_dir}/car.json #{role_dir}/cdr.json").should_succeed stderr: <<EOM
|
87
|
+
Updated Role cons
|
88
|
+
Updated Role car
|
89
|
+
Updated Role cdr
|
90
|
+
EOM
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright 2013-2016, Chef Software Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require "support/shared/integration/integration_helper"
|
18
|
+
require "support/shared/context/config"
|
19
|
+
|
20
|
+
describe "knife role list", :workstation do
|
21
|
+
include IntegrationSupport
|
22
|
+
include KnifeSupport
|
23
|
+
|
24
|
+
include_context "default config options"
|
25
|
+
|
26
|
+
when_the_chef_server "has some roles" do
|
27
|
+
before do
|
28
|
+
role "cons", {}
|
29
|
+
role "car", {}
|
30
|
+
role "cdr", {}
|
31
|
+
role "cat", {}
|
32
|
+
end
|
33
|
+
|
34
|
+
it "lists all cookbooks" do
|
35
|
+
knife("role list").should_succeed <<EOM
|
36
|
+
car
|
37
|
+
cat
|
38
|
+
cdr
|
39
|
+
cons
|
40
|
+
EOM
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright 2013-2016, Chef Software Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require "support/shared/integration/integration_helper"
|
18
|
+
require "support/shared/context/config"
|
19
|
+
|
20
|
+
describe "knife role show", :workstation do
|
21
|
+
include IntegrationSupport
|
22
|
+
include KnifeSupport
|
23
|
+
|
24
|
+
include_context "default config options"
|
25
|
+
|
26
|
+
when_the_chef_server "has some roles" do
|
27
|
+
before do
|
28
|
+
role "cons", {}
|
29
|
+
role "car", {}
|
30
|
+
role "cdr", {}
|
31
|
+
role "cat", {}
|
32
|
+
end
|
33
|
+
|
34
|
+
# rubocop:disable Style/TrailingWhitespace
|
35
|
+
it "shows a cookbook" do
|
36
|
+
knife("role show cons").should_succeed <<EOM
|
37
|
+
chef_type: role
|
38
|
+
default_attributes:
|
39
|
+
description:
|
40
|
+
env_run_lists:
|
41
|
+
json_class: Chef::Role
|
42
|
+
name: cons
|
43
|
+
override_attributes:
|
44
|
+
run_list:
|
45
|
+
EOM
|
46
|
+
end
|
47
|
+
# rubocop:enable Style/TrailingWhitespace
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
@@ -23,7 +23,7 @@ require "chef/log"
|
|
23
23
|
|
24
24
|
module KnifeSupport
|
25
25
|
DEBUG = ENV["DEBUG"]
|
26
|
-
def knife(*args)
|
26
|
+
def knife(*args, input: nil)
|
27
27
|
# Allow knife('role from file roles/blah.json') rather than requiring the
|
28
28
|
# arguments to be split like knife('role', 'from', 'file', 'roles/blah.json')
|
29
29
|
# If any argument will have actual spaces in it, the long form is required.
|
@@ -37,7 +37,7 @@ module KnifeSupport
|
|
37
37
|
Chef::Config[:concurrency] = 1
|
38
38
|
|
39
39
|
# Work on machines where we can't access /var
|
40
|
-
|
40
|
+
Dir.mktmpdir("checksums") do |checksums_cache_dir|
|
41
41
|
Chef::Config[:cache_options] = {
|
42
42
|
:path => checksums_cache_dir,
|
43
43
|
:skip_expires => true,
|
@@ -47,6 +47,13 @@ module KnifeSupport
|
|
47
47
|
# ourselves, thank you very much
|
48
48
|
stdout = StringIO.new
|
49
49
|
stderr = StringIO.new
|
50
|
+
|
51
|
+
stdin = if input
|
52
|
+
StringIO.new(input)
|
53
|
+
else
|
54
|
+
STDIN
|
55
|
+
end
|
56
|
+
|
50
57
|
old_loggers = Chef::Log.loggers
|
51
58
|
old_log_level = Chef::Log.level
|
52
59
|
begin
|
@@ -57,7 +64,7 @@ module KnifeSupport
|
|
57
64
|
instance = subcommand_class.new(args)
|
58
65
|
|
59
66
|
# Capture stdout/stderr
|
60
|
-
instance.ui = Chef::Knife::UI.new(stdout, stderr,
|
67
|
+
instance.ui = Chef::Knife::UI.new(stdout, stderr, stdin, disable_editing: true)
|
61
68
|
|
62
69
|
# Don't print stuff
|
63
70
|
Chef::Config[:verbosity] = ( DEBUG ? 2 : 0 )
|
@@ -212,6 +212,13 @@ Enable chef-client interval runs by setting `:client_fork = true` in your config
|
|
212
212
|
end
|
213
213
|
end
|
214
214
|
|
215
|
+
it "sets the repo path" do
|
216
|
+
expect(Chef::Config).to receive(:find_chef_repo_path).and_return("/var/chef")
|
217
|
+
app.reconfigure
|
218
|
+
expect(Chef::Config.has_key?(:chef_repo_path)).to be_truthy
|
219
|
+
expect(Chef::Config[:chef_repo_path]).to eq ("/var/chef")
|
220
|
+
end
|
221
|
+
|
215
222
|
it "runs chef-client in local mode" do
|
216
223
|
allow(app).to receive(:setup_application).and_return(true)
|
217
224
|
allow(app).to receive(:run_application).and_return(true)
|
@@ -120,8 +120,8 @@ describe Chef::CookbookVersion do
|
|
120
120
|
# Used to test file-specificity related file lookups
|
121
121
|
let(:node) do
|
122
122
|
Chef::Node.new.tap do |n|
|
123
|
-
n.
|
124
|
-
n.
|
123
|
+
n.normal[:platform] = "ubuntu"
|
124
|
+
n.normal[:platform_version] = "13.04"
|
125
125
|
n.name("testing")
|
126
126
|
end
|
127
127
|
end
|
@@ -203,8 +203,8 @@ describe Chef::CookbookVersion do
|
|
203
203
|
# Used to test file-specificity related file lookups
|
204
204
|
let(:node) do
|
205
205
|
Chef::Node.new.tap do |n|
|
206
|
-
n.
|
207
|
-
n.
|
206
|
+
n.normal[:platform] = "ubuntu"
|
207
|
+
n.normal[:platform_version] = "13.04"
|
208
208
|
n.name("testing")
|
209
209
|
end
|
210
210
|
end
|
@@ -171,20 +171,16 @@ describe Chef::DataCollector::Messages::Helpers do
|
|
171
171
|
end
|
172
172
|
|
173
173
|
describe '#update_metadata' do
|
174
|
-
let(:metadata) { double("metadata") }
|
175
|
-
|
176
174
|
it "updates the file" do
|
177
175
|
allow(TestMessage).to receive(:metadata_filename).and_return("fake_metadata_file.json")
|
178
|
-
allow(TestMessage).to receive(:metadata).and_return(
|
179
|
-
expect(metadata).to receive(:[]=).with("new_key", "new_value")
|
180
|
-
expect(metadata).to receive(:to_json).and_return("metadata_json")
|
176
|
+
allow(TestMessage).to receive(:metadata).and_return({ "key" => "current_value" })
|
181
177
|
expect(Chef::FileCache).to receive(:store).with(
|
182
178
|
"fake_metadata_file.json",
|
183
|
-
"
|
179
|
+
'{"key":"updated_value"}',
|
184
180
|
0644
|
185
181
|
)
|
186
182
|
|
187
|
-
TestMessage.update_metadata("
|
183
|
+
TestMessage.update_metadata("key", "updated_value")
|
188
184
|
end
|
189
185
|
end
|
190
186
|
end
|
@@ -18,6 +18,7 @@
|
|
18
18
|
#
|
19
19
|
|
20
20
|
require "spec_helper"
|
21
|
+
require "ffi_yajl"
|
21
22
|
require "chef/data_collector/messages/helpers"
|
22
23
|
|
23
24
|
describe Chef::DataCollector::Messages do
|
@@ -61,12 +62,14 @@ describe Chef::DataCollector::Messages do
|
|
61
62
|
end
|
62
63
|
|
63
64
|
describe '#run_end_message' do
|
64
|
-
let(:
|
65
|
-
let(:
|
65
|
+
let(:node) { Chef::Node.new }
|
66
|
+
let(:run_status) { Chef::RunStatus.new(node, Chef::EventDispatch::Dispatcher.new) }
|
67
|
+
let(:report1) { double("report1", report_data: { "status" => "updated" }) }
|
68
|
+
let(:report2) { double("report2", report_data: { "status" => "skipped" }) }
|
66
69
|
let(:reporter_data) do
|
67
70
|
{
|
68
71
|
run_status: run_status,
|
69
|
-
|
72
|
+
resources: [report1, report2],
|
70
73
|
}
|
71
74
|
end
|
72
75
|
|
@@ -75,6 +78,20 @@ describe Chef::DataCollector::Messages do
|
|
75
78
|
allow(run_status).to receive(:end_time).and_return(Time.now)
|
76
79
|
end
|
77
80
|
|
81
|
+
it "includes a valid node object in the payload" do
|
82
|
+
message = Chef::DataCollector::Messages.run_end_message(reporter_data)
|
83
|
+
expect(message["node"]).to be_an_instance_of(Chef::Node)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "returns a sane JSON representation of the node object" do
|
87
|
+
node.chef_environment = "my_test_environment"
|
88
|
+
node.run_list.add("recipe[my_test_cookbook::default]")
|
89
|
+
message = FFI_Yajl::Parser.parse(Chef::DataCollector::Messages.run_end_message(reporter_data).to_json)
|
90
|
+
|
91
|
+
expect(message["node"]["chef_environment"]).to eq("my_test_environment")
|
92
|
+
expect(message["node"]["run_list"]).to eq(["recipe[my_test_cookbook::default]"])
|
93
|
+
end
|
94
|
+
|
78
95
|
context "when the run was successful" do
|
79
96
|
let(:required_fields) do
|
80
97
|
%w{
|
@@ -85,6 +102,7 @@ describe Chef::DataCollector::Messages do
|
|
85
102
|
expanded_run_list
|
86
103
|
message_type
|
87
104
|
message_version
|
105
|
+
node
|
88
106
|
node_name
|
89
107
|
organization_name
|
90
108
|
resources
|
@@ -116,6 +134,12 @@ describe Chef::DataCollector::Messages do
|
|
116
134
|
end
|
117
135
|
expect(extra_fields).to eq([])
|
118
136
|
end
|
137
|
+
|
138
|
+
it "only includes updated resources in its count" do
|
139
|
+
message = Chef::DataCollector::Messages.run_end_message(reporter_data)
|
140
|
+
expect(message["total_resource_count"]).to eq(2)
|
141
|
+
expect(message["updated_resource_count"]).to eq(1)
|
142
|
+
end
|
119
143
|
end
|
120
144
|
|
121
145
|
context "when the run was not successful" do
|
@@ -129,6 +153,7 @@ describe Chef::DataCollector::Messages do
|
|
129
153
|
expanded_run_list
|
130
154
|
message_type
|
131
155
|
message_version
|
156
|
+
node
|
132
157
|
node_name
|
133
158
|
organization_name
|
134
159
|
resources
|
@@ -162,46 +187,4 @@ describe Chef::DataCollector::Messages do
|
|
162
187
|
end
|
163
188
|
end
|
164
189
|
end
|
165
|
-
|
166
|
-
describe '#node_update_message' do
|
167
|
-
let(:run_status) { Chef::RunStatus.new(Chef::Node.new, Chef::EventDispatch::Dispatcher.new) }
|
168
|
-
|
169
|
-
let(:required_fields) do
|
170
|
-
%w{
|
171
|
-
entity_name
|
172
|
-
entity_type
|
173
|
-
entity_uuid
|
174
|
-
id
|
175
|
-
message_type
|
176
|
-
message_version
|
177
|
-
organization_name
|
178
|
-
recorded_at
|
179
|
-
remote_hostname
|
180
|
-
requestor_name
|
181
|
-
requestor_type
|
182
|
-
run_id
|
183
|
-
service_hostname
|
184
|
-
source
|
185
|
-
task
|
186
|
-
user_agent
|
187
|
-
}
|
188
|
-
end
|
189
|
-
let(:optional_fields) { %w{data} }
|
190
|
-
|
191
|
-
it "is not missing any required fields" do
|
192
|
-
missing_fields = required_fields.select do |key|
|
193
|
-
!Chef::DataCollector::Messages.node_update_message(run_status).key?(key)
|
194
|
-
end
|
195
|
-
|
196
|
-
expect(missing_fields).to eq([])
|
197
|
-
end
|
198
|
-
|
199
|
-
it "does not have any extra fields" do
|
200
|
-
extra_fields = Chef::DataCollector::Messages.node_update_message(run_status).keys.select do |key|
|
201
|
-
!required_fields.include?(key) && !optional_fields.include?(key)
|
202
|
-
end
|
203
|
-
|
204
|
-
expect(extra_fields).to eq([])
|
205
|
-
end
|
206
|
-
end
|
207
190
|
end
|