hybrid_platforms_conductor 32.18.0 → 33.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (255) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +36 -0
  3. data/README.md +3 -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 +8 -7
  8. data/bin/nodes_to_deploy +2 -2
  9. data/bin/setup +6 -6
  10. data/bin/topograph +1 -1
  11. data/docs/config_dsl.md +23 -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/plugins.md +21 -0
  19. data/docs/plugins/secrets_reader/cli.md +31 -0
  20. data/docs/plugins/secrets_reader/thycotic.md +46 -0
  21. data/lib/hybrid_platforms_conductor/action.rb +4 -4
  22. data/lib/hybrid_platforms_conductor/actions_executor.rb +37 -42
  23. data/lib/hybrid_platforms_conductor/bitbucket.rb +5 -4
  24. data/lib/hybrid_platforms_conductor/cmd_runner.rb +26 -23
  25. data/lib/hybrid_platforms_conductor/cmdb.rb +2 -2
  26. data/lib/hybrid_platforms_conductor/common_config_dsl/bitbucket.rb +2 -1
  27. data/lib/hybrid_platforms_conductor/common_config_dsl/confluence.rb +2 -1
  28. data/lib/hybrid_platforms_conductor/common_config_dsl/file_system_tests.rb +5 -4
  29. data/lib/hybrid_platforms_conductor/common_config_dsl/github.rb +4 -3
  30. data/lib/hybrid_platforms_conductor/common_config_dsl/idempotence_tests.rb +2 -2
  31. data/lib/hybrid_platforms_conductor/config.rb +8 -4
  32. data/lib/hybrid_platforms_conductor/confluence.rb +1 -1
  33. data/lib/hybrid_platforms_conductor/connector.rb +5 -2
  34. data/lib/hybrid_platforms_conductor/core_extensions/cleanroom/fix_kwargs.rb +116 -0
  35. data/lib/hybrid_platforms_conductor/core_extensions/symbol/zero.rb +24 -0
  36. data/lib/hybrid_platforms_conductor/credentials.rb +39 -36
  37. data/lib/hybrid_platforms_conductor/current_dir_monitor.rb +4 -1
  38. data/lib/hybrid_platforms_conductor/deployer.rb +185 -127
  39. data/lib/hybrid_platforms_conductor/executable.rb +20 -15
  40. data/lib/hybrid_platforms_conductor/hpc_plugins/cmdb/config.rb +10 -7
  41. data/lib/hybrid_platforms_conductor/hpc_plugins/cmdb/host_ip.rb +1 -1
  42. data/lib/hybrid_platforms_conductor/hpc_plugins/cmdb/host_keys.rb +2 -2
  43. data/lib/hybrid_platforms_conductor/hpc_plugins/cmdb/platform_handlers.rb +4 -4
  44. data/lib/hybrid_platforms_conductor/hpc_plugins/connector/local.rb +5 -1
  45. data/lib/hybrid_platforms_conductor/hpc_plugins/connector/ssh.rb +45 -49
  46. data/lib/hybrid_platforms_conductor/hpc_plugins/log/remote_fs.rb +6 -5
  47. data/lib/hybrid_platforms_conductor/hpc_plugins/platform_handler/serverless_chef.rb +77 -79
  48. data/lib/hybrid_platforms_conductor/hpc_plugins/platform_handler/serverless_chef/dsl_parser.rb +13 -0
  49. data/lib/hybrid_platforms_conductor/hpc_plugins/platform_handler/serverless_chef/recipes_tree_builder.rb +39 -38
  50. data/lib/hybrid_platforms_conductor/hpc_plugins/platform_handler/yaml_inventory.rb +5 -4
  51. data/lib/hybrid_platforms_conductor/hpc_plugins/provisioner/docker.rb +43 -45
  52. data/lib/hybrid_platforms_conductor/hpc_plugins/provisioner/podman.rb +18 -20
  53. data/lib/hybrid_platforms_conductor/hpc_plugins/provisioner/proxmox.rb +119 -118
  54. data/lib/hybrid_platforms_conductor/hpc_plugins/provisioner/proxmox/proxmox_waiter.rb +39 -43
  55. data/lib/hybrid_platforms_conductor/hpc_plugins/provisioner/proxmox/reserve_proxmox_container +9 -13
  56. data/lib/hybrid_platforms_conductor/hpc_plugins/report/confluence.rb +2 -2
  57. data/lib/hybrid_platforms_conductor/hpc_plugins/report/mediawiki.rb +28 -21
  58. data/lib/hybrid_platforms_conductor/hpc_plugins/report/stdout.rb +26 -22
  59. data/lib/hybrid_platforms_conductor/hpc_plugins/secrets_reader/cli.rb +77 -0
  60. data/lib/hybrid_platforms_conductor/hpc_plugins/secrets_reader/my_secrets_reader_plugin.rb.sample +46 -0
  61. data/lib/hybrid_platforms_conductor/hpc_plugins/secrets_reader/thycotic.rb +90 -0
  62. data/lib/hybrid_platforms_conductor/hpc_plugins/test/bitbucket_conf.rb +3 -3
  63. data/lib/hybrid_platforms_conductor/hpc_plugins/test/check_deploy_and_idempotence.rb +4 -2
  64. data/lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_freshness.rb +0 -1
  65. data/lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_removes_root_access.rb +21 -19
  66. data/lib/hybrid_platforms_conductor/hpc_plugins/test/divergence.rb +2 -2
  67. data/lib/hybrid_platforms_conductor/hpc_plugins/test/executables.rb +2 -2
  68. data/lib/hybrid_platforms_conductor/hpc_plugins/test/file_system.rb +19 -21
  69. data/lib/hybrid_platforms_conductor/hpc_plugins/test/file_system_hdfs.rb +19 -21
  70. data/lib/hybrid_platforms_conductor/hpc_plugins/test/github_ci.rb +2 -3
  71. data/lib/hybrid_platforms_conductor/hpc_plugins/test/idempotence.rb +2 -2
  72. data/lib/hybrid_platforms_conductor/hpc_plugins/test/ip.rb +1 -1
  73. data/lib/hybrid_platforms_conductor/hpc_plugins/test/jenkins_ci_conf.rb +21 -22
  74. data/lib/hybrid_platforms_conductor/hpc_plugins/test/jenkins_ci_masters_ok.rb +10 -12
  75. data/lib/hybrid_platforms_conductor/hpc_plugins/test/linear_strategy.rb +9 -9
  76. data/lib/hybrid_platforms_conductor/hpc_plugins/test/local_users.rb +2 -2
  77. data/lib/hybrid_platforms_conductor/hpc_plugins/test/mounts.rb +2 -2
  78. data/lib/hybrid_platforms_conductor/hpc_plugins/test/orphan_files.rb +10 -9
  79. data/lib/hybrid_platforms_conductor/hpc_plugins/test/ports.rb +2 -2
  80. data/lib/hybrid_platforms_conductor/hpc_plugins/test/private_ips.rb +5 -5
  81. data/lib/hybrid_platforms_conductor/hpc_plugins/test/public_ips.rb +5 -5
  82. data/lib/hybrid_platforms_conductor/hpc_plugins/test/spectre.rb +4 -6
  83. data/lib/hybrid_platforms_conductor/hpc_plugins/test/veids.rb +3 -3
  84. data/lib/hybrid_platforms_conductor/hpc_plugins/test/vulnerabilities.rb +25 -24
  85. data/lib/hybrid_platforms_conductor/hpc_plugins/test_report/confluence.rb +2 -2
  86. data/lib/hybrid_platforms_conductor/hpc_plugins/test_report/stdout.rb +8 -6
  87. data/lib/hybrid_platforms_conductor/io_router.rb +14 -13
  88. data/lib/hybrid_platforms_conductor/json_dumper.rb +2 -2
  89. data/lib/hybrid_platforms_conductor/log.rb +2 -2
  90. data/lib/hybrid_platforms_conductor/logger_helpers.rb +19 -16
  91. data/lib/hybrid_platforms_conductor/nodes_handler.rb +89 -71
  92. data/lib/hybrid_platforms_conductor/parallel_threads.rb +7 -11
  93. data/lib/hybrid_platforms_conductor/platform_handler.rb +7 -7
  94. data/lib/hybrid_platforms_conductor/platforms_handler.rb +5 -3
  95. data/lib/hybrid_platforms_conductor/plugin.rb +2 -2
  96. data/lib/hybrid_platforms_conductor/plugins.rb +14 -8
  97. data/lib/hybrid_platforms_conductor/provisioner.rb +4 -4
  98. data/lib/hybrid_platforms_conductor/report.rb +2 -2
  99. data/lib/hybrid_platforms_conductor/reports_handler.rb +3 -2
  100. data/lib/hybrid_platforms_conductor/secrets_reader.rb +31 -0
  101. data/lib/hybrid_platforms_conductor/services_handler.rb +32 -29
  102. data/lib/hybrid_platforms_conductor/test_only_remote_node.rb +1 -1
  103. data/lib/hybrid_platforms_conductor/test_report.rb +15 -18
  104. data/lib/hybrid_platforms_conductor/tests_runner.rb +116 -118
  105. data/lib/hybrid_platforms_conductor/thycotic.rb +28 -19
  106. data/lib/hybrid_platforms_conductor/topographer.rb +200 -190
  107. data/lib/hybrid_platforms_conductor/topographer/plugins/graphviz.rb +8 -8
  108. data/lib/hybrid_platforms_conductor/topographer/plugins/json.rb +4 -4
  109. data/lib/hybrid_platforms_conductor/version.rb +1 -1
  110. data/spec/hybrid_platforms_conductor_test.rb +29 -6
  111. data/spec/hybrid_platforms_conductor_test/api/actions_executor/actions/bash_spec.rb +18 -11
  112. data/spec/hybrid_platforms_conductor_test/api/actions_executor/actions/interactive_spec.rb +2 -2
  113. data/spec/hybrid_platforms_conductor_test/api/actions_executor/actions/remote_bash_spec.rb +32 -21
  114. data/spec/hybrid_platforms_conductor_test/api/actions_executor/actions/ruby_spec.rb +75 -49
  115. data/spec/hybrid_platforms_conductor_test/api/actions_executor/actions/scp_spec.rb +27 -15
  116. data/spec/hybrid_platforms_conductor_test/api/actions_executor/actions_spec.rb +90 -59
  117. data/spec/hybrid_platforms_conductor_test/api/actions_executor/connection_spec.rb +46 -44
  118. data/spec/hybrid_platforms_conductor_test/api/actions_executor/connectors/local/connectable_nodes_spec.rb +12 -8
  119. data/spec/hybrid_platforms_conductor_test/api/actions_executor/connectors/local/remote_actions_spec.rb +4 -7
  120. data/spec/hybrid_platforms_conductor_test/api/actions_executor/connectors/ssh/cli_options_spec.rb +21 -22
  121. data/spec/hybrid_platforms_conductor_test/api/actions_executor/connectors/ssh/config_dsl_spec.rb +23 -24
  122. data/spec/hybrid_platforms_conductor_test/api/actions_executor/connectors/ssh/connectable_nodes_spec.rb +10 -6
  123. data/spec/hybrid_platforms_conductor_test/api/actions_executor/connectors/ssh/connections_spec.rb +106 -75
  124. data/spec/hybrid_platforms_conductor_test/api/actions_executor/connectors/ssh/global_helpers_spec.rb +145 -126
  125. data/spec/hybrid_platforms_conductor_test/api/actions_executor/connectors/ssh/node_helpers_spec.rb +3 -3
  126. data/spec/hybrid_platforms_conductor_test/api/actions_executor/connectors/ssh/remote_actions_spec.rb +29 -25
  127. data/spec/hybrid_platforms_conductor_test/api/actions_executor/logging_spec.rb +167 -142
  128. data/spec/hybrid_platforms_conductor_test/api/actions_executor/parallel_spec.rb +272 -244
  129. data/spec/hybrid_platforms_conductor_test/api/actions_executor/timeout_spec.rb +16 -16
  130. data/spec/hybrid_platforms_conductor_test/api/cmd_runner_spec.rb +42 -36
  131. data/spec/hybrid_platforms_conductor_test/api/config_spec.rb +24 -22
  132. data/spec/hybrid_platforms_conductor_test/api/deployer/check_spec.rb +4 -2
  133. data/spec/hybrid_platforms_conductor_test/api/deployer/config_dsl_spec.rb +24 -6
  134. data/spec/hybrid_platforms_conductor_test/api/deployer/deploy_spec.rb +34 -26
  135. data/spec/hybrid_platforms_conductor_test/api/deployer/log_plugins/remote_fs_spec.rb +21 -21
  136. data/spec/hybrid_platforms_conductor_test/api/deployer/parse_deploy_output_spec.rb +55 -59
  137. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioner_spec.rb +36 -62
  138. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/podman_spec.rb +17 -17
  139. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/proxmox/config_dsl_spec.rb +4 -4
  140. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/proxmox/create_spec.rb +44 -51
  141. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/proxmox/destroy_spec.rb +3 -3
  142. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/proxmox/ip_spec.rb +12 -16
  143. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/proxmox/reserve_proxmox_container/destroy_vm_spec.rb +31 -19
  144. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/proxmox/reserve_proxmox_container/expired_containers_spec.rb +324 -266
  145. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/proxmox/reserve_proxmox_container/ips_assignment_spec.rb +89 -61
  146. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/proxmox/reserve_proxmox_container/other_lxc_containers_resources_spec.rb +117 -93
  147. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/proxmox/reserve_proxmox_container/pve_node_resources_spec.rb +71 -54
  148. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/proxmox/reserve_proxmox_container/retries_spec.rb +10 -8
  149. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/proxmox/reserve_proxmox_container/vm_ids_assignment_spec.rb +80 -60
  150. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/proxmox/start_spec.rb +1 -1
  151. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/proxmox/state_spec.rb +1 -1
  152. data/spec/hybrid_platforms_conductor_test/api/deployer/provisioners/proxmox/stop_spec.rb +1 -1
  153. data/spec/hybrid_platforms_conductor_test/api/deployer/secrets_reader_plugins/cli_spec.rb +64 -0
  154. data/spec/hybrid_platforms_conductor_test/api/deployer/secrets_reader_plugins/thycotic_spec.rb +268 -0
  155. data/spec/hybrid_platforms_conductor_test/api/nodes_handler/cmdbs/config_spec.rb +8 -10
  156. data/spec/hybrid_platforms_conductor_test/api/nodes_handler/cmdbs/host_ip_spec.rb +33 -24
  157. data/spec/hybrid_platforms_conductor_test/api/nodes_handler/cmdbs/host_keys_spec.rb +64 -51
  158. data/spec/hybrid_platforms_conductor_test/api/nodes_handler/cmdbs/platform_handlers_spec.rb +3 -3
  159. data/spec/hybrid_platforms_conductor_test/api/nodes_handler/cmdbs_plugins_api_spec.rb +50 -51
  160. data/spec/hybrid_platforms_conductor_test/api/nodes_handler/common_spec.rb +91 -81
  161. data/spec/hybrid_platforms_conductor_test/api/nodes_handler/config_dsl_spec.rb +14 -16
  162. data/spec/hybrid_platforms_conductor_test/api/nodes_handler/git_diff_impacts_spec.rb +51 -75
  163. data/spec/hybrid_platforms_conductor_test/api/nodes_handler/nodes_selectors_spec.rb +35 -26
  164. data/spec/hybrid_platforms_conductor_test/api/nodes_handler/platform_handlers_plugins_api_spec.rb +24 -16
  165. data/spec/hybrid_platforms_conductor_test/api/nodes_handler/several_platforms_spec.rb +29 -19
  166. data/spec/hybrid_platforms_conductor_test/api/platform_handler_spec.rb +4 -4
  167. data/spec/hybrid_platforms_conductor_test/api/platform_handlers/serverless_chef/config_dsl_spec.rb +2 -2
  168. data/spec/hybrid_platforms_conductor_test/api/platform_handlers/serverless_chef/deploy_output_parsing_spec.rb +6 -6
  169. data/spec/hybrid_platforms_conductor_test/api/platform_handlers/serverless_chef/diff_impacts_spec.rb +57 -99
  170. data/spec/hybrid_platforms_conductor_test/api/platform_handlers/serverless_chef/inventory_spec.rb +4 -4
  171. data/spec/hybrid_platforms_conductor_test/api/platform_handlers/serverless_chef/packaging_spec.rb +32 -35
  172. data/spec/hybrid_platforms_conductor_test/api/platform_handlers/serverless_chef/services_deployment_spec.rb +10 -10
  173. data/spec/hybrid_platforms_conductor_test/api/platforms_handler_spec.rb +38 -27
  174. data/spec/hybrid_platforms_conductor_test/api/plugins_spec.rb +46 -52
  175. data/spec/hybrid_platforms_conductor_test/api/reports_handler_spec.rb +2 -2
  176. data/spec/hybrid_platforms_conductor_test/api/services_handler/actions_to_deploy_spec.rb +90 -58
  177. data/spec/hybrid_platforms_conductor_test/api/services_handler/deploy_allowed_spec.rb +38 -34
  178. data/spec/hybrid_platforms_conductor_test/api/services_handler/log_info_spec.rb +11 -9
  179. data/spec/hybrid_platforms_conductor_test/api/services_handler/package_spec.rb +193 -171
  180. data/spec/hybrid_platforms_conductor_test/api/services_handler/parse_deploy_output_spec.rb +66 -54
  181. data/spec/hybrid_platforms_conductor_test/api/services_handler/prepare_for_deploy_spec.rb +147 -133
  182. data/spec/hybrid_platforms_conductor_test/api/tests_runner/common_spec.rb +69 -49
  183. data/spec/hybrid_platforms_conductor_test/api/tests_runner/global_spec.rb +4 -3
  184. data/spec/hybrid_platforms_conductor_test/api/tests_runner/node_check_spec.rb +8 -5
  185. data/spec/hybrid_platforms_conductor_test/api/tests_runner/node_spec.rb +8 -5
  186. data/spec/hybrid_platforms_conductor_test/api/tests_runner/node_ssh_spec.rb +30 -27
  187. data/spec/hybrid_platforms_conductor_test/api/tests_runner/platform_spec.rb +12 -9
  188. data/spec/hybrid_platforms_conductor_test/api/tests_runner/reports_spec.rb +48 -47
  189. data/spec/hybrid_platforms_conductor_test/api/tests_runner/test_plugins/bitbucket_conf_spec.rb +5 -5
  190. data/spec/hybrid_platforms_conductor_test/api/tests_runner/test_plugins/github_ci_spec.rb +5 -5
  191. data/spec/hybrid_platforms_conductor_test/api/tests_runner/test_reports_plugins/confluence_spec.rb +5 -5
  192. data/spec/hybrid_platforms_conductor_test/cmdb_plugins/test_cmdb.rb +9 -9
  193. data/spec/hybrid_platforms_conductor_test/cmdb_plugins/{test_cmdb2.rb → test_cmdb_2.rb} +6 -6
  194. data/spec/hybrid_platforms_conductor_test/cmdb_plugins/test_cmdb_others.rb +3 -3
  195. data/spec/hybrid_platforms_conductor_test/cmdb_plugins/{test_cmdb_others2.rb → test_cmdb_others_2.rb} +2 -2
  196. data/spec/hybrid_platforms_conductor_test/docs_spec.rb +1 -1
  197. data/spec/hybrid_platforms_conductor_test/executables/{check-node_spec.rb → check_node_spec.rb} +4 -6
  198. data/spec/hybrid_platforms_conductor_test/executables/deploy_spec.rb +4 -6
  199. data/spec/hybrid_platforms_conductor_test/executables/get_impacted_nodes_spec.rb +76 -77
  200. data/spec/hybrid_platforms_conductor_test/executables/last_deploys_spec.rb +13 -15
  201. data/spec/hybrid_platforms_conductor_test/executables/nodes_to_deploy_spec.rb +289 -307
  202. data/spec/hybrid_platforms_conductor_test/executables/options/actions_executor_spec.rb +4 -6
  203. data/spec/hybrid_platforms_conductor_test/executables/options/cmd_runner_spec.rb +3 -5
  204. data/spec/hybrid_platforms_conductor_test/executables/options/common_spec.rb +8 -9
  205. data/spec/hybrid_platforms_conductor_test/executables/options/deployer_spec.rb +12 -196
  206. data/spec/hybrid_platforms_conductor_test/executables/options/nodes_handler_spec.rb +9 -10
  207. data/spec/hybrid_platforms_conductor_test/executables/options/nodes_selectors_spec.rb +9 -10
  208. data/spec/hybrid_platforms_conductor_test/executables/options/reports_handler_spec.rb +1 -1
  209. data/spec/hybrid_platforms_conductor_test/executables/options/tests_runner_spec.rb +22 -22
  210. data/spec/hybrid_platforms_conductor_test/executables/report_spec.rb +22 -16
  211. data/spec/hybrid_platforms_conductor_test/executables/run_spec.rb +32 -32
  212. data/spec/hybrid_platforms_conductor_test/executables/ssh_config_spec.rb +7 -9
  213. data/spec/hybrid_platforms_conductor_test/executables/test_spec.rb +3 -5
  214. data/spec/hybrid_platforms_conductor_test/helpers/actions_executor_helpers.rb +2 -2
  215. data/spec/hybrid_platforms_conductor_test/helpers/cmd_runner_helpers.rb +4 -3
  216. data/spec/hybrid_platforms_conductor_test/helpers/cmdb_helpers.rb +2 -2
  217. data/spec/hybrid_platforms_conductor_test/helpers/config_helpers.rb +1 -1
  218. data/spec/hybrid_platforms_conductor_test/helpers/connector_ssh_helpers.rb +12 -13
  219. data/spec/hybrid_platforms_conductor_test/helpers/deployer_helpers.rb +216 -14
  220. data/spec/hybrid_platforms_conductor_test/helpers/executables_helpers.rb +11 -11
  221. data/spec/hybrid_platforms_conductor_test/helpers/nodes_handler_helpers.rb +1 -1
  222. data/spec/hybrid_platforms_conductor_test/helpers/platforms_handler_helpers.rb +39 -28
  223. data/spec/hybrid_platforms_conductor_test/helpers/plugins_helpers.rb +1 -1
  224. data/spec/hybrid_platforms_conductor_test/helpers/provisioner_proxmox_helpers.rb +86 -111
  225. data/spec/hybrid_platforms_conductor_test/helpers/reports_handler_helpers.rb +1 -1
  226. data/spec/hybrid_platforms_conductor_test/helpers/serverless_chef_helpers.rb +3 -3
  227. data/spec/hybrid_platforms_conductor_test/helpers/services_handler_helpers.rb +1 -1
  228. data/spec/hybrid_platforms_conductor_test/helpers/tests_runner_helpers.rb +1 -1
  229. 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
  230. 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
  231. 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
  232. 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
  233. data/spec/hybrid_platforms_conductor_test/platform_handler_plugins/test.rb +1 -1
  234. data/spec/hybrid_platforms_conductor_test/platform_handler_plugins/{test2.rb → test_2.rb} +0 -0
  235. data/spec/hybrid_platforms_conductor_test/rubocop_spec.rb +31 -0
  236. data/spec/hybrid_platforms_conductor_test/serverless_chef_repositories/1_node/nodes/node.json +3 -3
  237. data/spec/hybrid_platforms_conductor_test/serverless_chef_repositories/data_bags/nodes/node.json +3 -3
  238. data/spec/hybrid_platforms_conductor_test/serverless_chef_repositories/recipes/cookbooks/test_cookbook_2/libraries/default.rb +1 -0
  239. data/spec/hybrid_platforms_conductor_test/serverless_chef_repositories/several_cookbooks/other_cookbooks/test_cookbook_2/libraries/default.rb +1 -0
  240. data/spec/hybrid_platforms_conductor_test/shared_examples/deployer.rb +952 -0
  241. data/spec/hybrid_platforms_conductor_test/test_connector.rb +4 -3
  242. data/spec/hybrid_platforms_conductor_test/test_log_no_read_plugin.rb +3 -1
  243. data/spec/hybrid_platforms_conductor_test/test_log_plugin.rb +3 -1
  244. data/spec/hybrid_platforms_conductor_test/test_plugins/global.rb +1 -0
  245. data/spec/hybrid_platforms_conductor_test/test_plugins/node.rb +1 -0
  246. data/spec/hybrid_platforms_conductor_test/test_plugins/node_check.rb +1 -0
  247. data/spec/hybrid_platforms_conductor_test/test_plugins/platform.rb +1 -0
  248. data/spec/hybrid_platforms_conductor_test/test_plugins/several_checks.rb +2 -2
  249. data/spec/hybrid_platforms_conductor_test/test_secrets_reader_plugin.rb +45 -0
  250. data/spec/hybrid_platforms_conductor_test/tests_report_plugin.rb +5 -6
  251. data/spec/spec_helper.rb +17 -18
  252. data/tools/check_md +16 -20
  253. data/tools/generate_mermaid +1 -1
  254. metadata +186 -144
  255. data/spec/hybrid_platforms_conductor_test/helpers/deployer_test_helpers.rb +0 -916
