chef-provisioning-opennebula 0.4.4 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +273 -4
  3. data/lib/chef/provider/one_flow_service.rb +346 -0
  4. data/lib/chef/provider/one_flow_template.rb +175 -0
  5. data/lib/chef/provider/one_image.rb +6 -6
  6. data/lib/chef/provider/one_template.rb +4 -6
  7. data/lib/chef/provider/one_user.rb +11 -14
  8. data/lib/chef/provider/one_vnet.rb +6 -9
  9. data/lib/chef/provider/one_vnet_lease.rb +3 -3
  10. data/lib/chef/provisioning/driver_init/opennebula.rb +1 -1
  11. data/lib/chef/provisioning/driver_init/server_version.rb +28 -0
  12. data/lib/chef/provisioning/opennebula_driver.rb +1 -1
  13. data/lib/chef/provisioning/opennebula_driver/credentials.rb +2 -2
  14. data/lib/chef/provisioning/opennebula_driver/driver.rb +132 -34
  15. data/lib/chef/provisioning/opennebula_driver/flow_lib.rb +491 -0
  16. data/lib/chef/provisioning/opennebula_driver/one_lib.rb +39 -49
  17. data/lib/chef/provisioning/opennebula_driver/resources.rb +2 -2
  18. data/lib/chef/provisioning/opennebula_driver/version.rb +2 -2
  19. data/lib/chef/resource/one_flow_service.rb +61 -0
  20. data/lib/chef/resource/one_flow_template.rb +53 -0
  21. data/lib/chef/resource/one_image.rb +2 -2
  22. data/lib/chef/resource/one_template.rb +1 -1
  23. data/lib/chef/resource/one_user.rb +1 -1
  24. data/lib/chef/resource/one_vnet.rb +2 -2
  25. data/lib/chef/resource/one_vnet_lease.rb +1 -1
  26. data/spec/config_sample.rb +12 -3
  27. data/spec/integration/test_all_integration_spec.rb +6 -272
  28. data/spec/integration/test_one_driver.rb +177 -0
  29. data/spec/integration/test_one_flow.rb +546 -0
  30. data/spec/recipes/OneDriver/{instantiate_one_template_spec.rb → allocate_change_profile.rb} +5 -7
  31. data/spec/recipes/OneDriver/{converge_back_two_vm_spec.rb → attach_one_image.rb} +4 -5
  32. data/spec/recipes/OneDriver/create_one_image.rb +20 -0
  33. data/spec/recipes/OneDriver/{create_one_template_int_spec.rb → create_one_template_ints.rb} +21 -4
  34. data/spec/recipes/OneDriver/create_one_template_mix.rb +51 -0
  35. data/spec/recipes/OneDriver/{create_one_image_spec.rb → create_one_template_strings.rb} +18 -7
  36. data/spec/recipes/OneDriver/{converge_back_one_vm_spec.rb → create_one_vnet.rb} +5 -5
  37. data/spec/recipes/OneDriver/delete/{OpenNebula-tpl-1-vm.rb → OpenNebula-test-img.rb} +2 -4
  38. data/spec/recipes/OneDriver/delete/{OpenNebula-back-1-vm.rb → OpenNebula-test-snap-img.rb} +2 -4
  39. data/spec/recipes/OneDriver/delete/OpenNebula-test-tpl-ints.rb +2 -4
  40. data/spec/recipes/OneDriver/delete/{OpenNebula-test-tpl.rb → OpenNebula-test-tpl-mix.rb} +2 -4
  41. data/spec/recipes/OneDriver/delete/OpenNebula-test-tpl-strings.rb +17 -0
  42. data/spec/recipes/OneDriver/delete/{OpenNebula-back-2-vm.rb → OpenNebula-test-vm-vnet.rb} +2 -4
  43. data/spec/recipes/OneDriver/delete/{OpenNebula-bootstrap-vm.rb → OpenNebula-test-vm.rb} +2 -4
  44. data/spec/recipes/OneDriver/delete/OpenNebula-test-vnet.rb +17 -0
  45. data/spec/recipes/OneDriver/{attach_back_one_vm_spec.rb → instantiate_one_template.rb} +7 -6
  46. data/spec/recipes/OneDriver/{converge_bootstrap_vm_spec.rb → instantiate_one_template_vnet.rb} +10 -8
  47. data/spec/recipes/OneDriver/snapshot_one_image.rb +19 -0
  48. data/spec/recipes/OneFlowService/action/boot.rb +19 -0
  49. data/spec/recipes/OneFlowService/action/delete.rb +18 -0
  50. data/spec/recipes/OneFlowService/action/delete_recreate.rb +18 -0
  51. data/spec/recipes/OneFlowService/action/hold.rb +19 -0
  52. data/spec/recipes/OneFlowService/action/poweroff.rb +18 -0
  53. data/spec/recipes/OneFlowService/action/poweroff_hard.rb +18 -0
  54. data/spec/recipes/OneFlowService/action/reboot.rb +18 -0
  55. data/spec/recipes/OneFlowService/action/reboot_hard.rb +18 -0
  56. data/spec/recipes/OneFlowService/action/release.rb +19 -0
  57. data/spec/recipes/OneFlowService/action/resume.rb +18 -0
  58. data/spec/recipes/OneFlowService/action/scale.rb +19 -0
  59. data/spec/recipes/OneFlowService/action/shutdown.rb +18 -0
  60. data/spec/recipes/OneFlowService/action/shutdown_hard.rb +18 -0
  61. data/spec/recipes/OneFlowService/action/shutdown_service.rb +17 -0
  62. data/spec/recipes/OneFlowService/action/snapshot_create.rb +18 -0
  63. data/spec/recipes/OneFlowService/action/stop.rb +18 -0
  64. data/spec/recipes/OneFlowService/action/suspend.rb +18 -0
  65. data/spec/recipes/OneFlowService/action/undeploy.rb +18 -0
  66. data/spec/recipes/OneFlowService/action/undeploy_hard.rb +18 -0
  67. data/spec/recipes/OneFlowService/chmod_simple_by_name.rb +19 -0
  68. data/spec/recipes/OneFlowService/chmod_simple_by_name_2.rb +18 -0
  69. data/spec/recipes/OneFlowService/chmod_tpl_opts.rb +31 -0
  70. data/spec/recipes/OneFlowService/delete/test_instance_template_options.rb +17 -0
  71. data/spec/recipes/OneFlowService/delete/test_role_action.rb +17 -0
  72. data/spec/recipes/OneFlowService/delete/test_simple_instance.rb +17 -0
  73. data/spec/recipes/OneFlowService/delete/test_simple_instance_by_id.rb +17 -0
  74. data/spec/recipes/{OneDriver/create_bootstrap_vm_spec.rb → OneFlowService/instance_role_action.rb} +19 -11
  75. data/spec/recipes/OneFlowService/instance_simple_by_id.rb +20 -0
  76. data/spec/recipes/OneFlowService/instance_simple_by_name.rb +18 -0
  77. data/spec/recipes/OneFlowService/instance_tpl_opts.rb +30 -0
  78. data/spec/recipes/OneFlowTemplate/chmod_simple_from_hash.rb +17 -0
  79. data/spec/recipes/OneFlowTemplate/chmod_update_simple_from_file.rb +19 -0
  80. data/spec/recipes/OneFlowTemplate/create_branch_from_one_id.rb +43 -0
  81. data/spec/recipes/OneFlowTemplate/create_branch_from_one_name.rb +20 -0
  82. data/spec/recipes/OneFlowTemplate/create_role_action_instance.rb +99 -0
  83. data/spec/recipes/OneFlowTemplate/create_simple_from_file.rb +18 -0
  84. data/spec/recipes/{OneDriver/attach_back_two_vm_spec.rb → OneFlowTemplate/create_simple_from_hash.rb} +8 -6
  85. data/spec/recipes/OneFlowTemplate/create_simple_from_web.rb +17 -0
  86. data/spec/recipes/{OneDriver/attach_one_image_spec.rb → OneFlowTemplate/create_simple_instance_tpl.rb} +8 -6
  87. data/spec/recipes/OneFlowTemplate/create_tpl_opts_from_file.rb +30 -0
  88. data/spec/recipes/OneFlowTemplate/create_tpl_opts_from_hash.rb +35 -0
  89. data/spec/recipes/OneFlowTemplate/delete/branch_from_one_id.rb +17 -0
  90. data/spec/recipes/OneFlowTemplate/delete/branch_from_one_name.rb +17 -0
  91. data/spec/recipes/OneFlowTemplate/delete/role_action_instance.rb +17 -0
  92. data/spec/recipes/OneFlowTemplate/delete/simple_from_file.rb +17 -0
  93. data/spec/recipes/OneFlowTemplate/delete/simple_from_hash.rb +17 -0
  94. data/spec/recipes/OneFlowTemplate/delete/simple_from_web.rb +17 -0
  95. data/spec/recipes/OneFlowTemplate/delete/simple_instance_tpl.rb +17 -0
  96. data/spec/recipes/OneFlowTemplate/delete/tpl_opts_from_file.rb +17 -0
  97. data/spec/recipes/OneFlowTemplate/delete/tpl_opts_from_hash.rb +17 -0
  98. data/spec/recipes/OneFlowTemplate/update_simple_from_hash.rb +57 -0
  99. data/spec/recipes/{driver_options_spec.rb → common.rb} +9 -3
  100. data/spec/spec_helper.rb +22 -17
  101. data/spec/support/opennebula_support.rb +75 -45
  102. metadata +114 -27
  103. data/spec/recipes/OneDriver/create_back_one_vm_spec.rb +0 -20
  104. data/spec/recipes/OneDriver/create_back_two_vm_spec.rb +0 -20
  105. data/spec/recipes/OneDriver/create_one_template_spec.rb +0 -21
  106. data/spec/recipes/OneDriver/delete/OpenNebula-bootstrap-img.rb +0 -19
  107. data/spec/recipes/OneDriver/delete/OpenNebula-snap-1-img.rb +0 -19
  108. data/spec/recipes/OneDriver/delete/OpenNebula-snap-2-img.rb +0 -19
  109. data/spec/recipes/OneDriver/snapshot_one_image_spec.rb +0 -21
  110. data/spec/recipes/OneDriver/snapshot_two_image_spec.rb +0 -21
