hybrid_platforms_conductor 33.0.0 → 33.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (242) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/bin/check-node +0 -1
  4. data/bin/deploy +0 -1
  5. data/bin/get_impacted_nodes +0 -1
  6. data/bin/last_deploys +8 -7
  7. data/bin/nodes_to_deploy +2 -2
  8. data/bin/setup +6 -6
  9. data/bin/topograph +1 -1
  10. data/lib/hybrid_platforms_conductor/action.rb +4 -4
  11. data/lib/hybrid_platforms_conductor/actions_executor.rb +37 -42
  12. data/lib/hybrid_platforms_conductor/bitbucket.rb +5 -4
  13. data/lib/hybrid_platforms_conductor/cmd_runner.rb +13 -12
  14. data/lib/hybrid_platforms_conductor/cmdb.rb +2 -2
  15. data/lib/hybrid_platforms_conductor/common_config_dsl/bitbucket.rb +2 -1
  16. data/lib/hybrid_platforms_conductor/common_config_dsl/confluence.rb +2 -1
  17. data/lib/hybrid_platforms_conductor/common_config_dsl/file_system_tests.rb +5 -4
  18. data/lib/hybrid_platforms_conductor/common_config_dsl/github.rb +4 -3
  19. data/lib/hybrid_platforms_conductor/common_config_dsl/idempotence_tests.rb +2 -2
  20. data/lib/hybrid_platforms_conductor/config.rb +7 -4
  21. data/lib/hybrid_platforms_conductor/confluence.rb +1 -1
  22. data/lib/hybrid_platforms_conductor/connector.rb +5 -2
  23. data/lib/hybrid_platforms_conductor/core_extensions/symbol/zero.rb +24 -0
  24. data/lib/hybrid_platforms_conductor/credentials.rb +39 -36
  25. data/lib/hybrid_platforms_conductor/current_dir_monitor.rb +4 -1
  26. data/lib/hybrid_platforms_conductor/deployer.rb +95 -96
  27. data/lib/hybrid_platforms_conductor/executable.rb +20 -15
  28. data/lib/hybrid_platforms_conductor/hpc_plugins/cmdb/config.rb +10 -7
  29. data/lib/hybrid_platforms_conductor/hpc_plugins/cmdb/host_ip.rb +1 -1
  30. data/lib/hybrid_platforms_conductor/hpc_plugins/cmdb/host_keys.rb +2 -2
  31. data/lib/hybrid_platforms_conductor/hpc_plugins/cmdb/platform_handlers.rb +4 -4
  32. data/lib/hybrid_platforms_conductor/hpc_plugins/connector/local.rb +2 -0
  33. data/lib/hybrid_platforms_conductor/hpc_plugins/connector/ssh.rb +45 -49
  34. data/lib/hybrid_platforms_conductor/hpc_plugins/log/remote_fs.rb +6 -5
  35. data/lib/hybrid_platforms_conductor/hpc_plugins/platform_handler/serverless_chef.rb +68 -66
  36. data/lib/hybrid_platforms_conductor/hpc_plugins/platform_handler/serverless_chef/dsl_parser.rb +13 -0
  37. data/lib/hybrid_platforms_conductor/hpc_plugins/platform_handler/serverless_chef/recipes_tree_builder.rb +39 -38
  38. data/lib/hybrid_platforms_conductor/hpc_plugins/platform_handler/yaml_inventory.rb +5 -4
  39. data/lib/hybrid_platforms_conductor/hpc_plugins/provisioner/docker.rb +43 -45
  40. data/lib/hybrid_platforms_conductor/hpc_plugins/provisioner/podman.rb +18 -20
  41. data/lib/hybrid_platforms_conductor/hpc_plugins/provisioner/proxmox.rb +118 -117
  42. data/lib/hybrid_platforms_conductor/hpc_plugins/provisioner/proxmox/proxmox_waiter.rb +39 -43
  43. data/lib/hybrid_platforms_conductor/hpc_plugins/provisioner/proxmox/reserve_proxmox_container +9 -13
  44. data/lib/hybrid_platforms_conductor/hpc_plugins/report/confluence.rb +2 -2
  45. data/lib/hybrid_platforms_conductor/hpc_plugins/report/mediawiki.rb +28 -21
  46. data/lib/hybrid_platforms_conductor/hpc_plugins/report/stdout.rb +26 -22
  47. data/lib/hybrid_platforms_conductor/hpc_plugins/secrets_reader/cli.rb +8 -6
  48. data/lib/hybrid_platforms_conductor/hpc_plugins/secrets_reader/thycotic.rb +7 -4
  49. data/lib/hybrid_platforms_conductor/hpc_plugins/test/bitbucket_conf.rb +3 -3
  50. data/lib/hybrid_platforms_conductor/hpc_plugins/test/check_deploy_and_idempotence.rb +4 -2
  51. data/lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_freshness.rb +0 -1
  52. data/lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_removes_root_access.rb +21 -19
  53. data/lib/hybrid_platforms_conductor/hpc_plugins/test/divergence.rb +2 -2
  54. data/lib/hybrid_platforms_conductor/hpc_plugins/test/executables.rb +2 -2
  55. data/lib/hybrid_platforms_conductor/hpc_plugins/test/file_system.rb +19 -21
  56. data/lib/hybrid_platforms_conductor/hpc_plugins/test/file_system_hdfs.rb +19 -21
  57. data/lib/hybrid_platforms_conductor/hpc_plugins/test/github_ci.rb +2 -3
  58. data/lib/hybrid_platforms_conductor/hpc_plugins/test/idempotence.rb +2 -2
  59. data/lib/hybrid_platforms_conductor/hpc_plugins/test/ip.rb +1 -1
  60. data/lib/hybrid_platforms_conductor/hpc_plugins/test/jenkins_ci_conf.rb +21 -22
  61. data/lib/hybrid_platforms_conductor/hpc_plugins/test/jenkins_ci_masters_ok.rb +10 -12
  62. data/lib/hybrid_platforms_conductor/hpc_plugins/test/linear_strategy.rb +9 -9
  63. data/lib/hybrid_platforms_conductor/hpc_plugins/test/local_users.rb +2 -2
  64. data/lib/hybrid_platforms_conductor/hpc_plugins/test/mounts.rb +2 -2
  65. data/lib/hybrid_platforms_conductor/hpc_plugins/test/orphan_files.rb +10 -9
  66. data/lib/hybrid_platforms_conductor/hpc_plugins/test/ports.rb +2 -2
  67. data/lib/hybrid_platforms_conductor/hpc_plugins/test/private_ips.rb +5 -5
  68. data/lib/hybrid_platforms_conductor/hpc_plugins/test/public_ips.rb +5 -5
  69. data/lib/hybrid_platforms_conductor/hpc_plugins/test/spectre.rb +4 -6
  70. data/lib/hybrid_platforms_conductor/hpc_plugins/test/veids.rb +3 -3
  71. data/lib/hybrid_platforms_conductor/hpc_plugins/test/vulnerabilities.rb +25 -24
  72. data/lib/hybrid_platforms_conductor/hpc_plugins/test_report/confluence.rb +2 -2
  73. data/lib/hybrid_platforms_conductor/hpc_plugins/test_report/stdout.rb +8 -6
  74. data/lib/hybrid_platforms_conductor/io_router.rb +14 -13
  75. data/lib/hybrid_platforms_conductor/json_dumper.rb +2 -2
  76. data/lib/hybrid_platforms_conductor/log.rb +2 -2
  77. data/lib/hybrid_platforms_conductor/logger_helpers.rb +19 -16
  78. data/lib/hybrid_platforms_conductor/nodes_handler.rb +89 -71
  79. data/lib/hybrid_platforms_conductor/parallel_threads.rb +7 -11
  80. data/lib/hybrid_platforms_conductor/platform_handler.rb +7 -7
  81. data/lib/hybrid_platforms_conductor/platforms_handler.rb +5 -3
  82. data/lib/hybrid_platforms_conductor/plugin.rb +2 -2
  83. data/lib/hybrid_platforms_conductor/plugins.rb +13 -8
  84. data/lib/hybrid_platforms_conductor/provisioner.rb +4 -4
  85. data/lib/hybrid_platforms_conductor/report.rb +2 -2
  86. data/lib/hybrid_platforms_conductor/reports_handler.rb +3 -2
  87. data/lib/hybrid_platforms_conductor/secrets_reader.rb +2 -2
  88. data/lib/hybrid_platforms_conductor/services_handler.rb +32 -29
  89. data/lib/hybrid_platforms_conductor/test_only_remote_node.rb +1 -1
  90. data/lib/hybrid_platforms_conductor/test_report.rb +15 -18
  91. data/lib/hybrid_platforms_conductor/tests_runner.rb +116 -118
  92. data/lib/hybrid_platforms_conductor/thycotic.rb +28 -19
  93. data/lib/hybrid_platforms_conductor/topographer.rb +200 -190
  94. data/lib/hybrid_platforms_conductor/topographer/plugins/graphviz.rb +8 -8
  95. data/lib/hybrid_platforms_conductor/topographer/plugins/json.rb +4 -4
  96. data/lib/hybrid_platforms_conductor/version.rb +1 -1
  97. data/spec/hybrid_platforms_conductor_test.rb +6 -6
  98. data/spec/hybrid_platforms_conductor_test/api/actions_executor/actions/bash_spec.rb +16 -11
  99. data/spec/hybrid_platforms_conductor_test/api/actions_executor/actions/interactive_spec.rb +1 -1
  100. data/spec/hybrid_platforms_conductor_test/api/actions_executor/actions/remote_bash_spec.rb +23 -18
  101. data/spec/hybrid_platforms_conductor_test/api/actions_executor/actions/ruby_spec.rb +67 -49
  102. data/spec/hybrid_platforms_conductor_test/api/actions_executor/actions/scp_spec.rb +20 -14
  103. data/spec/hybrid_platforms_conductor_test/api/actions_executor/actions_spec.rb +63 -50
  104. data/spec/hybrid_platforms_conductor_test/api/actions_executor/connection_spec.rb +35 -35
  105. data/spec/hybrid_platforms_conductor_test/api/actions_executor/connectors/local/connectable_nodes_spec.rb +12 -8
  106. data/spec/hybrid_platforms_conductor_test/api/actions_executor/connectors/local/remote_actions_spec.rb +4 -7
  107. data/spec/hybrid_platforms_conductor_test/api/actions_executor/connectors/ssh/cli_options_spec.rb +21 -22
  108. data/spec/hybrid_platforms_conductor_test/api/actions_executor/connectors/ssh/config_dsl_spec.rb +23 -24
  109. data/spec/hybrid_platforms_conductor_test/api/actions_executor/connectors/ssh/connectable_nodes_spec.rb +10 -6
  110. data/spec/hybrid_platforms_conductor_test/api/actions_executor/connectors/ssh/connections_spec.rb +73 -54
  111. data/spec/hybrid_platforms_conductor_test/api/actions_executor/connectors/ssh/global_helpers_spec.rb +145 -126
  112. data/spec/hybrid_platforms_conductor_test/api/actions_executor/connectors/ssh/node_helpers_spec.rb +3 -3
  113. data/spec/hybrid_platforms_conductor_test/api/actions_executor/connectors/ssh/remote_actions_spec.rb +29 -25
  114. data/spec/hybrid_platforms_conductor_test/api/actions_executor/logging_spec.rb +106 -91
  115. data/spec/hybrid_platforms_conductor_test/api/actions_executor/parallel_spec.rb +272 -244
  116. data/spec/hybrid_platforms_conductor_test/api/actions_executor/timeout_spec.rb +10 -12
  117. data/spec/hybrid_platforms_conductor_test/api/cmd_runner_spec.rb +36 -36
  118. data/spec/hybrid_platforms_conductor_test/api/config_spec.rb +24 -22
  119. data/spec/hybrid_platforms_conductor_test/api/deployer/check_spec.rb +4 -2
  120. data/spec/hybrid_platforms_conductor_test/api/deployer/config_dsl_spec.rb +7 -11
  121. data/spec/hybrid_platforms_conductor_test/api/deployer/deploy_spec.rb +34 -26
  122. data/spec/hybrid_platforms_conductor_test/api/deployer/log_plugins/remote_fs_spec.rb +21 -21
  123. data/spec/hybrid_platforms_conductor_test/api/deployer/parse_deploy_output_spec.rb +55 -59
  124. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioner_spec.rb +36 -62
  125. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/podman_spec.rb +17 -17
  126. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/proxmox/config_dsl_spec.rb +4 -4
  127. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/proxmox/create_spec.rb +44 -51
  128. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/proxmox/destroy_spec.rb +3 -3
  129. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/proxmox/ip_spec.rb +12 -16
  130. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/proxmox/reserve_proxmox_container/destroy_vm_spec.rb +31 -19
  131. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/proxmox/reserve_proxmox_container/expired_containers_spec.rb +324 -266
  132. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/proxmox/reserve_proxmox_container/ips_assignment_spec.rb +89 -61
  133. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/proxmox/reserve_proxmox_container/other_lxc_containers_resources_spec.rb +117 -93
  134. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/proxmox/reserve_proxmox_container/pve_node_resources_spec.rb +71 -54
  135. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/proxmox/reserve_proxmox_container/retries_spec.rb +10 -8
  136. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/proxmox/reserve_proxmox_container/vm_ids_assignment_spec.rb +80 -60
  137. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/proxmox/start_spec.rb +1 -1
  138. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/proxmox/state_spec.rb +1 -1
  139. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/proxmox/stop_spec.rb +1 -1
  140. data/spec/hybrid_platforms_conductor_test/api/deployer/secrets_reader_plugins/cli_spec.rb +21 -20
  141. data/spec/hybrid_platforms_conductor_test/api/deployer/secrets_reader_plugins/thycotic_spec.rb +70 -55
  142. data/spec/hybrid_platforms_conductor_test/api/nodes_handler/cmdbs/config_spec.rb +8 -10
  143. data/spec/hybrid_platforms_conductor_test/api/nodes_handler/cmdbs/host_ip_spec.rb +33 -24
  144. data/spec/hybrid_platforms_conductor_test/api/nodes_handler/cmdbs/host_keys_spec.rb +64 -51
  145. data/spec/hybrid_platforms_conductor_test/api/nodes_handler/cmdbs/platform_handlers_spec.rb +3 -3
  146. data/spec/hybrid_platforms_conductor_test/api/nodes_handler/cmdbs_plugins_api_spec.rb +50 -51
  147. data/spec/hybrid_platforms_conductor_test/api/nodes_handler/common_spec.rb +91 -81
  148. data/spec/hybrid_platforms_conductor_test/api/nodes_handler/config_dsl_spec.rb +14 -16
  149. data/spec/hybrid_platforms_conductor_test/api/nodes_handler/git_diff_impacts_spec.rb +51 -75
  150. data/spec/hybrid_platforms_conductor_test/api/nodes_handler/nodes_selectors_spec.rb +35 -26
  151. data/spec/hybrid_platforms_conductor_test/api/nodes_handler/platform_handlers_plugins_api_spec.rb +24 -16
  152. data/spec/hybrid_platforms_conductor_test/api/nodes_handler/several_platforms_spec.rb +29 -19
  153. data/spec/hybrid_platforms_conductor_test/api/platform_handler_spec.rb +4 -4
  154. data/spec/hybrid_platforms_conductor_test/api/platform_handlers/serverless_chef/config_dsl_spec.rb +2 -2
  155. data/spec/hybrid_platforms_conductor_test/api/platform_handlers/serverless_chef/deploy_output_parsing_spec.rb +6 -6
  156. data/spec/hybrid_platforms_conductor_test/api/platform_handlers/serverless_chef/diff_impacts_spec.rb +57 -99
  157. data/spec/hybrid_platforms_conductor_test/api/platform_handlers/serverless_chef/inventory_spec.rb +4 -4
  158. data/spec/hybrid_platforms_conductor_test/api/platform_handlers/serverless_chef/packaging_spec.rb +32 -35
  159. data/spec/hybrid_platforms_conductor_test/api/platform_handlers/serverless_chef/services_deployment_spec.rb +10 -10
  160. data/spec/hybrid_platforms_conductor_test/api/platforms_handler_spec.rb +38 -27
  161. data/spec/hybrid_platforms_conductor_test/api/plugins_spec.rb +46 -52
  162. data/spec/hybrid_platforms_conductor_test/api/reports_handler_spec.rb +2 -2
  163. data/spec/hybrid_platforms_conductor_test/api/services_handler/actions_to_deploy_spec.rb +90 -58
  164. data/spec/hybrid_platforms_conductor_test/api/services_handler/deploy_allowed_spec.rb +38 -34
  165. data/spec/hybrid_platforms_conductor_test/api/services_handler/log_info_spec.rb +11 -9
  166. data/spec/hybrid_platforms_conductor_test/api/services_handler/package_spec.rb +193 -171
  167. data/spec/hybrid_platforms_conductor_test/api/services_handler/parse_deploy_output_spec.rb +66 -54
  168. data/spec/hybrid_platforms_conductor_test/api/services_handler/prepare_for_deploy_spec.rb +147 -133
  169. data/spec/hybrid_platforms_conductor_test/api/tests_runner/common_spec.rb +69 -49
  170. data/spec/hybrid_platforms_conductor_test/api/tests_runner/global_spec.rb +4 -3
  171. data/spec/hybrid_platforms_conductor_test/api/tests_runner/node_check_spec.rb +8 -5
  172. data/spec/hybrid_platforms_conductor_test/api/tests_runner/node_spec.rb +8 -5
  173. data/spec/hybrid_platforms_conductor_test/api/tests_runner/node_ssh_spec.rb +30 -27
  174. data/spec/hybrid_platforms_conductor_test/api/tests_runner/platform_spec.rb +12 -9
  175. data/spec/hybrid_platforms_conductor_test/api/tests_runner/reports_spec.rb +48 -47
  176. data/spec/hybrid_platforms_conductor_test/api/tests_runner/test_plugins/bitbucket_conf_spec.rb +5 -5
  177. data/spec/hybrid_platforms_conductor_test/api/tests_runner/test_plugins/github_ci_spec.rb +5 -5
  178. data/spec/hybrid_platforms_conductor_test/api/tests_runner/test_reports_plugins/confluence_spec.rb +5 -5
  179. data/spec/hybrid_platforms_conductor_test/cmdb_plugins/test_cmdb.rb +9 -9
  180. data/spec/hybrid_platforms_conductor_test/cmdb_plugins/{test_cmdb2.rb → test_cmdb_2.rb} +6 -6
  181. data/spec/hybrid_platforms_conductor_test/cmdb_plugins/test_cmdb_others.rb +3 -3
  182. data/spec/hybrid_platforms_conductor_test/cmdb_plugins/{test_cmdb_others2.rb → test_cmdb_others_2.rb} +2 -2
  183. data/spec/hybrid_platforms_conductor_test/docs_spec.rb +1 -1
  184. data/spec/hybrid_platforms_conductor_test/executables/{check-node_spec.rb → check_node_spec.rb} +4 -6
  185. data/spec/hybrid_platforms_conductor_test/executables/deploy_spec.rb +4 -6
  186. data/spec/hybrid_platforms_conductor_test/executables/get_impacted_nodes_spec.rb +76 -77
  187. data/spec/hybrid_platforms_conductor_test/executables/last_deploys_spec.rb +13 -15
  188. data/spec/hybrid_platforms_conductor_test/executables/nodes_to_deploy_spec.rb +289 -307
  189. data/spec/hybrid_platforms_conductor_test/executables/options/actions_executor_spec.rb +4 -6
  190. data/spec/hybrid_platforms_conductor_test/executables/options/cmd_runner_spec.rb +3 -5
  191. data/spec/hybrid_platforms_conductor_test/executables/options/common_spec.rb +8 -9
  192. data/spec/hybrid_platforms_conductor_test/executables/options/deployer_spec.rb +12 -14
  193. data/spec/hybrid_platforms_conductor_test/executables/options/nodes_handler_spec.rb +9 -10
  194. data/spec/hybrid_platforms_conductor_test/executables/options/nodes_selectors_spec.rb +9 -10
  195. data/spec/hybrid_platforms_conductor_test/executables/options/reports_handler_spec.rb +1 -1
  196. data/spec/hybrid_platforms_conductor_test/executables/options/tests_runner_spec.rb +22 -22
  197. data/spec/hybrid_platforms_conductor_test/executables/report_spec.rb +22 -16
  198. data/spec/hybrid_platforms_conductor_test/executables/run_spec.rb +32 -32
  199. data/spec/hybrid_platforms_conductor_test/executables/ssh_config_spec.rb +7 -9
  200. data/spec/hybrid_platforms_conductor_test/executables/test_spec.rb +3 -5
  201. data/spec/hybrid_platforms_conductor_test/helpers/actions_executor_helpers.rb +2 -2
  202. data/spec/hybrid_platforms_conductor_test/helpers/cmd_runner_helpers.rb +4 -3
  203. data/spec/hybrid_platforms_conductor_test/helpers/cmdb_helpers.rb +2 -2
  204. data/spec/hybrid_platforms_conductor_test/helpers/config_helpers.rb +1 -1
  205. data/spec/hybrid_platforms_conductor_test/helpers/connector_ssh_helpers.rb +12 -13
  206. data/spec/hybrid_platforms_conductor_test/helpers/deployer_helpers.rb +216 -14
  207. data/spec/hybrid_platforms_conductor_test/helpers/executables_helpers.rb +11 -11
  208. data/spec/hybrid_platforms_conductor_test/helpers/nodes_handler_helpers.rb +1 -1
  209. data/spec/hybrid_platforms_conductor_test/helpers/platforms_handler_helpers.rb +39 -28
  210. data/spec/hybrid_platforms_conductor_test/helpers/plugins_helpers.rb +1 -1
  211. data/spec/hybrid_platforms_conductor_test/helpers/provisioner_proxmox_helpers.rb +86 -111
  212. data/spec/hybrid_platforms_conductor_test/helpers/reports_handler_helpers.rb +1 -1
  213. data/spec/hybrid_platforms_conductor_test/helpers/serverless_chef_helpers.rb +3 -3
  214. data/spec/hybrid_platforms_conductor_test/helpers/services_handler_helpers.rb +1 -1
  215. data/spec/hybrid_platforms_conductor_test/helpers/tests_runner_helpers.rb +1 -1
  216. data/spec/hybrid_platforms_conductor_test/mocked_lib/my_test_gem/hpc_plugins/test_plugin_type/{test_plugin_id1.rb → test_plugin_id_1.rb} +0 -0
  217. data/spec/hybrid_platforms_conductor_test/mocked_lib/my_test_gem/hpc_plugins/test_plugin_type/{test_plugin_id2.rb → test_plugin_id_2.rb} +0 -0
  218. data/spec/hybrid_platforms_conductor_test/mocked_lib/my_test_gem2/sub_dir/hpc_plugins/test_plugin_type/{test_plugin_id3.rb → test_plugin_id_3.rb} +0 -0
  219. data/spec/hybrid_platforms_conductor_test/mocked_lib/my_test_gem2/sub_dir/hpc_plugins/{test_plugin_type2/test_plugin_id4.rb → test_plugin_type_2/test_plugin_id_4.rb} +0 -0
  220. data/spec/hybrid_platforms_conductor_test/platform_handler_plugins/test.rb +1 -1
  221. data/spec/hybrid_platforms_conductor_test/platform_handler_plugins/{test2.rb → test_2.rb} +0 -0
  222. data/spec/hybrid_platforms_conductor_test/rubocop_spec.rb +31 -0
  223. data/spec/hybrid_platforms_conductor_test/serverless_chef_repositories/1_node/nodes/node.json +3 -3
  224. data/spec/hybrid_platforms_conductor_test/serverless_chef_repositories/data_bags/nodes/node.json +3 -3
  225. data/spec/hybrid_platforms_conductor_test/serverless_chef_repositories/recipes/cookbooks/test_cookbook_2/libraries/default.rb +1 -0
  226. data/spec/hybrid_platforms_conductor_test/serverless_chef_repositories/several_cookbooks/other_cookbooks/test_cookbook_2/libraries/default.rb +1 -0
  227. data/spec/hybrid_platforms_conductor_test/shared_examples/deployer.rb +952 -0
  228. data/spec/hybrid_platforms_conductor_test/test_connector.rb +3 -3
  229. data/spec/hybrid_platforms_conductor_test/test_log_no_read_plugin.rb +3 -1
  230. data/spec/hybrid_platforms_conductor_test/test_log_plugin.rb +3 -1
  231. data/spec/hybrid_platforms_conductor_test/test_plugins/global.rb +1 -0
  232. data/spec/hybrid_platforms_conductor_test/test_plugins/node.rb +1 -0
  233. data/spec/hybrid_platforms_conductor_test/test_plugins/node_check.rb +1 -0
  234. data/spec/hybrid_platforms_conductor_test/test_plugins/platform.rb +1 -0
  235. data/spec/hybrid_platforms_conductor_test/test_plugins/several_checks.rb +2 -2
  236. data/spec/hybrid_platforms_conductor_test/test_secrets_reader_plugin.rb +4 -4
  237. data/spec/hybrid_platforms_conductor_test/tests_report_plugin.rb +5 -6
  238. data/spec/spec_helper.rb +17 -18
  239. data/tools/check_md +16 -20
  240. data/tools/generate_mermaid +1 -1
  241. metadata +43 -13
  242. data/spec/hybrid_platforms_conductor_test/helpers/deployer_test_helpers.rb +0 -1152
