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
@@ -18,8 +18,8 @@ module HybridPlatformsConductorTest
18
18
  stderr_file = "#{Dir.tmpdir}/hpc_test/run.stderr"
19
19
  File.open(stdout_file, 'w') { |f| f.truncate(0) }
20
20
  File.open(stderr_file, 'w') { |f| f.truncate(0) }
21
- logger_stdout = Logger.new(stdout_file, level: :info)
22
- logger_stderr = Logger.new(stderr_file, level: :info)
21
+ test_logger_stdout = Logger.new(stdout_file, level: :info)
22
+ test_logger_stderr = Logger.new(stderr_file, level: :info)
23
23
  # Mock the Executable creation to redirect stdout and stderr correctly
24
24
  expect(HybridPlatformsConductor::Executable).to receive(:new).once.and_wrap_original do |original_method,
25
25
  check_options: true,
@@ -27,8 +27,8 @@ module HybridPlatformsConductorTest
27
27
  parallel_options: true,
28
28
  timeout_options: true,
29
29
  deploy_options: true,
30
- original_logger: Logger.new(STDOUT, level: :info),
31
- original_logger_stderr: Logger.new(STDERR, level: :info),
30
+ _logger: Logger.new($stdout, level: :info),
31
+ _logger_stderr: Logger.new($stderr, level: :info),
32
32
  &opts_block|
33
33
  original_method.call(
34
34
  check_options: check_options,
@@ -36,8 +36,8 @@ module HybridPlatformsConductorTest
36
36
  parallel_options: parallel_options,
37
37
  timeout_options: timeout_options,
38
38
  deploy_options: deploy_options,
39
- logger: logger_stdout,
40
- logger_stderr: logger_stderr,
39
+ logger: test_logger_stdout,
40
+ logger_stderr: test_logger_stderr,
41
41
  &opts_block
42
42
  )
43
43
  end
@@ -53,18 +53,18 @@ module HybridPlatformsConductorTest
53
53
  HybridPlatformsConductor::TestsRunner => test_tests_runner
54
54
  }
55
55
  # Make sure the tested components use the same loggers as the executable.
56
- components_to_mock.values.each do |component|
56
+ components_to_mock.each_value do |component|
57
57
  component.stdout_device = stdout_file
58
58
  component.stderr_device = stderr_file
59
59
  end
60
60
  # Make sure that when the executable creates components it uses ours
61
61
  components_to_mock.each do |component_class, component|
62
- allow(component_class).to receive(:new).once { component }
62
+ allow(component_class).to(receive(:new).once { component })
63
63
  end
64
64
  # Run the executable
65
65
  args.concat(['--debug']) if ENV['TEST_DEBUG'] == '1'
66
66
  ARGV.replace(args)
67
- old_0 = $0
67
+ old_program_name = $PROGRAM_NAME
68
68
  $0 = executable
69
69
  begin
70
70
  exit_code = nil
@@ -72,10 +72,10 @@ module HybridPlatformsConductorTest
72
72
  load "#{__dir__}/../../../bin/#{executable}"
73
73
  exit_code = 0
74
74
  rescue SystemExit
75
- exit_code = $!.status
75
+ exit_code = $ERROR_INFO.status
76
76
  end
77
77
  ensure
78
- $0 = old_0
78
+ $0 = old_program_name
79
79
  end
80
80
  stdout = File.read(stdout_file)
81
81
  stderr = File.read(stderr_file)
@@ -9,7 +9,7 @@ module HybridPlatformsConductorTest
9
9
  # Result::
10
10
  # * NodesHandler: NodesHandler on which we can do testing
11
11
  def test_nodes_handler
12
- @nodes_handler = HybridPlatformsConductor::NodesHandler.new logger: logger, logger_stderr: logger, config: test_config, cmd_runner: test_cmd_runner, platforms_handler: test_platforms_handler unless @nodes_handler
12
+ @nodes_handler ||= HybridPlatformsConductor::NodesHandler.new logger: logger, logger_stderr: logger, config: test_config, cmd_runner: test_cmd_runner, platforms_handler: test_platforms_handler
13
13
  @nodes_handler
14
14
  end
15
15
 
@@ -14,24 +14,24 @@ module HybridPlatformsConductorTest
14
14
  # * Parameters::
15
15
  # * *repositories* (Hash<String,String>): Path to the repositories, per repository name
16
16
  def with_repositories(names = [], as_git: false)
17
- repositories = Hash[names.map { |name| [name, "#{Dir.tmpdir}/hpc_test/#{name}"] }]
18
- repositories.values.each do |dir|
17
+ repositories = names.map { |name| [name, "#{Dir.tmpdir}/hpc_test/#{name}"] }.to_h
18
+ repositories.each_value do |dir|
19
19
  FileUtils.rm_rf dir