@@ -0,0 +1,30 @@
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 'gary' do
16
+ template 'file:///tmp/one_rspec_test.json'
17
+ template_options :name => 'test_tpl_opts_from_file',
18
+ :deployment => nil,
19
+ :roles => [
20
+ {
21
+ :name => 'gary_ubuntu',
22
+ :delete_role => true
23
+ },
24
+ {
25
+ :name => 'gary_ubuntu_new',
26
+ :vm_template => 'OpenNebula-test-tpl-strings'
27
+ }
28
+ ]
29
+ mode '640'
30
+ end
@@ -0,0 +1,35 @@
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 'gary' do
16
+ template :name => 'test_tpl_opts_from_hash',
17
+ :roles => [
18
+ {
19
+ :name => 'gary_ubuntu',
20
+ :vm_template => 'OpenNebula-test-tpl-strings'
21
+ }
22
+ ]
23
+ template_options :deployment => 'none',
24
+ :roles => [
25
+ {
26
+ :name => 'gary_ubuntu',
27
+ :delete_role => true
28
+ },
29
+ {
30
+ :name => 'gary_ubuntu_new',
31
+ :vm_template => 'OpenNebula-test-tpl-strings'
32
+ }
33
+ ]
34
+ action :create
35
+ end
@@ -0,0 +1,17 @@
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
@@ -0,0 +1,17 @@
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
@@ -0,0 +1,17 @@
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
@@ -0,0 +1,17 @@
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
@@ -0,0 +1,17 @@
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
@@ -0,0 +1,17 @@
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
@@ -0,0 +1,17 @@
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
@@ -0,0 +1,17 @@
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
@@ -0,0 +1,17 @@
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
@@ -0,0 +1,57 @@
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
+ template :deployment => 'none',
17
+ :roles => [
18
+ {
19
+ :name => 'gary_ubuntu',
20
+ :min_vms => 1,
21
+ :max_vms => 5,
22
+ :scheduled_policies => [
23
+ {
24
+ :type => "PERCENTAGE_CHANGE",
25
+ :recurrence => "0 1 1-10 * *",
26
+ :adjust => 3,
27
+ :min_adjust_step => 14
28
+ }
29
+ ]
30
+ },
31
+ {
32
+ :name => 'gary_ubuntu_2',
33
+ :vm_template => 'OpenNebula-test-tpl-strings',
34
+ :cooldown => 123,
35
+ :min_vms => 1,
36
+ :max_vms => 5,
37
+ :elasticity_policies => [
38
+ {
39
+ :type => "CHANGE",
40
+ :cooldown => 17,
41
+ :period => 15,
42
+ :adjust => 2,
43
+ :period_number => 2,
44
+ :expression => "ATT == 20"
45
+ },
46
+ {
47
+ :type => "CARDINALITY",
48
+ :cooldown => 14,
49
+ :period => 13,
50
+ :adjust => 3,
51
+ :period_number => 1,
52
+ :expression => "ATT > 20"
53
+ }
54
+ ]
55
+ }
56
+ ]
57
+ end
@@ -1,4 +1,4 @@
1
- # Copyright 2016, BlackBerry, Inc.
1
+ # Copyright 2016, BlackBerry Limited
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -14,14 +14,20 @@
14
14
 
