chef 12.18.31-universal-mingw32 → 12.19.33-universal-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +5 -4
- data/README.md +12 -13
- data/VERSION +1 -1
- data/acceptance/Gemfile +4 -4
- data/acceptance/Gemfile.lock +70 -69
- data/chef-universal-mingw32.gemspec +2 -3
- data/chef.gemspec +6 -6
- data/lib/chef/api_client.rb +8 -10
- data/lib/chef/api_client_v1.rb +9 -11
- data/lib/chef/application/apply.rb +8 -10
- data/lib/chef/application/client.rb +1 -1
- data/lib/chef/application/exit_code.rb +3 -5
- data/lib/chef/application/knife.rb +2 -2
- data/lib/chef/application/windows_service.rb +29 -30
- data/lib/chef/application/windows_service_manager.rb +1 -1
- data/lib/chef/audit/audit_event_proxy.rb +2 -2
- data/lib/chef/audit/control_group_data.rb +1 -1
- data/lib/chef/chef_class.rb +1 -0
- data/lib/chef/chef_fs/chef_fs_data_store.rb +5 -7
- data/lib/chef/chef_fs/command_line.rb +15 -16
- data/lib/chef/chef_fs/data_handler/client_data_handler.rb +1 -1
- data/lib/chef/chef_fs/data_handler/container_data_handler.rb +1 -1
- data/lib/chef/chef_fs/data_handler/cookbook_data_handler.rb +1 -1
- data/lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb +1 -1
- data/lib/chef/chef_fs/data_handler/environment_data_handler.rb +1 -1
- data/lib/chef/chef_fs/data_handler/group_data_handler.rb +1 -1
- data/lib/chef/chef_fs/data_handler/node_data_handler.rb +1 -1
- data/lib/chef/chef_fs/data_handler/organization_data_handler.rb +1 -1
- data/lib/chef/chef_fs/data_handler/role_data_handler.rb +1 -1
- data/lib/chef/chef_fs/data_handler/user_data_handler.rb +1 -1
- data/lib/chef/chef_fs/file_pattern.rb +2 -2
- data/lib/chef/chef_fs/file_system.rb +1 -1
- data/lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb +5 -6
- data/lib/chef/chef_fs/file_system/chef_server/cookbook_file.rb +8 -10
- data/lib/chef/chef_fs/file_system/chef_server/data_bags_dir.rb +8 -10
- data/lib/chef/chef_fs/file_system/chef_server/nodes_dir.rb +10 -12
- data/lib/chef/chef_fs/file_system/chef_server/policies_dir.rb +28 -30
- data/lib/chef/chef_fs/file_system/chef_server/policy_group_entry.rb +1 -1
- data/lib/chef/chef_fs/file_system/chef_server/rest_list_dir.rb +27 -29
- data/lib/chef/chef_fs/file_system/chef_server/rest_list_entry.rb +18 -24
- data/lib/chef/chef_fs/file_system/memory/memory_file.rb +1 -1
- data/lib/chef/chef_fs/file_system/multiplexed_dir.rb +10 -12
- data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb +10 -12
- data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb +9 -13
- data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb +2 -0
- data/lib/chef/chef_fs/file_system/repository/cookbooks_dir.rb +1 -1
- data/lib/chef/chef_fs/file_system/repository/nodes_dir.rb +3 -0
- data/lib/chef/chef_fs/parallelizer.rb +9 -11
- data/lib/chef/cookbook/cookbook_version_loader.rb +25 -31
- data/lib/chef/cookbook/metadata.rb +26 -26
- data/lib/chef/cookbook/syntax_check.rb +1 -1
- data/lib/chef/cookbook_version.rb +3 -3
- data/lib/chef/data_bag.rb +1 -1
- data/lib/chef/data_bag_item.rb +3 -3
- data/lib/chef/data_collector.rb +3 -4
- data/lib/chef/decorator.rb +1 -1
- data/lib/chef/deprecated.rb +30 -0
- data/lib/chef/dsl/audit.rb +2 -2
- data/lib/chef/dsl/declare_resource.rb +1 -1
- data/lib/chef/dsl/platform_introspection.rb +29 -31
- data/lib/chef/dsl/reboot_pending.rb +1 -1
- data/lib/chef/dsl/resources.rb +6 -8
- data/lib/chef/encrypted_data_bag_item.rb +2 -2
- data/lib/chef/environment.rb +9 -11
- data/lib/chef/event_loggers/windows_eventlog.rb +1 -1
- data/lib/chef/exceptions.rb +4 -1
- data/lib/chef/file_access_control/unix.rb +14 -14
- data/lib/chef/file_access_control/windows.rb +1 -1
- data/lib/chef/formatters/error_inspectors/api_error_formatting.rb +4 -5
- data/lib/chef/formatters/error_mapper.rb +6 -6
- data/lib/chef/http/api_versions.rb +50 -0
- data/lib/chef/http/validate_content_length.rb +2 -2
- data/lib/chef/json_compat.rb +6 -10
- data/lib/chef/key.rb +5 -5
- data/lib/chef/knife.rb +4 -4
- data/lib/chef/knife/cookbook_site_install.rb +2 -2
- data/lib/chef/knife/core/cookbook_scm_repo.rb +2 -2
- data/lib/chef/knife/core/gem_glob_loader.rb +1 -1
- data/lib/chef/knife/core/status_presenter.rb +1 -1
- data/lib/chef/knife/core/ui.rb +19 -25
- data/lib/chef/knife/data_bag_secret_options.rb +1 -1
- data/lib/chef/knife/deps.rb +32 -34
- data/lib/chef/knife/help.rb +1 -1
- data/lib/chef/knife/list.rb +1 -1
- data/lib/chef/knife/search.rb +2 -2
- data/lib/chef/knife/ssh.rb +37 -27
- data/lib/chef/knife/ssl_check.rb +1 -1
- data/lib/chef/knife/user_delete.rb +1 -1
- data/lib/chef/mash.rb +1 -1
- data/lib/chef/mixin/command.rb +2 -2
- data/lib/chef/mixin/create_path.rb +3 -5
- data/lib/chef/mixin/from_file.rb +2 -2
- data/lib/chef/mixin/get_source_from_package.rb +2 -2
- data/lib/chef/mixin/notifying_block.rb +7 -9
- data/lib/chef/mixin/params_validate.rb +3 -3
- data/lib/chef/mixin/securable.rb +1 -1
- data/lib/chef/mixin/shell_out.rb +23 -3
- data/lib/chef/mixin/unformatter.rb +2 -2
- data/lib/chef/mixin/uris.rb +4 -6
- data/lib/chef/mixin/versioned_api.rb +69 -0
- data/lib/chef/mixin/which.rb +25 -8
- data/lib/chef/mixin/windows_architecture_helper.rb +2 -2
- data/lib/chef/mixin/xml_escape.rb +3 -5
- data/lib/chef/monkey_patches/webrick-utils.rb +1 -1
- data/lib/chef/node.rb +8 -8
- data/lib/chef/node/attribute.rb +4 -4
- data/lib/chef/node/common_api.rb +5 -7
- data/lib/chef/org.rb +10 -12
- data/lib/chef/platform/provider_mapping.rb +7 -7
- data/lib/chef/platform/query_helpers.rb +1 -1
- data/lib/chef/policy_builder/policyfile.rb +1 -0
- data/lib/chef/property.rb +31 -0
- data/lib/chef/provider/batch.rb +1 -1
- data/lib/chef/provider/breakpoint.rb +1 -1
- data/lib/chef/provider/cookbook_file.rb +3 -3
- data/lib/chef/provider/cron.rb +38 -38
- data/lib/chef/provider/deploy.rb +81 -81
- data/lib/chef/provider/deploy/revision.rb +3 -5
- data/lib/chef/provider/directory.rb +32 -32
- data/lib/chef/provider/dsc_resource.rb +22 -6
- data/lib/chef/provider/env.rb +28 -28
- data/lib/chef/provider/env/windows.rb +1 -1
- data/lib/chef/provider/erl_call.rb +13 -13
- data/lib/chef/provider/execute.rb +5 -2
- data/lib/chef/provider/file.rb +49 -51
- data/lib/chef/provider/git.rb +55 -55
- data/lib/chef/provider/http_request.rb +36 -36
- data/lib/chef/provider/launchd.rb +2 -2
- data/lib/chef/provider/link.rb +50 -50
- data/lib/chef/provider/log.rb +2 -2
- data/lib/chef/provider/mdadm.rb +25 -25
- data/lib/chef/provider/mount/aix.rb +2 -2
- data/lib/chef/provider/mount/mount.rb +2 -2
- data/lib/chef/provider/ohai.rb +1 -1
- data/lib/chef/provider/osx_profile.rb +23 -23
- data/lib/chef/provider/package.rb +74 -56
- data/lib/chef/provider/package/aix.rb +55 -52
- data/lib/chef/provider/package/apt.rb +15 -13
- data/lib/chef/provider/package/cab.rb +49 -20
- data/lib/chef/provider/package/chocolatey.rb +9 -10
- data/lib/chef/provider/package/dnf.rb +20 -18
- data/lib/chef/provider/package/dnf/dnf_helper.py +1 -1
- data/lib/chef/provider/package/dnf/python_helper.rb +63 -26
- data/lib/chef/provider/package/dnf/version.rb +1 -1
- data/lib/chef/provider/package/dpkg.rb +8 -9
- data/lib/chef/provider/package/easy_install.rb +22 -22
- data/lib/chef/provider/package/freebsd/base.rb +10 -10
- data/lib/chef/provider/package/freebsd/pkg.rb +15 -15
- data/lib/chef/provider/package/freebsd/pkgng.rb +13 -15
- data/lib/chef/provider/package/freebsd/port.rb +7 -7
- data/lib/chef/provider/package/homebrew.rb +11 -10
- data/lib/chef/provider/package/ips.rb +18 -23
- data/lib/chef/provider/package/macports.rb +23 -23
- data/lib/chef/provider/package/msu.rb +11 -11
- data/lib/chef/provider/package/openbsd.rb +25 -22
- data/lib/chef/provider/package/pacman.rb +16 -16
- data/lib/chef/provider/package/paludis.rb +26 -27
- data/lib/chef/provider/package/portage.rb +22 -22
- data/lib/chef/provider/package/powershell.rb +17 -17
- data/lib/chef/provider/package/rpm.rb +25 -25
- data/lib/chef/provider/package/rubygems.rb +60 -60
- data/lib/chef/provider/package/smartos.rb +16 -16
- data/lib/chef/provider/package/solaris.rb +44 -44
- data/lib/chef/provider/package/windows.rb +3 -3
- data/lib/chef/provider/package/windows/exe.rb +6 -6
- data/lib/chef/provider/package/windows/msi.rb +6 -6
- data/lib/chef/provider/package/yum.rb +318 -268
- data/lib/chef/provider/package/yum/rpm_utils.rb +34 -34
- data/lib/chef/provider/package/yum/yum_cache.rb +12 -12
- data/lib/chef/provider/package/zypper.rb +11 -11
- data/lib/chef/provider/powershell_script.rb +15 -7
- data/lib/chef/provider/reboot.rb +10 -10
- data/lib/chef/provider/registry_key.rb +39 -39
- data/lib/chef/provider/remote_directory.rb +3 -3
- data/lib/chef/provider/remote_file.rb +3 -3
- data/lib/chef/provider/route.rb +1 -1
- data/lib/chef/provider/ruby_block.rb +3 -3
- data/lib/chef/provider/script.rb +42 -6
- data/lib/chef/provider/service.rb +49 -49
- data/lib/chef/provider/service/solaris.rb +1 -1
- data/lib/chef/provider/service/systemd.rb +1 -1
- data/lib/chef/provider/subversion.rb +39 -39
- data/lib/chef/provider/systemd_unit.rb +2 -0
- data/lib/chef/provider/template.rb +3 -3
- data/lib/chef/provider/user.rb +42 -42
- data/lib/chef/provider/whyrun_safe_ruby_block.rb +4 -4
- data/lib/chef/resource.rb +27 -16
- data/lib/chef/resource/apt_repository.rb +0 -1
- data/lib/chef/resource/chef_gem.rb +1 -1
- data/lib/chef/resource/dnf_package.rb +6 -3
- data/lib/chef/resource/dsc_resource.rb +9 -1
- data/lib/chef/resource/execute.rb +70 -6
- data/lib/chef/resource/file/verification/systemd_unit.rb +67 -0
- data/lib/chef/resource/freebsd_package.rb +1 -1
- data/lib/chef/resource/gem_package.rb +1 -1
- data/lib/chef/resource/launchd.rb +13 -1
- data/lib/chef/resource/package.rb +2 -2
- data/lib/chef/resource/registry_key.rb +1 -1
- data/lib/chef/resource/yum_package.rb +12 -3
- data/lib/chef/resource/yum_repository.rb +0 -1
- data/lib/chef/resource_collection/resource_collection_serialization.rb +3 -3
- data/lib/chef/resource_collection/resource_set.rb +2 -2
- data/lib/chef/resource_reporter.rb +1 -1
- data/lib/chef/run_context.rb +3 -3
- data/lib/chef/run_list/run_list_item.rb +1 -1
- data/lib/chef/run_list/versioned_recipe_list.rb +6 -6
- data/lib/chef/server_api.rb +2 -0
- data/lib/chef/server_api_versions.rb +40 -0
- data/lib/chef/shell.rb +1 -1
- data/lib/chef/shell/ext.rb +3 -3
- data/lib/chef/shell/shell_session.rb +1 -1
- data/lib/chef/user.rb +9 -11
- data/lib/chef/user_v1.rb +9 -11
- data/lib/chef/util/diff.rb +1 -1
- data/lib/chef/util/dsc/lcm_output_parser.rb +1 -1
- data/lib/chef/util/selinux.rb +1 -1
- data/lib/chef/util/windows/net_group.rb +18 -30
- data/lib/chef/util/windows/net_use.rb +7 -11
- data/lib/chef/util/windows/net_user.rb +11 -17
- data/lib/chef/util/windows/volume.rb +9 -15
- data/lib/chef/version.rb +1 -1
- data/lib/chef/version_class.rb +1 -1
- data/lib/chef/win32/api.rb +4 -6
- data/lib/chef/win32/api/file.rb +25 -31
- data/lib/chef/win32/api/installer.rb +2 -2
- data/lib/chef/win32/file.rb +4 -6
- data/lib/chef/win32/registry.rb +9 -9
- data/lib/chef/win32/security.rb +2 -2
- data/lib/chef/win32/security/acl.rb +2 -2
- data/lib/chef/win32/unicode.rb +2 -2
- data/lib/chef/win32/version.rb +1 -1
- data/spec/data/prefer_metadata_json/metadata.json +51 -0
- data/spec/data/prefer_metadata_json/metadata.rb +6 -0
- data/spec/data/prefer_metadata_json/recipes/default.rb +0 -0
- data/spec/functional/knife/ssh_spec.rb +5 -5
- data/spec/functional/resource/batch_spec.rb +5 -1
- data/spec/functional/resource/dsc_script_spec.rb +2 -4
- data/spec/functional/resource/execute_spec.rb +17 -0
- data/spec/functional/resource/user/dscl_spec.rb +2 -4
- data/spec/integration/client/client_spec.rb +33 -0
- data/spec/integration/recipes/recipe_dsl_spec.rb +58 -58
- data/spec/spec_helper.rb +4 -0
- data/spec/support/chef_helpers.rb +5 -7
- data/spec/support/platform_helpers.rb +6 -0
- data/spec/support/platforms/prof/gc.rb +4 -6
- data/spec/support/shared/context/client.rb +1 -1
- data/spec/support/shared/functional/execute_resource.rb +150 -0
- data/spec/support/shared/functional/windows_script.rb +74 -4
- data/spec/support/shared/unit/execute_resource.rb +37 -0
- data/spec/support/shared/unit/provider/file.rb +10 -0
- data/spec/unit/cookbook/cookbook_version_loader_spec.rb +9 -0
- data/spec/unit/cookbook/syntax_check_spec.rb +8 -2
- data/spec/unit/http/api_versions_spec.rb +69 -0
- data/spec/unit/knife/ssh_spec.rb +34 -36
- data/spec/unit/mixin/versioned_api_spec.rb +107 -0
- data/spec/unit/mixin/which.rb +160 -0
- data/spec/unit/platform_spec.rb +28 -1
- data/spec/unit/provider/deploy_spec.rb +1 -1
- data/spec/unit/provider/directory_spec.rb +10 -0
- data/spec/unit/provider/dsc_resource_spec.rb +175 -0
- data/spec/unit/provider/execute_spec.rb +0 -1
- data/spec/unit/provider/launchd_spec.rb +2 -2
- data/spec/unit/provider/package/aix_spec.rb +22 -22
- data/spec/unit/provider/package/apt_spec.rb +27 -27
- data/spec/unit/provider/package/cab_spec.rb +59 -5
- data/spec/unit/provider/package/dnf/python_helper_spec.rb +29 -0
- data/spec/unit/provider/package/dpkg_spec.rb +16 -16
- data/spec/unit/provider/package/easy_install_spec.rb +18 -18
- data/spec/unit/provider/package/freebsd/pkg_spec.rb +15 -15
- data/spec/unit/provider/package/freebsd/pkgng_spec.rb +9 -9
- data/spec/unit/provider/package/freebsd/port_spec.rb +9 -9
- data/spec/unit/provider/package/homebrew_spec.rb +9 -9
- data/spec/unit/provider/package/ips_spec.rb +37 -31
- data/spec/unit/provider/package/macports_spec.rb +10 -10
- data/spec/unit/provider/package/openbsd_spec.rb +10 -10
- data/spec/unit/provider/package/pacman_spec.rb +6 -6
- data/spec/unit/provider/package/paludis_spec.rb +7 -7
- data/spec/unit/provider/package/portage_spec.rb +6 -7
- data/spec/unit/provider/package/rpm_spec.rb +23 -23
- data/spec/unit/provider/package/rubygems_spec.rb +38 -38
- data/spec/unit/provider/package/solaris_spec.rb +15 -15
- data/spec/unit/provider/package/windows_spec.rb +2 -1
- data/spec/unit/provider/package/yum_spec.rb +51 -43
- data/spec/unit/provider/package/zypper_spec.rb +34 -34
- data/spec/unit/provider/package_spec.rb +8 -0
- data/spec/unit/provider/remote_file/sftp_spec.rb +3 -3
- data/spec/unit/provider/route_spec.rb +7 -1
- data/spec/unit/provider/script_spec.rb +49 -6
- data/spec/unit/resource/dsc_resource_spec.rb +6 -0
- data/spec/unit/resource/execute_spec.rb +214 -0
- data/spec/unit/resource/file/verification/systemd_unit_spec.rb +103 -0
- data/spec/unit/resource/freebsd_package_spec.rb +2 -2
- data/spec/unit/resource/package_spec.rb +5 -0
- data/spec/unit/resource/yum_package_spec.rb +42 -1
- data/spec/unit/resource_reporter_spec.rb +1 -1
- data/spec/unit/resource_spec.rb +18 -0
- data/spec/unit/server_api_versions_spec.rb +44 -0
- data/spec/unit/util/selinux_spec.rb +3 -14
- data/spec/unit/win32/error_spec.rb +67 -0
- data/spec/unit/win32/security_spec.rb +66 -0
- data/tasks/changelog.rb +1 -1
- data/tasks/dependencies.rb +20 -4
- metadata +39 -18
- data/lib/chef/monkey_patches/net-ssh-multi.rb +0 -141
@@ -19,50 +19,80 @@
|
|
19
19
|
require "chef/provider/package"
|
20
20
|
require "chef/resource/cab_package"
|
21
21
|
require "chef/mixin/shell_out"
|
22
|
+
require "chef/mixin/uris"
|
23
|
+
require "chef/mixin/checksum"
|
22
24
|
|
23
25
|
class Chef
|
24
26
|
class Provider
|
25
27
|
class Package
|
26
28
|
class Cab < Chef::Provider::Package
|
29
|
+
use_inline_resources
|
27
30
|
include Chef::Mixin::ShellOut
|
31
|
+
include Chef::Mixin::Uris
|
32
|
+
include Chef::Mixin::Checksum
|
28
33
|
|
29
34
|
provides :cab_package, os: "windows"
|
30
35
|
|
31
36
|
def load_current_resource
|
32
37
|
@current_resource = Chef::Resource::CabPackage.new(new_resource.name)
|
33
|
-
current_resource.source(
|
38
|
+
current_resource.source(cab_file_source)
|
34
39
|
new_resource.version(package_version)
|
35
40
|
current_resource.version(installed_version)
|
36
41
|
current_resource
|
37
42
|
end
|
38
43
|
|
44
|
+
def cab_file_source
|
45
|
+
@cab_file_source ||= uri_scheme?(new_resource.source) ? download_source_file : new_resource.source
|
46
|
+
end
|
47
|
+
|
48
|
+
def download_source_file
|
49
|
+
source_resource.run_action(:create)
|
50
|
+
Chef::Log.debug("#{new_resource} fetched source file to #{source_resource.path}")
|
51
|
+
source_resource.path
|
52
|
+
end
|
53
|
+
|
54
|
+
def source_resource
|
55
|
+
@source_resource ||= declare_resource(:remote_file, new_resource.name) do
|
56
|
+
path default_download_cache_path
|
57
|
+
source new_resource.source
|
58
|
+
backup false
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def default_download_cache_path
|
63
|
+
uri = ::URI.parse(new_resource.source)
|
64
|
+
filename = ::File.basename(::URI.unescape(uri.path))
|
65
|
+
file_cache_dir = Chef::FileCache.create_cache_path("package/")
|
66
|
+
Chef::Util::PathHelper.cleanpath("#{file_cache_dir}/#{filename}")
|
67
|
+
end
|
68
|
+
|
39
69
|
def install_package(name, version)
|
40
|
-
dism_command("/Add-Package /PackagePath:\"#{
|
70
|
+
dism_command("/Add-Package /PackagePath:\"#{cab_file_source}\"")
|
41
71
|
end
|
42
72
|
|
43
73
|
def remove_package(name, version)
|
44
|
-
dism_command("/Remove-Package /PackagePath:\"#{
|
74
|
+
dism_command("/Remove-Package /PackagePath:\"#{cab_file_source}\"")
|
45
75
|
end
|
46
76
|
|
47
77
|
def dism_command(command)
|
48
|
-
shellout = Mixlib::ShellOut.new("dism.exe /Online /English #{command} /NoRestart",
|
78
|
+
shellout = Mixlib::ShellOut.new("dism.exe /Online /English #{command} /NoRestart", timeout: new_resource.timeout)
|
49
79
|
with_os_architecture(nil) do
|
50
80
|
shellout.run_command
|
51
81
|
end
|
52
82
|
end
|
53
83
|
|
54
84
|
def installed_version
|
55
|
-
stdout = dism_command("/Get-PackageInfo /PackagePath:\"#{
|
85
|
+
stdout = dism_command("/Get-PackageInfo /PackagePath:\"#{cab_file_source}\"").stdout
|
56
86
|
package_info = parse_dism_get_package_info(stdout)
|
57
87
|
# e.g. Package_for_KB2975719~31bf3856ad364e35~amd64~~6.3.1.8
|
58
88
|
package = split_package_identity(package_info["package_information"]["package_identity"])
|
59
89
|
# Search for just the package name to catch a different version being installed
|
60
|
-
Chef::Log.debug("#{
|
90
|
+
Chef::Log.debug("#{new_resource} searching for installed package #{package['name']}")
|
61
91
|
found_packages = installed_packages.select { |p| p["package_identity"] =~ /^#{package['name']}~/ }
|
62
|
-
if found_packages.
|
92
|
+
if found_packages.empty?
|
63
93
|
nil
|
64
94
|
elsif found_packages.length == 1
|
65
|
-
stdout = dism_command("/Get-PackageInfo /PackageName:\"#{found_packages.first[
|
95
|
+
stdout = dism_command("/Get-PackageInfo /PackageName:\"#{found_packages.first['package_identity']}\"").stdout
|
66
96
|
find_version(stdout)
|
67
97
|
else
|
68
98
|
# Presuming this won't happen, otherwise we need to handle it
|
@@ -71,8 +101,8 @@ class Chef
|
|
71
101
|
end
|
72
102
|
|
73
103
|
def package_version
|
74
|
-
Chef::Log.debug("#{
|
75
|
-
stdout = dism_command("/Get-PackageInfo /PackagePath:\"#{
|
104
|
+
Chef::Log.debug("#{new_resource} getting product version for package at #{cab_file_source}")
|
105
|
+
stdout = dism_command("/Get-PackageInfo /PackagePath:\"#{cab_file_source}\"").stdout
|
76
106
|
find_version(stdout)
|
77
107
|
end
|
78
108
|
|
@@ -85,22 +115,21 @@ class Chef
|
|
85
115
|
# returns a hash of package state information given the output of dism /get-packages
|
86
116
|
# expected keys: package_identity
|
87
117
|
def parse_dism_get_packages(text)
|
88
|
-
packages =
|
118
|
+
packages = []
|
89
119
|
text.each_line do |line|
|
90
120
|
key, value = line.split(":") if line.start_with?("Package Identity")
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
end
|
121
|
+
next if key.nil? || value.nil?
|
122
|
+
package = {}
|
123
|
+
package[key.downcase.strip.tr(" ", "_")] = value.strip.chomp
|
124
|
+
packages << package
|
96
125
|
end
|
97
126
|
packages
|
98
127
|
end
|
99
128
|
|
100
129
|
# returns a hash of package information given the output of dism /get-packageinfo
|
101
130
|
def parse_dism_get_package_info(text)
|
102
|
-
package_data =
|
103
|
-
errors =
|
131
|
+
package_data = {}
|
132
|
+
errors = []
|
104
133
|
in_section = false
|
105
134
|
section_headers = [ "Package information", "Custom Properties", "Features" ]
|
106
135
|
text.each_line do |line|
|
@@ -112,7 +141,7 @@ class Chef
|
|
112
141
|
v = $2 # has to be first or the gsub below replaces this variable
|
113
142
|
k = $1.downcase.strip.tr(" ", "_")
|
114
143
|
if in_section
|
115
|
-
package_data[in_section] =
|
144
|
+
package_data[in_section] = {} unless package_data[in_section]
|
116
145
|
package_data[in_section][k] = v
|
117
146
|
else
|
118
147
|
package_data[k] = v
|
@@ -132,7 +161,7 @@ class Chef
|
|
132
161
|
end
|
133
162
|
|
134
163
|
def split_package_identity(identity)
|
135
|
-
data =
|
164
|
+
data = {}
|
136
165
|
data["name"], data["publisher"], data["arch"], data["resource_id"], data["version"] = identity.split("~")
|
137
166
|
data
|
138
167
|
end
|
@@ -30,8 +30,8 @@ class Chef
|
|
30
30
|
# Declare that our arguments should be arrays
|
31
31
|
use_multipackage_api
|
32
32
|
|
33
|
-
PATHFINDING_POWERSHELL_COMMAND = "[System.Environment]::GetEnvironmentVariable('ChocolateyInstall', 'MACHINE')"
|
34
|
-
CHOCO_MISSING_MSG = <<-EOS
|
33
|
+
PATHFINDING_POWERSHELL_COMMAND = "[System.Environment]::GetEnvironmentVariable('ChocolateyInstall', 'MACHINE')".freeze
|
34
|
+
CHOCO_MISSING_MSG = <<-EOS.freeze
|
35
35
|
Could not locate your Chocolatey install. To install chocolatey, we recommend
|
36
36
|
the 'chocolatey' cookbook (https://github.com/chocolatey/chocolatey-cookbook).
|
37
37
|
If Chocolatey is installed, ensure that the 'ChocolateyInstall' environment
|
@@ -59,8 +59,8 @@ EOS
|
|
59
59
|
# so we want to assert candidates exist for the alternate source
|
60
60
|
requirements.assert(:upgrade, :install) do |a|
|
61
61
|
a.assertion { candidates_exist_for_all_uninstalled? }
|
62
|
-
a.failure_message(Chef::Exceptions::Package, "No candidate version available for #{packages_missing_candidates.join(
|
63
|
-
a.whyrun("Assuming a repository that offers #{packages_missing_candidates.join(
|
62
|
+
a.failure_message(Chef::Exceptions::Package, "No candidate version available for #{packages_missing_candidates.join(', ')}")
|
63
|
+
a.whyrun("Assuming a repository that offers #{packages_missing_candidates.join(', ')} would have been configured")
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
@@ -133,12 +133,11 @@ EOS
|
|
133
133
|
end
|
134
134
|
|
135
135
|
# Choco does not have dpkg's distinction between purge and remove
|
136
|
-
|
136
|
+
alias purge_package remove_package
|
137
137
|
|
138
138
|
# Override the superclass check. The semantics for our new_resource.source is not files to
|
139
139
|
# install from, but like the rubygem provider's sources which are more like repos.
|
140
|
-
def check_resource_semantics
|
141
|
-
end
|
140
|
+
def check_resource_semantics!; end
|
142
141
|
|
143
142
|
private
|
144
143
|
|
@@ -160,7 +159,7 @@ EOS
|
|
160
159
|
def choco_install_path
|
161
160
|
@choco_install_path ||= powershell_out!(
|
162
161
|
PATHFINDING_POWERSHELL_COMMAND
|
163
|
-
|
162
|
+
).stdout.chomp
|
164
163
|
end
|
165
164
|
|
166
165
|
# Helper to dispatch a choco command through shell_out using the timeout
|
@@ -169,7 +168,7 @@ EOS
|
|
169
168
|
# @param args [String] variable number of string arguments
|
170
169
|
# @return [Mixlib::ShellOut] object returned from shell_out!
|
171
170
|
def choco_command(*args)
|
172
|
-
shell_out_with_timeout!(args_to_string(choco_exe, *args),
|
171
|
+
shell_out_with_timeout!(args_to_string(choco_exe, *args), returns: new_resource.returns)
|
173
172
|
end
|
174
173
|
|
175
174
|
# Use the available_packages Hash helper to create an array suitable for
|
@@ -268,7 +267,7 @@ EOS
|
|
268
267
|
# @param names [Array] original mixed case names
|
269
268
|
# @return [Array] same names in lower case
|
270
269
|
def lowercase_names(names)
|
271
|
-
names.map
|
270
|
+
names.map(&:downcase)
|
272
271
|
end
|
273
272
|
end
|
274
273
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#
|
2
|
-
# Copyright:: Copyright 2016, Chef Software
|
2
|
+
# Copyright:: Copyright 2016-2017, Chef Software Inc.
|
3
3
|
# License:: Apache License, Version 2.0
|
4
4
|
#
|
5
5
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -18,6 +18,7 @@
|
|
18
18
|
require "chef/provider/package"
|
19
19
|
require "chef/resource/dnf_package"
|
20
20
|
require "chef/mixin/which"
|
21
|
+
require "chef/mixin/shell_out"
|
21
22
|
require "chef/mixin/get_source_from_package"
|
22
23
|
require "chef/provider/package/dnf/python_helper"
|
23
24
|
require "chef/provider/package/dnf/version"
|
@@ -27,6 +28,7 @@ class Chef
|
|
27
28
|
class Package
|
28
29
|
class Dnf < Chef::Provider::Package
|
29
30
|
extend Chef::Mixin::Which
|
31
|
+
extend Chef::Mixin::ShellOut
|
30
32
|
include Chef::Mixin::GetSourceFromPackage
|
31
33
|
|
32
34
|
allow_nils
|
@@ -34,7 +36,7 @@ class Chef
|
|
34
36
|
use_package_name_for_source
|
35
37
|
|
36
38
|
provides :package, platform_family: %w{rhel fedora} do
|
37
|
-
which("dnf")
|
39
|
+
which("dnf") && shell_out("rpm -q dnf").stdout =~ /^dnf-[1-9]/
|
38
40
|
end
|
39
41
|
|
40
42
|
provides :dnf_package, os: "linux"
|
@@ -86,24 +88,24 @@ class Chef
|
|
86
88
|
|
87
89
|
def install_package(names, versions)
|
88
90
|
if new_resource.source
|
89
|
-
dnf(
|
91
|
+
dnf(options, "-y install", new_resource.source)
|
90
92
|
else
|
91
93
|
resolved_names = names.each_with_index.map { |name, i| available_version(i).to_s unless name.nil? }
|
92
|
-
dnf(
|
94
|
+
dnf(options, "-y install", resolved_names)
|
93
95
|
end
|
94
96
|
flushcache
|
95
97
|
end
|
96
98
|
|
97
99
|
# dnf upgrade does not work on uninstalled packaged, while install will upgrade
|
98
|
-
|
100
|
+
alias upgrade_package install_package
|
99
101
|
|
100
102
|
def remove_package(names, versions)
|
101
103
|
resolved_names = names.each_with_index.map { |name, i| installed_version(i).to_s unless name.nil? }
|
102
|
-
dnf(
|
104
|
+
dnf(options, "-y remove", resolved_names)
|
103
105
|
flushcache
|
104
106
|
end
|
105
107
|
|
106
|
-
|
108
|
+
alias purge_package remove_package
|
107
109
|
|
108
110
|
action :flush_cache do
|
109
111
|
flushcache
|
@@ -117,7 +119,7 @@ class Chef
|
|
117
119
|
# does not match what the dnf library accepts.
|
118
120
|
case line
|
119
121
|
when /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)$/
|
120
|
-
return Version.new($1, "#{$2 ==
|
122
|
+
return Version.new($1, "#{$2 == '(none)' ? '0' : $2}:#{$3}-#{$4}", $5)
|
121
123
|
end
|
122
124
|
end
|
123
125
|
end
|
@@ -126,11 +128,11 @@ class Chef
|
|
126
128
|
def available_version(index)
|
127
129
|
@available_version ||= []
|
128
130
|
|
129
|
-
if new_resource.source
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
131
|
+
@available_version[index] ||= if new_resource.source
|
132
|
+
resolve_source_to_version_obj
|
133
|
+
else
|
134
|
+
python_helper.query(:whatavailable, package_name_array[index], safe_version_array[index], safe_arch_array[index])
|
135
|
+
end
|
134
136
|
|
135
137
|
@available_version[index]
|
136
138
|
end
|
@@ -138,11 +140,11 @@ class Chef
|
|
138
140
|
# @returns Array<Version>
|
139
141
|
def installed_version(index)
|
140
142
|
@installed_version ||= []
|
141
|
-
if new_resource.source
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
143
|
+
@installed_version[index] ||= if new_resource.source
|
144
|
+
python_helper.query(:whatinstalled, available_version(index).name, safe_version_array[index], safe_arch_array[index])
|
145
|
+
else
|
146
|
+
python_helper.query(:whatinstalled, package_name_array[index], safe_version_array[index], safe_arch_array[index])
|
147
|
+
end
|
146
148
|
@installed_version[index]
|
147
149
|
end
|
148
150
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#
|
2
|
-
# Copyright:: Copyright 2016, Chef Software
|
2
|
+
# Copyright:: Copyright 2016-2017, Chef Software Inc.
|
3
3
|
# License:: Apache License, Version 2.0
|
4
4
|
#
|
5
5
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -15,6 +15,8 @@
|
|
15
15
|
# limitations under the License.
|
16
16
|
#
|
17
17
|
|
18
|
+
require "chef/mixin/which"
|
19
|
+
require "chef/mixin/shell_out"
|
18
20
|
require "chef/provider/package/dnf/version"
|
19
21
|
require "timeout"
|
20
22
|
|
@@ -24,7 +26,8 @@ class Chef
|
|
24
26
|
class Dnf < Chef::Provider::Package
|
25
27
|
class PythonHelper
|
26
28
|
include Singleton
|
27
|
-
|
29
|
+
include Chef::Mixin::Which
|
30
|
+
include Chef::Mixin::ShellOut
|
28
31
|
|
29
32
|
attr_accessor :stdin
|
30
33
|
attr_accessor :stdout
|
@@ -32,11 +35,16 @@ class Chef
|
|
32
35
|
attr_accessor :wait_thr
|
33
36
|
|
34
37
|
DNF_HELPER = ::File.expand_path(::File.join(::File.dirname(__FILE__), "dnf_helper.py")).freeze
|
35
|
-
|
38
|
+
|
39
|
+
def dnf_command
|
40
|
+
@dnf_command ||= which("python", "python3", "python2", "python2.7") do |f|
|
41
|
+
shell_out("#{f} -c 'import dnf'").exitstatus == 0
|
42
|
+
end + " #{DNF_HELPER}"
|
43
|
+
end
|
36
44
|
|
37
45
|
def start
|
38
46
|
ENV["PYTHONUNBUFFERED"] = "1"
|
39
|
-
@stdin, @stdout, @stderr, @wait_thr = Open3.popen3(
|
47
|
+
@stdin, @stdout, @stderr, @wait_thr = Open3.popen3(dnf_command)
|
40
48
|
end
|
41
49
|
|
42
50
|
def reap
|
@@ -53,6 +61,27 @@ class Chef
|
|
53
61
|
start if stdin.nil?
|
54
62
|
end
|
55
63
|
|
64
|
+
# @returns Array<Version>
|
65
|
+
def query(action, provides, version = nil, arch = nil)
|
66
|
+
with_helper do
|
67
|
+
json = build_query(action, provides, version, arch)
|
68
|
+
Chef::Log.debug "sending '#{json}' to python helper"
|
69
|
+
stdin.syswrite json + "\n"
|
70
|
+
output = stdout.sysread(4096).chomp
|
71
|
+
Chef::Log.debug "got '#{output}' from python helper"
|
72
|
+
version = parse_response(output)
|
73
|
+
Chef::Log.debug "parsed #{version} from python helper"
|
74
|
+
version
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def restart
|
79
|
+
reap
|
80
|
+
start
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
56
85
|
# i couldn't figure out how to decompose an evr on the python side, it seems reasonably
|
57
86
|
# painless to do it in ruby (generally massaging nevras in the ruby side is HIGHLY
|
58
87
|
# discouraged -- this is an "every rule has an exception" exception -- any additional
|
@@ -60,10 +89,12 @@ class Chef
|
|
60
89
|
def add_version(hash, version)
|
61
90
|
epoch = nil
|
62
91
|
if version =~ /(\S+):(\S+)/
|
63
|
-
epoch
|
92
|
+
epoch = $1
|
93
|
+
version = $2
|
64
94
|
end
|
65
95
|
if version =~ /(\S+)-(\S+)/
|
66
|
-
version
|
96
|
+
version = $1
|
97
|
+
release = $2
|
67
98
|
end
|
68
99
|
hash["epoch"] = epoch unless epoch.nil?
|
69
100
|
hash["release"] = release unless release.nil?
|
@@ -83,35 +114,41 @@ class Chef
|
|
83
114
|
array.each_slice(3).map { |x| Version.new(*x) }.first
|
84
115
|
end
|
85
116
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
Chef::Log.debug "sending '#{json}' to python helper"
|
91
|
-
stdin.syswrite json + "\n"
|
92
|
-
output = stdout.sysread(4096).chomp
|
93
|
-
Chef::Log.debug "got '#{output}' from python helper"
|
94
|
-
version = parse_response(output)
|
95
|
-
Chef::Log.debug "parsed #{version} from python helper"
|
96
|
-
version
|
117
|
+
def drain_stderr
|
118
|
+
output = ""
|
119
|
+
until IO.select([stderr], nil, nil, 0).nil?
|
120
|
+
output += stderr.sysread(4096).chomp
|
97
121
|
end
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
start
|
122
|
+
output
|
123
|
+
rescue
|
124
|
+
# we must rescue EOFError, and we don't much care about errors on stderr anyway
|
125
|
+
output
|
103
126
|
end
|
104
127
|
|
105
128
|
def with_helper
|
106
129
|
max_retries ||= 5
|
130
|
+
ret = nil
|
107
131
|
Timeout.timeout(600) do
|
108
132
|
check
|
109
|
-
yield
|
133
|
+
ret = yield
|
110
134
|
end
|
135
|
+
output = drain_stderr
|
136
|
+
unless output.empty?
|
137
|
+
Chef::Log.debug "discarding output on stderr from python helper: #{output}"
|
138
|
+
end
|
139
|
+
ret
|
111
140
|
rescue EOFError, Errno::EPIPE, Timeout::Error, Errno::ESRCH => e
|
112
|
-
|
113
|
-
|
114
|
-
|
141
|
+
output = drain_stderr
|
142
|
+
if ( max_retries -= 1 ) > 0
|
143
|
+
unless output.empty?
|
144
|
+
Chef::Log.debug "discarding output on stderr from python helper: #{output}"
|
145
|
+
end
|
146
|
+
restart
|
147
|
+
retry
|
148
|
+
else
|
149
|
+
raise e if output.empty?
|
150
|
+
raise "dnf-helper.py had stderr output:\n\n#{output}"
|
151
|
+
end
|
115
152
|
end
|
116
153
|
end
|
117
154
|
end
|