20
20
  FileUtils.mkdir_p dir
21
- if as_git
22
- git = Git.init(dir)
23
- FileUtils.touch("#{dir}/test_file")
24
- git.add('test_file')
25
- git.config('user.name', 'Thats Me')
26
- git.config('user.email', 'email@email.com')
27
- git.commit('Test commit')
28
- git.add_remote('origin', "https://my_remote.com/path/to/#{File.basename(dir)}.git")
29
- end
21
+ next unless as_git
22
+
23
+ git = Git.init(dir)
24
+ FileUtils.touch("#{dir}/test_file")
25
+ git.add('test_file')
26
+ git.config('user.name', 'Thats Me')
27
+ git.config('user.email', 'email@email.com')
28
+ git.commit('Test commit')
29
+ git.add_remote('origin', "https://my_remote.com/path/to/#{File.basename(dir)}.git")
30
30
  end
31
31
  begin
32
32
  yield repositories
33
33
  ensure
34
- repositories.values.each do |dir|
34
+ repositories.each_value do |dir|
35
35
  FileUtils.rm_rf dir
36
36
  end
37
37
  end
@@ -73,21 +73,28 @@ module HybridPlatformsConductorTest
73
73
  # Clean-up at the end.
74
74
  #
75
75
  # Parameters::
76
- # * *platforms_info* (Hash<String,Object>): Platforms info for the test platform [default = {}]
77
- # * *as_git* (Boolean): Do we initialize those repositories as Git repositories? [default = false]
78
- # * *additional_platforms_content* (String): Additional platforms content to be added [default = '']
76
+ # * *platforms_info* (Hash<String,Object>): Platforms info for the test platform
77
+ # * *as_git* (Boolean): Do we initialize those repositories as Git repositories? [default: false]
78
+ # * *additional_config* (String): Additional config to be added [default: '']
79
79
  # * Proc: Code called with the environment ready
80
80
  # * Parameters::
81
81
  # * *repositories* (Hash<String,String>): Path to the repositories, per repository name
82
- def with_test_platforms(platforms_info = {}, as_git = false, additional_platforms_content = '')
82
+ def with_test_platforms(platforms_info, as_git: false, additional_config: '')
83
83
  with_repositories(platforms_info.keys, as_git: as_git) do |repositories|
84
84
  platform_types = []
85
- with_platforms(repositories.map do |platform, dir|
86
- platform_type = platforms_info[platform].key?(:platform_type) ? platforms_info[platform][:platform_type] : :test
87
- platform_types << platform_type unless platform_types.include?(platform_type)
88
- "#{platform_type}_platform path: '#{dir}'"
89
- end.join("\n") + "\n#{additional_platforms_content}") do
90
- register_platform_handlers(Hash[platform_types.map { |platform_type| [platform_type, HybridPlatformsConductorTest::PlatformHandlerPlugins.const_get(platform_type.to_s.split('_').collect(&:capitalize).join.to_sym)] }])
85
+ with_platforms(
86
+ repositories.map do |platform, dir|
87
+ platform_type = platforms_info[platform].key?(:platform_type) ? platforms_info[platform][:platform_type] : :test
88
+ platform_types << platform_type unless platform_types.include?(platform_type)
89
+ "#{platform_type}_platform path: '#{dir}'"
90
+ end.join("\n") + "\n#{additional_config}"
91
+ ) do
92
+ register_platform_handlers(platform_types.map do |platform_type|
93
+ [
94
+ platform_type,
95
+ HybridPlatformsConductorTest::PlatformHandlerPlugins.const_get(platform_type.to_s.split('_').collect(&:capitalize).join.to_sym)
96
+ ]
97
+ end.to_h)
91
98
  self.test_platforms_info = platforms_info
92
99
  yield repositories
93
100
  end
@@ -98,15 +105,19 @@ module HybridPlatformsConductorTest
98
105
  # Clean-up at the end.
99
106
  #
100
107
  # Parameters::
101
- # * *platform_info* (Hash<Symbol,Object>): Platform info for the test platform [default = {}]
102
- # * *as_git* (Boolean): Do we initialize those repositories as Git repositories? [default = false]
103
- # * *additional_platforms_content* (String): Additional platforms content to be added [default = '']
108
+ # * *platform_info* (Hash<Symbol,Object>): Platform info for the test platform
109
+ # * *as_git* (Boolean): Do we initialize those repositories as Git repositories? [default: false]
110
+ # * *additional_config* (String): Additional config to be added [default: '']
104
111
  # * Proc: Code called with the environment ready