15
15
  require 'chef/provisioning/opennebula_driver'
16
16
  require 'fileutils'
17
- require "#{File.dirname(__FILE__)}/../config.rb"
18
17
 
19
18
  FileUtils.mkdir_p(CHEF_REPO_PATH.chomp('/'))
20
19
  with_chef_local_server :chef_repo_path => CHEF_REPO_PATH.chomp('/')
21
- with_driver((ONE_XMLRPC[0, 11] == 'opennebula:' ? ONE_XMLRPC : 'opennebula:' + ONE_XMLRPC).chomp('/'))
20
+ with_driver DRIVER_URL
21
+ with_flow_url ONE_FLOW_URL.chomp('/') unless ONE_FLOW_URL.nil?
22
22
 
23
23
  with_machine_options MACHINE_OPTIONS.merge(
24
24
  :bootstrap_options => {
25
25
  :template => VM_TEMPLATE
26
26
  }
27
27
  )
28
+
29
+ one_auth = Chef::Provisioning::OpenNebulaDriver.get_onelib(
30
+ :driver_url => DRIVER_URL
31
+ ).client.one_auth
32
+
33
+ username = one_auth.split(':').first
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright 2016, BlackBerry, Inc.
1
+ # Copyright 2016, BlackBerry Limited
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -19,31 +19,35 @@ require 'chef/provisioning'
19
19
  require 'chef/provisioning/opennebula_driver'