@@ -3,25 +3,23 @@ describe 'run executable' do
3
3
  # Setup a platform for run tests
4
4
  #
5
5
  # Parameters::
6
- # * Proc: Code called when the platform is setup
6
+ # * *block* (Proc): Code called when the platform is setup
7
7
  # * Parameters::
8
8
  # * *repository* (String): Platform's repository
9
- def with_test_platform_for_run
10
- with_test_platform({ nodes: { 'node1' => {}, 'node2' => {} } }) do |repository|
11
- yield repository
12
- end
9
+ def with_test_platform_for_run(&block)
10
+ with_test_platform({ nodes: { 'node1' => {}, 'node2' => {} } }, &block)
13
11
  end
14
12
 
15
13
  it 'executes a single command on a node' do
16
14
  with_test_platform_for_run do
17
- expect_actions_executor_runs([proc do |actions, timeout: nil, concurrent: false, log_to_dir: 'run_logs', log_to_stdout: true|
15
+ expect_actions_executor_runs([proc do |actions|
18
16
  expect(actions).to eq(['node1'] => [{ remote_bash: ['echo Hello'] }])
19
17
  test_actions_executor.stdout_device << "Hello\n"
20
18
  { 'node1' => [0, "Hello\n", ''] }
21
19
  end])
22
20
  exit_code, stdout, stderr = run 'run', '--node', 'node1', '--command', 'echo Hello'
23
21
  expect(exit_code).to eq 0
24
- expect(stdout).to match /Hello/
22
+ expect(stdout).to match(/Hello/)
25
23
  expect(stderr).to eq ''
26
24
  end
27
25
  end
@@ -30,15 +28,15 @@ describe 'run executable' do
30
28
  with_test_platform_for_run do |repository|
31
29
  commands_file = "#{repository}/commands.txt"
32
30
  File.write(commands_file, "echo Hello1\necho Hello2\n")
33
- expect_actions_executor_runs([proc do |actions, timeout: nil, concurrent: false, log_to_dir: 'run_logs', log_to_stdout: true|
31
+ expect_actions_executor_runs([proc do |actions|
34
32
  expect(actions).to eq(['node1'] => [{ remote_bash: [{ file: commands_file }] }])
35
33
  test_actions_executor.stdout_device << "Hello1\nHello2\n"
36
34
  { 'node1' => [0, "Hello1\nHello2\n", ''] }
37
35
  end])
38
36
  exit_code, stdout, stderr = run 'run', '--node', 'node1', '--command-file', commands_file
39
37
  expect(exit_code).to eq 0
40
- expect(stdout).to match /Hello1/
41
- expect(stdout).to match /Hello2/
38
+ expect(stdout).to match(/Hello1/)
39
+ expect(stdout).to match(/Hello2/)
42
40
  expect(stderr).to eq ''
43
41
  end
44
42
  end
@@ -53,14 +51,14 @@ describe 'run executable' do
53
51
  end])
54
52
  exit_code, stdout, stderr = run 'run', '--node', 'node1', '--command', 'echo Hello', '--timeout', '5'
55
53
  expect(exit_code).to eq 0
56
- expect(stdout).to match /Hello/
54
+ expect(stdout).to match(/Hello/)
57
55
  expect(stderr).to eq ''
58
56
  end
59
57
  end
60
58
 
61
59
  it 'executes a single command on a node and captures stderr correctly' do
62
60
  with_test_platform_for_run do
63
- expect_actions_executor_runs([proc do |actions, timeout: nil, concurrent: false, log_to_dir: 'run_logs', log_to_stdout: true|
61
+ expect_actions_executor_runs([proc do |actions|
64
62
  expect(actions).to eq(['node1'] => [{ remote_bash: ['echo Hello 2>&1'] }])
65
63
  test_actions_executor.stderr_device << "Hello\n"
66
64
  { 'node1' => [0, '', "Hello\n"] }
@@ -68,7 +66,7 @@ describe 'run executable' do
68
66
  exit_code, stdout, stderr = run 'run', '--node', 'node1', '--command', 'echo Hello 2>&1'
69
67
  expect(exit_code).to eq 0
70
68
  expect(stdout).to eq ''
71
- expect(stderr).to match /Hello/
69
+ expect(stderr).to match(/Hello/)
72
70
  end
73
71
  end
74
72
 
@@ -82,22 +80,22 @@ describe 'run executable' do
82
80
  end])
83
81
  exit_code, stdout, stderr = run 'run', '--node', 'node1', '--node', 'node2', '--command', 'echo Hello'
84
82
  expect(exit_code).to eq 0
85
- expect(stdout).to match /Hello/
83
+ expect(stdout).to match(/Hello/)
86
84
  expect(stderr).to eq ''
87
85
  end
88
86
  end
89
87
 
90
88
  it 'executes several commands' do
91
89
  with_test_platform_for_run do
92
- expect_actions_executor_runs([proc do |actions, timeout: nil, concurrent: false, log_to_dir: 'run_logs', log_to_stdout: true|
90
+ expect_actions_executor_runs([proc do |actions|
93
91
  expect(actions).to eq(['node1'] => [{ remote_bash: ['echo Hello1', 'echo Hello2'] }])
94
92
  test_actions_executor.stdout_device << "Hello1\nHello2\n"
95
93
  { 'node1' => [0, "Hello1\nHello2\n", ''] }
96
94
  end])
97
95
  exit_code, stdout, stderr = run 'run', '--node', 'node1', '--command', 'echo Hello1', '--command', 'echo Hello2'
98
96
  expect(exit_code).to eq 0
99
- expect(stdout).to match /Hello1/
100
- expect(stdout).to match /Hello2/
97
+ expect(stdout).to match(/Hello1/)
98
+ expect(stdout).to match(/Hello2/)
101
99
  expect(stderr).to eq ''
102
100
  end
103
101
  end
@@ -108,24 +106,26 @@ describe 'run executable' do
108
106
  File.write(commands_file_1, "echo Hello1\necho Hello2\n")
109
107
  commands_file_2 = "#{repository}/commands2.txt"
110
108
  File.write(commands_file_1, "echo Hello4\necho Hello5\n")
111
- expect_actions_executor_runs([proc do |actions, timeout: nil, concurrent: false, log_to_dir: 'run_logs', log_to_stdout: true|
112
- expect(actions).to eq(['node1'] => [{ remote_bash: [
113
- { file: commands_file_1 },
114
- 'echo Hello3',
115
- { file: commands_file_2 },
116
- 'echo Hello6'
117
- ] }])
109
+ expect_actions_executor_runs([proc do |actions|
110
+ expect(actions).to eq(
111
+ ['node1'] => [{ remote_bash: [
112
+ { file: commands_file_1 },
113
+ 'echo Hello3',
114
+ { file: commands_file_2 },
115
+ 'echo Hello6'
116
+ ] }]
117
+ )
118
118
  test_actions_executor.stdout_device << "Hello1\nHello2\nHello3\nHello4\nHello5\nHello6\n"
119
119
  { 'node1' => [0, "Hello1\nHello2\nHello3\nHello4\nHello5\nHello6\n", ''] }
120
120
  end])
121
121
  exit_code, stdout, stderr = run 'run', '--node', 'node1', '--commands-file', commands_file_1, '--command', 'echo Hello3', '--commands-file', commands_file_2, '--command', 'echo Hello6'
122
122
  expect(exit_code).to eq 0
123
- expect(stdout).to match /Hello1/
124
- expect(stdout).to match /Hello2/
125
- expect(stdout).to match /Hello3/
126
- expect(stdout).to match /Hello4/
127
- expect(stdout).to match /Hello5/
128
- expect(stdout).to match /Hello6/
123
+ expect(stdout).to match(/Hello1/)
124
+ expect(stdout).to match(/Hello2/)
125
+ expect(stdout).to match(/Hello3/)
126
+ expect(stdout).to match(/Hello4/)
127
+ expect(stdout).to match(/Hello5/)
128
+ expect(stdout).to match(/Hello6/)
129
129
  expect(stderr).to eq ''
130
130
  end
131
131
  end
@@ -140,14 +140,14 @@ describe 'run executable' do
140
140
  end])
141
141
  exit_code, stdout, stderr = run 'run', '--node', 'node1', '--node', 'node2', '--command', 'echo Hello', '--parallel'
142
142
  expect(exit_code).to eq 0
143
- expect(stdout).to match /Hello/
143
+ expect(stdout).to match(/Hello/)
144
144
  expect(stderr).to eq ''
145
145
  end
146
146
  end
147
147
 
148
148
  it 'executes an interactive session on a node' do
149
149
  with_test_platform_for_run do
150
- expect_actions_executor_runs([proc do |actions, timeout: nil, concurrent: false, log_to_dir: 'run_logs', log_to_stdout: true|
150
+ expect_actions_executor_runs([proc do |actions|
151
151
  expect(actions).to eq(['node1'] => [{ interactive: true }])
152
152
  { 'node1' => [0, '', ''] }
153
153
  end])
@@ -3,31 +3,29 @@ describe 'ssh_config executable' do
3
3
  # Setup a platform for ssh_config tests
4
4
  #
5
5
  # Parameters::
6
- # * Proc: Code called when the platform is setup
6
+ # * *block* (Proc): Code called when the platform is setup
7
7
  # * Parameters::
8
8
  # * *repository* (String): Platform's repository
9
- def with_test_platform_for_ssh_config
10
- with_test_platform({ nodes: { 'node1' => {}, 'node2' => {} } }) do |repository|
11
- yield repository
12
- end
9
+ def with_test_platform_for_ssh_config(&block)
10
+ with_test_platform({ nodes: { 'node1' => {}, 'node2' => {} } }, &block)
13
11
  end
14
12
 
15
13
  it 'dumps the SSH config without arguments' do
16
14
  with_test_platform_for_ssh_config do
17
- expect(test_actions_executor.connector(:ssh)).to receive(:ssh_config).with(ssh_exec: 'ssh') { '# SSH config' }
15
+ expect(test_actions_executor.connector(:ssh)).to receive(:ssh_config).with(ssh_exec: 'ssh').and_return('# SSH config')
18
16
  exit_code, stdout, stderr = run 'ssh_config'
19
17
  expect(exit_code).to eq 0
20
- expect(stdout).to match /# SSH config/
18
+ expect(stdout).to match(/# SSH config/)
21
19
  expect(stderr).to eq ''
22
20
  end
23
21
  end
24
22
 
25
23
  it 'dumps the SSH config with an alternate SSH executable' do
26
24
  with_test_platform_for_ssh_config do
27
- expect(test_actions_executor.connector(:ssh)).to receive(:ssh_config).with(ssh_exec: 'my_ssh') { '# SSH config' }
25
+ expect(test_actions_executor.connector(:ssh)).to receive(:ssh_config).with(ssh_exec: 'my_ssh').and_return('# SSH config')
28
26
  exit_code, stdout, stderr = run 'ssh_config', '--ssh-exec', 'my_ssh'
29
27
  expect(exit_code).to eq 0
30
- expect(stdout).to match /# SSH config/
28
+ expect(stdout).to match(/# SSH config/)
31
29
  expect(stderr).to eq ''
32
30
  end
33
31
  end
@@ -3,13 +3,11 @@ describe 'test executable' do
3
3
  # Setup a platform for test tests
4
4
  #
5
5
  # Parameters::
6
- # * Proc: Code called when the platform is setup
6
+ # * *block* (Proc): Code called when the platform is setup
7
7
  # * Parameters::
8
8
  # * *repository* (String): Platform's repository
9
- def with_test_platform_for_test
10
- with_test_platform({ nodes: { 'node' => {} } }) do |repository|
11
- yield repository
12
- end
9
+ def with_test_platform_for_test(&block)
10
+ with_test_platform({ nodes: { 'node' => {} } }, &block)
13
11
  end
14
12
 
15
13
  it 'executes a given test on a given node' do
@@ -58,7 +58,7 @@ module HybridPlatformsConductorTest
58
58
  def with_connections_mocked_on(expected_nodes)
59
59
  expect(test_actions_executor).to receive(:with_connections_prepared_to) do |nodes, no_exception: false, &client_code|
60
60
  expect(nodes.sort).to eq expected_nodes.sort
61
- client_code.call Hash[nodes.map { |node| [node, test_actions_executor.connector(:test_connector)] }]
61
+ client_code.call nodes.map { |node| [node, test_actions_executor.connector(:test_connector)] }.to_h
62
62
  end
63
63
  yield
64
64
  end
@@ -87,7 +87,7 @@ module HybridPlatformsConductorTest
87
87
  # Result::
88
88
  # * ActionsExecutor: ActionsExecutor on which we can do testing
89
89
  def test_actions_executor
90
- @actions_executor = HybridPlatformsConductor::ActionsExecutor.new logger: logger, logger_stderr: logger, config: test_config, cmd_runner: test_cmd_runner, nodes_handler: test_nodes_handler unless @actions_executor
90
+ @actions_executor ||= HybridPlatformsConductor::ActionsExecutor.new logger: logger, logger_stderr: logger, config: test_config, cmd_runner: test_cmd_runner, nodes_handler: test_nodes_handler
91
91
  @actions_executor
92
92
  end
93
93
 
@@ -38,6 +38,7 @@ module HybridPlatformsConductorTest
38
38
  remaining_expected_commands_mutex.synchronize do
39
39
  remaining_expected_commands.delete_if do |(expected_command, command_code, _options)|
40
40
  break unless found_command.nil?
41
+
41
42
  if (expected_command.is_a?(String) && expected_command == cmd) || (expected_command.is_a?(Regexp) && cmd =~ expected_command)
42
43
  found_command = expected_command
43
44
  found_command_code = command_code
@@ -86,8 +87,8 @@ module HybridPlatformsConductorTest
86
87
  end
87
88
  yield
88
89
  expect(
89
- remaining_expected_commands.select do |(_expected_command, _command_code, options)|
90
- !options[:optional]
90
+ remaining_expected_commands.reject do |(_expected_command, _command_code, options)|
91
+ options[:optional]
91
92
  end
92
93
  ).to eq([]), "Expected CmdRunner commands were not run:\n#{
93
94
  remaining_expected_commands.map do |(expected_command, _command_code, options)|
@@ -103,7 +104,7 @@ module HybridPlatformsConductorTest
103
104
  # Result::
104
105
  # * CmdRunner: CmdRunner on which we can do testing
105
106
  def test_cmd_runner
106
- @cmd_runner = HybridPlatformsConductor::CmdRunner.new logger: logger, logger_stderr: logger unless @cmd_runner
107
+ @cmd_runner ||= HybridPlatformsConductor::CmdRunner.new logger: logger, logger_stderr: logger
107
108
  @cmd_runner
108
109
  end
109
110
 
@@ -21,12 +21,12 @@ module HybridPlatformsConductorTest
21
21
  def register_test_cmdb(cmdb_names = [:test_cmdb])
22
22
  register_plugins(
23
23
  :cmdb,
24
- Hash[cmdb_names.map do |plugin_id|
24
+ cmdb_names.map do |plugin_id|
25
25
  [
26
26
  plugin_id,
27
27
  HybridPlatformsConductorTest::CmdbPlugins.const_get(plugin_id.to_s.split('_').collect(&:capitalize).join.to_sym)
28
28
  ]
29
- end]
29
+ end.to_h
30
30
  )
31
31
  end
32
32
 
@@ -9,7 +9,7 @@ module HybridPlatformsConductorTest
9
9
  # Result::
10
10
  # * Config: Config on which we can do testing
11
11
  def test_config
12
- @config = HybridPlatformsConductor::Config.new logger: logger, logger_stderr: logger unless @config
12
+ @config ||= HybridPlatformsConductor::Config.new logger: logger, logger_stderr: logger
13
13
  @config
14
14
  end
15
15
 
@@ -41,30 +41,30 @@ module HybridPlatformsConductorTest
41
41
  ssh_commands_per_connection = []
42
42
  if with_strict_host_key_checking
43
43
  ip = node_connection_info[:ip] || node_connection_info[:connection]
44
- ssh_commands_once.concat([
44
+ ssh_commands_once.concat(
45
45
  [
46
- "ssh-keyscan #{ip}",
47
- proc { [0, "#{ip} ssh-rsa fake_host_key_for_#{ip}", ''] }
46
+ [
47
+ "ssh-keyscan #{ip}",
48
+ proc { [0, "#{ip} ssh-rsa fake_host_key_for_#{ip}", ''] }
49
+ ]
48
50
  ]
49
- ])
51
+ )
50
52
  end
51
53
  if with_control_master_create
52
54
  control_master_created = false
53
55
  ssh_commands_per_connection << [
54
56
  if with_session_exec
55
- /^.+\/ssh #{with_batch_mode ? '-o BatchMode=yes ' : ''}-o ControlMaster=yes -o ControlPersist=yes hpc\.#{Regexp.escape(node)} true$/
57
+ %r{^.+/ssh #{with_batch_mode ? '-o BatchMode=yes ' : ''}-o ControlMaster=yes -o ControlPersist=yes hpc\.#{Regexp.escape(node)} true$}
56
58
  else
57
59
  unless ENV['hpc_interactive'] == 'false'
58
60
  # Mock the user hitting enter as the Control Master will be created in another thread and the main thread waits for user input.
59
61
  expect($stdin).to receive(:gets) do
60
62
  # We have to wait for the Control Master creation thread to actually create the Control Master before hitting Enter.
61
- while !control_master_created do
62
- sleep 0.1
63
- end
63
+ sleep 0.1 until control_master_created
64
64
  "\n"
65
65
  end
66
66
  end
67
- /^xterm -e '.+\/ssh -o ControlMaster=yes -o ControlPersist=yes hpc\.#{Regexp.escape(node)}'$/
67
+ %r{^xterm -e '.+/ssh -o ControlMaster=yes -o ControlPersist=yes hpc\.#{Regexp.escape(node)}'$}
68
68
  end,
69
69
  proc do
70
70
  control_file = test_actions_executor.connector(:ssh).send(:control_master_file, node_connection_info[:connection], '22', node_connection_info[:user])
@@ -88,13 +88,13 @@ module HybridPlatformsConductorTest
88
88
  end
89
89
  if with_control_master_check
90
90
  ssh_commands_per_connection << [
91
- /^.+\/ssh -O check hpc\.#{Regexp.escape(node)}$/,
91
+ %r{^.+/ssh -O check hpc\.#{Regexp.escape(node)}$},
92
92
  proc { [0, '', ''] }
93
93
  ]
94
94
  end
95
95
  if with_control_master_destroy
96
96
  ssh_commands_per_connection << [
97
- /^.+\/ssh -O exit hpc\.#{Regexp.escape(node)} 2>&1 \| grep -v 'Exit request sent\.'$/,
97
+ %r{^.+/ssh -O exit hpc\.#{Regexp.escape(node)} 2>&1 \| grep -v 'Exit request sent\.'$},
98
98
  proc do
99
99
  # Really mock the control file deletion
100
100
  File.unlink(test_actions_executor.connector(:ssh).send(:control_master_file, node_connection_info[:connection], '22', node_connection_info[:user]))
@@ -137,8 +137,7 @@ module HybridPlatformsConductorTest
137
137
  )
138
138
  with_test_platform(
139
139
  { nodes: { 'node' => { meta: { host_ip: '192.168.42.42', ssh_session_exec: session_exec } } } },
140
- false,
141
- additional_config
140
+ additional_config: additional_config
142
141
  ) do
143
142
  with_cmd_runner_mocked(
144
143
  [
@@ -12,7 +12,7 @@ module HybridPlatformsConductorTest
12
12
  # * *sudo* (String or nil): sudo supposed to be used, or nil if none [default: 'sudo -u root']
13
13
  def expect_action_to_lock_node(action, node, sudo: 'sudo -u root')
14
14
  expect(action[:scp].size).to eq 1
15
- expect(action[:scp].first[0]).to match /^.+\/mutex_dir$/
15
+ expect(action[:scp].first[0]).to match(%r{^.+/mutex_dir$})
16
16
  expect(action[:scp].first[1]).to eq '.'
17
17
  expect(action[:remote_bash]).to eq "while ! #{sudo ? "#{sudo} " : ''}./mutex_dir lock /tmp/hybrid_platforms_conductor_deploy_lock \"$(ps -o ppid= -p $$)\"; do echo -e 'Another deployment is running on #{node}. Waiting for it to finish to continue...' ; sleep 5 ; done"
18
18
  end
@@ -23,7 +23,7 @@ module HybridPlatformsConductorTest
23
23
  # * *action* (Hash<Symbol,Object>): The action to check
24
24
  # * *node* (String): The concerned node
25
25
  # * *sudo* (String or nil): sudo supposed to be used, or nil if none [default: 'sudo -u root']
26
- def expect_action_to_unlock_node(action, node, sudo: 'sudo -u root')
26
+ def expect_action_to_unlock_node(action, _node, sudo: 'sudo -u root')
27
27
  expect(action).to eq(remote_bash: "#{sudo ? "#{sudo} " : ''}./mutex_dir unlock /tmp/hybrid_platforms_conductor_deploy_lock")
28
28
  end
29
29
 
@@ -40,7 +40,7 @@ module HybridPlatformsConductorTest
40
40
  # * Hash<String, [Integer or Symbol, String, String] >: Expected result of those expected actions
41
41
  def expect_actions_to_deploy_on(actions, nodes, check: false, sudo: 'sudo -u root', expected_actions: [], mocked_result: nil)
42
42
  nodes = [nodes] if nodes.is_a?(String)
43
- mocked_result = Hash[nodes.map { |node| [node, [0, "#{check ? 'Check' : 'Deploy'} successful", '']] }] if mocked_result.nil?
43
+ mocked_result = nodes.map { |node| [node, [0, "#{check ? 'Check' : 'Deploy'} successful", '']] }.to_h if mocked_result.nil?
44
44
  expect(actions.size).to eq nodes.size
45
45
  nodes.each do |node|
46
46
  expect(actions.key?(node)).to eq true
@@ -65,7 +65,7 @@ module HybridPlatformsConductorTest
65
65
  expect(actions.key?(node)).to eq true
66
66
  expect_action_to_unlock_node(actions[node], node, sudo: sudo)
67
67
  end
68
- Hash[nodes.map { |node| [node, [0, 'Release mutex successful', '']] }]
68
+ nodes.map { |node| [node, [0, 'Release mutex successful', '']] }.to_h
69
69
  end
70
70
 
71
71
  # Expect a given set of actions to upload log files on a list of nodes (using the test_log log plugin)
@@ -80,7 +80,7 @@ module HybridPlatformsConductorTest
80
80
  expect(actions.key?(node)).to eq true
81
81
  expect(actions[node]).to eq [{ bash: "echo Save test logs to #{node}" }]
82
82
  end
83
- Hash[nodes.map { |node| [node, [0, 'Logs uploaded', '']] }]
83
+ nodes.map { |node| [node, [0, 'Logs uploaded', '']] }.to_h
84
84
  end
85
85
 
86
86
  # Get a test Deployer
@@ -88,7 +88,7 @@ module HybridPlatformsConductorTest
88
88
  # Result::
89
89
  # * Deployer: Deployer on which we can do testing
90
90
  def test_deployer
91
- @deployer = HybridPlatformsConductor::Deployer.new logger: logger, logger_stderr: logger, config: test_config, cmd_runner: test_cmd_runner, nodes_handler: test_nodes_handler, actions_executor: test_actions_executor, services_handler: test_services_handler unless @deployer
91
+ @deployer ||= HybridPlatformsConductor::Deployer.new logger: logger, logger_stderr: logger, config: test_config, cmd_runner: test_cmd_runner, nodes_handler: test_nodes_handler, actions_executor: test_actions_executor, services_handler: test_services_handler
92
92
  @deployer
93
93
  end
94
94
 
@@ -99,11 +99,8 @@ module HybridPlatformsConductorTest
99
99
  def expect_services_handler_to_deploy(services)
100
100
  expect(test_services_handler).to receive(:deploy_allowed?).with(
101
101
  services: services,
102
- secrets: {},
103
102
  local_environment: false
104
- ) do
105
- nil
106
- end
103
+ ).and_return(nil)
107
104
  expect(test_services_handler).to receive(:package).with(
108
105
  services: services,
109
106
  secrets: {},
@@ -115,20 +112,225 @@ module HybridPlatformsConductorTest
115
112
  local_environment: false,
116
113
  why_run: false
117
114
  )
118
- services.each do |node, services|
119
- expect(test_services_handler).to receive(:actions_to_deploy_on).with(node, services, false) do
115
+ services.each do |node, node_services|
116
+ expect(test_services_handler).to receive(:actions_to_deploy_on).with(node, node_services, false) do
120
117
  [{ bash: "echo \"Deploying on #{node}\"" }]
121
118
  end
122
- expect(test_services_handler).to receive(:log_info_for).with(node, services) do
119
+ expect(test_services_handler).to receive(:log_info_for).with(node, node_services) do
123
120
  {
124
121
  repo_name_0: 'platform',
125
122
  commit_id_0: '123456',
126
- commit_message_0: "Test commit for #{node}: #{services.join(', ')}"
123
+ commit_message_0: "Test commit for #{node}: #{node_services.join(', ')}"
127
124
  }
128
125
  end
129
126
  end
130
127
  end
131
128
 
129
+ # Get expected actions for a deployment
130
+ #
131
+ # Parameters::
132
+ # * *services* (Hash<String, Array<String> >): Expected nodes that should be deployed, with their corresponding services [default: { 'node' => %w[service] }]
133
+ # * *sudo* (String or nil): sudo supposed to be used, or nil if none [default: 'sudo -u root']
134
+ # * *check_mode* (Boolean): Are we testing in check mode? [default: @check_mode]
135
+ # * *mocked_deploy_result* (Hash or nil): Mocked result of the deployment actions, or nil to use the helper's default [default: nil]
136
+ # * *additional_expected_actions* (Array): Additional expected actions [default: []]
137
+ # * *expect_concurrent_actions* (Boolean): Are actions expected to be run in parallel? [default: false]
138
+ # * *expect_actions_timeout* (Integer or nil): Expected timeout in actions, or nil for none [default: nil]
139
+ def expected_actions_for_deploy_on(
140
+ services: { 'node' => %w[service] },
141
+ sudo: 'sudo -u root',
142
+ check_mode: @check_mode,
143
+ mocked_deploy_result: nil,
144
+ additional_expected_actions: [],
145
+ expect_concurrent_actions: false,
146
+ expect_actions_timeout: nil
147
+ )
148
+ actions = [
149
+ # First run, we expect the mutex to be setup, and the deployment actions to be run
150
+ proc do |actions_per_nodes, timeout: nil, concurrent: false, log_to_dir: 'run_logs', log_to_stdout: true|
151
+ expect(timeout).to eq expect_actions_timeout
152
+ expect(concurrent).to eq expect_concurrent_actions
153
+ expect(log_to_dir).to eq 'run_logs'
154
+ expect_actions_to_deploy_on(
155
+ actions_per_nodes,
156
+ services.keys,
157
+ check: check_mode,
158
+ sudo: sudo,
159
+ mocked_result: mocked_deploy_result,
160
+ expected_actions: additional_expected_actions
161
+ )
162
+ end,
163
+ # Second run, we expect the mutex to be released
164
+ proc { |actions_per_nodes| expect_actions_to_unlock(actions_per_nodes, services.keys, sudo: sudo) }
165
+ ]
166
+ services.each do |node, node_services|
167
+ expect(test_services_handler).to receive(:actions_to_deploy_on).with(node, node_services, check_mode) do
168
+ [{ bash: "echo \"#{check_mode ? 'Checking' : 'Deploying'} on #{node}\"" }]
169
+ end
170
+ end
171
+ # Third run, we expect logs to be uploaded on the node (only if not check mode)
172
+ unless check_mode
173
+ services.each do |node, node_services|
174
+ expect(test_services_handler).to receive(:log_info_for).with(node, node_services).and_return(
175
+ repo_name_0: 'platform',
176
+ commit_id_0: '123456',
177
+ commit_message_0: 'Test commit'
178
+ )
179
+ end
180
+ actions << proc { |actions_per_nodes| expect_actions_to_upload_logs(actions_per_nodes, services.keys) }
181
+ end
182
+ actions
183
+ end
184
+
185
+ # Prepare a platform ready to test deployments on.
186
+ #
187
+ # Parameters::
188
+ # * *nodes_info* (Hash): Node info to give the platform [default: 1 node having 1 service]
189
+ # * *expect_services_to_deploy* (Hash<String,Array<String>>): Expected services to be deployed [default: all services from nodes_info]
190
+ # * *expect_deploy_allowed* (Boolean): Should we expect the call to deploy_allowed? [default: true]
191
+ # * *expect_package* (Boolean): Should we expect packaging? [default: true]
192
+ # * *expect_prepare_for_deploy* (Boolean): Should we expect calls to prepare for deploy? [default: true]
193
+ # * *expect_connections_to_nodes* (Boolean): Should we expect connections to nodes? [default: true]
194
+ # * *expect_default_actions* (Boolean): Should we expect default actions? [default: true]
195
+ # * *expect_sudo* (String or nil): Expected sudo command, or nil if none [default: 'sudo -u root']
196
+ # * *expect_secrets* (Hash): Secrets to be expected during deployment [default: {}]
197
+ # * *expect_local_environment* (Boolean): Expected local environment flag [default: false]
198
+ # * *expect_additional_actions* (Array): Additional expected actions [default: []]
199
+ # * *expect_concurrent_actions* (Boolean): Are actions expected to be run in parallel? [default: false]
200
+ # * *expect_actions_timeout* (Integer or nil): Expected timeout in actions, or nil for none [default: nil]
201
+ # * *check_mode* (Boolean): Are we testing in check mode? [default: @check_mode]
202
+ # * *additional_config* (String): Additional configuration to set [default: '']
203
+ # * Proc: Code called once the platform is ready for testing the deployer
204
+ # * Parameters::
205
+ # * *repository* (String): Path to the repository
206
+ def with_platform_to_deploy(
207
+ nodes_info: { nodes: { 'node' => { services: %w[service] } } },
208
+ expect_services_to_deploy: nodes_info[:nodes].transform_values { |node_info| node_info[:services] },
209
+ expect_deploy_allowed: true,
210
+ expect_package: true,
211
+ expect_prepare_for_deploy: true,
212
+ expect_connections_to_nodes: true,
213
+ expect_default_actions: true,
214
+ expect_sudo: 'sudo -u root',
215
+ expect_secrets: {},
216
+ expect_local_environment: false,
217
+ expect_additional_actions: [],
218
+ expect_concurrent_actions: false,
219
+ expect_actions_timeout: nil,
220
+ check_mode: @check_mode,
221
+ additional_config: ''
222
+ )
223
+ with_test_platform(nodes_info, as_git: !check_mode, additional_config: "#{additional_config}\nsend_logs_to :test_log") do |repository|
224
+ # Mock the ServicesHandler accesses
225
+ if !check_mode && expect_deploy_allowed
226
+ expect(test_services_handler).to receive(:deploy_allowed?).with(
227
+ services: expect_services_to_deploy,
228
+ local_environment: expect_local_environment
229
+ ).and_return(nil)
230
+ end
231
+ if expect_package
232
+ expect(test_services_handler).to receive(:package).with(
233
+ services: expect_services_to_deploy,
234
+ secrets: expect_secrets,
235
+ local_environment: expect_local_environment
236
+ )
237
+ else
238
+ expect(test_services_handler).not_to receive(:package)
239
+ end
240
+ if expect_prepare_for_deploy
241
+ expect(test_services_handler).to receive(:prepare_for_deploy).with(
242
+ services: expect_services_to_deploy,
243
+ secrets: expect_secrets,
244
+ local_environment: expect_local_environment,
245
+ why_run: check_mode
246
+ )
247
+ else
248
+ expect(test_services_handler).not_to receive(:prepare_for_deploy)
249
+ end
250
+ test_deployer.use_why_run = true if check_mode
251
+ if expect_connections_to_nodes
252
+ with_connections_mocked_on(expect_services_to_deploy.keys) do
253
+ if expect_default_actions
254
+ expect_actions_executor_runs(
255
+ expected_actions_for_deploy_on(
256
+ services: expect_services_to_deploy,
257
+ check_mode: check_mode,
258
+ sudo: expect_sudo,
259
+ additional_expected_actions: expect_additional_actions,
260
+ expect_concurrent_actions: expect_concurrent_actions,
261
+ expect_actions_timeout: expect_actions_timeout
262
+ )
263
+ )
264
+ end
265
+ yield repository
266
+ end
267
+ else
268
+ yield repository
269
+ end
270
+ end
271
+ end
272
+
273
+ # Prepare a directory with certificates
274
+ #
275
+ # Parameters::
276
+ # * Proc: Code called with the directory created with a mocked certificate
277
+ # * Parameters::
278
+ # * *certs_dir* (String): Directory containing certificates
279
+ def with_certs_dir
280
+ with_repository do |repository|
281
+ certs_dir = "#{repository}/certificates"
282
+ FileUtils.mkdir_p certs_dir
283
+ File.write("#{certs_dir}/test_cert.crt", 'Hello')
284
+ yield certs_dir
285
+ end
286
+ end
287
+
288
+ # Prepare a platform ready to test deployments' retries on.
289
+ #
290
+ # Parameters::
291
+ # * *nodes_info* (Hash): Node info to give the platform [default: { nodes: { 'node' => {} } }]
292
+ # * *block* (Proc): Code called once the platform is ready for testing the deployer
293
+ # * Parameters::
294
+ # * *repository* (String): Path to the repository
295
+ def with_platform_to_retry_deploy(nodes_info: { nodes: { 'node' => { services: %w[service] } } }, &block)
296
+ with_platform_to_deploy(
297
+ nodes_info: nodes_info,
298
+ expect_default_actions: false,
299
+ additional_config: "
300
+ for_nodes([#{nodes_info[:nodes].keys.map { |node| "'#{node}'" }.join(', ')}]) do
301
+ retry_deploy_for_errors_on_stdout [
302
+ 'stdout non-deterministic error'
303
+ ]
304
+ retry_deploy_for_errors_on_stderr [
305
+ 'stderr non-deterministic error',
306
+ /stderr regexp error \\d+/
307
+ ]
308
+ end
309
+ for_nodes([#{nodes_info[:nodes].keys.map { |node| "'#{node}'" }.join(', ')}]) do
310
+ retry_deploy_for_errors_on_stdout [
311
+ /stdout regexp error \\d+/
312
+ ]
313
+ end
314
+ ",
315
+ &block
316
+ )
317
+ end
318
+
319
+ # Mock a sequential list of deployments
320
+ #
321
+ # Parameters::
322
+ # * *statuses* (Array<Hash<String,Status> or Status>)>): List of mocked deployment statuses per node name, or just the status for the default node.
323
+ # A status is a triplet [Integer or Symbol, String, String]: exit status, stdout and stderr.
324
+ def mock_deploys_with(statuses)
325
+ expect_actions_executor_runs(statuses.map do |status|
326
+ status = { 'node' => status } if status.is_a?(Array)
327
+ expected_actions_for_deploy_on(
328
+ services: status.keys.map { |node| [node, %w[service]] }.to_h,
329
+ mocked_deploy_result: status
330
+ )
331
+ end.flatten)
332
+ end
333
+
132
334
  end
133
335
 
134
336
  end