@@ -37,7 +37,7 @@ module HybridPlatformsConductor
37
37
  {
38
38
  ruby: proc do
39
39
  FileUtils.mkdir_p File.dirname(log_file)
40
- File.write(log_file, <<~EOS)
40
+ File.write(log_file, <<~EO_DEPLOYMENT_LOG)
41
41
  #{
42
42
  deployment_info.merge(
43
43
  debug: log_debug? ? 'Yes' : 'No',
@@ -49,7 +49,7 @@ module HybridPlatformsConductor
49
49
  #{stdout}
50
50
  #{MARKER_STDERR}
51
51
  #{stderr}
52
- EOS
52
+ EO_DEPLOYMENT_LOG
53
53
  end,
54
54
  remote_bash: "#{sudo_prefix}mkdir -p /var/log/deployments && #{sudo_prefix}chmod 600 /var/log/deployments"
55
55
  },
@@ -112,7 +112,7 @@ module HybridPlatformsConductor
112
112
  # * *exit_status* (Integer or Symbol): Deployment exit status
113
113
  # * *stdout* (String): Deployment stdout
114
114
  # * *stderr* (String): Deployment stderr
115
- def logs_for(node, exit_status, stdout, stderr)
115
+ def logs_for(_node, exit_status, stdout, stderr)
116
116
  # Expected format for stdout:
117
117
  # Property1: Value1
118
118
  # ...
@@ -133,7 +133,8 @@ module HybridPlatformsConductor
133
133
  deploy_info = {}
134
134
  stdout_lines[0..stdout_idx - 1].each do |line|
135
135
  if line =~ /^([^:]+): (.+)$/
136
- key_str, value = $1, $2
136
+ key_str = Regexp.last_match(1)
137
+ value = Regexp.last_match(2)
137
138
  key = key_str.to_sym
138
139
  # Type-cast some values
139
140
  case key_str
@@ -164,7 +165,7 @@ module HybridPlatformsConductor
164
165
  deployment_info: deploy_info,
165
166
  exit_status: exit_status =~ /^\d+$/ ? Integer(exit_status) : exit_status.to_sym,
166
167
  stdout: stdout_lines[stdout_idx + 1..stderr_idx - 1].join("\n"),
167
- stderr: stdout_lines[stderr_idx + 1..-1].join("\n")
168
+ stderr: stdout_lines[stderr_idx + 1..].join("\n")
168
169
  }