20
20
  require 'chef/run_context'
21
21
  require 'cheffish/rspec/matchers'
22
- require 'opennebula'
23
22
  require 'support/opennebula_support'
24
23
  require 'fileutils'
24
+ require_relative 'config.rb'
25
25
 
26
- def test_helper(context, recipe, expected, error = nil)
26
+ def idempotency_helper(context, recipe, expected = nil)
27
27
  context context do
28
- it { is_expected.to converge_test_recipe(recipe, expected, error) }
28
+ it { is_expected.to converge_test_recipe(:recipe => recipe, :expected => expected, :fail_if => '(up to date)') }
29
29
  end
30
30
  context "[SKIP] #{context}" do
31
- it { is_expected.to converge_test_recipe(recipe, :idempotent, error) }
31
+ it { is_expected.to converge_test_recipe(:recipe => recipe, :expected => '(up to date)', :fail_if => nil) }
32
32
  end
33
33
  end
34
34
 
35
35
  def cleanup
36
- chef_run(%w(
37
- OneDriver/delete/OpenNebula-test-tpl.rb
36
+ # OneDriver deletes are listed explicitly because they need to be run in a certain order.
37
+ cleanup_list = %w(
38
+ OneDriver/delete/OpenNebula-test-tpl-strings.rb
38
39
  OneDriver/delete/OpenNebula-test-tpl-ints.rb
39
- OneDriver/delete/OpenNebula-tpl-1-vm.rb
40
- OneDriver/delete/OpenNebula-bootstrap-vm.rb
41
- OneDriver/delete/OpenNebula-bootstrap-img.rb
42
- OneDriver/delete/OpenNebula-back-1-vm.rb
43
- OneDriver/delete/OpenNebula-back-2-vm.rb
44
- OneDriver/delete/OpenNebula-snap-1-img.rb
45
- OneDriver/delete/OpenNebula-snap-2-img.rb
46
- ))
40
+ OneDriver/delete/OpenNebula-test-tpl-mix.rb
41
+ OneDriver/delete/OpenNebula-test-vm.rb
42
+ OneDriver/delete/OpenNebula-test-vm-vnet.rb
43
+ OneDriver/delete/OpenNebula-test-vnet.rb
44
+ OneDriver/delete/OpenNebula-test-img.rb
45
+ OneDriver/delete/OpenNebula-test-snap-img.rb
46
+ ).map { |f| "#{File.dirname(__FILE__)}/recipes/" + f }
47
+ cleanup_list += Dir["#{File.dirname(__FILE__)}/recipes/OneFlowTemplate/delete/*.rb"] unless ONE_FLOW_URL.nil?
48
+ cleanup_list += Dir["#{File.dirname(__FILE__)}/recipes/OneFlowService/delete/*.rb"] unless ONE_FLOW_URL.nil?
49
+ err = get_error(chef_run(cleanup_list, false), 'Chef Client finished', nil)
50
+ fail "\n\nTest suite cleanup failed\n#{err.first}\n\n" unless err.first.nil?
47
51
  end
