chef-provisioning-opennebula 0.4.8 → 0.4.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +2 -3
- data/lib/chef/provisioning/opennebula_driver/driver.rb +7 -1
- data/lib/chef/provisioning/opennebula_driver/version.rb +1 -1
- data/spec/config_sample.rb +19 -18
- data/spec/integration/one_driver_spec.rb +84 -0
- data/spec/integration/one_flow_spec.rb +340 -0
- data/spec/recipes/OneDriver/{instantiate_one_template_vnet.rb → allocate_one_vm.rb} +6 -4
- data/spec/recipes/OneDriver/attach_one_image.rb +2 -2
- data/spec/recipes/OneDriver/converge_one_vm.rb +17 -0
- data/spec/recipes/OneDriver/create_one_image.rb +1 -1
- data/spec/recipes/OneDriver/create_one_template.rb +18 -0
- data/spec/recipes/OneDriver/create_one_vnet.rb +2 -2
- data/spec/recipes/OneDriver/{delete/OpenNebula-test-vm.rb → delete_one_img.rb} +1 -1
- data/spec/recipes/OneDriver/{delete/OpenNebula-test-img.rb → delete_one_snap-img.rb} +1 -1
- data/spec/recipes/{OneFlowService/delete/test_role_action.rb → OneDriver/delete_one_template.rb} +1 -1
- data/spec/recipes/OneDriver/{delete/OpenNebula-test-vm-vnet.rb → delete_one_vm.rb} +1 -1
- data/spec/recipes/OneDriver/{delete/OpenNebula-test-vnet.rb → delete_one_vnet.rb} +1 -1
- data/spec/recipes/OneDriver/ready_one_vm.rb +17 -0
- data/spec/recipes/OneDriver/snapshot_one_image.rb +3 -3
- data/spec/recipes/OneDriver/update_one_template.rb +20 -0
- data/spec/recipes/{OneFlowTemplate/create_branch_from_one_id.rb → OneFlow/branch_json_template_by_id.rb} +6 -6
- data/spec/recipes/OneFlow/branch_json_template_by_name.rb +42 -0
- data/spec/recipes/{OneFlowTemplate/chmod_simple_from_hash.rb → OneFlow/chmod_file_template.rb} +1 -1
- data/spec/recipes/{OneFlowService/chmod_simple_by_name_2.rb → OneFlow/chmod_json_service_by_id.rb} +2 -2
- data/spec/recipes/{OneFlowService/instance_simple_by_name.rb → OneFlow/chmod_json_service_by_name.rb} +2 -2
- data/spec/recipes/{OneDriver/delete/OpenNebula-test-snap-img.rb → OneFlow/chmod_json_template.rb} +2 -2
- data/spec/recipes/OneFlow/create_file_template.rb +18 -0
- data/spec/recipes/{OneFlowTemplate/create_tpl_opts_from_hash.rb → OneFlow/create_file_template_with_opts.rb} +8 -11
- data/spec/recipes/OneFlow/create_http_template.rb +17 -0
- data/spec/recipes/{OneFlowService/instance_simple_by_id.rb → OneFlow/create_json_service_by_id.rb} +4 -2
- data/spec/recipes/{OneFlowService/chmod_simple_by_name.rb → OneFlow/create_json_service_by_name.rb} +2 -2
- data/spec/recipes/{OneFlowService/instance_tpl_opts.rb → OneFlow/create_json_service_with_opts.rb} +8 -6
- data/spec/recipes/{OneFlowTemplate/create_simple_from_hash.rb → OneFlow/create_json_template.rb} +4 -3
- data/spec/recipes/{OneFlowTemplate/create_tpl_opts_from_file.rb → OneFlow/create_json_template_with_opts.rb} +15 -7
- data/spec/recipes/{OneFlowService/instance_role_action.rb → OneFlow/create_role_action_service.rb} +8 -8
- data/spec/recipes/OneFlow/create_role_action_template.rb +89 -0
- data/spec/recipes/OneFlow/delete_branched_template_by_id.rb +17 -0
- data/spec/recipes/OneFlow/delete_branched_template_by_name.rb +17 -0
- data/spec/recipes/{OneDriver/delete/OpenNebula-test-tpl-strings.rb → OneFlow/delete_file_template.rb} +1 -1
- data/spec/recipes/OneFlow/delete_file_template_with_opts.rb +17 -0
- data/spec/recipes/{OneDriver/delete/OpenNebula-test-tpl-ints.rb → OneFlow/delete_http_template.rb} +1 -1
- data/spec/recipes/{OneDriver/delete/OpenNebula-test-tpl-mix.rb → OneFlow/delete_json_service_by_id.rb} +1 -1
- data/spec/recipes/OneFlow/delete_json_service_by_name.rb +17 -0
- data/spec/recipes/OneFlow/delete_json_service_with_opts.rb +17 -0
- data/spec/recipes/OneFlow/delete_json_template.rb +17 -0
- data/spec/recipes/OneFlow/delete_json_template_with_opts.rb +17 -0
- data/spec/recipes/OneFlow/delete_role_action_service.rb +17 -0
- data/spec/recipes/OneFlow/delete_role_action_template.rb +17 -0
- data/spec/recipes/{OneFlowService/action/boot.rb → OneFlow/service_action_boot.rb} +4 -3
- data/spec/recipes/OneFlow/service_action_delete.rb +18 -0
- data/spec/recipes/{OneFlowService/action/delete_recreate.rb → OneFlow/service_action_delete_recreate.rb} +2 -2
- data/spec/recipes/{OneFlowService/action/hold.rb → OneFlow/service_action_hold.rb} +4 -3
- data/spec/recipes/{OneFlowService/action/poweroff.rb → OneFlow/service_action_poweroff.rb} +2 -2
- data/spec/recipes/{OneFlowService/action/poweroff_hard.rb → OneFlow/service_action_poweroff_hard.rb} +2 -2
- data/spec/recipes/{OneFlowService/action/reboot.rb → OneFlow/service_action_reboot.rb} +2 -2
- data/spec/recipes/{OneFlowService/action/reboot_hard.rb → OneFlow/service_action_reboot_hard.rb} +2 -2
- data/spec/recipes/{OneFlowService/action/release.rb → OneFlow/service_action_release.rb} +4 -3
- data/spec/recipes/OneFlow/service_action_resume_poweroff.rb +18 -0
- data/spec/recipes/OneFlow/service_action_resume_poweroff_hard.rb +18 -0
- data/spec/recipes/{OneFlowService/action/resume.rb → OneFlow/service_action_resume_stop.rb} +2 -2
- data/spec/recipes/OneFlow/service_action_resume_suspend.rb +18 -0
- data/spec/recipes/OneFlow/service_action_resume_undeploy.rb +18 -0
- data/spec/recipes/OneFlow/service_action_resume_undeploy_hard.rb +18 -0
- data/spec/recipes/{OneFlowService/action/scale.rb → OneFlow/service_action_scale.rb} +2 -2
- data/spec/recipes/{OneFlowService/action/shutdown.rb → OneFlow/service_action_shutdown.rb} +2 -2
- data/spec/recipes/{OneFlowService/action/shutdown_hard.rb → OneFlow/service_action_shutdown_hard.rb} +2 -2
- data/spec/recipes/{OneFlowService/action/snapshot_create.rb → OneFlow/service_action_snapshot_create.rb} +2 -2
- data/spec/recipes/{OneFlowService/action/stop.rb → OneFlow/service_action_stop.rb} +2 -2
- data/spec/recipes/{OneFlowService/action/suspend.rb → OneFlow/service_action_suspend.rb} +2 -2
- data/spec/recipes/{OneFlowService/action/undeploy.rb → OneFlow/service_action_undeploy.rb} +2 -2
- data/spec/recipes/{OneFlowService/action/undeploy_hard.rb → OneFlow/service_action_undeploy_hard.rb} +2 -2
- data/spec/recipes/{OneFlowService/action/shutdown_service.rb → OneFlow/shutdown_role_action_service.rb} +1 -1
- data/spec/recipes/{OneFlowTemplate/update_simple_from_hash.rb → OneFlow/update_json_template.rb} +17 -14
- data/spec/recipes/common.rb +0 -2
- data/spec/spec_helper.rb +97 -42
- metadata +86 -89
- data/spec/integration/test_all_integration_spec.rb +0 -21
- data/spec/integration/test_one_driver.rb +0 -177
- data/spec/integration/test_one_flow.rb +0 -546
- data/spec/recipes/OneDriver/allocate_change_profile.rb +0 -23
- data/spec/recipes/OneDriver/create_one_template_ints.rb +0 -38
- data/spec/recipes/OneDriver/create_one_template_mix.rb +0 -51
- data/spec/recipes/OneDriver/create_one_template_strings.rb +0 -34
- data/spec/recipes/OneDriver/instantiate_one_template.rb +0 -21
- data/spec/recipes/OneFlowService/action/delete.rb +0 -18
- data/spec/recipes/OneFlowService/chmod_tpl_opts.rb +0 -31
- data/spec/recipes/OneFlowService/delete/test_instance_template_options.rb +0 -17
- data/spec/recipes/OneFlowService/delete/test_simple_instance.rb +0 -17
- data/spec/recipes/OneFlowService/delete/test_simple_instance_by_id.rb +0 -17
- data/spec/recipes/OneFlowTemplate/chmod_update_simple_from_file.rb +0 -19
- data/spec/recipes/OneFlowTemplate/create_branch_from_one_name.rb +0 -20
- data/spec/recipes/OneFlowTemplate/create_role_action_instance.rb +0 -99
- data/spec/recipes/OneFlowTemplate/create_simple_from_file.rb +0 -18
- data/spec/recipes/OneFlowTemplate/create_simple_from_web.rb +0 -17
- data/spec/recipes/OneFlowTemplate/create_simple_instance_tpl.rb +0 -22
- data/spec/recipes/OneFlowTemplate/delete/branch_from_one_id.rb +0 -17
- data/spec/recipes/OneFlowTemplate/delete/branch_from_one_name.rb +0 -17
- data/spec/recipes/OneFlowTemplate/delete/role_action_instance.rb +0 -17
- data/spec/recipes/OneFlowTemplate/delete/simple_from_file.rb +0 -17
- data/spec/recipes/OneFlowTemplate/delete/simple_from_hash.rb +0 -17
- data/spec/recipes/OneFlowTemplate/delete/simple_from_web.rb +0 -17
- data/spec/recipes/OneFlowTemplate/delete/simple_instance_tpl.rb +0 -17
- data/spec/recipes/OneFlowTemplate/delete/tpl_opts_from_file.rb +0 -17
- data/spec/recipes/OneFlowTemplate/delete/tpl_opts_from_hash.rb +0 -17
- data/spec/support/opennebula_support.rb +0 -129
@@ -1,17 +0,0 @@
|
|
1
|
-
# Copyright 2016, BlackBerry Limited
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
one_flow_template 'test_simple_from_web' do
|
16
|
-
template 'https://dongyuzheng.com/static/misc/one_rspec_test.json'
|
17
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# Copyright 2016, BlackBerry Limited
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
one_flow_template 'test_simple_instance_tpl' do
|
16
|
-
template :roles => [
|
17
|
-
{
|
18
|
-
:name => 'gary_ubuntu',
|
19
|
-
:vm_template => 'OpenNebula-test-tpl-strings'
|
20
|
-
}
|
21
|
-
]
|
22
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# Copyright 2016, BlackBerry Limited
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
one_flow_template 'test_branch_from_one_id' do
|
16
|
-
action :delete
|
17
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# Copyright 2016, BlackBerry Limited
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
one_flow_template 'test_branch_from_one_name' do
|
16
|
-
action :delete
|
17
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# Copyright 2016, BlackBerry Limited
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
one_flow_template 'test_role_action_instance' do
|
16
|
-
action :delete
|
17
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# Copyright 2016, BlackBerry Limited
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
one_flow_template 'test_simple_from_file' do
|
16
|
-
action :delete
|
17
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# Copyright 2016, BlackBerry Limited
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
one_flow_template 'test_simple_from_hash' do
|
16
|
-
action :delete
|
17
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# Copyright 2016, BlackBerry Limited
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
one_flow_template 'test_simple_from_web' do
|
16
|
-
action :delete
|
17
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# Copyright 2016, BlackBerry Limited
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
one_flow_template 'test_simple_instance_tpl' do
|
16
|
-
action :delete
|
17
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# Copyright 2016, BlackBerry Limited
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
one_flow_template 'test_tpl_opts_from_file' do
|
16
|
-
action :delete
|
17
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# Copyright 2016, BlackBerry Limited
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
one_flow_template 'test_tpl_opts_from_hash' do
|
16
|
-
action :delete
|
17
|
-
end
|
@@ -1,129 +0,0 @@
|
|
1
|
-
# Copyright 2016, BlackBerry Limited
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
require 'cheffish/rspec/chef_run_support'
|
16
|
-
require 'cheffish/rspec/matchers'
|
17
|
-
require 'chef/provisioning/opennebula_driver'
|
18
|
-
require 'fileutils'
|
19
|
-
|
20
|
-
def chef_run(recipe, append_path = true)
|
21
|
-
recipe_array = recipe.is_a?(Array) ? recipe : [recipe]
|
22
|
-
recipe_array.map! { |r| './spec/recipes/' + r } if append_path
|
23
|
-
recipe_array = ['./spec/recipes/common.rb'] + recipe_array
|
24
|
-
FileUtils.rm_rf('/tmp/chef-provisioning-opennebula-rspec-recipe.rb')
|
25
|
-
File.open('/tmp/chef-provisioning-opennebula-rspec-recipe.rb', 'a') do |file|
|
26
|
-
file.puts("require '#{File.dirname(__FILE__)}/../config.rb'")
|
27
|
-
recipe_array.each do |recipe_file|
|
28
|
-
content = File.read(recipe_file)
|
29
|
-
file.puts('')
|
30
|
-
file.puts(content)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
chef_client = Mixlib::ShellOut.new(
|
34
|
-
'chef-client -z /tmp/chef-provisioning-opennebula-rspec-recipe.rb --force-formatter',
|
35
|
-
shellout_options(:timeout => 900)
|
36
|
-
)
|
37
|
-
chef_client.run_command
|
38
|
-
chef_client.stdout
|
39
|
-
end
|
40
|
-
|
41
|
-
def shellout_options(options = {})
|
42
|
-
{ :live_stream => STDOUT }.merge(options)
|
43
|
-
end
|
44
|
-
|
45
|
-
def format_error(msg)
|
46
|
-
"================================================================================\n#{msg}\n================================================================================\n "
|
47
|
-
end
|
48
|
-
|
49
|
-
def get_unique_file(path, basename, rest)
|
50
|
-
p = path.chomp('/')
|
51
|
-
fn = "#{p}/#{basename}#{rest}"
|
52
|
-
return fn unless File.exist?(fn)
|
53
|
-
n = 1
|
54
|
-
n += 1 while File.exist?("#{p}/#{basename}__#{n}#{rest}")
|
55
|
-
"#{p}/#{basename}__#{n}#{rest}"
|
56
|
-
end
|
57
|
-
|
58
|
-
def get_error(stdout, expected, fail_if)
|
59
|
-
stacktrace = stdout.match(/FATAL: Stacktrace dumped to (.*?chef-stacktrace\.out)/)
|
60
|
-
stacktrace = stacktrace ? stacktrace[1] : nil
|
61
|
-
err = stacktrace ? "Chef run did not report 'Chef Client finished'." : nil
|
62
|
-
|
63
|
-
case fail_if
|
64
|
-
when Regexp
|
65
|
-
return "stdout matched the following when it should not have:\n#{fail_if}", stacktrace if stdout =~ fail_if
|
66
|
-
when String
|
67
|
-
return "stdout included the following when it should not have:\n#{fail_if}", stacktrace if stdout.include?(fail_if)
|
68
|
-
end unless fail_if.nil?
|
69
|
-
|
70
|
-
# Each chef run can only fail due to one reason, so if it was an expected error, we can simply return nil
|
71
|
-
[' RuntimeError: ', ' NoMethodError: ', ' TypeError: ', ' ERROR: ', ' FATAL: '].each do |e|
|
72
|
-
the_error = (stdout.split(e).last).split("\n")[0...-1].join("\n")
|
73
|
-
case expected
|
74
|
-
when Regexp
|
75
|
-
if e + the_error =~ expected
|
76
|
-
return nil, nil
|
77
|
-
else
|
78
|
-
return "#{e.strip}\n#{the_error}", stacktrace
|
79
|
-
end
|
80
|
-
when String
|
81
|
-
if (e + the_error).include?(expected)
|
82
|
-
return nil, nil
|
83
|
-
else
|
84
|
-
return "#{e.strip}\n#{the_error}", stacktrace
|
85
|
-
end
|
86
|
-
else
|
87
|
-
return "#{e.strip}\n#{the_error}", stacktrace
|
88
|
-
end if stdout.include?(e)
|
89
|
-
end if err
|
90
|
-
|
91
|
-
return err, stacktrace if expected.nil?
|
92
|
-
|
93
|
-
case expected
|
94
|
-
when Regexp
|
95
|
-
return "stdout did not match the following when it should have:\n#{expected}", stacktrace unless stdout =~ expected
|
96
|
-
when String
|
97
|
-
return "stdout did not include the following when it should have:\n#{expected}", stacktrace unless stdout.include?(expected)
|
98
|
-
end
|
99
|
-
|
100
|
-
[err, stacktrace]
|
101
|
-
end
|
102
|
-
|
103
|
-
# data = {
|
104
|
-
# :recipe => 'recipe to test, must be given',
|
105
|
-
# :expected => 'fail if not match, can be errors',
|
106
|
-
# :fail_if => 'fail if match'
|
107
|
-
# }
|
108
|
-
RSpec::Matchers.define :converge_test_recipe do |data = {}|
|
109
|
-
fail 'All tests require a :recipe.' unless data[:recipe]
|
110
|
-
match do
|
111
|
-
stdout = chef_run(data[:recipe])
|
112
|
-
|
113
|
-
dir = RSpec.configuration.log_dir + '/' + File.dirname(data[:recipe])
|
114
|
-
FileUtils.mkdir_p(dir)
|
115
|
-
|
116
|
-
log_basename = File.basename(data[:recipe], '.*')
|
117
|
-
File.open(get_unique_file("./#{dir}", log_basename, '.stdout.log'), 'w+') { |file| file.write(stdout) }
|
118
|
-
|
119
|
-
@error_message, stacktrace = get_error(stdout, data[:expected], data[:fail_if])
|
120
|
-
@error_message = format_error(@error_message) unless @error_message.nil?
|
121
|
-
|
122
|
-
FileUtils.cp(stacktrace, get_unique_file("./#{dir}", log_basename, '.stacktrace.out')) if stacktrace
|
123
|
-
|
124
|
-
@error_message.nil?
|
125
|
-
end
|
126
|
-
failure_message do
|
127
|
-
@error_message
|
128
|
-
end
|
129
|
-
end
|