169
170
  end
170
171
  end
@@ -45,7 +45,7 @@ module HybridPlatformsConductor
45
45
  end
46
46
 
47
47
  end
48
- self.extend_config_dsl_with MyDSLExtension, :init_serverless_chef
48
+ extend_config_dsl_with MyDSLExtension, :init_serverless_chef
49
49
 
50
50
  # Constructor
51
51
  #
@@ -59,8 +59,8 @@ module HybridPlatformsConductor
59
59
  def initialize(
60
60
  platform_type,
61
61
  repository_path,
62
- logger: Logger.new(STDOUT),
63
- logger_stderr: Logger.new(STDERR),
62
+ logger: Logger.new($stdout),
63
+ logger_stderr: Logger.new($stderr),
64
64
  config: Config.new,
65
65
  cmd_runner: CmdRunner.new
66
66
  )
@@ -74,18 +74,16 @@ module HybridPlatformsConductor
74
74
  # [API] - @cmd_runner is accessible.
75
75
  def setup
76
76
  required_version = YAML.load_file("#{@repository_path}/chef_versions.yml")['workstation']
77
- Bundler.with_unbundled_env do
78
- exit_status, stdout, _stderr = @cmd_runner.run_cmd '/opt/chef-workstation/bin/chef --version', expected_code: [0, :command_error]
79
- existing_version =
80
- if exit_status == :command_error
81
- 'not installed'
82
- else
83
- expected_match = stdout.match(/^Chef Workstation version: (.+)\.\d+$/)
84
- expected_match.nil? ? 'unreadable' : expected_match[1]
85
- end
86
- log_debug "Current Chef version: #{existing_version}. Required version: #{required_version}"
87
- @cmd_runner.run_cmd "curl -L https://omnitruck.chef.io/install.sh | #{@cmd_runner.root? ? '' : 'sudo '}bash -s -- -P chef-workstation -v #{required_version}" unless existing_version == required_version
88
- end
77
+ exit_status, stdout, _stderr = @cmd_runner.run_cmd '/opt/chef-workstation/bin/chef --version', expected_code: [0, :command_error]
78
+ existing_version =
79
+ if exit_status == :command_error
80
+ 'not installed'
81
+ else
82
+ expected_match = stdout.match(/^Chef Workstation version: (.+)\.\d+$/)
83
+ expected_match.nil? ? 'unreadable' : expected_match[1]
84
+ end
85
+ log_debug "Current Chef version: #{existing_version}. Required version: #{required_version}"
86
+ @cmd_runner.run_cmd "curl -L https://omnitruck.chef.io/install.sh | #{@cmd_runner.root? ? '' : 'sudo '}bash -s -- -P chef-workstation -v #{required_version}" unless existing_version == required_version
89
87
  end