48
52
 
49
53
  RSpec.configure do |config|
@@ -54,10 +58,11 @@ RSpec.configure do |config|
54
58
  FileUtils.rm_rf(config.log_dir)
55
59
  FileUtils.mkdir_p(config.log_dir)
56
60
  FileUtils.rm_rf('nodes')
57
- fail 'Quick cleanup before testing failed.' unless cleanup.include?('Chef Client finished')
61
+ cleanup
58
62
  end
59
63
  config.after(:suite) do
60
64
  FileUtils.rm_rf('nodes')
61
- fail 'Quick cleanup after testing failed.' unless cleanup.include?('Chef Client finished')
65
+ cleanup
66
+ FileUtils.rm_rf('/tmp/chef-provisioning-opennebula-rspec-recipe.rb')
62
67
  end
63
68
  end
@@ -1,4 +1,4 @@
1
- # Copyright 2016, BlackBerry, Inc.
1
+ # Copyright 2016, BlackBerry Limited
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -17,10 +17,21 @@ require 'cheffish/rspec/matchers'
17
17
  require 'chef/provisioning/opennebula_driver'
18
18
  require 'fileutils'
19
19
 
20
- def chef_run(recipe)
20
+ def chef_run(recipe, append_path = true)
21
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
22
33
  chef_client = Mixlib::ShellOut.new(
23
- "bundle exec chef-client -z ./spec/recipes/driver_options_spec.rb #{recipe_array.map { |r| './spec/recipes/' + r }.join(' ')} --force-formatter",
34
+ 'chef-client -z /tmp/chef-provisioning-opennebula-rspec-recipe.rb --force-formatter',
24
35
  shellout_options(:timeout => 900)
25
36
  )
26
37
  chef_client.run_command
@@ -32,65 +43,84 @@ def shellout_options(options = {})
32
43
  end
33
44
 
34
45
  def format_error(msg)
35
- "================================================================================\n#{msg}\n================================================================================"
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}"
36
56
  end
37
57
 
