onceover 3.21.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (191) hide show
  1. checksums.yaml +4 -4
  2. data/.devcontainer/devcontainer.json +4 -6
  3. data/.github/dependabot.yml +17 -0
  4. data/.github/workflows/release.yaml +32 -0
  5. data/.github/workflows/tests.yaml +30 -4
  6. data/.gitignore +2 -1
  7. data/.rubocop.yml +4 -704
  8. data/.rubocop_todo.yml +828 -0
  9. data/CHANGELOG.md +1036 -0
  10. data/Gemfile +9 -0
  11. data/LICENSE +202 -0
  12. data/README.md +122 -32
  13. data/Rakefile +24 -14
  14. data/cucumber.yml +1 -0
  15. data/features/auto_vendored.feature +27 -0
  16. data/features/step_definitions/common.rb +5 -5
  17. data/features/step_definitions/run.rb +4 -0
  18. data/features/support/cache_helper.rb +0 -1
  19. data/features/support/command_helper.rb +0 -2
  20. data/features/support/controlrepo_helper.rb +0 -2
  21. data/features/zzz_run.feature +1 -8
  22. data/lib/onceover/beaker/spec_helper.rb +9 -9
  23. data/lib/onceover/beaker.rb +9 -12
  24. data/lib/onceover/cli/run.rb +1 -0
  25. data/lib/onceover/controlrepo.rb +22 -27
  26. data/lib/onceover/deploy.rb +30 -3
  27. data/lib/onceover/group.rb +1 -3
  28. data/lib/onceover/logger.rb +3 -3
  29. data/lib/onceover/node.rb +0 -2
  30. data/lib/onceover/rake_tasks.rb +9 -4
  31. data/lib/onceover/rspec/formatters.rb +5 -8
  32. data/lib/onceover/runner.rb +1 -1
  33. data/lib/onceover/test.rb +2 -3
  34. data/lib/onceover/testconfig.rb +2 -2
  35. data/lib/onceover/vendored_modules.rb +186 -0
  36. data/onceover.gemspec +26 -30
  37. data/spec/fixtures/controlrepos/caching/spec/factsets/README.md +1 -1
  38. data/spec/fixtures/controlrepos/caching/spec/pre_conditions/README.md +1 -1
  39. data/spec/fixtures/controlrepos/factsets/spec/factsets/README.md +1 -1
  40. data/spec/fixtures/controlrepos/puppet_controlrepo/.atom-build.json +9 -0
  41. data/spec/fixtures/controlrepos/puppet_controlrepo/.gitignore +5 -0
  42. data/spec/fixtures/controlrepos/puppet_controlrepo/.ruby-version +1 -0
  43. data/spec/fixtures/controlrepos/puppet_controlrepo/.travis.yml +13 -0
  44. data/spec/fixtures/controlrepos/puppet_controlrepo/Gemfile +22 -0
  45. data/spec/fixtures/controlrepos/puppet_controlrepo/Jenkinsfile +50 -0
  46. data/spec/fixtures/controlrepos/puppet_controlrepo/Puppetfile +102 -0
  47. data/spec/fixtures/controlrepos/puppet_controlrepo/README.md +4 -0
  48. data/spec/fixtures/controlrepos/puppet_controlrepo/Rakefile +6 -0
  49. data/spec/fixtures/controlrepos/puppet_controlrepo/data/common.yaml +558 -0
  50. data/spec/fixtures/controlrepos/puppet_controlrepo/data/datacenter/melbourne.yaml +12 -0
  51. data/spec/fixtures/controlrepos/puppet_controlrepo/data/datacenter/singapore.yaml +12 -0
  52. data/spec/fixtures/controlrepos/puppet_controlrepo/data/environments/development.yaml +3 -0
  53. data/spec/fixtures/controlrepos/puppet_controlrepo/data/environments/production.yaml +3 -0
  54. data/spec/fixtures/controlrepos/puppet_controlrepo/data/size/vol.large.yaml +27 -0
  55. data/spec/fixtures/controlrepos/puppet_controlrepo/environment.conf +3 -0
  56. data/spec/fixtures/controlrepos/puppet_controlrepo/hiera.yaml +25 -0
  57. data/spec/fixtures/controlrepos/puppet_controlrepo/manifests/site.pp +11 -0
  58. data/spec/fixtures/controlrepos/puppet_controlrepo/scripts/code_manager_config_version.rb +19 -0
  59. data/spec/fixtures/controlrepos/puppet_controlrepo/scripts/config_version.rb +25 -0
  60. data/spec/fixtures/controlrepos/puppet_controlrepo/scripts/config_version.sh +12 -0
  61. data/spec/fixtures/controlrepos/puppet_controlrepo/scripts/count_changed_classes.rb +26 -0
  62. data/spec/fixtures/controlrepos/puppet_controlrepo/scripts/get_changed_classes.rb +26 -0
  63. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/console/functions/user/token.pp +10 -0
  64. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/console/manifests/init.pp +14 -0
  65. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/console/manifests/user.pp +35 -0
  66. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/deployments/lib/puppet/functions/deployments/generate.rb +15 -0
  67. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/deployments/plans/signed_deployment.pp +126 -0
  68. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/facts.d/test.sh +2 -0
  69. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/files/artifactory/config_descriptor.xml +265 -0
  70. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/files/autosign.sh +23 -0
  71. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/files/hudson.tasks.Shell.xml +4 -0
  72. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/files/motd +4 -0
  73. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/files/polar_clock/index.html +198 -0
  74. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/apt.pp +9 -0
  75. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/aws_nodes.pp +54 -0
  76. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/base/aws.pp +9 -0
  77. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/base/rhel.pp +50 -0
  78. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/base/windows/hardening.pp +57 -0
  79. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/base/windows.pp +52 -0
  80. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/base.pp +79 -0
  81. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/cd4pe/artifactory.pp +64 -0
  82. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/cd4pe/connection.pp +95 -0
  83. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/cd4pe/haproxy.pp +65 -0
  84. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/cd4pe/replicated.pp +53 -0
  85. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/compile/balancer.pp +28 -0
  86. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/compile/master.pp +19 -0
  87. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/dns/host_record.pp +16 -0
  88. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/dns/server.pp +66 -0
  89. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/docker.pp +5 -0
  90. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/eyeunify/base.pp +43 -0
  91. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/eyeunify/core/database_connection.pp +42 -0
  92. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/eyeunify/core.pp +72 -0
  93. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/eyeunify/ctrl.pp +57 -0
  94. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/eyeunify/database.pp +32 -0
  95. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/eyeunify/exec.pp +11 -0
  96. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/file_sync/client.pp +165 -0
  97. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/file_sync/master_patch.pp +37 -0
  98. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/grafana/dashboard.pp +17 -0
  99. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/haproxy.pp +43 -0
  100. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/init.pp +3 -0
  101. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/jenkins/plugins.pp +87 -0
  102. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/jenkins.pp +65 -0
  103. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/jira/aio.pp +39 -0
  104. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/jira/app.pp +27 -0
  105. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/jira/db.pp +25 -0
  106. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/metrics/collectd/compile.pp +82 -0
  107. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/metrics/collectd.pp +28 -0
  108. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/metrics/dashboard.pp +28 -0
  109. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/mysql_server.pp +7 -0
  110. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/nginx.pp +24 -0
  111. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/polar_clock.pp +55 -0
  112. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/puppetmaster/api_auth.pp +82 -0
  113. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/puppetmaster/autosign.pp +33 -0
  114. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/puppetmaster/aws.pp +58 -0
  115. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/puppetmaster/tuning.pp +139 -0
  116. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/puppetmaster.pp +139 -0
  117. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/rvm.pp +13 -0
  118. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/sumologic.pp +11 -0
  119. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/sunburst/windows.pp +104 -0
  120. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/vagrant.pp +25 -0
  121. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/manifests/windows/webserver.pp +27 -0
  122. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/templates/cd4pe/connection_script.sh.epp +110 -0
  123. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/templates/controlrepo_deploy_jenkins_job.xml.epp +51 -0
  124. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/templates/dashboard.json.epp +403 -0
  125. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/templates/jenkins_secret_text.json.epp +1 -0
  126. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/templates/onceover_jenkins_job.xml.epp +51 -0
  127. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/profile/templates/userdata.epp +17 -0
  128. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/role/manifests/cd4pe.pp +29 -0
  129. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/role/manifests/clock.pp +16 -0
  130. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/role/manifests/compile/balancer.pp +5 -0
  131. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/role/manifests/compile/master.pp +5 -0
  132. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/role/manifests/eyeunify/aio.pp +10 -0
  133. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/role/manifests/eyeunify/controller.pp +10 -0
  134. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/role/manifests/eyeunify/database.pp +7 -0
  135. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/role/manifests/eyeunify/exec.pp +6 -0
  136. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/role/manifests/init.pp +3 -0
  137. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/role/manifests/lb.pp +14 -0
  138. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/role/manifests/metrics.pp +5 -0
  139. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/role/manifests/mysql.pp +13 -0
  140. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/role/manifests/windows/base.pp +5 -0
  141. data/spec/fixtures/controlrepos/puppet_controlrepo/site-modules/role/manifests/windows/webserver.pp +6 -0
  142. data/spec/fixtures/controlrepos/puppet_controlrepo/spec/.gitignore +5 -0
  143. data/spec/fixtures/controlrepos/puppet_controlrepo/spec/acceptance/nodesets/onceover-nodes.yml +94 -0
  144. data/spec/fixtures/controlrepos/puppet_controlrepo/spec/classes/test_spec.rb +8 -0
  145. data/spec/fixtures/controlrepos/puppet_controlrepo/spec/factsets/CentOS-7.0-64-master-2017.3.2.json +531 -0
  146. data/spec/fixtures/controlrepos/puppet_controlrepo/spec/factsets/CentOS-7.0-64-master.json +429 -0
  147. data/spec/fixtures/controlrepos/puppet_controlrepo/spec/factsets/CentOS-7.0-64.json +353 -0
  148. data/spec/fixtures/controlrepos/puppet_controlrepo/spec/factsets/Windows_Server-2008r2-64.json +184 -0
  149. data/spec/fixtures/controlrepos/puppet_controlrepo/spec/factsets/Windows_Server-2012r2-64.json +165 -0
  150. data/spec/fixtures/controlrepos/puppet_controlrepo/spec/hiera.yaml +18 -0
  151. data/spec/fixtures/controlrepos/puppet_controlrepo/spec/matchers/file_matchers.rb +16 -0
  152. data/spec/fixtures/controlrepos/puppet_controlrepo/spec/onceover.yaml +54 -0
  153. data/spec/fixtures/controlrepos/puppet_controlrepo/spec/pre_conditions/site.pp +150 -0
  154. data/spec/fixtures/controlrepos/puppet_controlrepo/spec/r10k.yaml +2 -0
  155. data/spec/fixtures/controlrepos/puppet_controlrepo/spec/shared_examples/helper.rb +91 -0
  156. data/spec/fixtures/controlrepos/puppet_controlrepo/spec/unit/00_parse_spec.rb +76 -0
  157. data/spec/fixtures/controlrepos/puppet_controlrepo/spec/unit/01_linting_spec_example.rb +69 -0
  158. data/spec/fixtures/controlrepos/puppet_controlrepo/spec/unit/03_puppetfile_spec_example.rb +35 -0
  159. data/spec/fixtures/controlrepos/vendored/Puppetfile +3 -0
  160. data/spec/fixtures/controlrepos/vendored/Puppetfile.cron +5 -0
  161. data/spec/fixtures/controlrepos/vendored/environment.conf +1 -0
  162. data/spec/fixtures/controlrepos/vendored/site-modules/role/manifests/cron.pp +9 -0
  163. data/spec/fixtures/controlrepos/vendored/spec/vendored_modules/augeas_core-puppet_agent-7.30.0.json +1 -0
  164. data/spec/fixtures/controlrepos/vendored/spec/vendored_modules/augeas_core-puppet_agent-8.6.0.json +1 -0
  165. data/spec/fixtures/controlrepos/vendored/spec/vendored_modules/cron_core-puppet_agent-7.30.0.json +1 -0
  166. data/spec/fixtures/controlrepos/vendored/spec/vendored_modules/cron_core-puppet_agent-8.6.0.json +1 -0
  167. data/spec/fixtures/controlrepos/vendored/spec/vendored_modules/host_core-puppet_agent-7.30.0.json +1 -0
  168. data/spec/fixtures/controlrepos/vendored/spec/vendored_modules/host_core-puppet_agent-8.6.0.json +1 -0
  169. data/spec/fixtures/controlrepos/vendored/spec/vendored_modules/mount_core-puppet_agent-7.30.0.json +1 -0
  170. data/spec/fixtures/controlrepos/vendored/spec/vendored_modules/mount_core-puppet_agent-8.6.0.json +1 -0
  171. data/spec/fixtures/controlrepos/vendored/spec/vendored_modules/repo_tree-puppet_agent-7.30.0.json +1 -0
  172. data/spec/fixtures/controlrepos/vendored/spec/vendored_modules/repo_tree-puppet_agent-8.6.0.json +1 -0
  173. data/spec/fixtures/controlrepos/vendored/spec/vendored_modules/scheduled_task-puppet_agent-7.30.0.json +1 -0
  174. data/spec/fixtures/controlrepos/vendored/spec/vendored_modules/scheduled_task-puppet_agent-8.6.0.json +1 -0
  175. data/spec/fixtures/controlrepos/vendored/spec/vendored_modules/selinux_core-puppet_agent-7.30.0.json +1 -0
  176. data/spec/fixtures/controlrepos/vendored/spec/vendored_modules/selinux_core-puppet_agent-8.6.0.json +1 -0
  177. data/spec/fixtures/controlrepos/vendored/spec/vendored_modules/sshkeys_core-puppet_agent-7.30.0.json +1 -0
  178. data/spec/fixtures/controlrepos/vendored/spec/vendored_modules/sshkeys_core-puppet_agent-8.6.0.json +1 -0
  179. data/spec/fixtures/controlrepos/vendored/spec/vendored_modules/yumrepo_core-puppet_agent-7.30.0.json +1 -0
  180. data/spec/fixtures/controlrepos/vendored/spec/vendored_modules/yumrepo_core-puppet_agent-8.6.0.json +1 -0
  181. data/spec/fixtures/controlrepos/vendored/spec/vendored_modules/zfs_core-puppet_agent-7.30.0.json +1 -0
  182. data/spec/fixtures/controlrepos/vendored/spec/vendored_modules/zfs_core-puppet_agent-8.6.0.json +1 -0
  183. data/spec/fixtures/controlrepos/vendored/spec/vendored_modules/zone_core-puppet_agent-7.30.0.json +1 -0
  184. data/spec/fixtures/controlrepos/vendored/spec/vendored_modules/zone_core-puppet_agent-8.6.0.json +1 -0
  185. data/spec/onceover/controlrepo_spec.rb +1 -1
  186. data/templates/factsets_README.md.erb +1 -1
  187. data/templates/pre_conditions_README.md.erb +1 -1
  188. data/templates/spec_helper.rb.erb +0 -2
  189. data/templates/test_spec.rb.erb +3 -0
  190. metadata +173 -68
  191. data/.gitmodules +0 -4