90
88
 
91
89
  # Get the list of known nodes.
@@ -146,11 +144,10 @@ module HybridPlatformsConductor
146
144
  if info[:status].nil?
147
145
  {}
148
146
  else
149
- Hash[
150
- (info[:status][:added_files] + info[:status][:changed_files] + info[:status][:untracked_files]).
151
- sort.
152
- map { |f| [f, File.mtime("#{@repository_path}/#{f}").strftime('%F %T')] }
153
- ]
147
+ (info[:status][:added_files] + info[:status][:changed_files] + info[:status][:untracked_files]).
148
+ sort.
149
+ map { |f| [f, File.mtime("#{@repository_path}/#{f}").strftime('%F %T')] }.
150
+ to_h
154
151
  end,
155
152
  deleted_files: info[:status].nil? ? [] : info[:status][:deleted_files].sort
156
153
  }
@@ -159,40 +156,39 @@ module HybridPlatformsConductor
159
156
  package_dir = "dist/#{local_environment ? 'local' : 'prod'}/#{service}"
160
157
  package_info_file = "#{@repository_path}/#{package_dir}/hpc_package.info"
161
158
  current_package_info = File.exist?(package_info_file) ? JSON.parse(File.read(package_info_file)).transform_keys(&:to_sym) : {}
162
- unless current_package_info == package_info
163
- Bundler.with_unbundled_env do
164
- policy_file = "policyfiles/#{service}.rb"
165
- if local_environment
166
- local_policy_file = "policyfiles/#{service}.local.rb"
167
- # In local mode, we always regenerate the lock file as we may modify the run list
168
- run_list = known_cookbook_paths.any? { |cookbook_path| File.exist?("#{@repository_path}/#{cookbook_path}/hpc_test/recipes/before_run.rb") } ? ['hpc_test::before_run'] : []
169
- dsl_parser = DslParser.new
170
- dsl_parser.parse("#{@repository_path}/#{policy_file}")
171
- run_list.concat dsl_parser.calls.find { |call_info| call_info[:method] == :run_list }[:args].flatten
172
- run_list << 'hpc_test::after_run' if known_cookbook_paths.any? { |cookbook_path| File.exist?("#{@repository_path}/#{cookbook_path}/hpc_test/recipes/after_run.rb") }
173
- File.write("#{@repository_path}/#{local_policy_file}", File.read("#{@repository_path}/#{policy_file}") + "\nrun_list #{run_list.map { |recipe| "'#{recipe}'" }.join(', ')}\n")
174
- policy_file = local_policy_file
175
- end
176
- lock_file = "#{File.dirname(policy_file)}/#{File.basename(policy_file, '.rb')}.lock.json"
177
- # If the policy lock file does not exist, generate it
178
- @cmd_runner.run_cmd "cd #{@repository_path} && /opt/chef-workstation/bin/chef install #{policy_file} --chef-license accept" unless File.exist?("#{@repository_path}/#{lock_file}")
179
- extra_cp_data_bags = File.exist?("#{@repository_path}/data_bags") ? " && cp -ar data_bags/ #{package_dir}/" : ''
180
- @cmd_runner.run_cmd "cd #{@repository_path} && \
181
- #{@cmd_runner.root? ? '' : 'sudo '}rm -rf #{package_dir} && \
182
- /opt/chef-workstation/bin/chef export #{policy_file} #{package_dir} --chef-license accept#{extra_cp_data_bags}"
183
- end
184
- unless @cmd_runner.dry_run
185
- # Create secrets file
186
- secrets_file = "#{@repository_path}/#{package_dir}/data_bags/hpc_secrets/hpc_secrets.json"
187
- FileUtils.mkdir_p(File.dirname(secrets_file))
188
- File.write(secrets_file, secrets.merge(id: 'hpc_secrets').to_json)
189
- # Remember the package info
190
- File.write(package_info_file, package_info.to_json)
191
- end
159
+ next if current_package_info == package_info
160
+
161
+ policy_file = "policyfiles/#{service}.rb"
162
+ if local_environment
163
+ local_policy_file = "policyfiles/#{service}.local.rb"
164
+ # In local mode, we always regenerate the lock file as we may modify the run list
165
+ run_list = known_cookbook_paths.any? { |cookbook_path| File.exist?("#{@repository_path}/#{cookbook_path}/hpc_test/recipes/before_run.rb") } ? ['hpc_test::before_run'] : []
166
+ dsl_parser = DslParser.new
167
+ dsl_parser.parse("#{@repository_path}/#{policy_file}")
168
+ run_list.concat dsl_parser.calls.find { |call_info| call_info[:method] == :run_list }[:args].flatten
169
+ run_list << 'hpc_test::after_run' if known_cookbook_paths.any? { |cookbook_path| File.exist?("#{@repository_path}/#{cookbook_path}/hpc_test/recipes/after_run.rb") }
170
+ File.write("#{@repository_path}/#{local_policy_file}", File.read("#{@repository_path}/#{policy_file}") + "\nrun_list #{run_list.map { |recipe| "'#{recipe}'" }.join(', ')}\n")
171
+ policy_file = local_policy_file
192
172
  end