38
- # gets runtime / idempotency-related errors from stdout
39
- def get_error(stdout, expected = nil, error = nil)
40
- err = stdout.include?('Chef Client finished') ? nil : "Chef run did not report 'Chef Client finished', no errors were detected."
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
41
62
 
42
- unless error.nil?
43
- case error
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
44
74
  when Regexp
45
- return "stdout matched:\n#{error}" if stdout =~ error
75
+ if e + the_error =~ expected
76
+ return nil, nil
77
+ else
78
+ return "#{e.strip}\n#{the_error}", stacktrace
79
+ end
46
80
  when String
47
- return "stdout included:\n#{error}" if stdout.include?(error)
48
- end
49
- end
50
-
51
- if stdout.include?('RuntimeError: ')
52
- return "RuntimeError\n" + (stdout.split('RuntimeError: ').last).split("\n").first
53
- elsif stdout.include?('NoMethodError: ')
54
- return "NoMethodError\n" + (stdout.split('NoMethodError: ').last).split("\n").first
55
- elsif stdout.include?('ERROR: ') && err
56
- return "ERROR\n" + (stdout.split('ERROR: ').last).split("\n").first
57
- elsif stdout.include?('FATAL: ')
58
- return "FATAL\nAn unknown fatal error has occurred."
59
- end
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
60
90
 
61
- return err if expected.nil?
91
+ return err, stacktrace if expected.nil?
62
92
 
63
93
  case expected
64
- when Symbol
65
- fail "The only symbol supported for 'expected' is :idempotent, you passed :#{expected}" unless expected == :idempotent
66
- return 'Chef run did not idempotently skip when it should have.' unless stdout.include?('(up to date)')
67
94
  when Regexp
68
- return "Chef run idempotently skipped when it should not have.\nIf you intended for it to skip, pass in :idempotent as 'expected' instead." if stdout.include?('(up to date)')
69
- return "No match in stdout for:\n#{expected}" unless stdout =~ expected
95
+ return "stdout did not match the following when it should have:\n#{expected}", stacktrace unless stdout =~ expected
70
96
  when String
71
- return "Chef run idempotently skipped when it should not have.\nIf you intended for it to skip, pass in :idempotent as 'expected' instead." if stdout.include?('(up to date)')
72
- return "stdout did not include:\n#{expected}" unless stdout.include?(expected)
97
+ return "stdout did not include the following when it should have:\n#{expected}", stacktrace unless stdout.include?(expected)
73
98
  end
74
99
 
75
- err
100
+ [err, stacktrace]
76
101
  end
77
102
 
78
- RSpec::Matchers.define :converge_test_recipe do |recipe = nil, expected = :idempotent, error = nil|
79
- fail 'All tests require a recipe.' if recipe.nil?
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]
80
110
  match do
81
- stdout = chef_run(recipe)
82
- # logs each chef run
83
- dir = RSpec.configuration.log_dir + '/' + File.dirname(recipe)
111
+ stdout = chef_run(data[:recipe])
112
+
113
+ dir = RSpec.configuration.log_dir + '/' + File.dirname(data[:recipe])
84
114
  FileUtils.mkdir_p(dir)
85
- log_basename = expected == :idempotent ? File.basename(recipe, '.*') + '__i' : File.basename(recipe, '.*')
86
- File.open("./#{dir}/#{log_basename}_stdout.log", 'w+') { |file| file.write(stdout) }
87
- @error_message = get_error(stdout, expected, error)
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])
88
120
  @error_message = format_error(@error_message) unless @error_message.nil?
89
- # copies the stacktrace for tests that have failed
90
- FileUtils.cp(
91
- "#{ENV['HOME']}/.chef/local-mode-cache/cache/chef-stacktrace.out",
92
- "./#{dir}/#{log_basename}_stacktrace.out"
93
- ) unless @error_message.nil?
121
+
122
+ FileUtils.cp(stacktrace, get_unique_file("./#{dir}", log_basename, '.stacktrace.out')) if stacktrace
123
+
94
124
  @error_message.nil?
95
125
  end
96
126
  failure_message do