105
112
  # * Parameters::
106
113
  # * *repository* (String): Path to the repository
107
- def with_test_platform(platform_info = {}, as_git = false, additional_platforms_content = '')
114
+ def with_test_platform(platform_info, as_git: false, additional_config: '')
108
115
  platform_name = as_git ? 'my_remote_platform' : 'platform'
109
- with_test_platforms({ platform_name => platform_info }, as_git, additional_platforms_content) do |repositories|
116
+ with_test_platforms(
117
+ { platform_name => platform_info },
118
+ as_git: as_git,
119
+ additional_config: additional_config
120
+ ) do |repositories|
110
121
  yield repositories[platform_name]
111
122
  end
112
123
  end
@@ -116,7 +127,7 @@ module HybridPlatformsConductorTest
116
127
  # Result::
117
128
  # * PlatformsHandler: PlatformsHandler on which we can do testing
118
129
  def test_platforms_handler
119
- @platforms_handler = HybridPlatformsConductor::PlatformsHandler.new logger: logger, logger_stderr: logger, config: test_config, cmd_runner: test_cmd_runner unless @platforms_handler
130
+ @platforms_handler ||= HybridPlatformsConductor::PlatformsHandler.new logger: logger, logger_stderr: logger, config: test_config, cmd_runner: test_cmd_runner
120
131
  @platforms_handler
121
132
  end
122
133
 
@@ -18,7 +18,7 @@ module HybridPlatformsConductorTest
18
18
  # * *replace* (Boolean): Should we replace the plugins or add them?
19
19
  # Hash< Symbol, Hash<Symbol, Object> >
20
20
  @plugins_to_mock = {}
21
- allow(HybridPlatformsConductor::Plugins).to receive(:new).and_wrap_original do |original_new, plugins_type, init_plugin: nil, parse_gems: true, logger: Logger.new(STDOUT), logger_stderr: Logger.new(STDERR)|
21
+ allow(HybridPlatformsConductor::Plugins).to receive(:new).and_wrap_original do |original_new, plugins_type, init_plugin: nil, parse_gems: true, logger: Logger.new($stdout), logger_stderr: Logger.new($stderr)|
22
22
  # If this plugin type is to be mocked, then don't parse gems and provide the mocked plugins instead