173
+ lock_file = "#{File.dirname(policy_file)}/#{File.basename(policy_file, '.rb')}.lock.json"
174
+ # If the policy lock file does not exist, generate it
175
+ @cmd_runner.run_cmd "cd #{@repository_path} && /opt/chef-workstation/bin/chef install #{policy_file} --chef-license accept" unless File.exist?("#{@repository_path}/#{lock_file}")
176
+ extra_cp_data_bags = File.exist?("#{@repository_path}/data_bags") ? " && cp -ar data_bags/ #{package_dir}/" : ''
177
+ @cmd_runner.run_cmd "cd #{@repository_path} && \
178
+ #{@cmd_runner.root? ? '' : 'sudo '}rm -rf #{package_dir} && \
179
+ /opt/chef-workstation/bin/chef export #{policy_file} #{package_dir} --chef-license accept#{extra_cp_data_bags}"
180
+ next if @cmd_runner.dry_run
181
+
182
+ # Create secrets file
183
+ secrets_file = "#{@repository_path}/#{package_dir}/data_bags/hpc_secrets/hpc_secrets.json"
184
+ FileUtils.mkdir_p(File.dirname(secrets_file))
185
+ File.write(secrets_file, secrets.merge(id: 'hpc_secrets').to_json)
186
+ # Remember the package info
187
+ File.write(package_info_file, package_info.to_json)
193
188
  end
