chef 11.14.0.alpha.4 → 11.14.0.rc.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CONTRIBUTING.md +0 -4
- data/README.md +1 -1
- data/distro/common/man/man1/chef-shell.1 +4 -4
- data/distro/common/man/man1/knife-bootstrap.1 +14 -11
- data/distro/common/man/man1/knife-client.1 +14 -11
- data/distro/common/man/man1/knife-configure.1 +7 -7
- data/distro/common/man/man1/knife-cookbook-site.1 +23 -23
- data/distro/common/man/man1/knife-cookbook.1 +23 -23
- data/distro/common/man/man1/knife-data-bag.1 +13 -13
- data/distro/common/man/man1/knife-delete.1 +9 -9
- data/distro/common/man/man1/knife-deps.1 +9 -9
- data/distro/common/man/man1/knife-diff.1 +10 -10
- data/distro/common/man/man1/knife-download.1 +9 -9
- data/distro/common/man/man1/knife-edit.1 +7 -7
- data/distro/common/man/man1/knife-environment.1 +10 -10
- data/distro/common/man/man1/knife-exec.1 +7 -7
- data/distro/common/man/man1/knife-index-rebuild.1 +1 -1
- data/distro/common/man/man1/knife-list.1 +12 -12
- data/distro/common/man/man1/knife-node.1 +12 -9
- data/distro/common/man/man1/knife-raw.1 +7 -7
- data/distro/common/man/man1/knife-recipe-list.1 +1 -1
- data/distro/common/man/man1/knife-role.1 +8 -8
- data/distro/common/man/man1/knife-search.1 +9 -9
- data/distro/common/man/man1/knife-serve.1 +109 -0
- data/distro/common/man/man1/knife-show.1 +8 -8
- data/distro/common/man/man1/knife-ssh.1 +9 -9
- data/distro/common/man/man1/knife-ssl-check.1 +9 -9
- data/distro/common/man/man1/knife-ssl-fetch.1 +10 -10
- data/distro/common/man/man1/knife-status.1 +9 -9
- data/distro/common/man/man1/knife-tag.1 +7 -7
- data/distro/common/man/man1/knife-upload.1 +10 -10
- data/distro/common/man/man1/knife-user.1 +9 -9
- data/distro/common/man/man1/knife-xargs.1 +7 -7
- data/distro/common/man/man1/knife.1 +118 -14
- data/distro/common/man/man8/chef-client.8 +13 -10
- data/distro/common/man/man8/chef-solo.8 +13 -14
- data/distro/common/markdown/man1/knife.mkd +1 -1
- data/lib/chef/application/knife.rb +1 -1
- data/lib/chef/application/windows_service.rb +0 -1
- data/lib/chef/chef_fs/file_system.rb +6 -2
- data/lib/chef/config.rb +3 -2
- data/lib/chef/config_fetcher.rb +1 -1
- data/lib/chef/cookbook/metadata.rb +20 -14
- data/lib/chef/cookbook/synchronizer.rb +24 -13
- data/lib/chef/encrypted_data_bag_item/decryptor.rb +3 -3
- data/lib/chef/encrypted_data_bag_item/encryptor.rb +2 -2
- data/lib/chef/exceptions.rb +1 -0
- data/lib/chef/file_content_management/deploy/mv_windows.rb +1 -1
- data/lib/chef/formatters/error_inspectors/resource_failure_inspector.rb +1 -1
- data/lib/chef/http.rb +6 -1
- data/lib/chef/http/http_request.rb +9 -1
- data/lib/chef/http/simple.rb +2 -1
- data/lib/chef/json_compat.rb +5 -16
- data/lib/chef/knife/bootstrap.rb +2 -0
- data/lib/chef/knife/bootstrap/archlinux-gems.erb +2 -2
- data/lib/chef/knife/core/object_loader.rb +3 -1
- data/lib/chef/knife/ssh.rb +14 -7
- data/lib/chef/mixin/convert_to_class_name.rb +1 -0
- data/lib/chef/mixin/windows_architecture_helper.rb +24 -4
- data/lib/chef/platform/provider_mapping.rb +13 -0
- data/lib/chef/provider/env/windows.rb +3 -6
- data/lib/chef/provider/git.rb +1 -2
- data/lib/chef/provider/log.rb +15 -1
- data/lib/chef/provider/package/apt.rb +3 -3
- data/lib/chef/provider/package/dpkg.rb +35 -16
- data/lib/chef/provider/package/paludis.rb +91 -0
- data/lib/chef/provider/package/rpm.rb +3 -2
- data/lib/chef/provider/package/yum-dump.py +6 -6
- data/lib/chef/provider/package/yum.rb +2 -0
- data/lib/chef/provider/registry_key.rb +4 -5
- data/lib/chef/provider/remote_file/cache_control_data.rb +1 -1
- data/lib/chef/provider/service/solaris.rb +1 -1
- data/lib/chef/provider/service/upstart.rb +2 -1
- data/lib/chef/provider/service/windows.rb +37 -9
- data/lib/chef/provider/user/pw.rb +1 -1
- data/lib/chef/provider/user/useradd.rb +1 -1
- data/lib/chef/provider/windows_script.rb +2 -1
- data/lib/chef/providers.rb +1 -0
- data/lib/chef/resource.rb +10 -0
- data/lib/chef/resource/file.rb +0 -9
- data/lib/chef/resource/package.rb +14 -4
- data/lib/chef/resource/paludis_package.rb +33 -0
- data/lib/chef/resource/registry_key.rb +62 -3
- data/lib/chef/resource/service.rb +21 -4
- data/lib/chef/resource_reporter.rb +10 -0
- data/lib/chef/resources.rb +1 -0
- data/lib/chef/role.rb +14 -10
- data/lib/chef/shell.rb +8 -0
- data/lib/chef/shell/shell_session.rb +3 -3
- data/lib/chef/user.rb +12 -11
- data/lib/chef/util/selinux.rb +1 -1
- data/lib/chef/version.rb +1 -1
- data/lib/chef/version_constraint.rb +6 -5
- data/lib/chef/win32/api/process.rb +1 -0
- data/lib/chef/win32/api/system.rb +14 -0
- data/lib/chef/win32/error.rb +1 -1
- data/lib/chef/win32/security.rb +5 -5
- data/lib/chef/win32/version.rb +6 -2
- data/spec/data/trusted_certs/opscode.pem +57 -35
- data/spec/functional/application_spec.rb +2 -2
- data/spec/functional/resource/mount_spec.rb +3 -1
- data/spec/functional/shell_spec.rb +10 -0
- data/spec/functional/tiny_server_spec.rb +2 -2
- data/spec/support/chef_helpers.rb +1 -1
- data/spec/support/shared/functional/securable_resource.rb +11 -2
- data/spec/support/shared/functional/securable_resource_with_reporting.rb +13 -2
- data/spec/tiny_server.rb +1 -1
- data/spec/unit/config_spec.rb +5 -0
- data/spec/unit/cookbook/metadata_spec.rb +24 -0
- data/spec/unit/environment_spec.rb +6 -0
- data/spec/unit/http/http_request_spec.rb +91 -0
- data/spec/unit/http_spec.rb +23 -0
- data/spec/unit/knife/bootstrap_spec.rb +2 -2
- data/spec/unit/knife/ssh_spec.rb +7 -13
- data/spec/unit/knife_spec.rb +1 -1
- data/spec/unit/mixin/convert_to_class_name_spec.rb +4 -0
- data/spec/unit/provider/git_spec.rb +2 -2
- data/spec/unit/provider/log_spec.rb +18 -0
- data/spec/unit/provider/mount/solaris_spec.rb +3 -1
- data/spec/unit/provider/package/apt_spec.rb +85 -40
- data/spec/unit/provider/package/dpkg_spec.rb +24 -48
- data/spec/unit/provider/package/paludis_spec.rb +135 -0
- data/spec/unit/provider/package/rpm_spec.rb +40 -32
- data/spec/unit/provider/package/yum_spec.rb +11 -4
- data/spec/unit/provider/registry_key_spec.rb +67 -53
- data/spec/unit/provider/remote_file/cache_control_data_spec.rb +10 -1
- data/spec/unit/provider/service/solaris_smf_service_spec.rb +23 -2
- data/spec/unit/provider/service/upstart_service_spec.rb +7 -0
- data/spec/unit/provider/service/windows_spec.rb +72 -0
- data/spec/unit/provider/user/pw_spec.rb +21 -4
- data/spec/unit/provider/user/useradd_spec.rb +10 -0
- data/spec/unit/resource/package_spec.rb +26 -18
- data/spec/unit/resource/registry_key_spec.rb +28 -0
- data/spec/unit/resource/service_spec.rb +14 -0
- data/spec/unit/resource_reporter_spec.rb +37 -12
- data/spec/unit/resource_spec.rb +41 -6
- data/spec/unit/rest_spec.rb +2 -2
- data/spec/unit/role_spec.rb +46 -28
- data/spec/unit/shell/shell_session_spec.rb +42 -2
- data/spec/unit/shell_spec.rb +1 -1
- data/spec/unit/user_spec.rb +12 -0
- data/spec/unit/util/selinux_spec.rb +4 -4
- data/spec/unit/version_constraint_spec.rb +14 -2
- metadata +195 -161
- checksums.yaml +0 -7
data/lib/chef/knife/ssh.rb
CHANGED
@@ -170,12 +170,16 @@ class Chef
|
|
170
170
|
# if a command line attribute was not passed, and we have a
|
171
171
|
# cloud public_hostname, use that. see #configure_attribute
|
172
172
|
# for the source of config[:attribute] and
|
173
|
-
# config[:
|
174
|
-
if config[:
|
175
|
-
|
173
|
+
# config[:attribute_from_cli]
|
174
|
+
if config[:attribute_from_cli]
|
175
|
+
Chef::Log.debug("Using node attribute '#{config[:attribute_from_cli]}' from the command line as the ssh target")
|
176
|
+
host = extract_nested_value(item, config[:attribute_from_cli])
|
176
177
|
elsif item[:cloud] && item[:cloud][:public_hostname]
|
178
|
+
Chef::Log.debug("Using node attribute 'cloud[:public_hostname]' automatically as the ssh target")
|
177
179
|
host = item[:cloud][:public_hostname]
|
178
180
|
else
|
181
|
+
# ssh attribute from a configuration file or the default will land here
|
182
|
+
Chef::Log.debug("Using node attribute '#{config[:attribute]}' as the ssh target")
|
179
183
|
host = extract_nested_value(item, config[:attribute])
|
180
184
|
end
|
181
185
|
# next if we couldn't find the specified attribute in the
|
@@ -413,10 +417,8 @@ class Chef
|
|
413
417
|
# Thus we can differentiate between a config file value and a command line override at this point by checking config[:attribute]
|
414
418
|
# We can tell here if fqdn was passed from the command line, rather than being the default, by checking config[:attribute]
|
415
419
|
# However, after here, we cannot tell these things, so we must preserve config[:attribute]
|
416
|
-
config[:
|
417
|
-
config[:attribute] = (Chef::Config[:knife][:ssh_attribute] ||
|
418
|
-
config[:attribute] ||
|
419
|
-
"fqdn").strip
|
420
|
+
config[:attribute_from_cli] = config[:attribute]
|
421
|
+
config[:attribute] = (config[:attribute_from_cli] || Chef::Config[:knife][:ssh_attribute] || "fqdn").strip
|
420
422
|
end
|
421
423
|
|
422
424
|
def cssh
|
@@ -431,6 +433,11 @@ class Chef
|
|
431
433
|
end
|
432
434
|
raise Chef::Exceptions::Exec, "no command found for cssh" unless cssh_cmd
|
433
435
|
|
436
|
+
# pass in the consolidated itentity file option to cssh(X)
|
437
|
+
if config[:identity_file]
|
438
|
+
cssh_cmd << " --ssh_args '-i #{File.expand_path(config[:identity_file])}'"
|
439
|
+
end
|
440
|
+
|
434
441
|
session.servers_for.each do |server|
|
435
442
|
cssh_cmd << " #{server.user ? "#{server.user}@#{server.host}" : server.host}"
|
436
443
|
end
|
@@ -19,19 +19,26 @@
|
|
19
19
|
|
20
20
|
require 'chef/exceptions'
|
21
21
|
require 'win32/api' if Chef::Platform.windows?
|
22
|
+
require 'chef/win32/api/process' if Chef::Platform.windows?
|
23
|
+
require 'chef/win32/api/error' if Chef::Platform.windows?
|
22
24
|
|
23
25
|
class Chef
|
24
26
|
module Mixin
|
25
27
|
module WindowsArchitectureHelper
|
26
28
|
|
29
|
+
if Chef::Platform.windows?
|
30
|
+
include Chef::ReservedNames::Win32::API::Process
|
31
|
+
include Chef::ReservedNames::Win32::API::Error
|
32
|
+
end
|
33
|
+
|
27
34
|
def node_windows_architecture(node)
|
28
35
|
node[:kernel][:machine].to_sym
|
29
36
|
end
|
30
37
|
|
31
38
|
def wow64_architecture_override_required?(node, desired_architecture)
|
32
|
-
|
39
|
+
desired_architecture == :x86_64 &&
|
33
40
|
node_windows_architecture(node) == :x86_64 &&
|
34
|
-
|
41
|
+
is_i386_process_on_x86_64_windows?
|
35
42
|
end
|
36
43
|
|
37
44
|
def node_supports_windows_architecture?(node, desired_architecture)
|
@@ -51,8 +58,21 @@ class Chef
|
|
51
58
|
end
|
52
59
|
end
|
53
60
|
|
54
|
-
def
|
55
|
-
Chef::Platform.windows?
|
61
|
+
def is_i386_process_on_x86_64_windows?
|
62
|
+
if Chef::Platform.windows?
|
63
|
+
is_64_bit_process_result = FFI::MemoryPointer.new(:int)
|
64
|
+
|
65
|
+
# The return value of IsWow64Process is nonzero value if the API call succeeds.
|
66
|
+
# The result data are returned in the last parameter, not the return value.
|
67
|
+
call_succeeded = IsWow64Process(GetCurrentProcess(), is_64_bit_process_result)
|
68
|
+
|
69
|
+
# The result is nonzero if IsWow64Process's calling process, in the case here
|
70
|
+
# this process, is running under WOW64, i.e. the result is nonzero if this
|
71
|
+
# process is 32-bit (aka :i386).
|
72
|
+
result = (call_succeeded != 0) && (is_64_bit_process_result.get_int(0) != 0)
|
73
|
+
else
|
74
|
+
false
|
75
|
+
end
|
56
76
|
end
|
57
77
|
|
58
78
|
def disable_wow64_file_redirection( node )
|
@@ -72,6 +72,11 @@ class Chef
|
|
72
72
|
">= 11.10" => {
|
73
73
|
:ifconfig => Chef::Provider::Ifconfig::Debian
|
74
74
|
}
|
75
|
+
# Chef::Provider::Service::Upstart is a candidate to be used in
|
76
|
+
# ubuntu versions >= 13.10 but it currently requires all the
|
77
|
+
# services to have an entry under /etc/init. We need to update it
|
78
|
+
# to use the service ctl apis in order to migrate to using it on
|
79
|
+
# ubuntu >= 13.10.
|
75
80
|
},
|
76
81
|
:gcel => {
|
77
82
|
:default => {
|
@@ -363,6 +368,14 @@ class Chef
|
|
363
368
|
:package => Chef::Provider::Package::Aix
|
364
369
|
}
|
365
370
|
},
|
371
|
+
:exherbo => {
|
372
|
+
:default => {
|
373
|
+
:package => Chef::Provider::Package::Paludis,
|
374
|
+
:service => Chef::Provider::Service::Systemd,
|
375
|
+
:cron => Chef::Provider::Cron,
|
376
|
+
:mdadm => Chef::Provider::Mdadm
|
377
|
+
}
|
378
|
+
},
|
366
379
|
:default => {
|
367
380
|
:file => Chef::Provider::File,
|
368
381
|
:directory => Chef::Provider::Directory,
|
@@ -16,14 +16,13 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
18
|
|
19
|
-
if RUBY_PLATFORM =~ /mswin|mingw32|windows/
|
20
|
-
require 'Win32API'
|
21
|
-
end
|
19
|
+
require 'chef/win32/api/system' if RUBY_PLATFORM =~ /mswin|mingw32|windows/
|
22
20
|
|
23
21
|
class Chef
|
24
22
|
class Provider
|
25
23
|
class Env
|
26
24
|
class Windows < Chef::Provider::Env
|
25
|
+
include Chef::ReservedNames::Win32::API::System if RUBY_PLATFORM =~ /mswin|mingw32|windows/
|
27
26
|
|
28
27
|
def create_env
|
29
28
|
obj = env_obj(@new_resource.key_name)
|
@@ -73,10 +72,8 @@ class Chef
|
|
73
72
|
SMTO_NOTIMEOUTIFNOTHUNG = 0x0008
|
74
73
|
|
75
74
|
def broadcast_env_change
|
76
|
-
result = 0
|
77
75
|
flags = SMTO_BLOCK | SMTO_ABORTIFHUNG | SMTO_NOTIMEOUTIFNOTHUNG
|
78
|
-
|
79
|
-
@send_message.call(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 'Environment', flags, 5000, result)
|
76
|
+
SendMessageTimeoutA(HWND_BROADCAST, WM_SETTINGCHANGE, 0, FFI::MemoryPointer.from_string('Environment').address, flags, 5000, nil)
|
80
77
|
end
|
81
78
|
end
|
82
79
|
end
|
data/lib/chef/provider/git.rb
CHANGED
@@ -95,8 +95,7 @@ class Chef
|
|
95
95
|
|
96
96
|
def action_sync
|
97
97
|
if existing_git_clone?
|
98
|
-
|
99
|
-
Chef::Log.debug "#{@new_resource} current revision: #{current_rev} target revision: #{target_revision}"
|
98
|
+
Chef::Log.debug "#{@new_resource} current revision: #{@current_resource.revision} target revision: #{target_revision}"
|
100
99
|
unless current_revision_matches_target_revision?
|
101
100
|
fetch_updates
|
102
101
|
enable_submodules
|
data/lib/chef/provider/log.rb
CHANGED
@@ -25,6 +25,9 @@ class Chef
|
|
25
25
|
# Chef log provider, allows logging to chef's logs from recipes
|
26
26
|
class ChefLog < Chef::Provider
|
27
27
|
|
28
|
+
# ordered array of the log levels
|
29
|
+
@@levels = [ :debug, :info, :warn, :error, :fatal ]
|
30
|
+
|
28
31
|
# No concept of a 'current' resource for logs, this is a no-op
|
29
32
|
#
|
30
33
|
# === Return
|
@@ -39,7 +42,18 @@ class Chef
|
|
39
42
|
# true:: Always return true
|
40
43
|
def action_write
|
41
44
|
Chef::Log.send(@new_resource.level, @new_resource.message)
|
42
|
-
|
45
|
+
|
46
|
+
# resolve the integers for the current log levels
|
47
|
+
global_level = Mixlib::Log::LEVELS.fetch(Chef::Log.level)
|
48
|
+
resource_level = Mixlib::Log::LEVELS.fetch(@new_resource.level)
|
49
|
+
|
50
|
+
# If the resource level is greater than or the same os the global
|
51
|
+
# level, then it should have been written to the log. Mark the
|
52
|
+
# resource as updated.
|
53
|
+
if resource_level >= global_level
|
54
|
+
@new_resource.updated_by_last_action(true)
|
55
|
+
end
|
56
|
+
|
43
57
|
end
|
44
58
|
|
45
59
|
end
|
@@ -55,7 +55,7 @@ class Chef
|
|
55
55
|
Chef::Log.debug("#{@new_resource} checking package status for #{package}")
|
56
56
|
installed = false
|
57
57
|
|
58
|
-
shell_out!("apt-cache#{expand_options(default_release_options)} policy #{package}").stdout.each_line do |line|
|
58
|
+
shell_out!("apt-cache#{expand_options(default_release_options)} policy #{package}", :timeout => @new_resource.timeout).stdout.each_line do |line|
|
59
59
|
case line
|
60
60
|
when /^\s{2}Installed: (.+)$/
|
61
61
|
installed_version = $1
|
@@ -72,7 +72,7 @@ class Chef
|
|
72
72
|
if candidate_version == '(none)'
|
73
73
|
# This may not be an appropriate assumption, but it shouldn't break anything that already worked -- btm
|
74
74
|
@is_virtual_package = true
|
75
|
-
showpkg = shell_out!("apt-cache showpkg #{package}").stdout
|
75
|
+
showpkg = shell_out!("apt-cache showpkg #{package}", :timeout => @new_resource.timeout).stdout
|
76
76
|
providers = Hash.new
|
77
77
|
# Returns all lines after 'Reverse Provides:'
|
78
78
|
showpkg.rpartition(/Reverse Provides:\s*#{$/}/)[2].each_line do |line|
|
@@ -132,7 +132,7 @@ class Chef
|
|
132
132
|
# interactive prompts. Command is run with default localization rather
|
133
133
|
# than forcing locale to "C", so command output may not be stable.
|
134
134
|
def run_noninteractive(command)
|
135
|
-
shell_out!(command, :env => { "DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil })
|
135
|
+
shell_out!(command, :env => { "DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil }, :timeout => @new_resource.timeout)
|
136
136
|
end
|
137
137
|
|
138
138
|
end
|
@@ -24,13 +24,14 @@ require 'chef/mixin/get_source_from_package'
|
|
24
24
|
class Chef
|
25
25
|
class Provider
|
26
26
|
class Package
|
27
|
-
class Dpkg < Chef::Provider::Package
|
27
|
+
class Dpkg < Chef::Provider::Package
|
28
28
|
# http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version
|
29
29
|
DPKG_INFO = /([a-z\d\-\+\.]+)\t([\w\d.~:-]+)/
|
30
30
|
DPKG_INSTALLED = /^Status: install ok installed/
|
31
31
|
DPKG_VERSION = /^Version: (.+)$/
|
32
32
|
|
33
33
|
include Chef::Mixin::GetSourceFromPackage
|
34
|
+
|
34
35
|
def define_resource_requirements
|
35
36
|
super
|
36
37
|
requirements.assert(:install) do |a|
|
@@ -98,31 +99,49 @@ class Chef
|
|
98
99
|
end
|
99
100
|
|
100
101
|
def install_package(name, version)
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
"DEBIAN_FRONTEND" => "noninteractive"
|
105
|
-
}
|
102
|
+
Chef::Log.info("#{@new_resource} installing #{@new_resource.source}")
|
103
|
+
run_noninteractive(
|
104
|
+
"dpkg -i#{expand_options(@new_resource.options)} #{@new_resource.source}"
|
106
105
|
)
|
107
106
|
end
|
108
107
|
|
109
108
|
def remove_package(name, version)
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
"DEBIAN_FRONTEND" => "noninteractive"
|
114
|
-
}
|
109
|
+
Chef::Log.info("#{@new_resource} removing #{@new_resource.package_name}")
|
110
|
+
run_noninteractive(
|
111
|
+
"dpkg -r#{expand_options(@new_resource.options)} #{@new_resource.package_name}"
|
115
112
|
)
|
116
113
|
end
|
117
114
|
|
118
115
|
def purge_package(name, version)
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
"DEBIAN_FRONTEND" => "noninteractive"
|
123
|
-
}
|
116
|
+
Chef::Log.info("#{@new_resource} purging #{@new_resource.package_name}")
|
117
|
+
run_noninteractive(
|
118
|
+
"dpkg -P#{expand_options(@new_resource.options)} #{@new_resource.package_name}"
|
124
119
|
)
|
125
120
|
end
|
121
|
+
|
122
|
+
def upgrade_package(name, version)
|
123
|
+
install_package(name, version)
|
124
|
+
end
|
125
|
+
|
126
|
+
def preseed_package(preseed_file)
|
127
|
+
Chef::Log.info("#{@new_resource} pre-seeding package installation instructions")
|
128
|
+
run_noninteractive("debconf-set-selections #{preseed_file}")
|
129
|
+
end
|
130
|
+
|
131
|
+
def reconfig_package(name, version)
|
132
|
+
Chef::Log.info("#{@new_resource} reconfiguring")
|
133
|
+
run_noninteractive("dpkg-reconfigure #{name}")
|
134
|
+
end
|
135
|
+
|
136
|
+
# Runs command via shell_out with magic environment to disable
|
137
|
+
# interactive prompts. Command is run with default localization rather
|
138
|
+
# than forcing locale to "C", so command output may not be stable.
|
139
|
+
#
|
140
|
+
# FIXME: This should be "LC_ALL" => "en_US.UTF-8" in order to stabilize the output and get UTF-8
|
141
|
+
def run_noninteractive(command)
|
142
|
+
shell_out!(command, :env => { "DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil })
|
143
|
+
end
|
144
|
+
|
126
145
|
end
|
127
146
|
end
|
128
147
|
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Vasiliy Tolstov (<v.tolstov@selfip.ru>)
|
3
|
+
# Copyright:: Copyright (c) 2014 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'chef/provider/package'
|
20
|
+
require 'chef/resource/package'
|
21
|
+
require 'chef/mixin/shell_out'
|
22
|
+
|
23
|
+
class Chef
|
24
|
+
class Provider
|
25
|
+
class Package
|
26
|
+
class Paludis < Chef::Provider::Package
|
27
|
+
|
28
|
+
include Chef::Mixin::ShellOut
|
29
|
+
|
30
|
+
def load_current_resource
|
31
|
+
@current_resource = Chef::Resource::Package.new(@new_resource.package_name)
|
32
|
+
@current_resource.package_name(@new_resource.package_name)
|
33
|
+
|
34
|
+
@current_resource.version(nil)
|
35
|
+
|
36
|
+
Chef::Log.debug("Checking package status for #{@new_resource.package_name}")
|
37
|
+
installed = false
|
38
|
+
re = Regexp.new('(.*)[[:blank:]](.*)[[:blank:]](.*)$')
|
39
|
+
|
40
|
+
shell_out!("cave -L warning print-ids -m \"*/#{@new_resource.package_name.split('/').last}\" -f \"%c/%p %v %r\n\"").stdout.each_line do |line|
|
41
|
+
res = re.match(line)
|
42
|
+
unless res.nil?
|
43
|
+
case res[3]
|
44
|
+
when 'accounts', 'installed-accounts'
|
45
|
+
next
|
46
|
+
when 'installed'
|
47
|
+
installed = true
|
48
|
+
@current_resource.version(res[2])
|
49
|
+
else
|
50
|
+
@candidate_version = res[2]
|
51
|
+
@current_resource.version(nil)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
@current_resource
|
57
|
+
end
|
58
|
+
|
59
|
+
def install_package(name, version)
|
60
|
+
if(version)
|
61
|
+
pkg = "=#{name}-#{version}"
|
62
|
+
else
|
63
|
+
pkg = "#{@new_resource.package_name}"
|
64
|
+
end
|
65
|
+
shell_out!("cave -L warning resolve -x#{expand_options(@new_resource.options)} \"#{pkg}\"")
|
66
|
+
end
|
67
|
+
|
68
|
+
def upgrade_package(name, version)
|
69
|
+
install_package(name, version)
|
70
|
+
end
|
71
|
+
|
72
|
+
def remove_package(name, version)
|
73
|
+
if(version)
|
74
|
+
pkg = "=#{@new_resource.package_name}-#{version}"
|
75
|
+
else
|
76
|
+
pkg = "#{@new_resource.package_name}"
|
77
|
+
end
|
78
|
+
|
79
|
+
shell_out!("cave -L warning uninstall -x#{expand_options(@new_resource.options)} \"#{pkg}\"")
|
80
|
+
end
|
81
|
+
|
82
|
+
def purge_package(name, version)
|
83
|
+
remove_package(name, version)
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
|
@@ -60,9 +60,10 @@ class Chef
|
|
60
60
|
status = popen4("rpm -qp --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' #{@new_resource.source}") do |pid, stdin, stdout, stderr|
|
61
61
|
stdout.each do |line|
|
62
62
|
case line
|
63
|
-
when /([\w\
|
63
|
+
when /([\w\d+_.-]+)\s([\w\d_.-]+)/
|
64
64
|
@current_resource.package_name($1)
|
65
65
|
@new_resource.version($2)
|
66
|
+
@candidate_version = $2
|
66
67
|
end
|
67
68
|
end
|
68
69
|
end
|
@@ -77,7 +78,7 @@ class Chef
|
|
77
78
|
@rpm_status = popen4("rpm -q --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' #{@current_resource.package_name}") do |pid, stdin, stdout, stderr|
|
78
79
|
stdout.each do |line|
|
79
80
|
case line
|
80
|
-
when /([\w\
|
81
|
+
when /([\w\d+_.-]+)\s([\w\d_.-]+)/
|
81
82
|
Chef::Log.debug("#{@new_resource} current version is #{$2}")
|
82
83
|
@current_resource.version($2)
|
83
84
|
end
|
@@ -43,9 +43,6 @@ from distutils import version
|
|
43
43
|
|
44
44
|
YUM_PID_FILE='/var/run/yum.pid'
|
45
45
|
|
46
|
-
# Seconds to wait for exclusive access to yum
|
47
|
-
LOCK_TIMEOUT = 10
|
48
|
-
|
49
46
|
YUM_VER = version.StrictVersion(yum.__version__)
|
50
47
|
YUM_MAJOR = YUM_VER.version[0]
|
51
48
|
|
@@ -219,8 +216,8 @@ def yum_dump(options):
|
|
219
216
|
# Wrap the collection and output of packages in yum's global lock to prevent
|
220
217
|
# any inconsistencies.
|
221
218
|
try:
|
222
|
-
# Spin up to
|
223
|
-
countdown =
|
219
|
+
# Spin up to --yum-lock-timeout option
|
220
|
+
countdown = options.yum_lock_timeout
|
224
221
|
while True:
|
225
222
|
try:
|
226
223
|
yb.doLock(YUM_PID_FILE)
|
@@ -230,7 +227,7 @@ def yum_dump(options):
|
|
230
227
|
countdown -= 1
|
231
228
|
if countdown == 0:
|
232
229
|
print >> sys.stderr, "yum-dump Locking Error! Couldn't obtain an " \
|
233
|
-
"exclusive yum lock in %d seconds. Giving up." %
|
230
|
+
"exclusive yum lock in %d seconds. Giving up." % options.yum_lock_timeout
|
234
231
|
return 200
|
235
232
|
else:
|
236
233
|
break
|
@@ -281,6 +278,9 @@ def main():
|
|
281
278
|
parser.add_option("--disablerepo",
|
282
279
|
action="callback", callback=gather_repo_opts, type="string", dest="repo_control", default=[],
|
283
280
|
help="disable repositories by id or glob")
|
281
|
+
parser.add_option("--yum-lock-timeout",
|
282
|
+
action="store", type="int", dest="yum_lock_timeout", default=30,
|
283
|
+
help="Time in seconds to wait for yum process lock")
|
284
284
|
|
285
285
|
(options, args) = parser.parse_args()
|
286
286
|
|