From 6fb9f26bdfb5976afe8b35d407705c1f696e0234 Mon Sep 17 00:00:00 2001 From: Corey Hemminger Date: Tue, 16 Jul 2024 11:29:59 -0500 Subject: [PATCH 1/7] Update generator kitchen templates for modern platforms Signed-off-by: Corey Hemminger --- .../templates/default/kitchen.yml.erb | 16 ++++++-- .../templates/default/kitchen_dokken.yml.erb | 39 ++++++++++++++++--- .../default/kitchen_policyfile.yml.erb | 16 ++++++-- 3 files changed, 58 insertions(+), 13 deletions(-) diff --git a/lib/chef-cli/skeletons/code_generator/templates/default/kitchen.yml.erb b/lib/chef-cli/skeletons/code_generator/templates/default/kitchen.yml.erb index 002cd9c6..d033d713 100644 --- a/lib/chef-cli/skeletons/code_generator/templates/default/kitchen.yml.erb +++ b/lib/chef-cli/skeletons/code_generator/templates/default/kitchen.yml.erb @@ -10,7 +10,7 @@ driver: # - ["forwarded_port", {guest: 80, host: 8080}] provisioner: - name: chef_zero + name: chef_infra # You may wish to disable always updating cookbooks in CI or other testing environments. # For example: # always_update_cookbooks: <%%= !ENV['CI'] %> @@ -19,14 +19,22 @@ provisioner: ## product_name and product_version specifies a specific Chef product and version to install. ## see the Chef documentation for more details: https://docs.chef.io/workstation/config_yml_kitchen/ # product_name: chef - # product_version: 17 + # product_version: 18 verifier: name: inspec platforms: - - name: ubuntu-20.04 - - name: centos-8 + - name: almalinux-9 + - name: amazonlinux-2023 + - name: centos-stream-9 + - name: debian-12 + - name: fedora-latest + - name: freebsd-14 + - name: opensuse-leap-15 + - name: oraclelinux-9 + - name: rockylinux-9 + - name: ubuntu-24.04 suites: - name: default diff --git a/lib/chef-cli/skeletons/code_generator/templates/default/kitchen_dokken.yml.erb b/lib/chef-cli/skeletons/code_generator/templates/default/kitchen_dokken.yml.erb index 277f5ec8..8d5e17f5 100644 --- a/lib/chef-cli/skeletons/code_generator/templates/default/kitchen_dokken.yml.erb +++ b/lib/chef-cli/skeletons/code_generator/templates/default/kitchen_dokken.yml.erb @@ -15,17 +15,46 @@ verifier: platforms: # @see https://github.com/chef-cookbooks/testing_examples/blob/main/kitchen.dokken.yml # @see https://hub.docker.com/u/dokken - - name: ubuntu-20.04 + - name: almalinux-9 driver: - image: dokken/ubuntu-20.04 + image: dokken/almalinux-9 + pid_one_command: /usr/lib/systemd/systemd + - name: amazonlinux-2023 + driver: + image: dokken/amazonlinux-2023 + pid_one_command: /usr/lib/systemd/systemd + - name: centos-stream-9 + driver: + image: dokken/centos-stream-9 + pid_one_command: /usr/lib/systemd/systemd + - name: debian-12 + driver: + image: dokken/debian-12 pid_one_command: /bin/systemd intermediate_instructions: - RUN /usr/bin/apt-get update - - - name: centos-8 + - name: fedora-latest + driver: + image: dokken/fedora-latest + pid_one_command: /usr/lib/systemd/systemd + - name: opensuse-leap-15 driver: - image: dokken/centos-8 + image: dokken/opensuse-leap-15 pid_one_command: /usr/lib/systemd/systemd + - name: oraclelinux-9 + driver: + image: dokken/oraclelinux-9 + pid_one_command: /usr/lib/systemd/systemd + - name: rockylinux-9 + driver: + image: dokken/rockylinux-9 + pid_one_command: /usr/lib/systemd/systemd + - name: ubuntu-24.04 + driver: + image: dokken/ubuntu-24.04 + pid_one_command: /bin/systemd + intermediate_instructions: + - RUN /usr/bin/apt-get update suites: - name: default diff --git a/lib/chef-cli/skeletons/code_generator/templates/default/kitchen_policyfile.yml.erb b/lib/chef-cli/skeletons/code_generator/templates/default/kitchen_policyfile.yml.erb index cef02196..da81dcb1 100644 --- a/lib/chef-cli/skeletons/code_generator/templates/default/kitchen_policyfile.yml.erb +++ b/lib/chef-cli/skeletons/code_generator/templates/default/kitchen_policyfile.yml.erb @@ -10,19 +10,27 @@ driver: # - ["forwarded_port", {guest: 80, host: 8080}] provisioner: - name: chef_zero + name: chef_infra ## product_name and product_version specifies a specific Chef product and version to install. ## see the Chef documentation for more details: https://docs.chef.io/workstation/config_yml_kitchen/ # product_name: chef - # product_version: 17 + # product_version: 18 verifier: name: inspec platforms: - - name: ubuntu-20.04 - - name: centos-8 + - name: almalinux-9 + - name: amazonlinux-2023 + - name: centos-stream-9 + - name: debian-12 + - name: fedora-latest + - name: freebsd-14 + - name: opensuse-leap-15 + - name: oraclelinux-9 + - name: rockylinux-9 + - name: ubuntu-24.04 suites: - name: default From 42d938a04217abdf70a4cde12eff568a06598831 Mon Sep 17 00:00:00 2001 From: Corey Hemminger Date: Tue, 16 Jul 2024 11:51:26 -0500 Subject: [PATCH 2/7] Update tests for new generator kitchen.yml changes Signed-off-by: Corey Hemminger --- .../generator_commands/cookbook_spec.rb | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/spec/unit/command/generator_commands/cookbook_spec.rb b/spec/unit/command/generator_commands/cookbook_spec.rb index 606434a2..6e59a2b5 100644 --- a/spec/unit/command/generator_commands/cookbook_spec.rb +++ b/spec/unit/command/generator_commands/cookbook_spec.rb @@ -388,19 +388,27 @@ def with_argv(argv) # - ["forwarded_port", {guest: 80, host: 8080}] provisioner: - name: chef_zero + name: chef_infra ## product_name and product_version specifies a specific Chef product and version to install. ## see the Chef documentation for more details: https://docs.chef.io/workstation/config_yml_kitchen/ # product_name: chef - # product_version: 17 + # product_version: 18 verifier: name: inspec platforms: - - name: ubuntu-20.04 - - name: centos-8 + - name: almalinux-9 + - name: amazonlinux-2023 + - name: centos-stream-9 + - name: debian-12 + - name: fedora-latest + - name: freebsd-14 + - name: opensuse-leap-15 + - name: oraclelinux-9 + - name: rockylinux-9 + - name: ubuntu-24.04 suites: - name: default @@ -520,7 +528,7 @@ def with_argv(argv) # - ["forwarded_port", {guest: 80, host: 8080}] provisioner: - name: chef_zero + name: chef_infra # You may wish to disable always updating cookbooks in CI or other testing environments. # For example: # always_update_cookbooks: <%= !ENV['CI'] %> @@ -529,14 +537,22 @@ def with_argv(argv) ## product_name and product_version specifies a specific Chef product and version to install. ## see the Chef documentation for more details: https://docs.chef.io/workstation/config_yml_kitchen/ # product_name: chef - # product_version: 17 + # product_version: 18 verifier: name: inspec platforms: - - name: ubuntu-20.04 - - name: centos-8 + - name: almalinux-9 + - name: amazonlinux-2023 + - name: centos-stream-9 + - name: debian-12 + - name: fedora-latest + - name: freebsd-14 + - name: opensuse-leap-15 + - name: oraclelinux-9 + - name: rockylinux-9 + - name: ubuntu-24.04 suites: - name: default From 9bdda397b2632d250dadee41be03a605b831c605 Mon Sep 17 00:00:00 2001 From: Corey Hemminger Date: Tue, 16 Jul 2024 12:15:00 -0500 Subject: [PATCH 3/7] update ruby versions for expeditor Signed-off-by: Corey Hemminger --- .expeditor/verify.pipeline.yml | 24 ++++++++++++------------ .github/workflows/sonarqube.yml | 4 ++-- .github/workflows/unit.yml | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.expeditor/verify.pipeline.yml b/.expeditor/verify.pipeline.yml index d4c15cf3..724faebb 100644 --- a/.expeditor/verify.pipeline.yml +++ b/.expeditor/verify.pipeline.yml @@ -11,32 +11,32 @@ expeditor: steps: -- label: run-specs-ruby-2.7 +- label: run-specs-ruby-3.1 command: - .expeditor/run_linux_tests.sh rspec expeditor: executor: docker: - image: ruby:2.7 + image: ruby:3.1 -- label: run-specs-ruby-3.0 +- label: run-specs-ruby-3.3 command: - .expeditor/run_linux_tests.sh rspec expeditor: executor: docker: - image: ruby:3.0 + image: ruby:3.3 -- label: run-specs-windows-2.7 +- label: run-specs-windows-3.1 command: - powershell .expeditor/run_windows_tests.ps1 rspec expeditor: executor: docker: host_os: windows - image: rubydistros/windows-2019:2.7 + image: rubydistros/windows-2019:3.1 -- label: run-specs-windows-ruby-3.0 +- label: run-specs-windows-ruby-3.3 command: - powershell .expeditor/run_windows_tests.ps1 rspec expeditor: @@ -44,20 +44,20 @@ steps: docker: host_os: windows shell: ["powershell", "-Command"] - image: rubydistros/windows-2019:3.0 + image: rubydistros/windows-2019:3.3 -- label: cookstyle-generator-cb-tests-ruby-2.7 +- label: cookstyle-generator-cb-tests-ruby-3.1 command: - .expeditor/run_linux_tests.sh "rake style:cookstyle" expeditor: executor: docker: - image: ruby:2.7 + image: ruby:3.1 -- label: chefstyle-tests-ruby-2.7 +- label: chefstyle-tests-ruby-3.1 command: - .expeditor/run_linux_tests.sh "rake style:chefstyle" expeditor: executor: docker: - image: ruby:2.7 + image: ruby:3.1 diff --git a/.github/workflows/sonarqube.yml b/.github/workflows/sonarqube.yml index e2fbb22e..d40c169f 100644 --- a/.github/workflows/sonarqube.yml +++ b/.github/workflows/sonarqube.yml @@ -14,7 +14,7 @@ jobs: runs-on: ip-range-controlled # needs: [build] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: # Disabling shallow clone is recommended for improving relevancy of reporting fetch-depth: 0 @@ -30,4 +30,4 @@ jobs: # - uses: sonarsource/sonarqube-quality-gate-action@master # timeout-minutes: 5 # env: - # SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} \ No newline at end of file + # SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/.github/workflows/unit.yml b/.github/workflows/unit.yml index 869dce15..61ec18ec 100644 --- a/.github/workflows/unit.yml +++ b/.github/workflows/unit.yml @@ -16,7 +16,7 @@ jobs: name: Coverage runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up ruby 3.1 uses: ruby/setup-ruby@v1 with: From 74350b8f7bb19aa98e3a34d70c526ae5e54bdfca Mon Sep 17 00:00:00 2001 From: Corey Hemminger Date: Tue, 16 Jul 2024 14:17:50 -0500 Subject: [PATCH 4/7] test Signed-off-by: Corey Hemminger --- .rubocop.yml | 11 +++++++++++ Gemfile | 18 +++++------------- chef-cli.gemspec | 2 +- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index dc75993e..cd9f4dbd 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,14 @@ +--- +require: + - chefstyle + +AllCops: + TargetRubyVersion: 3.1 + Include: + - "**/*.rb" + Exclude: + - "vendor/**/*" + - "spec/**/*" Style/StringLiterals: Exclude: - "spec/unit/fixtures/**/*" diff --git a/Gemfile b/Gemfile index b6918aaa..7461ea33 100644 --- a/Gemfile +++ b/Gemfile @@ -2,24 +2,16 @@ source "https://rubygems.org" gemspec +gem "logger", "< 1.6" # 1.6 causes errors with mixlib-log < 3.1.1 + group :test do gem "rake" gem "rspec", "~> 3.8" gem "rspec-expectations", "~> 3.8" gem "rspec-mocks", "~> 3.8" - gem "cookstyle", "=7.7.2" # this forces dependabot PRs to open which triggers cookstyle CI on the chef generate command - gem "chefstyle", "=1.6.2" - gem "test-kitchen", "=3.5.1" # pinning test-kitchen to 3.5.1 which supports ruby < 3.1 . Need to update this to latest once we update the ruby to 3.1 and chef to 18.x in chef-cli - - if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.6") - gem "chef-zero", "~> 14" - gem "chef", "~> 15" - gem "chef-utils", "=16.6.14" - end - if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.7") - gem "ohai", "~> 16" - end - + gem "cookstyle" + gem "chefstyle" + gem "test-kitchen" gem "simplecov", require: false end diff --git a/chef-cli.gemspec b/chef-cli.gemspec index 2badc276..36fc7a2b 100644 --- a/chef-cli.gemspec +++ b/chef-cli.gemspec @@ -29,7 +29,7 @@ Gem::Specification.new do |gem| gem.license = "Apache-2.0" gem.homepage = "https://www.chef.io/" - gem.required_ruby_version = ">= 2.7" + gem.required_ruby_version = ">= 3.1" gem.files = %w{Rakefile LICENSE} + Dir.glob("Gemfile*") + # Includes Gemfile and locks From f478dadc337cef7bad407efd20dcb58ba528ceaa Mon Sep 17 00:00:00 2001 From: nikhil2611 Date: Wed, 14 Aug 2024 15:15:19 +0530 Subject: [PATCH 5/7] fixed the rubocop and chefstyle errors Signed-off-by: nikhil2611 --- .rubocop.yml | 2 +- chef-cli.gemspec | 6 +--- .../command/clean_policy_cookbooks.rb | 2 +- .../command/clean_policy_revisions.rb | 2 +- lib/chef-cli/command/delete_policy.rb | 4 +-- lib/chef-cli/command/delete_policy_group.rb | 4 +-- lib/chef-cli/command/diff.rb | 6 ++-- lib/chef-cli/command/export.rb | 2 +- lib/chef-cli/command/install.rb | 2 +- lib/chef-cli/command/push.rb | 4 +-- lib/chef-cli/command/push_archive.rb | 6 ++-- lib/chef-cli/command/show_policy.rb | 6 ++-- lib/chef-cli/command/undelete.rb | 4 +-- lib/chef-cli/command/update.rb | 4 +-- .../policyfile/artifactory_cookbook_source.rb | 14 ++++----- .../policyfile/chef_server_cookbook_source.rb | 16 ++++------ .../policyfile/community_cookbook_source.rb | 12 ++++---- .../policyfile/delivery_supermarket_source.rb | 14 ++++----- lib/chef-cli/policyfile/dsl.rb | 6 ++-- lib/chef-cli/policyfile/git_lock_fetcher.rb | 2 +- .../policyfile_location_specification.rb | 30 ++++++++----------- .../policyfile/solution_dependencies.rb | 2 +- lib/chef-cli/policyfile/uploader.rb | 2 +- lib/chef-cli/policyfile_compiler.rb | 4 +-- lib/chef-cli/policyfile_lock.rb | 2 +- .../policyfile_services/export_repo.rb | 12 ++++---- lib/chef-cli/policyfile_services/install.rb | 4 +-- lib/chef-cli/policyfile_services/push.rb | 4 +-- .../policyfile_services/push_archive.rb | 4 +-- .../policyfile_services/update_attributes.rb | 4 +-- .../repo/cookbooks/example/recipes/default.rb | 2 +- .../code_generator/recipes/helpers.rb | 2 +- .../clean_policies_spec.rb | 2 +- 33 files changed, 87 insertions(+), 105 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index cd9f4dbd..62ed74a2 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -6,7 +6,7 @@ AllCops: TargetRubyVersion: 3.1 Include: - "**/*.rb" - Exclude: + Exclude: - "vendor/**/*" - "spec/**/*" Style/StringLiterals: diff --git a/chef-cli.gemspec b/chef-cli.gemspec index 36fc7a2b..968898d2 100644 --- a/chef-cli.gemspec +++ b/chef-cli.gemspec @@ -43,11 +43,7 @@ Gem::Specification.new do |gem| gem.add_dependency "mixlib-shellout", ">= 2.0", "< 4.0" gem.add_dependency "ffi-yajl", ">= 1.0", "< 3.0" gem.add_dependency "minitar", "~> 0.6" - if RUBY_VERSION.match?(/3.1/) - gem.add_dependency "chef", "~> 18.0" - else - gem.add_dependency "chef", "~> 17.0" - end + gem.add_dependency "chef", "~> 18.0" gem.add_dependency "solve", "< 5.0", "> 2.0" gem.add_dependency "addressable", ">= 2.3.5", "< 2.9" gem.add_dependency "cookbook-omnifetch", "~> 0.5" diff --git a/lib/chef-cli/command/clean_policy_cookbooks.rb b/lib/chef-cli/command/clean_policy_cookbooks.rb index 740c876b..9fda99f7 100644 --- a/lib/chef-cli/command/clean_policy_cookbooks.rb +++ b/lib/chef-cli/command/clean_policy_cookbooks.rb @@ -70,7 +70,7 @@ def run(params) def clean_policy_cookbooks_service @clean_policy_cookbooks_service ||= - PolicyfileServices::CleanPolicyCookbooks.new(config: chef_config, ui: ui) + PolicyfileServices::CleanPolicyCookbooks.new(config: chef_config, ui:) end def debug? diff --git a/lib/chef-cli/command/clean_policy_revisions.rb b/lib/chef-cli/command/clean_policy_revisions.rb index 5302b7bb..ec419b65 100644 --- a/lib/chef-cli/command/clean_policy_revisions.rb +++ b/lib/chef-cli/command/clean_policy_revisions.rb @@ -67,7 +67,7 @@ def run(params) def clean_policies_service @policy_list_service ||= - PolicyfileServices::CleanPolicies.new(config: chef_config, ui: ui) + PolicyfileServices::CleanPolicies.new(config: chef_config, ui:) end def debug? diff --git a/lib/chef-cli/command/delete_policy.rb b/lib/chef-cli/command/delete_policy.rb index d7172b56..d22088f3 100644 --- a/lib/chef-cli/command/delete_policy.rb +++ b/lib/chef-cli/command/delete_policy.rb @@ -69,8 +69,8 @@ def run(params) def rm_policy_service @rm_policy_service ||= PolicyfileServices::RmPolicy.new(config: chef_config, - ui: ui, - policy_name: policy_name) + ui:, + policy_name:) end def debug? diff --git a/lib/chef-cli/command/delete_policy_group.rb b/lib/chef-cli/command/delete_policy_group.rb index da337bbf..9e81e1dc 100644 --- a/lib/chef-cli/command/delete_policy_group.rb +++ b/lib/chef-cli/command/delete_policy_group.rb @@ -69,8 +69,8 @@ def run(params) def rm_policy_group_service @rm_policy_group_service ||= PolicyfileServices::RmPolicyGroup.new(config: chef_config, - ui: ui, - policy_group: policy_group) + ui:, + policy_group:) end def debug? diff --git a/lib/chef-cli/command/diff.rb b/lib/chef-cli/command/diff.rb index 83698319..a8d48ec3 100644 --- a/lib/chef-cli/command/diff.rb +++ b/lib/chef-cli/command/diff.rb @@ -145,10 +145,10 @@ def print_diff def differ(ui = self.ui) Policyfile::Differ.new(old_name: old_base.name, - old_lock: old_lock, + old_lock:, new_name: new_base.name, - new_lock: new_lock, - ui: ui) + new_lock:, + ui:) end def http_client diff --git a/lib/chef-cli/command/export.rb b/lib/chef-cli/command/export.rb index aa3ee462..699c6b77 100644 --- a/lib/chef-cli/command/export.rb +++ b/lib/chef-cli/command/export.rb @@ -127,7 +127,7 @@ def archive? def export_service @export_service ||= PolicyfileServices::ExportRepo.new( policyfile: policyfile_relative_path, - export_dir: export_dir, + export_dir:, root_dir: Dir.pwd, archive: archive?, force: config[:force], diff --git a/lib/chef-cli/command/install.rb b/lib/chef-cli/command/install.rb index 8c21d8c6..4dc3c3f6 100644 --- a/lib/chef-cli/command/install.rb +++ b/lib/chef-cli/command/install.rb @@ -74,7 +74,7 @@ def run(params = []) end def installer - @installer ||= PolicyfileServices::Install.new(policyfile: policyfile_relative_path, ui: ui, root_dir: Dir.pwd, config: chef_config) + @installer ||= PolicyfileServices::Install.new(policyfile: policyfile_relative_path, ui:, root_dir: Dir.pwd, config: chef_config) end def debug? diff --git a/lib/chef-cli/command/push.rb b/lib/chef-cli/command/push.rb index 77bf3b1e..7d4d142f 100644 --- a/lib/chef-cli/command/push.rb +++ b/lib/chef-cli/command/push.rb @@ -84,8 +84,8 @@ def debug? def push @push ||= PolicyfileServices::Push.new(policyfile: policyfile_relative_path, - ui: ui, - policy_group: policy_group, + ui:, + policy_group:, config: chef_config, root_dir: Dir.pwd) end diff --git a/lib/chef-cli/command/push_archive.rb b/lib/chef-cli/command/push_archive.rb index c0906e80..cec78fa5 100644 --- a/lib/chef-cli/command/push_archive.rb +++ b/lib/chef-cli/command/push_archive.rb @@ -83,9 +83,9 @@ def handle_error(error) def push_archive_service @push_archive_service ||= ChefCLI::PolicyfileServices::PushArchive.new( - archive_file: archive_file, - policy_group: policy_group, - ui: ui, + archive_file:, + policy_group:, + ui:, config: chef_config ) end diff --git a/lib/chef-cli/command/show_policy.rb b/lib/chef-cli/command/show_policy.rb index 2eea2c89..b6d29b94 100644 --- a/lib/chef-cli/command/show_policy.rb +++ b/lib/chef-cli/command/show_policy.rb @@ -87,9 +87,9 @@ def run(params) def show_policy_service @policy_list_service ||= PolicyfileServices::ShowPolicy.new(config: chef_config, - ui: ui, - policy_name: policy_name, - policy_group: policy_group, + ui:, + policy_name:, + policy_group:, show_orphans: show_orphans?, summary_diff: show_summary_diff?, pager: enable_pager?) diff --git a/lib/chef-cli/command/undelete.rb b/lib/chef-cli/command/undelete.rb index 990037b7..0af1e642 100644 --- a/lib/chef-cli/command/undelete.rb +++ b/lib/chef-cli/command/undelete.rb @@ -93,8 +93,8 @@ def run(params) def undelete_service @undelete_service ||= PolicyfileServices::Undelete.new(config: chef_config, - ui: ui, - undo_record_id: undo_record_id) + ui:, + undo_record_id:) end def debug? diff --git a/lib/chef-cli/command/update.rb b/lib/chef-cli/command/update.rb index ad7dbfd8..1867e4ec 100644 --- a/lib/chef-cli/command/update.rb +++ b/lib/chef-cli/command/update.rb @@ -100,12 +100,12 @@ def run(params = []) end def installer - @installer ||= PolicyfileServices::Install.new(policyfile: policyfile_relative_path, ui: ui, root_dir: Dir.pwd, config: chef_config, overwrite: true) + @installer ||= PolicyfileServices::Install.new(policyfile: policyfile_relative_path, ui:, root_dir: Dir.pwd, config: chef_config, overwrite: true) end def attributes_updater @attributes_updater ||= - PolicyfileServices::UpdateAttributes.new(policyfile: policyfile_relative_path, ui: ui, root_dir: Dir.pwd, chef_config: chef_config) + PolicyfileServices::UpdateAttributes.new(policyfile: policyfile_relative_path, ui:, root_dir: Dir.pwd, chef_config:) end def debug? diff --git a/lib/chef-cli/policyfile/artifactory_cookbook_source.rb b/lib/chef-cli/policyfile/artifactory_cookbook_source.rb index f3bc20f9..c4c9d37c 100644 --- a/lib/chef-cli/policyfile/artifactory_cookbook_source.rb +++ b/lib/chef-cli/policyfile/artifactory_cookbook_source.rb @@ -54,14 +54,12 @@ def preferred_source_for?(cookbook_name) end def universe_graph - @universe_graph ||= begin - full_community_graph.inject({}) do |normalized_graph, (cookbook_name, metadata_by_version)| - normalized_graph[cookbook_name] = metadata_by_version.inject({}) do |deps_by_version, (version, metadata)| - deps_by_version[version] = metadata["dependencies"] - deps_by_version - end - normalized_graph + @universe_graph ||= full_community_graph.inject({}) do |normalized_graph, (cookbook_name, metadata_by_version)| + normalized_graph[cookbook_name] = metadata_by_version.inject({}) do |deps_by_version, (version, metadata)| + deps_by_version[version] = metadata["dependencies"] + deps_by_version end + normalized_graph end end @@ -90,7 +88,7 @@ def artifactory_api_key def http_connection_for(base_url) headers = { "X-Jfrog-Art-API" => artifactory_api_key } - @http_connections[base_url] ||= Chef::HTTP::Simple.new(base_url, headers: headers) + @http_connections[base_url] ||= Chef::HTTP::Simple.new(base_url, headers:) end def full_community_graph diff --git a/lib/chef-cli/policyfile/chef_server_cookbook_source.rb b/lib/chef-cli/policyfile/chef_server_cookbook_source.rb index b08453e8..78c092e4 100644 --- a/lib/chef-cli/policyfile/chef_server_cookbook_source.rb +++ b/lib/chef-cli/policyfile/chef_server_cookbook_source.rb @@ -52,14 +52,12 @@ def preferred_source_for?(cookbook_name) end def universe_graph - @universe_graph ||= begin - full_chef_server_graph.inject({}) do |normalized_graph, (cookbook_name, metadata_by_version)| - normalized_graph[cookbook_name] = metadata_by_version.inject({}) do |deps_by_version, (version, metadata)| - deps_by_version[version] = metadata["dependencies"] - deps_by_version - end - normalized_graph + @universe_graph ||= full_chef_server_graph.inject({}) do |normalized_graph, (cookbook_name, metadata_by_version)| + normalized_graph[cookbook_name] = metadata_by_version.inject({}) do |deps_by_version, (version, metadata)| + deps_by_version[version] = metadata["dependencies"] + deps_by_version end + normalized_graph end end @@ -90,9 +88,7 @@ def http_connection_for(base_url) def full_chef_server_graph @full_chef_server_graph ||= - begin - http_connection_for(uri.to_s).get("/universe") - end + http_connection_for(uri.to_s).get("/universe") end end end diff --git a/lib/chef-cli/policyfile/community_cookbook_source.rb b/lib/chef-cli/policyfile/community_cookbook_source.rb index 56620a81..e637f89d 100644 --- a/lib/chef-cli/policyfile/community_cookbook_source.rb +++ b/lib/chef-cli/policyfile/community_cookbook_source.rb @@ -52,14 +52,12 @@ def ==(other) end def universe_graph - @universe_graph ||= begin - full_community_graph.inject({}) do |normalized_graph, (cookbook_name, metadata_by_version)| - normalized_graph[cookbook_name] = metadata_by_version.inject({}) do |deps_by_version, (version, metadata)| - deps_by_version[version] = metadata["dependencies"] - deps_by_version - end - normalized_graph + @universe_graph ||= full_community_graph.inject({}) do |normalized_graph, (cookbook_name, metadata_by_version)| + normalized_graph[cookbook_name] = metadata_by_version.inject({}) do |deps_by_version, (version, metadata)| + deps_by_version[version] = metadata["dependencies"] + deps_by_version end + normalized_graph end end diff --git a/lib/chef-cli/policyfile/delivery_supermarket_source.rb b/lib/chef-cli/policyfile/delivery_supermarket_source.rb index 165f7886..db64d67e 100644 --- a/lib/chef-cli/policyfile/delivery_supermarket_source.rb +++ b/lib/chef-cli/policyfile/delivery_supermarket_source.rb @@ -66,15 +66,13 @@ def default_source_args end def universe_graph - @universe_graph ||= begin - @community_source.universe_graph.inject({}) do |truncated, (cookbook_name, version_and_deps_list)| - sorted_versions = version_and_deps_list.keys.sort_by do |version_string| - Semverse::Version.new(version_string) - end - greatest_version = sorted_versions.last - truncated[cookbook_name] = { greatest_version => version_and_deps_list[greatest_version] } - truncated + @universe_graph ||= @community_source.universe_graph.inject({}) do |truncated, (cookbook_name, version_and_deps_list)| + sorted_versions = version_and_deps_list.keys.sort_by do |version_string| + Semverse::Version.new(version_string) end + greatest_version = sorted_versions.last + truncated[cookbook_name] = { greatest_version => version_and_deps_list[greatest_version] } + truncated end end diff --git a/lib/chef-cli/policyfile/dsl.rb b/lib/chef-cli/policyfile/dsl.rb index db3a7832..9108b5e3 100644 --- a/lib/chef-cli/policyfile/dsl.rb +++ b/lib/chef-cli/policyfile/dsl.rb @@ -27,7 +27,7 @@ module ChefCLI module Policyfile class DSL - RUN_LIST_ITEM_COMPONENT = /^[.[:alnum:]_-]+$/.freeze + RUN_LIST_ITEM_COMPONENT = /^[.[:alnum:]_-]+$/ include StorageConfigDelegation @@ -203,7 +203,7 @@ def set_default_chef_server_source(source_uri, &block) if source_uri.nil? @errors << "You must specify the server's URI when using a default_source :chef_server" else - set_default_source(ChefServerCookbookSource.new(source_uri, chef_config: chef_config, &block)) + set_default_source(ChefServerCookbookSource.new(source_uri, chef_config:, &block)) end end @@ -211,7 +211,7 @@ def set_default_artifactory_source(source_uri, &block) if source_uri.nil? @errors << "You must specify the server's URI when using a default_source :artifactory" else - set_default_source(ArtifactoryCookbookSource.new(source_uri, chef_config: chef_config, &block)) + set_default_source(ArtifactoryCookbookSource.new(source_uri, chef_config:, &block)) end end diff --git a/lib/chef-cli/policyfile/git_lock_fetcher.rb b/lib/chef-cli/policyfile/git_lock_fetcher.rb index b69f6e5d..c705cc08 100644 --- a/lib/chef-cli/policyfile/git_lock_fetcher.rb +++ b/lib/chef-cli/policyfile/git_lock_fetcher.rb @@ -87,7 +87,7 @@ def errors # @return [Hash] The source_options that describe how to fetch this exact lock again def source_options_for_lock source_options.merge({ - revision: revision, + revision:, }) end diff --git a/lib/chef-cli/policyfile/policyfile_location_specification.rb b/lib/chef-cli/policyfile/policyfile_location_specification.rb index 91ea19bd..062df6ff 100644 --- a/lib/chef-cli/policyfile/policyfile_location_specification.rb +++ b/lib/chef-cli/policyfile/policyfile_location_specification.rb @@ -62,20 +62,18 @@ def revision_id # @return A policyfile lock fetcher compatible with the given source_options def fetcher - @fetcher ||= begin - if source_options[:path] && !source_options[:git] - Policyfile::LocalLockFetcher.new(name, source_options, storage_config) - elsif source_options[:remote] - Policyfile::RemoteLockFetcher.new(name, source_options) - elsif source_options[:server] - Policyfile::ChefServerLockFetcher.new(name, source_options, chef_config) - elsif source_options[:git] - Policyfile::GitLockFetcher.new(name, source_options, storage_config) - else - raise ChefCLI::InvalidPolicyfileLocation.new( - "Invalid policyfile lock location type. The supported locations are: #{LOCATION_TYPES.join(", ")}" - ) - end + @fetcher ||= if source_options[:path] && !source_options[:git] + Policyfile::LocalLockFetcher.new(name, source_options, storage_config) + elsif source_options[:remote] + Policyfile::RemoteLockFetcher.new(name, source_options) + elsif source_options[:server] + Policyfile::ChefServerLockFetcher.new(name, source_options, chef_config) + elsif source_options[:git] + Policyfile::GitLockFetcher.new(name, source_options, storage_config) + else + raise ChefCLI::InvalidPolicyfileLocation.new( + "Invalid policyfile lock location type. The supported locations are: #{LOCATION_TYPES.join(", ")}" + ) end end @@ -106,9 +104,7 @@ def errors # # @return [PolicyfileLock] the loaded policyfile lock def policyfile_lock - @policyfile_lock ||= begin - PolicyfileLock.new(storage_config, ui: ui).build_from_lock_data(fetcher.lock_data) - end + @policyfile_lock ||= PolicyfileLock.new(storage_config, ui:).build_from_lock_data(fetcher.lock_data) end # @return [Hash] The source_options that describe how to fetch this exact lock again diff --git a/lib/chef-cli/policyfile/solution_dependencies.rb b/lib/chef-cli/policyfile/solution_dependencies.rb index 1aae6298..33da85cf 100644 --- a/lib/chef-cli/policyfile/solution_dependencies.rb +++ b/lib/chef-cli/policyfile/solution_dependencies.rb @@ -28,7 +28,7 @@ class SolutionDependencies class Cookbook - VALID_STRING_FORMAT = /\A[^\s]+ \([^\s]+\)\Z/.freeze + VALID_STRING_FORMAT = /\A[^\s]+ \([^\s]+\)\Z/ def self.valid_str?(str) !!(str =~ VALID_STRING_FORMAT) diff --git a/lib/chef-cli/policyfile/uploader.rb b/lib/chef-cli/policyfile/uploader.rb index 03f1ed1b..14e6a263 100644 --- a/lib/chef-cli/policyfile/uploader.rb +++ b/lib/chef-cli/policyfile/uploader.rb @@ -207,7 +207,7 @@ def upload_cookbooks remote_already_has_cookbook?(cb_with_lock.cookbook) end - Reports::Upload.new(reused_cbs: reused_cbs, uploaded_cbs: uploaded_cbs, ui: ui).show + Reports::Upload.new(reused_cbs:, uploaded_cbs:, ui:).show true end diff --git a/lib/chef-cli/policyfile_compiler.rb b/lib/chef-cli/policyfile_compiler.rb index a61a8a61..f30847d1 100644 --- a/lib/chef-cli/policyfile_compiler.rb +++ b/lib/chef-cli/policyfile_compiler.rb @@ -42,7 +42,7 @@ class PolicyfileCompiler SOURCE_TYPES_WITH_FIXED_VERSIONS = %i{git path}.freeze def self.evaluate(policyfile_string, policyfile_filename, ui: nil, chef_config: nil) - compiler = new(ui: ui, chef_config: chef_config) + compiler = new(ui:, chef_config:) compiler.evaluate_policyfile(policyfile_string, policyfile_filename) compiler end @@ -61,7 +61,7 @@ def self.evaluate(policyfile_string, policyfile_filename, ui: nil, chef_config: def initialize(ui: nil, chef_config: nil) @storage_config = Policyfile::StorageConfig.new - @dsl = Policyfile::DSL.new(storage_config, chef_config: chef_config) + @dsl = Policyfile::DSL.new(storage_config, chef_config:) @artifact_server_cookbook_location_specs = {} @merged_graph = nil diff --git a/lib/chef-cli/policyfile_lock.rb b/lib/chef-cli/policyfile_lock.rb index ba81120f..887a8727 100644 --- a/lib/chef-cli/policyfile_lock.rb +++ b/lib/chef-cli/policyfile_lock.rb @@ -64,7 +64,7 @@ def cookbook_version_width end end - RUN_LIST_ITEM_FORMAT = /\Arecipe\[[^\s]+::[^\s]+\]\Z/.freeze + RUN_LIST_ITEM_FORMAT = /\Arecipe\[[^\s]+::[^\s]+\]\Z/ def self.build(storage_config) lock = new(storage_config) diff --git a/lib/chef-cli/policyfile_services/export_repo.rb b/lib/chef-cli/policyfile_services/export_repo.rb index 70ff6955..56930b79 100644 --- a/lib/chef-cli/policyfile_services/export_repo.rb +++ b/lib/chef-cli/policyfile_services/export_repo.rb @@ -121,12 +121,12 @@ def with_staging_dir random_string = SecureRandom.hex(2) path = "chef-export-#{random_string}" Dir.mktmpdir(path) do |d| - begin - @staging_dir = d - yield - ensure - @staging_dir = nil - end + + @staging_dir = d + yield + ensure + @staging_dir = nil + end end diff --git a/lib/chef-cli/policyfile_services/install.rb b/lib/chef-cli/policyfile_services/install.rb index d0fbd2a8..9b46ed72 100644 --- a/lib/chef-cli/policyfile_services/install.rb +++ b/lib/chef-cli/policyfile_services/install.rb @@ -73,7 +73,7 @@ def policyfile_content end def policyfile_compiler - @policyfile_compiler ||= ChefCLI::PolicyfileCompiler.evaluate(policyfile_content, policyfile_expanded_path, ui: ui, chef_config: chef_config) + @policyfile_compiler ||= ChefCLI::PolicyfileCompiler.evaluate(policyfile_content, policyfile_expanded_path, ui:, chef_config:) end def expanded_run_list @@ -89,7 +89,7 @@ def policyfile_lock @policyfile_lock ||= begin lock_data = FFI_Yajl::Parser.new.parse(policyfile_lock_content) - PolicyfileLock.new(storage_config, ui: ui).build_from_lock_data(lock_data) + PolicyfileLock.new(storage_config, ui:).build_from_lock_data(lock_data) end end diff --git a/lib/chef-cli/policyfile_services/push.rb b/lib/chef-cli/policyfile_services/push.rb index f145b8ad..1d7481b7 100644 --- a/lib/chef-cli/policyfile_services/push.rb +++ b/lib/chef-cli/policyfile_services/push.rb @@ -64,8 +64,8 @@ def policy_data def uploader ChefCLI::Policyfile::Uploader.new(policyfile_lock, policy_group, - ui: ui, - http_client: http_client, + ui:, + http_client:, policy_document_native_api: config.policy_document_native_api) end diff --git a/lib/chef-cli/policyfile_services/push_archive.rb b/lib/chef-cli/policyfile_services/push_archive.rb index 0b54d3b3..a6546e55 100644 --- a/lib/chef-cli/policyfile_services/push_archive.rb +++ b/lib/chef-cli/policyfile_services/push_archive.rb @@ -69,8 +69,8 @@ def run # @api private def uploader ChefCLI::Policyfile::Uploader.new(policyfile_lock, policy_group, - ui: ui, - http_client: http_client, + ui:, + http_client:, policy_document_native_api: config.policy_document_native_api) end diff --git a/lib/chef-cli/policyfile_services/update_attributes.rb b/lib/chef-cli/policyfile_services/update_attributes.rb index 4a9fcc4c..1af294a5 100644 --- a/lib/chef-cli/policyfile_services/update_attributes.rb +++ b/lib/chef-cli/policyfile_services/update_attributes.rb @@ -78,7 +78,7 @@ def policyfile_content end def policyfile_compiler - @policyfile_compiler ||= ChefCLI::PolicyfileCompiler.evaluate(policyfile_content, policyfile_expanded_path, ui: ui, chef_config: chef_config) + @policyfile_compiler ||= ChefCLI::PolicyfileCompiler.evaluate(policyfile_content, policyfile_expanded_path, ui:, chef_config:) end def policyfile_lock_content @@ -88,7 +88,7 @@ def policyfile_lock_content def policyfile_lock @policyfile_lock ||= begin lock_data = FFI_Yajl::Parser.new.parse(policyfile_lock_content) - PolicyfileLock.new(storage_config, ui: ui).build_from_lock_data(lock_data) + PolicyfileLock.new(storage_config, ui:).build_from_lock_data(lock_data) end end diff --git a/lib/chef-cli/skeletons/code_generator/files/default/repo/cookbooks/example/recipes/default.rb b/lib/chef-cli/skeletons/code_generator/files/default/repo/cookbooks/example/recipes/default.rb index e3f5f0e1..82f8fa31 100644 --- a/lib/chef-cli/skeletons/code_generator/files/default/repo/cookbooks/example/recipes/default.rb +++ b/lib/chef-cli/skeletons/code_generator/files/default/repo/cookbooks/example/recipes/default.rb @@ -1,7 +1,7 @@ # This is a Chef Infra Client recipe file. It can be used to specify resources # which will apply configuration to a server. -log "Welcome to Chef Infra Client, #{node['example']['name']}!" do +log "Welcome to Chef Infra Client, #{node["example"]["name"]}!" do level :info end diff --git a/lib/chef-cli/skeletons/code_generator/recipes/helpers.rb b/lib/chef-cli/skeletons/code_generator/recipes/helpers.rb index b73526ad..3eac7924 100644 --- a/lib/chef-cli/skeletons/code_generator/recipes/helpers.rb +++ b/lib/chef-cli/skeletons/code_generator/recipes/helpers.rb @@ -15,5 +15,5 @@ def camelize(name) template helpers_path do source 'helpers.rb.erb' helpers(ChefCLI::Generator::TemplateHelper) - variables(cookbook_class_name: cookbook_class_name, helper_class_name: helper_class_name) + variables(cookbook_class_name:, helper_class_name:) end diff --git a/spec/unit/policyfile_services/clean_policies_spec.rb b/spec/unit/policyfile_services/clean_policies_spec.rb index 6c8a010e..6d462fc2 100644 --- a/spec/unit/policyfile_services/clean_policies_spec.rb +++ b/spec/unit/policyfile_services/clean_policies_spec.rb @@ -215,7 +215,7 @@ # this will continue to print that out until they remove HTTPServerException expected_message = <<~ERROR Failed to delete some policy revisions: - - appserver (4444444444444444444444444444444444444444444444444444444444444444): Net::HTTPServerException 403 \"Unauthorized\" + - appserver (4444444444444444444444444444444444444444444444444444444444444444): Net::HTTPClientException 403 \"Unauthorized\" ERROR expect { clean_policies_service.run }.to raise_error do |error| From 3e63eac9adba11f9d4d4bf5e1995bd4b109fd4d7 Mon Sep 17 00:00:00 2001 From: nikhil2611 Date: Wed, 14 Aug 2024 15:39:16 +0530 Subject: [PATCH 6/7] fixed the test cases Signed-off-by: nikhil2611 --- spec/unit/command/generator_commands/repo_spec.rb | 2 +- spec/unit/policyfile_lock_serialization_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/unit/command/generator_commands/repo_spec.rb b/spec/unit/command/generator_commands/repo_spec.rb index 86499b83..77fec47e 100644 --- a/spec/unit/command/generator_commands/repo_spec.rb +++ b/spec/unit/command/generator_commands/repo_spec.rb @@ -256,7 +256,7 @@ def generator_context let(:file) { "cookbooks/example/recipes/default.rb" } it "has the right contents" do - expect(file_contents).to match(/log "Welcome to Chef Infra Client, \#\{node\['example'\]\['name'\]\}!" do/) + expect(file_contents).to match(/log "Welcome to Chef Infra Client, \#\{node\["example"\]\["name"\]\}!" do/) end end end diff --git a/spec/unit/policyfile_lock_serialization_spec.rb b/spec/unit/policyfile_lock_serialization_spec.rb index 2ebe433a..8abcb416 100644 --- a/spec/unit/policyfile_lock_serialization_spec.rb +++ b/spec/unit/policyfile_lock_serialization_spec.rb @@ -137,7 +137,7 @@ it "requires the values in named_run_lists to be valid run lists" do bad_named_run_lists = valid_lock_data.dup - bad_named_run_lists["named_run_lists"] = { "bad" => [ 42 ] } + bad_named_run_lists["named_run_lists"] = { "bad" => [ "42" ] } expect { lockfile.build_from_lock_data(bad_named_run_lists) }.to raise_error(ChefCLI::InvalidLockfile) end From 86243c3baacf948e9900fcdefea101c07d29cba4 Mon Sep 17 00:00:00 2001 From: Chef Expeditor Date: Sat, 17 Aug 2024 09:22:04 +0000 Subject: [PATCH 7/7] Bump version to 5.6.15 by Chef Expeditor Obvious fix; these changes are the result of automation not creative thinking. --- CHANGELOG.md | 12 ++++++++++-- VERSION | 2 +- lib/chef-cli/version.rb | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab0020e3..566fd0e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,16 @@ - + +## [v5.6.15](https://github.com/chef/chef-cli/tree/v5.6.15) (2024-08-17) + +#### Merged Pull Requests +- Update generator kitchen templates for modern platforms [#234](https://github.com/chef/chef-cli/pull/234) ([Stromweld](https://github.com/Stromweld)) - + +### Changes not yet released to rubygems.org + +#### Merged Pull Requests +- Update generator kitchen templates for modern platforms [#234](https://github.com/chef/chef-cli/pull/234) ([Stromweld](https://github.com/Stromweld)) diff --git a/VERSION b/VERSION index db4dd40c..1c3c4476 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -5.6.14 \ No newline at end of file +5.6.15 \ No newline at end of file diff --git a/lib/chef-cli/version.rb b/lib/chef-cli/version.rb index 7a0f8886..94f10de0 100644 --- a/lib/chef-cli/version.rb +++ b/lib/chef-cli/version.rb @@ -16,5 +16,5 @@ # module ChefCLI - VERSION = "5.6.14".freeze + VERSION = "5.6.15".freeze end