194
189
  end
195
190
 
191
+ # rubocop:disable Lint/UnusedMethodArgument
196
192
  # Prepare deployments.
197
193
  # This method is called just before getting and executing the actions to be deployed.
198
194
  # It is called once per platform.
@@ -208,6 +204,7 @@ module HybridPlatformsConductor
208
204
  def prepare_for_deploy(services:, secrets:, local_environment:, why_run:)
209
205
  @local_env = local_environment
210
206
  end
207
+ # rubocop:enable Lint/UnusedMethodArgument
211
208
 
212
209
  # Get the list of actions to perform to deploy on a given node.
213
210
  # Those actions can be executed in parallel with other deployments on other nodes. They must be thread safe.
@@ -242,6 +239,7 @@ module HybridPlatformsConductor
242
239
  package_name = File.basename(package_dir)
243
240
  chef_versions_file = "#{@repository_path}/chef_versions.yml"
244
241
  raise "Missing file #{chef_versions_file} specifying the Chef Infra Client version to be deployed" unless File.exist?(chef_versions_file)
242
+
245
243
  required_chef_client_version = YAML.load_file(chef_versions_file)['client']
246
244
  sudo = (@actions_executor.connector(:ssh).ssh_user == 'root' ? '' : "#{@nodes_handler.sudo_on(node)} ")