@@ -0,0 +1,186 @@
1
+ require 'puppet/version'
2
+ require 'net/http'
3
+ require 'uri'
4
+ require 'multi_json'
5
+ require 'r10k/module_loader/puppetfile'
6
+ require 'onceover/logger'
7
+
8
+ ### operations
9
+ #
10
+ # 1. resolve all the component json files in the puppet-agent repo for vendored modules
11
+ # 2. parse each json file and determine vendored modules repo + ref
12
+ #
13
+ ###
14
+
15
+ ## Example
16
+ #
17
+ # vm = Onceover::VendoredModules.new
18
+ # puts vm.vendored_references
19
+ # puppetfile = R10K::ModuleLoader::Puppetfile.new(basedir: '.')
20
+ # vm.puppetfile_missing_vendored(puppetfile)
21
+ # puts vm.missing_vendored.inspect
22
+
23
+ class Onceover
24
+ class VendoredModules
25
+ attr_reader :vendored_references, :missing_vendored
26
+
27
+ def initialize(opts = {})
28
+ @repo = opts[:repo] || Onceover::Controlrepo.new
29
+ @cachedir = opts[:cachedir] || File.join(@repo.tempdir, 'vendored_modules')
30
+ @puppet_version = Gem::Version.new(Puppet.version)
31
+ @puppet_major_version = Gem::Version.new(@puppet_version.segments[0])
32
+ @force_update = opts[:force_update] || false
33
+
34
+ @missing_vendored = []
35
+
36
+ # This only applies to puppet >= 6 so bail early
37
+ raise 'Auto resolving vendored modules only applies to puppet versions >= 6' unless @puppet_major_version >= Gem::Version.new('6')
38
+
39
+ # Create cachedir
40
+ unless File.directory?(@cachedir)
41
+ logger.debug "Creating #{@cachedir}"
42
+ FileUtils.mkdir_p(@cachedir)
43
+ end
44
+
45
+ # Location of user provided caches:
46
+ # control-repo/spec/vendored_modules/<component>-puppet_agent-<agent version>.json
47
+ @manual_vendored_dir = File.join(@repo.spec_dir, 'vendored_modules')
48
+
49
+ # Get the entire file tree of the puppetlabs/puppet-agent repository
50
+ # https://docs.github.com/en/rest/git/trees?apiVersion=2022-11-28#get-a-tree
51
+ puppet_agent_tree = query_or_cache(
52
+ "https://api.github.com/repos/puppetlabs/puppet-agent/git/trees/#{@puppet_version}",
53
+ { recursive: true },
54
+ component_cache('repo_tree'),
55
+ )
56
+ # Get only the module-puppetlabs-<something>_core.json component files
57
+ vendored_components = puppet_agent_tree['tree'].select { |file| %r{configs/components/module-puppetlabs-\w+\.json}.match(file['path']) }
58
+ # Get the contents of each component file
59
+ # https://docs.github.com/en/rest/git/blobs?apiVersion=2022-11-28#get-a-blob
60
+ @vendored_references = vendored_components.map do |component|
61
+ mod_slug = component['path'].match(/.*(puppetlabs-\w+).json$/)[1]
62
+ mod_name = mod_slug.match(/puppetlabs-(\w+)/)[1]
63
+ query_or_cache(
64
+ component['url'],
65
+ nil,
66
+ component_cache(mod_name),
67
+ )
68
+ end
69
+ end
70
+
71
+ def component_cache(component)
72
+ # Ideally we want a cache for the version of the puppet agent used in tests
73
+ desired_name = "#{component}-puppet_agent-#{@puppet_version}.json"
74
+ # By default look for any caches created during previous runs
75
+ cache_file = File.join(@cachedir, desired_name)
76
+
77
+ # If the user provides their own cache
78
+ if !@force_update && File.directory?(@manual_vendored_dir)
79
+ # Check for any '<component>-puppet_agent-<puppet version>.json' files
80
+ dg = Dir.glob(File.join(@manual_vendored_dir, "#{component}-puppet_agent*"))
81
+ # Check if there are multiple versions of the component cache
82
+ if dg.size > 1
83
+ # If there is the same version supplied as whats being tested against use that
84
+ if dg.any? { |s| s[desired_name] }
85
+ cache_file = File.join(@manual_vendored_dir, desired_name)
86
+ # If there are any with the same major version, use the latest supplied
87
+ elsif dg.any? { |s| s["#{component}-puppet_agent-#{@puppet_major_version}"] }
88
+ maj_match = dg.select { |f| /#{component}-puppet_agent-#{@puppet_major_version}.\d+\.\d+\.json/.match(f) }
89
+ maj_match.each do |f|
90
+ next unless (version_from_file(cache_file) == version_from_file(desired_name)) || (version_from_file(f) >= version_from_file(cache_file))
91
+
92
+ # if the current cache version matches the desired version, use the first matching major version in user cache
93
+ # if there are multiple major version matches in user cache, use the latest
94
+ cache_file = f
95
+ end
96
+ # Otherwise just use the latest supplied
97
+ else
98
+ dg.each { |f| cache_file = f if version_from_file(f) >= version_from_file(cache_file) }
99
+ end
100
+ # If there is only one use that
101
+ elsif dg.size == 1
102
+ cache_file = dg[0]
103
+ end
104
+ end
105
+
106
+ # Warn the user if cached version does not match whats being used to test
107
+ cache_version = version_from_file(cache_file)
108
+ logger.warn "Cache for #{component} is for puppet_agent #{cache_version}, while you are testing against puppet_agent #{@puppet_version}. Consider updating your cache to ensure consistent behavior in your tests" if cache_version != @puppet_version
109
+
110
+ cache_file
111
+ end
112
+
113
+ def version_from_file(cache_file)
114
+ version_regex = /.*-puppet_agent-(\d+\.\d+\.\d+)\.json/
115
+ Gem::Version.new(version_regex.match(cache_file)[1])
116
+ end
117
+
118
+ # Currently expects to be passed a R10K::Puppetfile object.
119
+ # ex: R10K::ModuleLoader::Puppetfile.new(basedir: '.')
120
+ def puppetfile_missing_vendored(puppetfile)
121
+ puppetfile.load
122
+ @vendored_references.each do |mod|
123
+ # Extract name and slug from url
124
+ mod_slug = mod['url'].match(/.*(puppetlabs-\w+)\.git/)[1]
125
+ mod_name = mod_slug.match(/^puppetlabs-(\w+)$/)[1]
126
+ # Array of modules whos names match
127
+ existing = puppetfile.modules.select { |e_mod| e_mod.name == mod_name }
128
+ if existing.empty?
129
+ # Change url to https instead of ssh to allow anonymous git clones
130
+ # so that users do not need to have an ssh keypair associated with a Github account
131
+ url = mod['url'].gsub('git@github.com:', 'https://github.com/')
132
+ @missing_vendored << { mod_slug => { git: url, ref: mod['ref'] } }
133
+ logger.debug "#{mod_name} found to be missing in Puppetfile"
134
+ else
135
+ logger.debug "#{mod_name} found in Puppetfile. Using the specified version"
136
+ end
137
+ end
138
+ end
139
+
140
+ # Return json from a query whom caches, or from the cache to avoid spamming github
141
+ def query_or_cache(url, params, filepath)
142
+ if (File.exist? filepath) && (@force_update == false)
143
+ logger.debug "Using cache: #{filepath}"
144
+ json = read_json_dump(filepath)
145
+ else
146
+ logger.debug "Making GET request to: #{url}"
147
+ json = github_get(url, params)
148
+ logger.debug "Caching response to: #{filepath}"
149
+ write_json_dump(filepath, json)
150
+ end
151
+ json
152
+ end
153
+
154
+ # Given a github url and optional query parameters, return the parsed json body
155
+ def github_get(url, params)
156
+ uri = URI.parse(url)
157
+ uri.query = URI.encode_www_form(params) if params
158
+ http = Net::HTTP.new(uri.host, uri.port)
159
+ http.use_ssl = (uri.scheme == 'https')
160
+ request = Net::HTTP::Get.new(uri.request_uri)
161
+ request['Accept'] = 'application/vnd.github.raw+json'
162
+ request['X-GitHub-Api-Version'] = '2022-11-28'
163
+ response = http.request(request)
164
+
165
+ case response
166
+ when Net::HTTPOK # 200
167
+ MultiJson.load(response.body)
168
+ else
169
+ # Expose the ratelimit response headers
170
+ # https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api?apiVersion=2022-11-28#checking-the-status-of-your-rate-limit
171
+ ratelimit_headers = response.to_hash.select { |k, _v| k =~ /x-ratelimit.*/ }
172
+ raise "#{response.code} #{response.message} #{ratelimit_headers}"
173
+ end
174
+ end
175
+
176
+ # Returns parsed json of file
177
+ def read_json_dump(filepath)
178
+ MultiJson.load(File.read(filepath))
179
+ end
180
+
181
+ # Writes json to a file
182
+ def write_json_dump(filepath, json_data)
183
+ File.write(filepath, MultiJson.dump(json_data))
184
+ end
185
+ end
186
+ end
data/onceover.gemspec CHANGED
@@ -1,13 +1,13 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
- $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift File.expand_path('lib', __dir__)
4
4
 
5
- Gem::Specification.new do |s|
5
+ Gem::Specification.new do |s| # rubocop:disable Gemspec/RequireMFA
6
6
  s.name = "onceover"
7
- s.version = "3.21.0"
8
- s.authors = ["Dylan Ratcliffe"]
9
- s.email = ["dylan.ratcliffe@puppet.com"]
10
- s.homepage = "https://github.com/dylanratcliffe/onceover"
7
+ s.version = "4.0.0"
8
+ s.authors = ["Dylan Ratcliffe", 'Vox Pupuli']
9
+ s.email = ["voxpupuli@groups.io"]
10
+ s.homepage = "https://github.com/voxpupuli/onceover"
11
11
  s.summary = "Testing tools for Puppet controlrepos"
12
12
  s.description = "Automatically generates tests for your Puppet code"
13
13
  s.licenses = 'Apache-2.0'
@@ -17,29 +17,25 @@ Gem::Specification.new do |s|
17
17
  s.bindir = 'bin'
18
18
  s.executables = 'onceover'
19
19
 
20
- # Runtime dependencies, but also probably dependencies of requiring projects
21
- s.add_runtime_dependency 'backticks', '>= 1.0.2'
22
- s.add_runtime_dependency 'colored', '~> 1.2'
23
- s.add_runtime_dependency 'cri', '>= 2.6'
24
- s.add_runtime_dependency 'deep_merge', '>= 1.0.0'
25
- s.add_runtime_dependency 'git'
26
- s.add_runtime_dependency 'logging', '>= 2.0.0'
27
- s.add_runtime_dependency 'multi_json', '~> 1.10'
28
- s.add_runtime_dependency 'parallel_tests', ">= 2.0.0"
29
- s.add_runtime_dependency 'puppet', '>=4.0'
30
- s.add_runtime_dependency 'puppetlabs_spec_helper', ">= 0.4.0"
31
- s.add_runtime_dependency 'r10k', '>=2.1.0'
32
- s.add_runtime_dependency 'rake', '>= 10.0.0'
33
- s.add_runtime_dependency 'rspec', '>= 3.0.0'
34
- s.add_runtime_dependency 'rspec-puppet', ">= 2.4.0"
35
- s.add_runtime_dependency 'rspec_junit_formatter', '>= 0.2.0'
36
- s.add_runtime_dependency 'terminal-table', '>= 1.8.0'
37
- s.add_runtime_dependency 'versionomy', '>= 0.5.0'
20
+ s.required_ruby_version = Gem::Requirement.new('>= 2.7')
38
21
 
39
- s.add_development_dependency 'cucumber', '~> 4.1'
40
- s.add_development_dependency 'pry', '~> 0.13.1'
41
- # We need to depend on rubocop <= 1.12 in order to support Ruby 2.4 (Puppet
42
- # 5). Once we drop support for Puppet 5 we can re-open this
43
- s.add_development_dependency 'rubocop', '>= 1.6.1', '<= 1.12'
44
- s.add_development_dependency 'rubygems-tasks', '~> 0.2.5'
22
+ # Runtime dependencies, but also probably dependencies of requiring projects
23
+ s.add_dependency 'backticks', '>= 1.0.2'
24
+ s.add_dependency 'colored', '>= 1.2'
25
+ s.add_dependency 'cri', '>= 2.6'
26
+ s.add_dependency 'deep_merge', '>= 1.0.0'
27
+ s.add_dependency 'git'
28
+ s.add_dependency 'logging', '>= 2.0.0'
29
+ s.add_dependency 'multi_json', '>= 1.10'
30
+ s.add_dependency 'parallel_tests', ">= 2.0.0"
31
+ s.add_dependency 'puppet', '>=4.0'
32
+ s.add_dependency 'puppetlabs_spec_helper', ">= 0.4.0"
33
+ s.add_dependency 'r10k', '>=2.1.0'
34
+ s.add_dependency 'rake', '>= 10.0.0'
35
+ s.add_dependency 'rspec', '>= 3.0.0'
36
+ s.add_dependency 'rspec_junit_formatter', '>= 0.2.0'
37
+ s.add_dependency 'rspec-puppet', ">= 2.4.0"
38
+ s.add_dependency 'terminal-table', '>= 1.8.0'
39
+ s.add_dependency 'versionomy', '>= 0.5.0'
40
+ s.add_development_dependency 'voxpupuli-rubocop', '~> 3.0.0'
45
41
  end
@@ -4,4 +4,4 @@ This directory is where we put any custom factsets that we want to use. They can
4
4
 
5
5
  **Hot tip:** If you already have factsets in here when you run `onceover init` they will be picked up and added to the config file Automatically
6
6
 
7
- More info: https://github.com/dylanratcliffe/onceover#factsets
7
+ More info: https://github.com/voxpupuli/onceover#factsets
@@ -21,4 +21,4 @@ service { 'pe-puppetserver':
21
21
 
22
22
  This will mean that the `pe-puppetserver` service is in the catalog for spec testing and will even allow you to try to restart it during acceptance tests without the service actually being present.
23
23
 
24
- More info: https://github.com/dylanratcliffe/onceover#using-workarounds
24
+ More info: https://github.com/voxpupuli/onceover#using-workarounds
@@ -4,4 +4,4 @@ This directory is where we put any custom factsets that we want to use. They can
4
4
 
5
5
  **Hot tip:** If you already have factsets in here when you run `onceover init` they will be picked up and added to the config file Automatically
6
6
 
7
- More info: https://github.com/dylanratcliffe/onceover#factsets
7
+ More info: https://github.com/voxpupuli/onceover#factsets
@@ -0,0 +1,9 @@
1
+ {
2
+ "cmd": "bundle exec onceover run spec",
3
+ "name": "onceover spec",
4
+ "cwd": "{PROJECT_PATH}",
5
+ "errorMatch": [
6
+ "compilation:\\s.*production\\/(?<file>[\\w\\/]*.pp):(?<line>\\d*):(?<col>\\d*)"
7
+ ],
8
+ "atomCommandName": "onceover:spec"
9
+ }
@@ -0,0 +1,5 @@
1
+ .onceover
2
+ .DS_Store
3
+ .bundle
4
+ Gemfile.lock
5
+ vendor
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+
3
+ cache:
4
+ bundler: true
5
+ directories:
6
+ - .onceover
7
+
8
+ script: bundle exec onceover run spec --force
9
+ bundler_args: --without development --path vendor/bundle
10
+
11
+ rvm:
12
+ - 2.3.0
13
+ - 2.3.3
@@ -0,0 +1,22 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :development do
4
+ gem 'pry'
5
+ gem 'pry-byebug'
6
+ gem 'rb-readline'
7
+ gem 'puppet-debugger'
8
+ end
9
+
10
+ if ENV['ONCEOVER_gem'] == 'local'
11
+ gem 'onceover', :path => '/Users/dylan/git/onceover'
12
+ # gem 'onceover-octocatalog-diff', :path => '/Users/dylan/git/onceover-octocatalog-diff'
13
+ else
14
+ gem 'onceover', :git => 'https://github.com/voxpupuli/onceover.git'#, :branch => 'issue-51'
15
+ # gem 'onceover-octocatalog-diff', :git => 'https://github.com/dylanratcliffe/onceover-octocatalog-diff.git'
16
+ end
17
+
18
+ gem 'hiera-eyaml'
19
+ gem 'puppet', ENV['PUPPET_version'] || '~> 8'
20
+
21
+ # Require by telegraf module
22
+ gem 'toml-rb'
@@ -0,0 +1,50 @@
1
+ node {
2
+ puppet.credentials 'PE-Deploy-Token'
3
+ stage('Git Checkout') { // for display purposes
4
+ // Get some code from a GitHub repository
5
+ checkout([
6
+ $class: 'GitSCM',
7
+ branches: [[name: env.BRANCH_NAME]],
8
+ doGenerateSubmoduleConfigurations: false,
9
+ userRemoteConfigs: [[url: 'https://github.com/dylanratcliffe/puppet_controlrepo.git']]])
10
+ }
11
+ stage('Install Gems') {
12
+ // Run the onceover tests
13
+ sh '''source /usr/local/rvm/scripts/rvm && bundle install --path=.gems --binstubs'''
14
+ }
15
+ stage('Run Onceover Tests') {
16
+ // Run the onceover tests
17
+ try {
18
+ sh '''source /usr/local/rvm/scripts/rvm && ./bin/onceover run spec'''
19
+ } catch (error) {
20
+ junit '.onceover/spec.xml'
21
+ throw error
22
+ }
23
+ }
24
+ stage('Deploy Code') {
25
+ echo env.BRANCH_NAME
26
+ puppet.codeDeploy env.BRANCH_NAME
27
+ }
28
+ stage('Run Puppet') {
29
+ // Get all of the classes that have changed
30
+ changedClasses = sh(returnStdout: true, script: './scripts/get_changed_classes.rb').trim().split('\n')
31
+ // Get the number of classes that have changed
32
+ numChangedClasses = sh(returnStdout: true, script: './scripts/count_changed_classes.rb').trim().toInteger()
33
+ // Generate a query that we will use
34
+ nodeQuery = ('nodes { resources { type = "Class" and title in ' + ("[\"" + changedClasses.join("\",\"") + "\"]") + ' } and catalog_environment = "' + env.BRANCH_NAME +'" }').toString()
35
+ // If things have changed then execute the query
36
+ if (numChangedClasses > 0) {
37
+ echo nodeQuery
38
+ affectedNodes = puppet.query nodeQuery
39
+ // If nothing has been affected by the change we don't need to try to
40
+ // initiate the run
41
+ if (affectedNodes.size() > 0) {
42
+ puppet.job env.BRANCH_NAME, query: nodeQuery
43
+ } else {
44
+ echo "Classes: " + changedClasses.join(",") + " changed. But no nodes were affected, skipping run."
45
+ }
46
+ } else {
47
+ echo "No classes changed, skipping this step."
48
+ }
49
+ }
50
+ }
@@ -0,0 +1,102 @@
1
+ #mod 'dylanratcliffe/sumologic',
2
+ # :git => 'https://github.com/dylanratcliffe/sumologic.git'
3
+ mod 'dylanratcliffe/sumologic', '1.0.2'
4
+ mod 'nwops-debug', '0.1.3'
5
+ mod 'puppetlabs/mysql', '8.0.0'
6
+ mod 'puppetlabs/inifile', '2.5.0'
7
+ mod 'puppet-r10k', '6.8.0'
8
+ mod 'gentoo/portage', '2.3.0'
9
+ mod 'puppetlabs/gcc', '0.3.0'
10
+ mod 'puppetlabs/git', '0.5.0'
11
+ mod 'puppetlabs/pe_gem', '0.2.0'
12
+ mod 'puppetlabs/ruby', '1.0.0'
13
+ mod 'puppetlabs/vcsrepo', '2.4.0'
14
+ mod 'puppet-make', '2.1.1'
15
+ mod 'puppet/jira', '3.5.2'
16
+ mod 'actionjack/crowd', '0.1.1'
17
+ mod 'puppetlabs/java', '3.3.0'
18
+ mod 'puppetlabs-java_ks', '2.3.0'
19
+ mod 'puppetlabs/postgresql', '5.11.0'
20
+ mod 'mkrakowitzer/deploy', '0.0.3'
21
+ mod 'nanliu/staging', '1.0.3'
22
+ mod 'puppetlabs/apt', '6.3.0'
23
+ mod 'puppetlabs/concat', '5.2.0'
24
+ mod 'puppetlabs/firewall', '1.15.0'
25
+ mod 'puppet/hiera', '3.3.4'
26
+ mod 'danzilio/report_all_the_things', '0.1.0'
27
+ mod 'rtyler-jenkins', '1.7.0'
28
+ mod 'unibet/vagrant', '0.2.1'
29
+ mod 'darin/zypprepo', '1.0.2'
30
+ mod 'puppet/nginx', '0.15.0'
31
+ mod 'puppet/nodejs', '6.0.0'
32
+ mod 'puppet/wget', '2.0.1'
33
+ mod 'stahnma/epel', '1.3.1'
34
+ mod 'puppetlabs/apache', '4.0.0'
35
+ mod 'puppet/collectd', '10.1.0'
36
+ mod 'puppet-yum', '3.1.1'
37
+ mod 'puppetlabs/puppetserver_gem', '1.1.1'
38
+ mod 'WhatsARanjit/node_manager', '0.7.1'
39
+
40
+ mod 'pltraining-rbac', '0.0.10'
41
+ mod 'camptocamp/systemd', '2.1.0'
42
+ mod 'puppetlabs/stdlib', '5.2.0'
43
+ mod 'maestrodev/rvm', '1.13.1'
44
+ mod 'golja/gnupg', '1.2.3'
45
+ mod 'treydock/gpg_key', '0.1.0'
46
+ mod 'evenup/hubot', '0.2.0'
47
+ mod 'puppetlabs/haproxy', '4.3.0'
48
+ mod 'puppetlabs/aws', '2.1.0'
49
+ #mod 'danieldreier/autosign', '0.1.2'
50
+ mod 'autosign',
51
+ :git => 'https://github.com/dylanratcliffe/puppet-autosign.git',
52
+ :ref => '07ca3e0ad181483bd40ad1bd25466a19ac240fa7'
53
+ mod 'puppetlabs/hocon', '0.9.4' # Hold due to MODULES-5837
54
+ mod 'puppetlabs/dsc', '1.8.0'
55
+ mod 'puppetlabs/powershell', '2.2.0'
56
+ mod 'puppetlabs/reboot', '2.1.2'
57
+ mod 'puppetlabs/chocolatey', '3.1.1'
58
+ mod 'puppet-selinux', '1.6.1'
59
+ mod 'puppet-windows_env', '3.2.0'
60
+ mod 'puppet-archive', '7.0.0'
61
+ mod 'puppetlabs-transition', '0.1.1'
62
+ mod 'dylanratcliffe-windows_disk_facts','0.2.5'
63
+ mod 'biemond-wildfly', '2.3.2'
64
+ mod 'jethrocarr-initfact', '1.0.1'
65
+ mod 'puppetlabs-iis', '4.5.0'
66
+ mod 'puppetlabs-registry', '2.1.0'
67
+ mod 'puppetlabs-acl', '3.2.1'
68
+ mod 'trlinkin-noop', '1.0.0'
69
+ mod 'puppetlabs-puppet_agent', '2.0.1'
70
+ mod 'puppetlabs-exec', '0.3.0'
71
+ # CIDR Based Facts Example
72
+ mod 'dylanratcliffe-cidr_facts', '0.1.6'
73
+ mod 'puppet-grafana', '7.0.0'
74
+ mod 'puppetlabs-puppet_metrics_dashboard', '2.5.0'
75
+ mod 'puppet-telegraf', '4.1.0'
76
+
77
+ mod 'compliance_api',
78
+ :git => 'https://github.com/dylanratcliffe/puppet-compliance_api.git',
79
+ :ref => 'master'
80
+
81
+ mod 'deployment_signature',
82
+ :git => 'https://github.com/dylanratcliffe/puppet-deployment_signature.git',
83
+ :ref => 'master'
84
+
85
+
86
+ mod 'puppetlabs-bolt_shim', '0.2.1'
87
+ mod 'puppetlabs-facts', '0.5.0'
88
+ mod 'puppetlabs-service', '0.5.0'
89
+ mod 'puppetlabs-package', '0.4.1'
90
+ mod 'puppetlabs-puppet_conf', '0.3.0'
91
+ mod 'puppetlabs-yumrepo_core', '1.0.7'
92
+ mod 'puppetlabs-augeas_core', '1.0.4'
93
+ mod 'puppetlabs-cd4pe', '3.0.1'
94
+ mod 'puppetlabs-puppet_authorization', '0.5.1'
95
+ mod 'puppetlabs-docker', '3.12.1'
96
+ mod 'puppetlabs-translate', '1.2.0'
97
+ mod 'puppetlabs-pe_databases', '1.1.0'
98
+ mod 'puppetlabs-cron_core', '1.0.4'
99
+ mod 'puppetlabs-support_tasks', '1.1.2'
100
+ mod 'inkblot-bind', '7.4.0'
101
+ mod 'saz-resolv_conf', '4.2.1'
102
+ mod 'kinners00-nessus_agent', '1.1.3'
@@ -0,0 +1,4 @@
1
+ # puppet_controlrepo
2
+
3
+ [![Build Status](https://travis-ci.org/dylanratcliffe/puppet_controlrepo.svg?branch=production)](https://travis-ci.org/dylanratcliffe/puppet_controlrepo)
4
+
@@ -0,0 +1,6 @@
1
+ require 'puppetlabs_spec_helper/rake_tasks'
2
+
3
+ #desc "Run acceptance tests"
4
+ #RSpec::Core::RakeTask.new(:acceptance) do |t|
5
+ # t.pattern = 'spec/acceptance'
6
+ #end