hybrid_platforms_conductor 32.17.0 → 33.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (283) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +36 -0
  3. data/README.md +6 -3
  4. data/bin/check-node +0 -1
  5. data/bin/deploy +0 -1
  6. data/bin/get_impacted_nodes +0 -1
  7. data/bin/last_deploys +12 -8
  8. data/bin/nodes_to_deploy +6 -6
  9. data/bin/setup +6 -6
  10. data/bin/topograph +1 -1
  11. data/docs/config_dsl.md +45 -1
  12. data/docs/executables.md +6 -7
  13. data/docs/executables/check-node.md +3 -3
  14. data/docs/executables/deploy.md +3 -3
  15. data/docs/executables/dump_nodes_json.md +3 -3
  16. data/docs/executables/test.md +3 -3
  17. data/docs/executables/topograph.md +3 -3
  18. data/docs/gen/mermaid/README.md-0.png +0 -0
  19. data/docs/gen/mermaid/docs/executables/check-node.md-0.png +0 -0
  20. data/docs/gen/mermaid/docs/executables/deploy.md-0.png +0 -0
  21. data/docs/gen/mermaid/docs/executables/free_ips.md-0.png +0 -0
  22. data/docs/gen/mermaid/docs/executables/get_impacted_nodes.md-0.png +0 -0
  23. data/docs/gen/mermaid/docs/executables/last_deploys.md-0.png +0 -0
  24. data/docs/gen/mermaid/docs/executables/nodes_to_deploy.md-0.png +0 -0
  25. data/docs/gen/mermaid/docs/executables/report.md-0.png +0 -0
  26. data/docs/gen/mermaid/docs/executables/run.md-0.png +0 -0
  27. data/docs/gen/mermaid/docs/executables/ssh_config.md-0.png +0 -0
  28. data/docs/gen/mermaid/docs/executables/test.md-0.png +0 -0
  29. data/docs/plugins.md +46 -0
  30. data/docs/plugins/connector/ssh.md +1 -1
  31. data/docs/plugins/log/remote_fs.md +26 -0
  32. data/docs/plugins/secrets_reader/cli.md +31 -0
  33. data/docs/plugins/secrets_reader/thycotic.md +46 -0
  34. data/docs/plugins/test/check_deploy_and_idempotence.md +1 -1
  35. data/docs/plugins/test/connection.md +1 -0
  36. data/docs/plugins/test/deploy_removes_root_access.md +1 -1
  37. data/docs/plugins/test/file_system.md +1 -0
  38. data/docs/plugins/test/hostname.md +1 -0
  39. data/docs/plugins/test/ip.md +1 -0
  40. data/docs/plugins/test/local_users.md +1 -0
  41. data/docs/plugins/test/mounts.md +1 -0
  42. data/docs/plugins/test/orphan_files.md +1 -0
  43. data/docs/plugins/test/ports.md +1 -0
  44. data/docs/plugins/test/spectre.md +1 -0
  45. data/docs/plugins/test/vulnerabilities.md +1 -0
  46. data/lib/hybrid_platforms_conductor/action.rb +4 -4
  47. data/lib/hybrid_platforms_conductor/actions_executor.rb +45 -43
  48. data/lib/hybrid_platforms_conductor/bitbucket.rb +5 -4
  49. data/lib/hybrid_platforms_conductor/cmd_runner.rb +13 -12
  50. data/lib/hybrid_platforms_conductor/cmdb.rb +2 -2
  51. data/lib/hybrid_platforms_conductor/common_config_dsl/bitbucket.rb +2 -1
  52. data/lib/hybrid_platforms_conductor/common_config_dsl/confluence.rb +2 -1
  53. data/lib/hybrid_platforms_conductor/common_config_dsl/file_system_tests.rb +5 -4
  54. data/lib/hybrid_platforms_conductor/common_config_dsl/github.rb +4 -3
  55. data/lib/hybrid_platforms_conductor/common_config_dsl/idempotence_tests.rb +2 -2
  56. data/lib/hybrid_platforms_conductor/config.rb +8 -4
  57. data/lib/hybrid_platforms_conductor/confluence.rb +1 -1
  58. data/lib/hybrid_platforms_conductor/connector.rb +5 -2
  59. data/lib/hybrid_platforms_conductor/core_extensions/cleanroom/fix_kwargs.rb +116 -0
  60. data/lib/hybrid_platforms_conductor/core_extensions/symbol/zero.rb +24 -0
  61. data/lib/hybrid_platforms_conductor/credentials.rb +39 -36
  62. data/lib/hybrid_platforms_conductor/current_dir_monitor.rb +4 -1
  63. data/lib/hybrid_platforms_conductor/deployer.rb +275 -224
  64. data/lib/hybrid_platforms_conductor/executable.rb +20 -15
  65. data/lib/hybrid_platforms_conductor/hpc_plugins/cmdb/config.rb +10 -7
  66. data/lib/hybrid_platforms_conductor/hpc_plugins/cmdb/host_ip.rb +1 -1
  67. data/lib/hybrid_platforms_conductor/hpc_plugins/cmdb/host_keys.rb +2 -2
  68. data/lib/hybrid_platforms_conductor/hpc_plugins/cmdb/platform_handlers.rb +4 -4
  69. data/lib/hybrid_platforms_conductor/hpc_plugins/connector/local.rb +2 -0
  70. data/lib/hybrid_platforms_conductor/hpc_plugins/connector/ssh.rb +45 -49
  71. data/lib/hybrid_platforms_conductor/hpc_plugins/log/my_log_plugin.rb.sample +100 -0
  72. data/lib/hybrid_platforms_conductor/hpc_plugins/log/remote_fs.rb +180 -0
  73. data/lib/hybrid_platforms_conductor/hpc_plugins/platform_handler/serverless_chef.rb +68 -66
  74. data/lib/hybrid_platforms_conductor/hpc_plugins/platform_handler/serverless_chef/dsl_parser.rb +13 -0
  75. data/lib/hybrid_platforms_conductor/hpc_plugins/platform_handler/serverless_chef/recipes_tree_builder.rb +39 -38
  76. data/lib/hybrid_platforms_conductor/hpc_plugins/platform_handler/yaml_inventory.rb +5 -4
  77. data/lib/hybrid_platforms_conductor/hpc_plugins/provisioner/docker.rb +43 -45
  78. data/lib/hybrid_platforms_conductor/hpc_plugins/provisioner/podman.rb +18 -20
  79. data/lib/hybrid_platforms_conductor/hpc_plugins/provisioner/proxmox.rb +118 -117
  80. data/lib/hybrid_platforms_conductor/hpc_plugins/provisioner/proxmox/proxmox_waiter.rb +39 -43
  81. data/lib/hybrid_platforms_conductor/hpc_plugins/provisioner/proxmox/reserve_proxmox_container +9 -13
  82. data/lib/hybrid_platforms_conductor/hpc_plugins/report/confluence.rb +2 -2
  83. data/lib/hybrid_platforms_conductor/hpc_plugins/report/mediawiki.rb +28 -21
  84. data/lib/hybrid_platforms_conductor/hpc_plugins/report/stdout.rb +26 -22
  85. data/lib/hybrid_platforms_conductor/hpc_plugins/secrets_reader/cli.rb +77 -0
  86. data/lib/hybrid_platforms_conductor/hpc_plugins/secrets_reader/my_secrets_reader_plugin.rb.sample +46 -0
  87. data/lib/hybrid_platforms_conductor/hpc_plugins/secrets_reader/thycotic.rb +90 -0
  88. data/lib/hybrid_platforms_conductor/hpc_plugins/test/bitbucket_conf.rb +3 -3
  89. data/lib/hybrid_platforms_conductor/hpc_plugins/test/check_deploy_and_idempotence.rb +4 -2
  90. data/lib/hybrid_platforms_conductor/hpc_plugins/test/connection.rb +3 -1
  91. data/lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_freshness.rb +7 -21
  92. data/lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_removes_root_access.rb +21 -19
  93. data/lib/hybrid_platforms_conductor/hpc_plugins/test/divergence.rb +2 -2
  94. data/lib/hybrid_platforms_conductor/hpc_plugins/test/executables.rb +2 -2
  95. data/lib/hybrid_platforms_conductor/hpc_plugins/test/file_system.rb +21 -22
  96. data/lib/hybrid_platforms_conductor/hpc_plugins/test/file_system_hdfs.rb +19 -21
  97. data/lib/hybrid_platforms_conductor/hpc_plugins/test/github_ci.rb +2 -3
  98. data/lib/hybrid_platforms_conductor/hpc_plugins/test/hostname.rb +3 -1
  99. data/lib/hybrid_platforms_conductor/hpc_plugins/test/idempotence.rb +2 -2
  100. data/lib/hybrid_platforms_conductor/hpc_plugins/test/ip.rb +4 -2
  101. data/lib/hybrid_platforms_conductor/hpc_plugins/test/jenkins_ci_conf.rb +21 -22
  102. data/lib/hybrid_platforms_conductor/hpc_plugins/test/jenkins_ci_masters_ok.rb +10 -12
  103. data/lib/hybrid_platforms_conductor/hpc_plugins/test/linear_strategy.rb +9 -9
  104. data/lib/hybrid_platforms_conductor/hpc_plugins/test/local_users.rb +5 -3
  105. data/lib/hybrid_platforms_conductor/hpc_plugins/test/mounts.rb +5 -3
  106. data/lib/hybrid_platforms_conductor/hpc_plugins/test/orphan_files.rb +13 -10
  107. data/lib/hybrid_platforms_conductor/hpc_plugins/test/ports.rb +5 -3
  108. data/lib/hybrid_platforms_conductor/hpc_plugins/test/private_ips.rb +5 -5
  109. data/lib/hybrid_platforms_conductor/hpc_plugins/test/public_ips.rb +5 -5
  110. data/lib/hybrid_platforms_conductor/hpc_plugins/test/spectre.rb +7 -7
  111. data/lib/hybrid_platforms_conductor/hpc_plugins/test/veids.rb +3 -3
  112. data/lib/hybrid_platforms_conductor/hpc_plugins/test/vulnerabilities.rb +27 -25
  113. data/lib/hybrid_platforms_conductor/hpc_plugins/test_report/confluence.rb +2 -2
  114. data/lib/hybrid_platforms_conductor/hpc_plugins/test_report/stdout.rb +8 -6
  115. data/lib/hybrid_platforms_conductor/io_router.rb +14 -13
  116. data/lib/hybrid_platforms_conductor/json_dumper.rb +2 -2
  117. data/lib/hybrid_platforms_conductor/log.rb +31 -0
  118. data/lib/hybrid_platforms_conductor/logger_helpers.rb +19 -16
  119. data/lib/hybrid_platforms_conductor/nodes_handler.rb +89 -71
  120. data/lib/hybrid_platforms_conductor/parallel_threads.rb +7 -11
  121. data/lib/hybrid_platforms_conductor/platform_handler.rb +7 -7
  122. data/lib/hybrid_platforms_conductor/platforms_handler.rb +5 -3
  123. data/lib/hybrid_platforms_conductor/plugin.rb +2 -2
  124. data/lib/hybrid_platforms_conductor/plugins.rb +14 -8
  125. data/lib/hybrid_platforms_conductor/provisioner.rb +4 -4
  126. data/lib/hybrid_platforms_conductor/report.rb +2 -2
  127. data/lib/hybrid_platforms_conductor/reports_handler.rb +3 -2
  128. data/lib/hybrid_platforms_conductor/secrets_reader.rb +31 -0
  129. data/lib/hybrid_platforms_conductor/services_handler.rb +32 -29
  130. data/lib/hybrid_platforms_conductor/test_only_remote_node.rb +18 -0
  131. data/lib/hybrid_platforms_conductor/test_report.rb +15 -18
  132. data/lib/hybrid_platforms_conductor/tests_runner.rb +116 -118
  133. data/lib/hybrid_platforms_conductor/thycotic.rb +28 -19
  134. data/lib/hybrid_platforms_conductor/topographer.rb +200 -190
  135. data/lib/hybrid_platforms_conductor/topographer/plugins/graphviz.rb +8 -8
  136. data/lib/hybrid_platforms_conductor/topographer/plugins/json.rb +4 -4
  137. data/lib/hybrid_platforms_conductor/version.rb +1 -1
  138. data/spec/hybrid_platforms_conductor_test.rb +33 -12
  139. data/spec/hybrid_platforms_conductor_test/api/actions_executor/actions/bash_spec.rb +18 -11
  140. data/spec/hybrid_platforms_conductor_test/api/actions_executor/actions/interactive_spec.rb +2 -2
  141. data/spec/hybrid_platforms_conductor_test/api/actions_executor/actions/remote_bash_spec.rb +32 -21
  142. data/spec/hybrid_platforms_conductor_test/api/actions_executor/actions/ruby_spec.rb +75 -49
  143. data/spec/hybrid_platforms_conductor_test/api/actions_executor/actions/scp_spec.rb +27 -15
  144. data/spec/hybrid_platforms_conductor_test/api/actions_executor/actions_spec.rb +90 -59
  145. data/spec/hybrid_platforms_conductor_test/api/actions_executor/connection_spec.rb +46 -44
  146. data/spec/hybrid_platforms_conductor_test/api/actions_executor/connectors/local/connectable_nodes_spec.rb +12 -8
  147. data/spec/hybrid_platforms_conductor_test/api/actions_executor/connectors/local/remote_actions_spec.rb +4 -7
  148. data/spec/hybrid_platforms_conductor_test/api/actions_executor/connectors/ssh/cli_options_spec.rb +21 -22
  149. data/spec/hybrid_platforms_conductor_test/api/actions_executor/connectors/ssh/config_dsl_spec.rb +23 -24
  150. data/spec/hybrid_platforms_conductor_test/api/actions_executor/connectors/ssh/connectable_nodes_spec.rb +10 -6
  151. data/spec/hybrid_platforms_conductor_test/api/actions_executor/connectors/ssh/connections_spec.rb +106 -75
  152. data/spec/hybrid_platforms_conductor_test/api/actions_executor/connectors/ssh/global_helpers_spec.rb +145 -126
  153. data/spec/hybrid_platforms_conductor_test/api/actions_executor/connectors/ssh/node_helpers_spec.rb +3 -3
  154. data/spec/hybrid_platforms_conductor_test/api/actions_executor/connectors/ssh/remote_actions_spec.rb +29 -25
  155. data/spec/hybrid_platforms_conductor_test/api/actions_executor/logging_spec.rb +167 -142
  156. data/spec/hybrid_platforms_conductor_test/api/actions_executor/parallel_spec.rb +272 -244
  157. data/spec/hybrid_platforms_conductor_test/api/actions_executor/timeout_spec.rb +16 -16
  158. data/spec/hybrid_platforms_conductor_test/api/cmd_runner_spec.rb +36 -36
  159. data/spec/hybrid_platforms_conductor_test/api/config_spec.rb +24 -22
  160. data/spec/hybrid_platforms_conductor_test/api/deployer/check_spec.rb +4 -2
  161. data/spec/hybrid_platforms_conductor_test/api/deployer/config_dsl_spec.rb +43 -5
  162. data/spec/hybrid_platforms_conductor_test/api/deployer/deploy_spec.rb +199 -216
  163. data/spec/hybrid_platforms_conductor_test/api/deployer/log_plugins/remote_fs_spec.rb +223 -0
  164. data/spec/hybrid_platforms_conductor_test/api/deployer/parse_deploy_output_spec.rb +55 -59
  165. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioner_spec.rb +36 -62
  166. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/podman_spec.rb +17 -17
  167. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/proxmox/config_dsl_spec.rb +4 -4
  168. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/proxmox/create_spec.rb +44 -51
  169. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/proxmox/destroy_spec.rb +3 -3
  170. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/proxmox/ip_spec.rb +12 -16
  171. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/proxmox/reserve_proxmox_container/destroy_vm_spec.rb +31 -19
  172. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/proxmox/reserve_proxmox_container/expired_containers_spec.rb +324 -266
  173. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/proxmox/reserve_proxmox_container/ips_assignment_spec.rb +89 -61
  174. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/proxmox/reserve_proxmox_container/other_lxc_containers_resources_spec.rb +117 -93
  175. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/proxmox/reserve_proxmox_container/pve_node_resources_spec.rb +71 -54
  176. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/proxmox/reserve_proxmox_container/retries_spec.rb +10 -8
  177. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/proxmox/reserve_proxmox_container/vm_ids_assignment_spec.rb +80 -60
  178. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/proxmox/start_spec.rb +1 -1
  179. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/proxmox/state_spec.rb +1 -1
  180. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/proxmox/stop_spec.rb +1 -1
  181. data/spec/hybrid_platforms_conductor_test/api/deployer/secrets_reader_plugins/cli_spec.rb +64 -0
  182. data/spec/hybrid_platforms_conductor_test/api/deployer/secrets_reader_plugins/thycotic_spec.rb +268 -0
  183. data/spec/hybrid_platforms_conductor_test/api/nodes_handler/cmdbs/config_spec.rb +8 -10
  184. data/spec/hybrid_platforms_conductor_test/api/nodes_handler/cmdbs/host_ip_spec.rb +33 -24
  185. data/spec/hybrid_platforms_conductor_test/api/nodes_handler/cmdbs/host_keys_spec.rb +64 -51
  186. data/spec/hybrid_platforms_conductor_test/api/nodes_handler/cmdbs/platform_handlers_spec.rb +3 -3
  187. data/spec/hybrid_platforms_conductor_test/api/nodes_handler/cmdbs_plugins_api_spec.rb +50 -51
  188. data/spec/hybrid_platforms_conductor_test/api/nodes_handler/common_spec.rb +91 -81
  189. data/spec/hybrid_platforms_conductor_test/api/nodes_handler/config_dsl_spec.rb +14 -16
  190. data/spec/hybrid_platforms_conductor_test/api/nodes_handler/git_diff_impacts_spec.rb +51 -75
  191. data/spec/hybrid_platforms_conductor_test/api/nodes_handler/nodes_selectors_spec.rb +35 -26
  192. data/spec/hybrid_platforms_conductor_test/api/nodes_handler/platform_handlers_plugins_api_spec.rb +24 -16
  193. data/spec/hybrid_platforms_conductor_test/api/nodes_handler/several_platforms_spec.rb +29 -19
  194. data/spec/hybrid_platforms_conductor_test/api/platform_handler_spec.rb +4 -4
  195. data/spec/hybrid_platforms_conductor_test/api/platform_handlers/serverless_chef/config_dsl_spec.rb +2 -2
  196. data/spec/hybrid_platforms_conductor_test/api/platform_handlers/serverless_chef/deploy_output_parsing_spec.rb +6 -6
  197. data/spec/hybrid_platforms_conductor_test/api/platform_handlers/serverless_chef/diff_impacts_spec.rb +57 -99
  198. data/spec/hybrid_platforms_conductor_test/api/platform_handlers/serverless_chef/inventory_spec.rb +4 -4
  199. data/spec/hybrid_platforms_conductor_test/api/platform_handlers/serverless_chef/packaging_spec.rb +32 -35
  200. data/spec/hybrid_platforms_conductor_test/api/platform_handlers/serverless_chef/services_deployment_spec.rb +10 -10
  201. data/spec/hybrid_platforms_conductor_test/api/platforms_handler_spec.rb +38 -27
  202. data/spec/hybrid_platforms_conductor_test/api/plugins_spec.rb +46 -52
  203. data/spec/hybrid_platforms_conductor_test/api/reports_handler_spec.rb +2 -2
  204. data/spec/hybrid_platforms_conductor_test/api/services_handler/actions_to_deploy_spec.rb +90 -58
  205. data/spec/hybrid_platforms_conductor_test/api/services_handler/deploy_allowed_spec.rb +38 -34
  206. data/spec/hybrid_platforms_conductor_test/api/services_handler/log_info_spec.rb +11 -9
  207. data/spec/hybrid_platforms_conductor_test/api/services_handler/package_spec.rb +193 -171
  208. data/spec/hybrid_platforms_conductor_test/api/services_handler/parse_deploy_output_spec.rb +66 -54
  209. data/spec/hybrid_platforms_conductor_test/api/services_handler/prepare_for_deploy_spec.rb +147 -133
  210. data/spec/hybrid_platforms_conductor_test/api/tests_runner/common_spec.rb +69 -49
  211. data/spec/hybrid_platforms_conductor_test/api/tests_runner/global_spec.rb +5 -4
  212. data/spec/hybrid_platforms_conductor_test/api/tests_runner/node_check_spec.rb +8 -5
  213. data/spec/hybrid_platforms_conductor_test/api/tests_runner/node_spec.rb +8 -5
  214. data/spec/hybrid_platforms_conductor_test/api/tests_runner/node_ssh_spec.rb +30 -27
  215. data/spec/hybrid_platforms_conductor_test/api/tests_runner/platform_spec.rb +12 -9
  216. data/spec/hybrid_platforms_conductor_test/api/tests_runner/reports_spec.rb +48 -47
  217. data/spec/hybrid_platforms_conductor_test/api/tests_runner/test_plugins/bitbucket_conf_spec.rb +5 -5
  218. data/spec/hybrid_platforms_conductor_test/api/tests_runner/test_plugins/github_ci_spec.rb +5 -5
  219. data/spec/hybrid_platforms_conductor_test/api/tests_runner/test_reports_plugins/confluence_spec.rb +5 -5
  220. data/spec/hybrid_platforms_conductor_test/cmdb_plugins/test_cmdb.rb +9 -9
  221. data/spec/hybrid_platforms_conductor_test/cmdb_plugins/{test_cmdb2.rb → test_cmdb_2.rb} +6 -6
  222. data/spec/hybrid_platforms_conductor_test/cmdb_plugins/test_cmdb_others.rb +3 -3
  223. data/spec/hybrid_platforms_conductor_test/cmdb_plugins/{test_cmdb_others2.rb → test_cmdb_others_2.rb} +2 -2
  224. data/spec/hybrid_platforms_conductor_test/docs_spec.rb +1 -1
  225. data/spec/hybrid_platforms_conductor_test/executables/{check-node_spec.rb → check_node_spec.rb} +4 -6
  226. data/spec/hybrid_platforms_conductor_test/executables/deploy_spec.rb +4 -6
  227. data/spec/hybrid_platforms_conductor_test/executables/get_impacted_nodes_spec.rb +76 -77
  228. data/spec/hybrid_platforms_conductor_test/executables/last_deploys_spec.rb +159 -113
  229. data/spec/hybrid_platforms_conductor_test/executables/nodes_to_deploy_spec.rb +299 -160
  230. data/spec/hybrid_platforms_conductor_test/executables/options/actions_executor_spec.rb +4 -6
  231. data/spec/hybrid_platforms_conductor_test/executables/options/cmd_runner_spec.rb +3 -5
  232. data/spec/hybrid_platforms_conductor_test/executables/options/common_spec.rb +8 -8
  233. data/spec/hybrid_platforms_conductor_test/executables/options/deployer_spec.rb +12 -196
  234. data/spec/hybrid_platforms_conductor_test/executables/options/nodes_handler_spec.rb +9 -10
  235. data/spec/hybrid_platforms_conductor_test/executables/options/nodes_selectors_spec.rb +9 -10
  236. data/spec/hybrid_platforms_conductor_test/executables/options/reports_handler_spec.rb +1 -1
  237. data/spec/hybrid_platforms_conductor_test/executables/options/tests_runner_spec.rb +22 -22
  238. data/spec/hybrid_platforms_conductor_test/executables/report_spec.rb +22 -16
  239. data/spec/hybrid_platforms_conductor_test/executables/run_spec.rb +32 -32
  240. data/spec/hybrid_platforms_conductor_test/executables/ssh_config_spec.rb +7 -9
  241. data/spec/hybrid_platforms_conductor_test/executables/test_spec.rb +3 -5
  242. data/spec/hybrid_platforms_conductor_test/helpers/actions_executor_helpers.rb +2 -2
  243. data/spec/hybrid_platforms_conductor_test/helpers/cmd_runner_helpers.rb +4 -3
  244. data/spec/hybrid_platforms_conductor_test/helpers/cmdb_helpers.rb +2 -2
  245. data/spec/hybrid_platforms_conductor_test/helpers/config_helpers.rb +1 -1
  246. data/spec/hybrid_platforms_conductor_test/helpers/connector_ssh_helpers.rb +12 -13
  247. data/spec/hybrid_platforms_conductor_test/helpers/deployer_helpers.rb +245 -56
  248. data/spec/hybrid_platforms_conductor_test/helpers/executables_helpers.rb +11 -11
  249. data/spec/hybrid_platforms_conductor_test/helpers/nodes_handler_helpers.rb +1 -1
  250. data/spec/hybrid_platforms_conductor_test/helpers/platforms_handler_helpers.rb +39 -28
  251. data/spec/hybrid_platforms_conductor_test/helpers/plugins_helpers.rb +1 -1
  252. data/spec/hybrid_platforms_conductor_test/helpers/provisioner_proxmox_helpers.rb +86 -111
  253. data/spec/hybrid_platforms_conductor_test/helpers/reports_handler_helpers.rb +1 -1
  254. data/spec/hybrid_platforms_conductor_test/helpers/serverless_chef_helpers.rb +3 -3
  255. data/spec/hybrid_platforms_conductor_test/helpers/services_handler_helpers.rb +1 -1
  256. data/spec/hybrid_platforms_conductor_test/helpers/tests_runner_helpers.rb +1 -1
  257. 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
  258. 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
  259. 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
  260. 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
  261. data/spec/hybrid_platforms_conductor_test/platform_handler_plugins/test.rb +1 -1
  262. data/spec/hybrid_platforms_conductor_test/platform_handler_plugins/{test2.rb → test_2.rb} +0 -0
  263. data/spec/hybrid_platforms_conductor_test/rubocop_spec.rb +31 -0
  264. data/spec/hybrid_platforms_conductor_test/serverless_chef_repositories/1_node/nodes/node.json +3 -3
  265. data/spec/hybrid_platforms_conductor_test/serverless_chef_repositories/data_bags/nodes/node.json +3 -3
  266. data/spec/hybrid_platforms_conductor_test/serverless_chef_repositories/recipes/cookbooks/test_cookbook_2/libraries/default.rb +1 -0
  267. data/spec/hybrid_platforms_conductor_test/serverless_chef_repositories/several_cookbooks/other_cookbooks/test_cookbook_2/libraries/default.rb +1 -0
  268. data/spec/hybrid_platforms_conductor_test/shared_examples/deployer.rb +952 -0
  269. data/spec/hybrid_platforms_conductor_test/test_connector.rb +3 -3
  270. data/spec/hybrid_platforms_conductor_test/test_log_no_read_plugin.rb +84 -0
  271. data/spec/hybrid_platforms_conductor_test/test_log_plugin.rb +105 -0
  272. data/spec/hybrid_platforms_conductor_test/test_plugins/global.rb +1 -0
  273. data/spec/hybrid_platforms_conductor_test/test_plugins/node.rb +1 -0
  274. data/spec/hybrid_platforms_conductor_test/test_plugins/node_check.rb +1 -0
  275. data/spec/hybrid_platforms_conductor_test/test_plugins/platform.rb +1 -0
  276. data/spec/hybrid_platforms_conductor_test/test_plugins/several_checks.rb +2 -2
  277. data/spec/hybrid_platforms_conductor_test/test_secrets_reader_plugin.rb +45 -0
  278. data/spec/hybrid_platforms_conductor_test/tests_report_plugin.rb +5 -6
  279. data/spec/spec_helper.rb +17 -18
  280. data/tools/check_md +16 -20
  281. data/tools/generate_mermaid +1 -1
  282. metadata +195 -144
  283. data/spec/hybrid_platforms_conductor_test/helpers/deployer_test_helpers.rb +0 -916
@@ -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