diff options
author | Tim Smith <tsmith@chef.io> | 2020-04-01 22:06:47 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-01 22:06:47 -0700 |
commit | a5592057a0cf6dac7f3dc29d4ec316d58576cb41 (patch) | |
tree | c1b53872b9db5e2845f43687d30dad7461d38ac1 | |
parent | 54b9e1d117de8da78d168245378cc9fed83a644c (diff) | |
parent | c787455e7c5a3afe851c4b95b4b9ad234969a150 (diff) | |
download | chef-a5592057a0cf6dac7f3dc29d4ec316d58576cb41.tar.gz |
Merge pull request #9570 from chef/lcg/unified-mode4
Convert more resources to unified_mode
25 files changed, 85 insertions, 65 deletions
diff --git a/lib/chef/provider/launchd.rb b/lib/chef/provider/launchd.rb index b33ba097bb..3516cadda7 100644 --- a/lib/chef/provider/launchd.rb +++ b/lib/chef/provider/launchd.rb @@ -89,24 +89,41 @@ class Chef end def manage_plist(action) - return unless manage_agent?(action) - if source - res = cookbook_file_resource + cookbook_file @path do + cookbook_name = cookbook if cookbook + name(@path) if @path + backup(backup) if backup + group(group) if group + mode(mode) if mode + owner(owner) if owner + source(source) if source + action(action) + only_if { manage_agent?(action) } + end else - res = file_resource + file @path do + name(@path) if @path + backup(backup) if backup + content(content) if content? + group(group) if group + mode(mode) if mode + owner(owner) if owner + action(action) + only_if { manage_agent?(action) } + end end - res.run_action(action) - new_resource.updated_by_last_action(true) if res.updated? - res.updated end def manage_service(action) - return unless manage_agent?(action) - - res = service_resource - res.run_action(action) - new_resource.updated_by_last_action(true) if res.updated? + macosx_service label do + name(label) if label + service_name(label) if label + plist(@path) if @path + session_type(session_type) if session_type + action(action) + only_if { manage_agent?(action) } + end end def manage_agent?(action) @@ -127,38 +144,6 @@ class Chef true end - def service_resource - res = Chef::Resource::MacosxService.new(label, run_context) - res.name(label) if label - res.service_name(label) if label - res.plist(@path) if @path - res.session_type(session_type) if session_type - res - end - - def file_resource - res = Chef::Resource::File.new(@path, run_context) - res.name(@path) if @path - res.backup(backup) if backup - res.content(content) if content? - res.group(group) if group - res.mode(mode) if mode - res.owner(owner) if owner - res - end - - def cookbook_file_resource - res = Chef::Resource::CookbookFile.new(@path, run_context) - res.cookbook_name = cookbook if cookbook - res.name(@path) if @path - res.backup(backup) if backup - res.group(group) if group - res.mode(mode) if mode - res.owner(owner) if owner - res.source(source) if source - res - end - def define_resource_requirements requirements.assert( :create, :create_if_missing, :delete, :enable, :disable diff --git a/lib/chef/provider/osx_profile.rb b/lib/chef/provider/osx_profile.rb index 1a5484ccbf..ba63d4b02a 100644 --- a/lib/chef/provider/osx_profile.rb +++ b/lib/chef/provider/osx_profile.rb @@ -33,6 +33,7 @@ class Chef current_resource.profile_name(new_resource.profile_name) all_profiles = get_installed_profiles + # FIXME: stop mutating the desired state new_resource.profile( new_resource.profile || new_resource.profile_name @@ -149,6 +150,7 @@ class Chef ::File.dirname(cookbook_file) ) ) + # FIXME: should use a real cookbook file, or document what this craziness is remote_file = Chef::Resource::CookbookFile.new( ::File.join( get_cache_dir, @@ -180,6 +182,7 @@ class Chef end def write_profile_to_disk + # FIXME: use a real chef file resource and stop hacking up tempfiles directly new_resource.path(Chef::FileCache.create_cache_path("profiles")) tempfile = Chef::FileContentManagement::Tempfile.new(new_resource).tempfile tempfile.write(@new_profile_hash.to_plist) diff --git a/lib/chef/provider/powershell_script.rb b/lib/chef/provider/powershell_script.rb index 00cc450253..1bdcc9c08b 100644 --- a/lib/chef/provider/powershell_script.rb +++ b/lib/chef/provider/powershell_script.rb @@ -22,6 +22,7 @@ require_relative "windows_script" class Chef class Provider class PowershellScript < Chef::Provider::WindowsScript + # FIXME: use composition not inheritance provides :powershell_script diff --git a/lib/chef/provider/systemd_unit.rb b/lib/chef/provider/systemd_unit.rb index c5cd9a1960..f1b104de21 100644 --- a/lib/chef/provider/systemd_unit.rb +++ b/lib/chef/provider/systemd_unit.rb @@ -232,14 +232,15 @@ class Chef end end - def manage_unit_file(action = :nothing) - Chef::Resource::File.new(unit_path, run_context).tap do |f| - f.owner "root" - f.group "root" - f.mode "0644" - f.content new_resource.to_ini - f.verify :systemd_unit if new_resource.verify - end.run_action(action) + def manage_unit_file(the_action = :nothing) + file unit_path do + owner "root" + group "root" + mode "0644" + content new_resource.to_ini + verify :systemd_unit if new_resource.verify + action the_action + end end def daemon_reload diff --git a/lib/chef/provider/yum_repository.rb b/lib/chef/provider/yum_repository.rb index 9ae3bad29c..97d49d1bed 100644 --- a/lib/chef/provider/yum_repository.rb +++ b/lib/chef/provider/yum_repository.rb @@ -1,6 +1,6 @@ # # Author:: Thom May (<thom@chef.io>) -# Copyright:: Copyright (c) 2016-2017, Chef Software Inc. +# Copyright:: Copyright (c) 2016-2020, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/chef/resource/chef_vault_secret.rb b/lib/chef/resource/chef_vault_secret.rb index b1272df6f2..8652dc1c98 100644 --- a/lib/chef/resource/chef_vault_secret.rb +++ b/lib/chef/resource/chef_vault_secret.rb @@ -21,6 +21,8 @@ require "chef-vault" class Chef class Resource class ChefVaultSecret < Chef::Resource + unified_mode true + provides :chef_vault_secret introduced "16.0" @@ -116,16 +118,14 @@ class Chef action :delete do description "Deletes the item and the item's keys ('id'_keys)." - converge_by("remove #{new_resource.id} and #{new_resource.id}_keys from #{new_resource.data_bag}") do - chef_data_bag_item new_resource.id do - data_bag new_resource.data_bag - action :delete - end + chef_data_bag_item new_resource.id do + data_bag new_resource.data_bag + action :delete + end - chef_data_bag_item [new_resource.id, "keys"].join("_") do - data_bag new_resource.data_bag - action :delete - end + chef_data_bag_item [new_resource.id, "keys"].join("_") do + data_bag new_resource.data_bag + action :delete end end end diff --git a/lib/chef/resource/group.rb b/lib/chef/resource/group.rb index d2948b36c7..058a5a63d4 100644 --- a/lib/chef/resource/group.rb +++ b/lib/chef/resource/group.rb @@ -20,6 +20,7 @@ class Chef class Resource class Group < Chef::Resource + unified_mode true state_attrs :members description "Use the group resource to manage a local group." diff --git a/lib/chef/resource/launchd.rb b/lib/chef/resource/launchd.rb index 87addde5d7..d939559b02 100644 --- a/lib/chef/resource/launchd.rb +++ b/lib/chef/resource/launchd.rb @@ -21,6 +21,7 @@ require_relative "../resource" class Chef class Resource class Launchd < Chef::Resource + unified_mode true provides :launchd description "Use the launchd resource to manage system-wide services (daemons) and per-user services (agents) on the macOS platform." diff --git a/lib/chef/resource/macports_package.rb b/lib/chef/resource/macports_package.rb index 256048928a..afd0d69bec 100644 --- a/lib/chef/resource/macports_package.rb +++ b/lib/chef/resource/macports_package.rb @@ -21,6 +21,7 @@ require_relative "package" class Chef class Resource class MacportsPackage < Chef::Resource::Package + unified_mode true provides :macports_package description "Use the macports_package resource to manage packages for the macOS platform." diff --git a/lib/chef/resource/mount.rb b/lib/chef/resource/mount.rb index 15fabf2982..4a96aad353 100644 --- a/lib/chef/resource/mount.rb +++ b/lib/chef/resource/mount.rb @@ -23,6 +23,7 @@ class Chef class Resource class Mount < Chef::Resource description "Use the mount resource to manage a mounted file system." + unified_mode true provides :mount diff --git a/lib/chef/resource/msu_package.rb b/lib/chef/resource/msu_package.rb index 7ccd28ba95..830aac9797 100644 --- a/lib/chef/resource/msu_package.rb +++ b/lib/chef/resource/msu_package.rb @@ -23,6 +23,7 @@ class Chef class Resource class MsuPackage < Chef::Resource::Package include Chef::Mixin::Uris + unified_mode true provides :msu_package diff --git a/lib/chef/resource/openbsd_package.rb b/lib/chef/resource/openbsd_package.rb index 05d77b44dc..fa49ddf44f 100644 --- a/lib/chef/resource/openbsd_package.rb +++ b/lib/chef/resource/openbsd_package.rb @@ -25,6 +25,7 @@ require_relative "../provider/package/openbsd" class Chef class Resource class OpenbsdPackage < Chef::Resource::Package + unified_mode true provides :openbsd_package provides :package, os: "openbsd" diff --git a/lib/chef/resource/osx_profile.rb b/lib/chef/resource/osx_profile.rb index 2a350124f7..5389696b72 100644 --- a/lib/chef/resource/osx_profile.rb +++ b/lib/chef/resource/osx_profile.rb @@ -21,6 +21,8 @@ require_relative "../resource" class Chef class Resource class OsxProfile < Chef::Resource + unified_mode true + provides :osx_profile provides :osx_config_profile diff --git a/lib/chef/resource/package.rb b/lib/chef/resource/package.rb index 9a7134aad9..4e7b4133f6 100644 --- a/lib/chef/resource/package.rb +++ b/lib/chef/resource/package.rb @@ -22,6 +22,7 @@ require_relative "../resource" class Chef class Resource class Package < Chef::Resource + unified_mode true provides :package description "Use the package resource to manage packages. When the package is"\ diff --git a/lib/chef/resource/powershell_package.rb b/lib/chef/resource/powershell_package.rb index 7fb926db7c..7ae967a389 100644 --- a/lib/chef/resource/powershell_package.rb +++ b/lib/chef/resource/powershell_package.rb @@ -16,12 +16,11 @@ # require_relative "package" -require_relative "../mixin/uris" class Chef class Resource class PowershellPackage < Chef::Resource::Package - include Chef::Mixin::Uris + unified_mode true provides :powershell_package diff --git a/lib/chef/resource/powershell_package_source.rb b/lib/chef/resource/powershell_package_source.rb index 2710974a73..d253de0958 100644 --- a/lib/chef/resource/powershell_package_source.rb +++ b/lib/chef/resource/powershell_package_source.rb @@ -21,6 +21,8 @@ require_relative "../json_compat" class Chef class Resource class PowershellPackageSource < Chef::Resource + unified_mode true + provides :powershell_package_source description "Use the powershell_package_source resource to register a PowerShell package repository." diff --git a/lib/chef/resource/powershell_script.rb b/lib/chef/resource/powershell_script.rb index 727ff6609a..49f1fa75fa 100644 --- a/lib/chef/resource/powershell_script.rb +++ b/lib/chef/resource/powershell_script.rb @@ -20,6 +20,8 @@ require_relative "windows_script" class Chef class Resource class PowershellScript < Chef::Resource::WindowsScript + unified_mode true + provides :powershell_script, os: "windows" property :flags, String, diff --git a/lib/chef/resource/rhsm_register.rb b/lib/chef/resource/rhsm_register.rb index ea57d0f9c2..5088cd2d62 100644 --- a/lib/chef/resource/rhsm_register.rb +++ b/lib/chef/resource/rhsm_register.rb @@ -127,12 +127,14 @@ class Chef end def registered_with_rhsm? + # FIXME: use shell_out cmd = Mixlib::ShellOut.new("subscription-manager status", env: { LANG: "en_US" }) cmd.run_command !cmd.stdout.match(/Overall Status: Unknown/) end def katello_cert_rpm_installed? + # FIXME: use shell_out cmd = Mixlib::ShellOut.new("rpm -qa | grep katello-ca-consumer") cmd.run_command !cmd.stdout.match(/katello-ca-consumer/).nil? diff --git a/lib/chef/resource/rhsm_repo.rb b/lib/chef/resource/rhsm_repo.rb index b1a8d06d6f..95fb36b071 100644 --- a/lib/chef/resource/rhsm_repo.rb +++ b/lib/chef/resource/rhsm_repo.rb @@ -20,6 +20,8 @@ require_relative "../resource" class Chef class Resource class RhsmRepo < Chef::Resource + unified_mode true + provides(:rhsm_repo) { true } description "Use the rhsm_repo resource to enable or disable Red Hat Subscription Manager"\ @@ -54,6 +56,7 @@ class Chef action_class do def repo_enabled?(repo) + # FIXME: use shell_out() cmd = Mixlib::ShellOut.new("subscription-manager repos --list-enabled", env: { LANG: "en_US" }) cmd.run_command repo == "*" || !cmd.stdout.match(/Repo ID:\s+#{repo}$/).nil? diff --git a/lib/chef/resource/rhsm_subscription.rb b/lib/chef/resource/rhsm_subscription.rb index b7c84e95b4..3e805b9ae1 100644 --- a/lib/chef/resource/rhsm_subscription.rb +++ b/lib/chef/resource/rhsm_subscription.rb @@ -20,6 +20,8 @@ require_relative "../resource" class Chef class Resource class RhsmSubscription < Chef::Resource + unified_mode true + provides(:rhsm_subscription) { true } description "Use the rhsm_subscription resource to add or remove Red Hat Subscription Manager"\ @@ -55,6 +57,7 @@ class Chef action_class do def subscription_attached?(subscription) + # FIXME: use shell_out cmd = Mixlib::ShellOut.new("subscription-manager list --consumed | grep #{subscription}", env: { LANG: "en_US" }) cmd.run_command !cmd.stdout.match(/Pool ID:\s+#{subscription}$/).nil? @@ -65,6 +68,7 @@ class Chef pool = nil serial = nil + # FIXME: use shell_out cmd = Mixlib::ShellOut.new("subscription-manager list --consumed", env: { LANG: "en_US" }) cmd.run_command cmd.stdout.lines.each do |line| diff --git a/lib/chef/resource/service.rb b/lib/chef/resource/service.rb index 46054f21d9..71eb344483 100644 --- a/lib/chef/resource/service.rb +++ b/lib/chef/resource/service.rb @@ -1,7 +1,7 @@ # # Author:: AJ Christensen (<aj@hjksolutions.com>) # Author:: Tyler Cloke (<tyler@chef.io>) -# Copyright:: Copyright 2008-2019, Chef Software Inc. +# Copyright:: Copyright 2008-2020, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -27,6 +27,7 @@ class Chef class Service < Chef::Resource include ChefUtils::DSL::Service extend ChefUtils::DSL::Service + unified_mode true provides :service, target_mode: true diff --git a/lib/chef/resource/ssh_known_hosts_entry.rb b/lib/chef/resource/ssh_known_hosts_entry.rb index e652f82def..d248146a01 100644 --- a/lib/chef/resource/ssh_known_hosts_entry.rb +++ b/lib/chef/resource/ssh_known_hosts_entry.rb @@ -23,6 +23,8 @@ require_relative "../dist" class Chef class Resource class SshKnownHostsEntry < Chef::Resource + unified_mode true + provides :ssh_known_hosts_entry description "Use the ssh_known_hosts_entry resource to add an entry for the specified host in /etc/ssh/ssh_known_hosts or a user's known hosts file if specified." diff --git a/lib/chef/resource/systemd_unit.rb b/lib/chef/resource/systemd_unit.rb index 1c318ded5c..0d477323f9 100644 --- a/lib/chef/resource/systemd_unit.rb +++ b/lib/chef/resource/systemd_unit.rb @@ -23,6 +23,8 @@ require "iniparse" class Chef class Resource class SystemdUnit < Chef::Resource + unified_mode true + provides(:systemd_unit) { true } description "Use the systemd_unit resource to create, manage, and run systemd units." diff --git a/lib/chef/resource/yum_repository.rb b/lib/chef/resource/yum_repository.rb index 28e5c809c5..1136ae56da 100644 --- a/lib/chef/resource/yum_repository.rb +++ b/lib/chef/resource/yum_repository.rb @@ -21,6 +21,8 @@ require_relative "../resource" class Chef class Resource class YumRepository < Chef::Resource + unified_mode true + provides(:yum_repository) { true } description "Use the yum_repository resource to manage a Yum repository configuration"\ diff --git a/lib/chef/resource/zypper_repository.rb b/lib/chef/resource/zypper_repository.rb index 6cc0929fad..f55a42e6a8 100644 --- a/lib/chef/resource/zypper_repository.rb +++ b/lib/chef/resource/zypper_repository.rb @@ -21,6 +21,8 @@ require_relative "../resource" class Chef class Resource class ZypperRepository < Chef::Resource + unified_mode true + provides(:zypper_repository) { true } provides(:zypper_repo) { true } |