23
23
  mocked_plugins = original_new.call(
24
24
  plugins_type,
@@ -98,21 +98,17 @@ module HybridPlatformsConductorTest
98
98
  expect(password).to eq proxmox_password
99
99
  expect(realm).to eq proxmox_realm
100
100
  expect(options[:verify_ssl]).to eq false
101
- proxmox = double 'Proxmox info instance'
101
+ proxmox = instance_double ::Proxmox::Proxmox
102
102
  # Mock initialization
103
- expect(proxmox).to receive(:logger=) do
104
- # Nothing
105
- end
106
- expect(proxmox).to receive(:logger_stderr=) do
107
- # Nothing
108
- end
103
+ expect(proxmox).to receive(:logger=).and_return(nil)
104
+ expect(proxmox).to receive(:logger_stderr=).and_return(nil)
109
105
  # Mock checking existing nodes
110
106
  idx_try = 0
111
107
  expect(proxmox).to receive(:get).exactly(nbr_api_errors + 1).times.with('nodes') do
112
108
  idx_try += 1
113
109
  idx_try <= nbr_api_errors ? 'NOK: error code = 500' : nodes_info
114
110
  end
115
- extra_expects.call(proxmox) unless extra_expects.nil?
111
+ extra_expects&.call(proxmox)
116
112
  proxmox
117
113
  end
118
114
  end
@@ -142,14 +138,10 @@ module HybridPlatformsConductorTest
142
138
  expect(password).to eq proxmox_password
143
139
  expect(realm).to eq 'pam'
144
140
  expect(options[:verify_ssl]).to eq false
145
- proxmox = double 'Proxmox create instance'
141
+ proxmox = instance_double ::Proxmox::Proxmox
146
142
  # Mock initialization
147
- expect(proxmox).to receive(:logger=) do
148
- # Nothing
149
- end
150
- expect(proxmox).to receive(:logger_stderr=) do
151
- # Nothing
152
- end
143
+ expect(proxmox).to receive(:logger=).and_return(nil)
144
+ expect(proxmox).to receive(:logger_stderr=).and_return(nil)
153
145
  # Mock start a container
154
146
  idx_try = 0
155
147
  expect(proxmox).to receive(:post).exactly(nbr_api_errors + (task_status.nil? ? 0 : 1)).times.with('nodes/pve_node_name/lxc/1024/status/start') do
@@ -189,18 +181,12 @@ module HybridPlatformsConductorTest
189
181
  expect(password).to eq proxmox_password
190
182
  expect(realm).to eq 'pam'
191
183
  expect(options[:verify_ssl]).to eq false
192
- proxmox = double 'Proxmox create instance'
184
+ proxmox = instance_double ::Proxmox::Proxmox
193
185
  # Mock initialization
194
- expect(proxmox).to receive(:logger=) do
195
- # Nothing
196
- end
197
- expect(proxmox).to receive(:logger_stderr=) do
198
- # Nothing
199
- end
186
+ expect(proxmox).to receive(:logger=).and_return(nil)
187
+ expect(proxmox).to receive(:logger_stderr=).and_return(nil)
200
188
  # Mock start a container
201
- expect(proxmox).to receive(:post).with('nodes/pve_node_name/lxc/1024/status/stop') do
202
- 'UPID:pve_node_name:0000A504:6DEABF24:5F44669B:stop::root@pam:'
203
- end
189
+ expect(proxmox).to receive(:post).with('nodes/pve_node_name/lxc/1024/status/stop').and_return('UPID:pve_node_name:0000A504:6DEABF24:5F44669B:stop::root@pam:')
204
190
  # Mock checking task status
205
191
  expect(proxmox).to receive(:get).with('nodes/pve_node_name/tasks/UPID:pve_node_name:0000A504:6DEABF24:5F44669B:stop::root@pam:/status') do
206
192
  { 'status' => task_status }
@@ -230,18 +216,12 @@ module HybridPlatformsConductorTest
230
216
  expect(password).to eq proxmox_password
231
217
  expect(realm).to eq 'pam'
232
218
  expect(options[:verify_ssl]).to eq false
233
- proxmox = double 'Proxmox create instance'
219
+ proxmox = instance_double ::Proxmox::Proxmox
234
220
  # Mock initialization
235
- expect(proxmox).to receive(:logger=) do
236
- # Nothing
237
- end
238
- expect(proxmox).to receive(:logger_stderr=) do
239
- # Nothing
240
- end
221
+ expect(proxmox).to receive(:logger=).and_return(nil)
222
+ expect(proxmox).to receive(:logger_stderr=).and_return(nil)
241
223
  # Mock start a container
242
- expect(proxmox).to receive(:delete).with('nodes/pve_node_name/lxc/1024') do
243
- 'UPID:pve_node_name:0000A504:6DEABF24:5F44669B:destroy::root@pam:'
244
- end
224
+ expect(proxmox).to receive(:delete).with('nodes/pve_node_name/lxc/1024').and_return('UPID:pve_node_name:0000A504:6DEABF24:5F44669B:destroy::root@pam:')
245
225
  # Mock checking task status
246
226
  expect(proxmox).to receive(:get).with('nodes/pve_node_name/tasks/UPID:pve_node_name:0000A504:6DEABF24:5F44669B:destroy::root@pam:/status') do
247
227
  { 'status' => task_status }
@@ -273,14 +253,10 @@ module HybridPlatformsConductorTest
273
253
  expect(password).to eq proxmox_password
274
254
  expect(realm).to eq 'pam'
275
255
  expect(options[:verify_ssl]).to eq false
276
- proxmox = double 'Proxmox create instance'
256
+ proxmox = instance_double ::Proxmox::Proxmox
277
257
  # Mock initialization
278
- expect(proxmox).to receive(:logger=) do
279
- # Nothing
280
- end
281
- expect(proxmox).to receive(:logger_stderr=) do
282
- # Nothing
283
- end
258
+ expect(proxmox).to receive(:logger=).and_return(nil)
259
+ expect(proxmox).to receive(:logger_stderr=).and_return(nil)
284
260
  # Mock getting status of a container
285
261
  idx_try = 0
286
262
  expect(proxmox).to receive(:get).exactly(nbr_api_errors + (status.nil? ? 0 : 1)).times.with('nodes/pve_node_name/lxc') do
@@ -307,6 +283,9 @@ module HybridPlatformsConductorTest
307
283
  end
308
284
  end
309
285
 
286
+ # Give access to the actions that have been called on the mocked Proxmox instances
287
+ attr_reader(*%i[proxmox_actions proxmox_create_options proxmox_destroy_options])
288
+
310
289
  # Mock a call to the reserve_proxmox_container sync node
311
290
  #
312
291
  # Parameters::
@@ -334,24 +313,24 @@ module HybridPlatformsConductorTest
334
313
  expect(actions['node'].size).to eq 4
335
314
  # First action should be to copy the reserve_proxmox_container code
336
315
  expect(actions['node'][0].keys).to eq [:scp]
337
- expect(actions['node'][0][:scp].first[0]).to match /^.+\/hpc_plugins\/provisioner\/proxmox\/$/
316
+ expect(actions['node'][0][:scp].first[0]).to match(%r{^.+/hpc_plugins/provisioner/proxmox/$})
338
317
  expect(actions['node'][0][:scp].first[1]).to eq '.'
339
318
  # Second action should be to create directories
340
- expect(actions['node'][1]).to eq({
319
+ expect(actions['node'][1]).to eq(
341
320
  remote_bash: "mkdir -p ./proxmox/config\nmkdir -p ./proxmox/create"
342
- })
321
+ )
343
322
  # Next actions should be to copy the config/create/destroy files
344
323
  expect(actions['node'][2].keys).to eq [:scp]
345
- expect(actions['node'][2][:scp].first[0]).to match /^.+\/create_#{Regexp.escape(expected_file_id)}\.json$/
324
+ expect(actions['node'][2][:scp].first[0]).to match(%r{^.+/create_#{Regexp.escape(expected_file_id)}\.json$})
346
325
  expect(actions['node'][2][:scp].first[1]).to eq './proxmox/create'
347
326
  expect(actions['node'][3].keys).to eq [:scp]
348
- expect(actions['node'][3][:scp].first[0]).to match /^.+\/config_#{Regexp.escape(expected_file_id)}\.json$/
327
+ expect(actions['node'][3][:scp].first[0]).to match(%r{^.+/config_#{Regexp.escape(expected_file_id)}\.json$})
349
328
  expect(actions['node'][3][:scp].first[1]).to eq './proxmox/config'
350
329
  @proxmox_create_options = JSON.parse(File.read(actions['node'][2][:scp].first[0]))
351
330
  { 'node' => [0, '', ''] }
352
331
  end,
353
332
  proc do |actions|
354
- expect(actions).to eq({
333
+ expect(actions).to eq(
355
334
  'node' => {
356
335
  remote_bash: {
357
336
  commands: "#{expected_sudo ? 'sudo -u root -E ' : ''}./proxmox/reserve_proxmox_container --create ./proxmox/create/create_#{expected_file_id}.json --config ./proxmox/config/config_#{expected_file_id}.json",
@@ -362,7 +341,7 @@ module HybridPlatformsConductorTest
362
341
  }
363
342
  }
364
343
  }
365
- })
344
+ )
366
345
  result =
367
346
  if error_on_create
368
347
  { error: error_on_create }
@@ -373,10 +352,10 @@ module HybridPlatformsConductorTest
373
352
  vm_ip: '192.168.0.100'
374
353
  }
375
354
  end
376
- { 'node' => [0, <<~EOS, ''] }
355
+ { 'node' => [0, <<~EO_STDOUT, ''] }
377
356
  ===== JSON =====
378
357
  #{JSON.pretty_generate(result)}
379
- EOS
358
+ EO_STDOUT
380
359
  end
381
360
  ]
382
361
  if destroy_vm
@@ -386,24 +365,24 @@ module HybridPlatformsConductorTest
386
365
  expect(actions['node'].size).to eq 4
387
366
  # First action should be to copy the reserve_proxmox_container code
388
367
  expect(actions['node'][0].keys).to eq [:scp]
389
- expect(actions['node'][0][:scp].first[0]).to match /^.+\/hpc_plugins\/provisioner\/proxmox\/$/
368
+ expect(actions['node'][0][:scp].first[0]).to match(%r{^.+/hpc_plugins/provisioner/proxmox/$})
390
369
  expect(actions['node'][0][:scp].first[1]).to eq '.'
391
370
  # Second action should be to create directories
392
- expect(actions['node'][1]).to eq({
371
+ expect(actions['node'][1]).to eq(
393
372
  remote_bash: "mkdir -p ./proxmox/config\nmkdir -p ./proxmox/destroy"
394
- })
373
+ )
395
374
  # Next actions should be to copy the config/create/destroy files
396
375
  expect(actions['node'][2].keys).to eq [:scp]
397
- expect(actions['node'][2][:scp].first[0]).to match /^.+\/destroy_#{Regexp.escape(expected_file_id)}\.json$/
376
+ expect(actions['node'][2][:scp].first[0]).to match(%r{^.+/destroy_#{Regexp.escape(expected_file_id)}\.json$})
398
377
  expect(actions['node'][2][:scp].first[1]).to eq './proxmox/destroy'
399
378
  expect(actions['node'][3].keys).to eq [:scp]
400
- expect(actions['node'][3][:scp].first[0]).to match /^.+\/config_#{Regexp.escape(expected_file_id)}\.json$/
379
+ expect(actions['node'][3][:scp].first[0]).to match(%r{^.+/config_#{Regexp.escape(expected_file_id)}\.json$})
401
380
  expect(actions['node'][3][:scp].first[1]).to eq './proxmox/config'
402
381
  @proxmox_destroy_options = JSON.parse(File.read(actions['node'][2][:scp].first[0]))
403
382
  { 'node' => [0, '', ''] }
404
383
  end,
405
384
  proc do |actions|
406
- expect(actions).to eq({
385
+ expect(actions).to eq(
407
386
  'node' => {
408
387
  remote_bash: {
409
388
  commands: "#{expected_sudo ? 'sudo -u root -E ' : ''}./proxmox/reserve_proxmox_container --destroy ./proxmox/destroy/destroy_#{expected_file_id}.json --config ./proxmox/config/config_#{expected_file_id}.json",
@@ -414,7 +393,7 @@ module HybridPlatformsConductorTest
414
393
  }
415
394
  }
416
395
  }
417
- })
396
+ )
418
397
  result =
419
398
  if error_on_destroy
420
399
  { error: error_on_destroy }
@@ -425,10 +404,10 @@ module HybridPlatformsConductorTest
425
404
  vm_ip: '192.168.0.100'
426
405
  }
427
406
  end
428
- { 'node' => [0, <<~EOS, ''] }
407
+ { 'node' => [0, <<~EO_STDOUT, ''] }
429
408
  ===== JSON =====
430
409
  #{JSON.pretty_generate(result)}
431
- EOS
410
+ EO_STDOUT
432
411
  end
433
412
  ]
434
413
  end
@@ -515,8 +494,8 @@ module HybridPlatformsConductorTest
515
494
  mock_proxmox_calls_with(
516
495
  mocked_pve_nodes.map do |pve_nodes|
517
496
  # Complete pve_nodes with default values
518
- pve_nodes = Hash[pve_nodes.map do |pve_node_name, pve_node_info|
519
- pve_node_info[:lxc_containers] = Hash[(pve_node_info.key?(:lxc_containers) ? pve_node_info[:lxc_containers] : {}).map do |vm_id, vm_info|
497
+ pve_nodes = pve_nodes.map do |pve_node_name, pve_node_info|
498
+ pve_node_info[:lxc_containers] = (pve_node_info.key?(:lxc_containers) ? pve_node_info[:lxc_containers] : {}).map do |vm_id, vm_info|
520
499
  [
521
500
  vm_id,
522
501
  {
@@ -531,7 +510,7 @@ module HybridPlatformsConductorTest
531
510
  environment: 'test_env'
532
511
  }.merge(vm_info)
533
512
  ]
534
- end]
513
+ end.to_h
535
514
  [
536
515
  pve_node_name,
537
516
  {
@@ -540,7 +519,7 @@ module HybridPlatformsConductorTest
540
519
  storage_total: 100 * 1024 * 1024 * 1024
541
520
  }.merge(pve_node_info)
542
521
  ]
543
- end]
522
+ end.to_h
544
523
  proc do |url, pve_node, user, password, realm, options|
545
524
  expect(url).to eq 'https://my-proxmox.my-domain.com:8006/api2/json/'
546
525
  expect(pve_node).to eq 'my-proxmox'
@@ -548,30 +527,30 @@ module HybridPlatformsConductorTest
548
527
  expect(password).to eq proxmox_password
549
528
  expect(realm).to eq proxmox_realm
550
529
  expect(options[:verify_ssl]).to eq false
551
- proxmox = double 'Proxmox create instance'
530
+ proxmox = instance_double ::Proxmox::Proxmox
552
531
  # Mock getting status of a container
553
532
  allow(proxmox).to receive(:get) do |path|
554
533
  case path
555
534
  when 'nodes'
556
535
  pve_nodes.keys.map { |pve_node_name| { 'node' => pve_node_name } }
557
- when /^nodes\/([^\/]+)\/status$/
558
- pve_node_name = $1
536
+ when %r{^nodes/([^/]+)/status$}
537
+ pve_node_name = Regexp.last_match(1)
559
538
  {
560
539
  'loadavg' => pve_nodes[pve_node_name][:loadavg].map(&:to_s),
561
540
  'memory' => {
562
541
  'total' => pve_nodes[pve_node_name][:memory_total]
563
542
  }
564
543
  }
565
- when /^nodes\/([^\/]+)\/storage$/
566
- pve_node_name = $1
544
+ when %r{^nodes/([^/]+)/storage$}
545
+ pve_node_name = Regexp.last_match(1)
567
546
  [
568
547
  {
569
548
  'storage' => 'local-lvm',
570
549
  'total' => pve_nodes[pve_node_name][:storage_total]
571
550
  }
572
551
  ]
573
- when /^nodes\/([^\/]+)\/lxc$/
574
- pve_node_name = $1
552
+ when %r{^nodes/([^/]+)/lxc$}
553
+ pve_node_name = Regexp.last_match(1)
575
554
  if pve_nodes[pve_node_name][:error_strings].nil? || pve_nodes[pve_node_name][:error_strings].empty?
576
555
  pve_nodes[pve_node_name][:lxc_containers].map do |vm_id, vm_info|
577
556
  {
@@ -584,28 +563,26 @@ module HybridPlatformsConductorTest
584
563
  else
585
564
  pve_nodes[pve_node_name][:error_strings].shift
586
565
  end
587
- when /^nodes\/([^\/]+)\/lxc\/([^\/]+)\/config$/
588
- pve_node_name = $1
589
- vmid = $2
566
+ when %r{^nodes/([^/]+)/lxc/([^/]+)/config$}
567
+ pve_node_name = Regexp.last_match(1)
568
+ vmid = Regexp.last_match(2)
590
569
  {
591
570
  'net0' => "ip=#{pve_nodes[pve_node_name][:lxc_containers][Integer(vmid)][:ip]}/32",
592
- 'description' => <<~EOS
571
+ 'description' => <<~EO_DESCRIPTION
593
572
  ===== HPC info =====
594
573
  node: #{pve_nodes[pve_node_name][:lxc_containers][Integer(vmid)][:node]}
595
574
  environment: #{pve_nodes[pve_node_name][:lxc_containers][Integer(vmid)][:environment]}
596
575
  debug: #{pve_nodes[pve_node_name][:lxc_containers][Integer(vmid)][:debug] ? 'true' : 'false'}
597
576
  creation_date: #{pve_nodes[pve_node_name][:lxc_containers][Integer(vmid)][:creation_date].strftime('%FT%T')}
598
- EOS
577
+ EO_DESCRIPTION
599
578
  }
600
- when /^nodes\/([^\/]+)\/lxc\/([^\/]+)\/status\/current$/
601
- pve_node_name = $1
602
- vmid = $2
579
+ when %r{^nodes/([^/]+)/lxc/([^/]+)/status/current$}
580
+ pve_node_name = Regexp.last_match(1)
581
+ vmid = Regexp.last_match(2)
603
582
  {
604
583
  'status' => pve_nodes[pve_node_name][:lxc_containers][Integer(vmid)][:status]
605
584
  }
606
- when /^nodes\/([^\/]+)\/tasks\/([^\/]+)\/status$/
607
- pve_node_name = $1
608
- task = $2
585
+ when %r{^nodes/[^/]+/tasks/[^/]+/status$}
609
586
  # Mock tasks completion
610
587
  {
611
588
  'status' => 'OK'
@@ -618,12 +595,12 @@ module HybridPlatformsConductorTest
618
595
  allow(proxmox).to receive(:post) do |path, args|
619
596
  @proxmox_actions << [:post, path, args].compact
620
597
  case path
621
- when /^nodes\/([^\/]+)\/lxc$/
622
- pve_node_name = $1
598
+ when %r{^nodes/([^/]+)/lxc$}
599
+ pve_node_name = Regexp.last_match(1)
623
600
  "UPID:#{pve_node_name}:0000A504:6DEABF24:5F44669B:create::root@pam:"
624
- when /^nodes\/([^\/]+)\/lxc\/([^\/]+)\/status\/stop$/
625
- pve_node_name = $1
626
- vmid = $2
601
+ when %r{^nodes/([^/]+)/lxc/([^/]+)/status/stop$}
602
+ pve_node_name = Regexp.last_match(1)
603
+ vmid = Regexp.last_match(2)
627
604
  "UPID:#{pve_node_name}:0000A504:6DEABF24:5F44669B:stop_#{vmid}::root@pam:"
628
605
  else
629
606
  raise "Unknown Proxmox API post call: #{path}. Please adapt the test framework."
@@ -633,9 +610,9 @@ module HybridPlatformsConductorTest
633
610
  allow(proxmox).to receive(:delete) do |path|
634
611
  @proxmox_actions << [:delete, path]
635
612
  case path
636
- when /^nodes\/([^\/]+)\/lxc\/([^\/]+)$/
637
- pve_node_name = $1
638
- vmid = $2
613
+ when %r{^nodes/([^/]+)/lxc/([^/]+)$}
614
+ pve_node_name = Regexp.last_match(1)
615
+ vmid = Regexp.last_match(2)
639
616
  # Make sure we delete the mocked information as well
640
617
  pve_nodes[pve_node_name][:lxc_containers].delete(Integer(vmid))
641
618
  "UPID:#{pve_node_name}:0000A504:6DEABF24:5F44669B:destroy_#{vmid}::root@pam:"
@@ -668,9 +645,9 @@ module HybridPlatformsConductorTest
668
645
  case dir
669
646
  when '/sys/fs/cgroup/*/lxc/*'
670
647
  block.nil? ? remaining_leftovers : remaining_leftovers.each(&block)
671
- when /^\/sys\/fs\/cgroup\/\*\/lxc\/(.+)$/
672
- vm_id_str = $1
673
- file_pattern = /^\/sys\/fs\/cgroup\/.+\/lxc\/#{Regexp.escape(vm_id_str)}$/
648
+ when %r{^/sys/fs/cgroup/\*/lxc/(.+)$}
649
+ vm_id_str = Regexp.last_match(1)
650
+ file_pattern = %r{^/sys/fs/cgroup/.+/lxc/#{Regexp.escape(vm_id_str)}$}
674
651
  matched_files = remaining_leftovers.select { |file| file =~ file_pattern }
675
652
  block.nil? ? matched_files : matched_files.each(&block)
676
653
  else
@@ -760,17 +737,15 @@ module HybridPlatformsConductorTest
760
737
  $stdout = StringIO.new unless logger.debug?
761
738
  begin
762
739
  load "#{@repository}/proxmox/reserve_proxmox_container"
763
- if logger.debug?
764
- raise 'This test can\'t run in debug mode.'
765
- else
766
- @stdout = $stdout.string
767
- end
740
+ raise 'This test can\'t run in debug mode.' if logger.debug?
741
+
742
+ @stdout = $stdout.string
768
743
  ensure
769
744
  ARGV.replace old_argv
770
745
  $stdout = old_stdout
771
746
  end
772
747
  stdout_lines = @stdout.split("\n")
773
- JSON.parse(stdout_lines[stdout_lines.index('===== JSON =====') + 1..-1].join("\n")).transform_keys(&:to_sym)
748
+ JSON.parse(stdout_lines[stdout_lines.index('===== JSON =====') + 1..].join("\n")).transform_keys(&:to_sym)
774
749
  end
775
750
 
776
751
  # Call the reserve_proxmox_container script and get its result as JSON.
@@ -839,26 +814,26 @@ module HybridPlatformsConductorTest
839
814
  # Parameters::
840
815
  # * *expected_proxmox_actions* (Array<Array>): Expected Proxmox actions
841
816
  def expect_proxmox_actions_to_be(expected_proxmox_actions)
842
- expect(@proxmox_actions.size).to eq(expected_proxmox_actions.size), <<~EOS
817
+ expect(@proxmox_actions.size).to eq(expected_proxmox_actions.size), <<~EO_ERROR_MESSAGE
843
818
  Expected #{expected_proxmox_actions.size} Proxmox actions, but got #{@proxmox_actions.size} instead:
844
819
  ----- Received:
845
820
  #{@proxmox_actions.map(&:inspect).join("\n")}
846
821
  ----- Expected:
847
822
  #{expected_proxmox_actions.map(&:inspect).join("\n")}
848
- EOS
823
+ EO_ERROR_MESSAGE
849
824
  @proxmox_actions.zip(expected_proxmox_actions).each do |proxmox_action, expected_proxmox_action|
850
825
  expect(proxmox_action.size).to eq expected_proxmox_action.size
851
826
  expect(proxmox_action[0..1]).to eq expected_proxmox_action[0..1]
852
- if proxmox_action.size >= 3
853
- # The third argument is a Hash that might have Regexp in the expectation
854
- expect(proxmox_action[2].keys.sort).to eq expected_proxmox_action[2].keys.sort
855
- proxmox_action[2].each do |property, value|
856
- expected_value = expected_proxmox_action[2][property]
857
- if expected_value.is_a?(Regexp)
858
- expect(value).to match expected_value
859
- else
860
- expect(value).to eq expected_value
861
- end
827
+ next if proxmox_action.size < 3
828
+
829
+ # The third argument is a Hash that might have Regexp in the expectation
830
+ expect(proxmox_action[2].keys.sort).to eq expected_proxmox_action[2].keys.sort
831
+ proxmox_action[2].each do |property, value|
832
+ expected_value = expected_proxmox_action[2][property]
833
+ if expected_value.is_a?(Regexp)
834
+ expect(value).to match expected_value
835
+ else
836
+ expect(value).to eq expected_value
862
837
  end
863
838
  end
864
839
  end