247
245
  [
@@ -285,7 +283,7 @@ module HybridPlatformsConductor
285
283
  # * *:changed*: The task has been changed
286
284
  # * *:identical*: The task has not been changed
287
285
  # * *diffs* (String): Differences, if any
288
- def parse_deploy_output(stdout, stderr)
286
+ def parse_deploy_output(stdout, _stderr)
289
287
  tasks = []
290
288
  current_task = nil
291
289
  stdout.split("\n").each do |line|
@@ -293,8 +291,8 @@ module HybridPlatformsConductor
293
291
  case line.gsub(/\e\[[^\x40-\x7E]*[\x40-\x7E]/, '').strip
294
292
  when /^\* (\w+\[[^\]]+\]) action (.+)$/
295
293
  # New task
296
- task_name = $1
297
- task_action = $2
294
+ task_name = Regexp.last_match(1)
295
+ task_action = Regexp.last_match(2)
298
296
  current_task = {
299
297
  name: task_name,
300
298
  action: task_action,
@@ -303,7 +301,7 @@ module HybridPlatformsConductor
303
301
  tasks << current_task
304
302
  when /^- (.+)$/
305
303
  # Diff on the current task
306
- diff_description = $1
304
+ diff_description = Regexp.last_match(1)
307
305
  unless current_task.nil?
308
306
  current_task[:diffs] = '' unless current_task.key?(:diffs)
309
307
  current_task[:diffs] << "#{diff_description}\n"
@@ -333,25 +331,23 @@ module HybridPlatformsConductor
333
331
  impacted_recipes = []
334
332
  impacted_global = false
335
333
  files_diffs.keys.sort.each do |impacted_file|
336
- if impacted_file =~ /^policyfiles\/([^\/]+)\.rb$/
337
- log_debug "[#{impacted_file}] - Impacted service: #{$1}"
338
- impacted_services << $1
339
- elsif impacted_file =~ /^policyfiles\/([^\/]+)\.lock.json$/
340
- log_debug "[#{impacted_file}] - Impacted service: #{$1}"
341
- impacted_services << $1
342
- elsif impacted_file =~ /^nodes\/([^\/]+)\.json/
343
- log_debug "[#{impacted_file}] - Impacted node: #{$1}"
344
- impacted_nodes << $1
334
+ case impacted_file
335
+ when %r{^policyfiles/([^/]+)\.rb$}, %r{^policyfiles/([^/]+)\.lock.json$}
336
+ log_debug "[#{impacted_file}] - Impacted service: #{Regexp.last_match(1)}"
337
+ impacted_services << Regexp.last_match(1)
338
+ when %r{^nodes/([^/]+)\.json}
339
+ log_debug "[#{impacted_file}] - Impacted node: #{Regexp.last_match(1)}"
340
+ impacted_nodes << Regexp.last_match(1)
345
341
  else
346
- cookbook_path = known_cookbook_paths.find { |cookbooks_path| impacted_file =~ /^#{Regexp.escape(cookbooks_path)}\/.+$/ }
342
+ cookbook_path = known_cookbook_paths.find { |cookbooks_path| impacted_file =~ %r{^#{Regexp.escape(cookbooks_path)}/.+$} }
347
343
  if cookbook_path.nil?
348
344
  # Global file
349
345
  log_debug "[#{impacted_file}] - Global file impacted"
350
346
  impacted_global = true
351
347
  else
352
348
  # File belonging to a cookbook
353
- cookbook_name, file_path = impacted_file.match(/^#{cookbook_path}\/(\w+)\/(.+)$/)[1..2]
354
- cookbook = cookbook_name.to_sym
349
+ file_cookbook_name, file_path = impacted_file.match(%r{^#{cookbook_path}/(\w+)/(.+)$})[1..2]
350
+ cookbook = file_cookbook_name.to_sym
355
351
  # Small helper to register a recipe
356
352
  register = proc do |source, recipe_name, cookbook_name: cookbook|
357
353
  cookbook_name = cookbook_name.to_sym if cookbook_name.is_a?(String)
@@ -359,41 +355,41 @@ module HybridPlatformsConductor
359
355
  impacted_recipes << [cookbook_name, recipe_name.to_sym]
360
356
  end
361
357
  case file_path
362
- when /recipes\/(.+)\.rb/
363
- register.call('direct', $1)
364
- when /attributes\/.+\.rb/, 'metadata.rb'
358
+ when %r{recipes/(.+)\.rb}
359
+ register.call('direct', Regexp.last_match(1))
360
+ when %r{attributes/.+\.rb}, 'metadata.rb'
365
361
  # Consider all recipes are impacted
366
362
  Dir.glob("#{@repository_path}/#{cookbook_path}/#{cookbook}/recipes/*.rb") do |recipe_path|
367
363
  register.call('attributes', File.basename(recipe_path, '.rb'))
368
364
  end
369
- when /(templates|files)\/(.+)/
365
+ when %r{(templates|files)/(.+)}
370
366
  # Find recipes using this file name
371
- included_file = File.basename($2)
367
+ included_file = File.basename(Regexp.last_match(2))
372
368
  template_regexp = /["']#{Regexp.escape(included_file)}["']/
373
369
  Dir.glob("#{@repository_path}/#{cookbook_path}/#{cookbook}/recipes/*.rb") do |recipe_path|
374
370
  register.call("included file #{included_file}", File.basename(recipe_path, '.rb')) if File.read(recipe_path) =~ template_regexp
375
371
  end
376
- when /resources\/(.+)/
372
+ when %r{resources/(.+)}
377
373
  # Find any recipe using this resource
378
- included_resource = "#{cookbook}_#{File.basename($1, '.rb')}"
374
+ included_resource = "#{cookbook}_#{File.basename(Regexp.last_match(1), '.rb')}"
379
375
  resource_regexp = /(\W|^)#{Regexp.escape(included_resource)}(\W|$)/
380
376
  known_cookbook_paths.each do |cookbooks_path|
381
377
  Dir.glob("#{@repository_path}/#{cookbooks_path}/**/recipes/*.rb") do |recipe_path|
382
378
  if File.read(recipe_path) =~ resource_regexp
383
- cookbook_name, recipe_name = recipe_path.match(/#{cookbooks_path}\/(\w+)\/recipes\/(\w+)\.rb/)[1..2]
379
+ cookbook_name, recipe_name = recipe_path.match(%r{#{cookbooks_path}/(\w+)/recipes/(\w+)\.rb})[1..2]
384
380
  register.call("included resource #{included_resource}", recipe_name, cookbook_name: cookbook_name)
385
381
  end
386
382
  end
387
383
  end
388
- when /libraries\/(.+)/
384
+ when %r{libraries/(.+)}
389
385
  # Find any recipe using methods from this library
390
- lib_methods_regexps = File.read("#{@repository_path}/#{impacted_file}").scan(/(\W|^)def\s+(\w+)(\W|$)/).map { |_grp1, method_name, _grp2| /(\W|^)#{Regexp.escape(method_name)}(\W|$)/ }
386
+ lib_methods_regexps = File.read("#{@repository_path}/#{impacted_file}").scan(/(\W|^)def\s+(\w+)(\W|$)/).map { |_grp_1, method_name, _grp_2| /(\W|^)#{Regexp.escape(method_name)}(\W|$)/ }
391
387
  known_cookbook_paths.each do |cookbooks_path|
392
388
  Dir.glob("#{@repository_path}/#{cookbooks_path}/**/recipes/*.rb") do |recipe_path|
393
389
  file_content = File.read(recipe_path)
394
390
  found_lib_regexp = lib_methods_regexps.find { |regexp| file_content =~ regexp }
395
391
  unless found_lib_regexp.nil?
396
- cookbook_name, recipe_name = recipe_path.match(/#{cookbooks_path}\/(\w+)\/recipes\/(\w+)\.rb/)[1..2]
392
+ cookbook_name, recipe_name = recipe_path.match(%r{#{cookbooks_path}/(\w+)/recipes/(\w+)\.rb})[1..2]
397
393
  register.call("included library helper #{found_lib_regexp.source[6..-7]}", recipe_name, cookbook_name: cookbook_name)
398
394
  end
399
395
  end
@@ -476,6 +472,7 @@ module HybridPlatformsConductor
476
472
  dsl_parser.parse(policy_file)
477
473
  run_list_call = dsl_parser.calls.find { |call_info| call_info[:method] == :run_list }
478
474
  raise "Policy #{policy} has no run list defined in #{policy_file}" if run_list_call.nil?
475
+
479
476
  run_list_call[:args].map { |recipe_def| decode_recipe(recipe_def) }
480
477
  end
481
478
 
@@ -493,13 +490,14 @@ module HybridPlatformsConductor
493
490
  # * Symbol: The cookbook name
494
491
  # * Symbol: The recipe name
495
492
  def decode_recipe(recipe_def)
496
- recipe_def = $1 if recipe_def =~ /^recipe\[(.+)\]$/
493
+ recipe_def = Regexp.last_match(1) if recipe_def =~ /^recipe\[(.+)\]$/
497
494
  cookbook, recipe = recipe_def.split('::').map(&:to_sym)
498
495
  recipe = :default if recipe.nil?
499
496
  # Find the cookbook it belongs to
500
497
  cookbook_dir = known_cookbook_paths.find { |cookbook_path| File.exist?("#{@repository_path}/#{cookbook_path}/#{cookbook}") }
501
498
  raise "Unknown recipe #{cookbook}::#{recipe} from cookbook #{@repository_path}/#{cookbook_dir}/#{cookbook}." if !cookbook_dir.nil? && !File.exist?("#{@repository_path}/#{cookbook_dir}/#{cookbook}/recipes/#{recipe}.rb")
502
- return cookbook_dir, cookbook, recipe
499
+
500
+ [cookbook_dir, cookbook, recipe]
503
501
  end
504
502
 
505
503
  private
@@ -29,6 +29,10 @@ module HybridPlatformsConductor
29
29
  instance_eval(File.read(source))
30
30
  end
31
31
 
32
+ # Intercept all missing methods
33
+ #
34
+ # Parameters::
35
+ # * *method_name* (Symbol): The missing method being called
32
36
  def method_missing(method_name, *args, &block)
33
37
  sub_calls = []
34
38
  @calls << {
@@ -40,6 +44,15 @@ module HybridPlatformsConductor
40
44
  DslParser.new(sub_calls)
41
45
  end
42
46
 
47
+ # Make sure we register the methods we handle in method_missing
48
+ #
49
+ # Parameters::
50
+ # * *name* (Symbol): The missing method name
51
+ # * *include_private* (Boolean): Should we include private methods in the search?
52
+ def respond_to_missing?(_name, _include_private)
53
+ true
54
+ end
55
+
43
56
  end
44
57
 
45
58
  end
@@ -40,11 +40,14 @@ module HybridPlatformsConductor
40
40
  add_recipe_in_tree(cookbook_dir, cookbook, recipe)
41
41
  end
42
42
  end
43
+ # Make sure we don't combine those 2 loops
44
+ # rubocop:disable Style/CombinableLoops
43
45
  @platform.deployable_services.each do |service|
44
- @platform.policy_run_list(service).each do |(cookbook_dir, cookbook, recipe)|
46
+ @platform.policy_run_list(service).each do |(_cookbook_dir, cookbook, recipe)|
45
47
  mark_recipe_used_by_policy(cookbook, recipe, service)
46
48
  end
47
49
  end
50
+ # rubocop:enable Style/CombinableLoops
48
51
  @recipes_tree
49
52
  end
50
53
 
@@ -58,25 +61,25 @@ module HybridPlatformsConductor
58
61
  # * *recipe* (Symbol): The recipe name
59
62
  def add_recipe_in_tree(cookbook_dir, cookbook, recipe)
60
63
  @recipes_tree[cookbook] = {} unless @recipes_tree.key?(cookbook)
61
- unless @recipes_tree[cookbook].key?(recipe)
62
- recipe_info =
63
- if cookbook_dir.nil?
64
- # This recipe comes from an external cookbook, we won't get into it.
65
- {
66
- included_recipes: [],
67
- used_templates: [],
68
- used_files: [],
69
- used_cookbooks: []
70
- }
71
- else
72
- recipe_usage(cookbook_dir, cookbook, recipe)
73
- end
74
- @recipes_tree[cookbook][recipe] = recipe_info.merge(
75
- used_by_policies: []
76
- )
77
- recipe_info[:included_recipes].each do |(sub_cookbook_dir, sub_cookbook, sub_recipe)|
78
- add_recipe_in_tree(sub_cookbook_dir, sub_cookbook, sub_recipe)
64
+ return if @recipes_tree[cookbook].key?(recipe)
65
+
66
+ recipe_info =
67
+ if cookbook_dir.nil?
68
+ # This recipe comes from an external cookbook, we won't get into it.
69
+ {
70
+ included_recipes: [],
71
+ used_templates: [],
72
+ used_files: [],
73
+ used_cookbooks: []
74
+ }
75
+ else
76
+ recipe_usage(cookbook_dir, cookbook, recipe)
79
77
  end
78
+ @recipes_tree[cookbook][recipe] = recipe_info.merge(
79
+ used_by_policies: []
80
+ )
81
+ recipe_info[:included_recipes].each do |(sub_cookbook_dir, sub_cookbook, sub_recipe)|
82
+ add_recipe_in_tree(sub_cookbook_dir, sub_cookbook, sub_recipe)
80
83
  end
81
84
  end
82
85
 
@@ -115,18 +118,18 @@ module HybridPlatformsConductor
115
118
  recipe_content.
116
119
  scan(/source\s+(["'])(.+?)\1/).
117
120
  each do |(_sub_grp, source)|
118
- sources << source unless source =~ /^https?:\/\//
121
+ sources << source unless source =~ %r{^https?://}
119
122
  end
120
123
  erb_sources = sources.select { |source| File.extname(source).downcase == '.erb' }
121
124
  non_erb_sources = sources - erb_sources
122
125
  erb_sources.concat(recipe_content.scan(/template:?\s+(["'])(.+?)\1/).map { |(_sub_grp, source)| source })
123
126
  # Check for known resources and library methods
124
127
  used_cookbooks = []
125
- known_resources.each do |cookbook, methods|
126
- used_cookbooks << cookbook if methods.any? { |method_name| recipe_content.include?(method_name) }
128
+ known_resources.each do |itr_cookbook, methods|
129
+ used_cookbooks << itr_cookbook if methods.any? { |method_name| recipe_content.include?(method_name) }
127
130
  end
128
- known_library_methods.each do |cookbook, methods|
129
- used_cookbooks << cookbook if methods.any? { |method_name| recipe_content.include?(method_name) }
131
+ known_library_methods.each do |itr_cookbook, methods|
132
+ used_cookbooks << itr_cookbook if methods.any? { |method_name| recipe_content.include?(method_name) }
130
133
  end
131
134
  {
132
135
  included_recipes: used_recipes,
@@ -171,9 +174,9 @@ module HybridPlatformsConductor
171
174
  @known_library_methods = {}
172
175
  for_each_cookbook do |cookbook, cookbook_dir|
173
176
  if File.exist?("#{cookbook_dir}/libraries")
174
- found_methods = Dir.glob("#{cookbook_dir}/libraries/*.rb").
175
- map { |lib_file| File.read(lib_file).scan(/\bdef\s+(\w+)\b/).map { |(method_name)| method_name } }.
176
- flatten - INVALID_LIBRARY_METHODS
177
+ found_methods = Dir.glob("#{cookbook_dir}/libraries/*.rb").
178
+ map { |lib_file| File.read(lib_file).scan(/\bdef\s+(\w+)\b/).map { |(method_name)| method_name } }.
179
+ flatten - INVALID_LIBRARY_METHODS
177
180
  @known_library_methods[cookbook] = found_methods unless found_methods.empty?
178
181
  end
179
182
  end
@@ -184,15 +187,13 @@ module HybridPlatformsConductor
184
187
  # Iterate over all cookbooks
185
188
  #
186
189
  # Parameters::
187
- # * Proc: Code called for each cookbook:
190
+ # * *block* (Proc): Code called for each cookbook:
188
191
  # * Parameters::
189
192
  # * *cookbook* (Symbol): Cookbook name
190
193
  # * *cookbook_dir* (String): Cookbook directory
191
- def for_each_cookbook
194
+ def for_each_cookbook(&block)
192
195
  @platform.known_cookbook_paths.each do |cookbook_path|
193
- cookbooks_in(cookbook_path).each do |cookbook, cookbook_dir|
194
- yield cookbook, cookbook_dir
195
- end
196
+ cookbooks_in(cookbook_path).each(&block)
196
197
  end
197
198
  end
198
199
 
@@ -203,7 +204,7 @@ module HybridPlatformsConductor
203
204
  # Result::
204
205
  # * Hash<Symbol, String>: List of cookbook directories, per cookbook name
205
206
  def cookbooks_in(cookbook_type)
206
- Hash[Dir.glob("#{@platform.repository_path}/#{cookbook_type}/*").map { |dir| [File.basename(dir).to_sym, dir] }.sort]
207
+ Dir.glob("#{@platform.repository_path}/#{cookbook_type}/*").map { |dir| [File.basename(dir).to_sym, dir] }.sort.to_h
207
208
  end
208
209
 
209
210
  # Mark a recipe (and its included recipes) as used by a policy
@@ -213,11 +214,11 @@ module HybridPlatformsConductor
213
214
  # * *recipe* (Symbol): The recipe
214
215
  # * *used_by_policy* (String): The policy using this recipe
215
216
  def mark_recipe_used_by_policy(cookbook, recipe, used_by_policy)
216
- unless @recipes_tree[cookbook][recipe][:used_by_policies].include?(used_by_policy)
217
- @recipes_tree[cookbook][recipe][:used_by_policies] << used_by_policy
218
- @recipes_tree[cookbook][recipe][:included_recipes].each do |(_sub_cookbook_dir, sub_cookbook, sub_recipe)|
219
- mark_recipe_used_by_policy(sub_cookbook, sub_recipe, used_by_policy)
220
- end
217
+ return if @recipes_tree[cookbook][recipe][:used_by_policies].include?(used_by_policy)
218
+
219
+ @recipes_tree[cookbook][recipe][:used_by_policies] << used_by_policy
220
+ @recipes_tree[cookbook][recipe][:included_recipes].each do |(_sub_cookbook_dir, sub_cookbook, sub_recipe)|
221
+ mark_recipe_used_by_policy(sub_cookbook, sub_recipe, used_by_policy)
221
222
  end
222
223
  end
223
224