chef 12.17.44-universal-mingw32 → 12.18.31-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (178) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +0 -1
  3. data/README.md +3 -2
  4. data/Rakefile +9 -0
  5. data/VERSION +1 -1
  6. data/acceptance/Gemfile.lock +17 -17
  7. data/distro/common/html/knife_environment.html +4 -8
  8. data/distro/common/man/man1/knife-environment.1 +4 -16
  9. data/distro/powershell/chef/chef.psm1 +139 -24
  10. data/lib/chef/application.rb +5 -4
  11. data/lib/chef/application/windows_service_manager.rb +6 -4
  12. data/lib/chef/chef_fs/chef_fs_data_store.rb +1 -1
  13. data/lib/chef/chef_fs/command_line.rb +1 -1
  14. data/lib/chef/chef_fs/file_system/chef_server/rest_list_entry.rb +8 -1
  15. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb +1 -1
  16. data/lib/chef/chef_fs/file_system/repository/nodes_dir.rb +1 -1
  17. data/lib/chef/cookbook/chefignore.rb +1 -1
  18. data/lib/chef/cookbook/cookbook_version_loader.rb +4 -4
  19. data/lib/chef/cookbook/metadata.rb +2 -2
  20. data/lib/chef/cookbook_loader.rb +1 -1
  21. data/lib/chef/data_collector.rb +24 -13
  22. data/lib/chef/data_collector/messages.rb +8 -6
  23. data/lib/chef/data_collector/messages/helpers.rb +1 -1
  24. data/lib/chef/deprecated.rb +30 -0
  25. data/lib/chef/dsl/platform_introspection.rb +2 -2
  26. data/lib/chef/encrypted_data_bag_item.rb +1 -1
  27. data/lib/chef/encrypted_data_bag_item/decryptor.rb +2 -2
  28. data/lib/chef/environment.rb +1 -1
  29. data/lib/chef/exceptions.rb +5 -5
  30. data/lib/chef/file_access_control/unix.rb +5 -5
  31. data/lib/chef/formatters/error_description.rb +1 -1
  32. data/lib/chef/http/basic_client.rb +1 -1
  33. data/lib/chef/http/json_input.rb +2 -2
  34. data/lib/chef/knife.rb +1 -1
  35. data/lib/chef/knife/cookbook_site_install.rb +1 -1
  36. data/lib/chef/knife/core/cookbook_scm_repo.rb +1 -1
  37. data/lib/chef/knife/core/ui.rb +1 -1
  38. data/lib/chef/mixin/command.rb +1 -0
  39. data/lib/chef/mixin/deep_merge.rb +1 -1
  40. data/lib/chef/mixin/shell_out.rb +58 -3
  41. data/lib/chef/mixin/which.rb +5 -9
  42. data/lib/chef/mixin/wide_string.rb +1 -1
  43. data/lib/chef/node.rb +1 -1
  44. data/lib/chef/node/attribute.rb +4 -5
  45. data/lib/chef/node_map.rb +18 -2
  46. data/lib/chef/platform/provider_handler_map.rb +2 -2
  47. data/lib/chef/platform/provider_mapping.rb +5 -0
  48. data/lib/chef/platform/resource_handler_map.rb +2 -2
  49. data/lib/chef/provider/env/windows.rb +1 -1
  50. data/lib/chef/provider/git.rb +1 -1
  51. data/lib/chef/provider/group.rb +41 -46
  52. data/lib/chef/provider/group/aix.rb +12 -19
  53. data/lib/chef/provider/group/dscl.rb +46 -43
  54. data/lib/chef/provider/group/gpasswd.rb +7 -7
  55. data/lib/chef/provider/group/groupadd.rb +29 -34
  56. data/lib/chef/provider/group/groupmod.rb +26 -31
  57. data/lib/chef/provider/group/pw.rb +28 -31
  58. data/lib/chef/provider/group/suse.rb +9 -9
  59. data/lib/chef/provider/group/usermod.rb +10 -11
  60. data/lib/chef/provider/group/windows.rb +18 -20
  61. data/lib/chef/provider/ifconfig.rb +52 -63
  62. data/lib/chef/provider/ifconfig/aix.rb +23 -28
  63. data/lib/chef/provider/ifconfig/debian.rb +23 -22
  64. data/lib/chef/provider/ifconfig/redhat.rb +12 -12
  65. data/lib/chef/provider/mount/mount.rb +1 -1
  66. data/lib/chef/provider/osx_profile.rb +4 -2
  67. data/lib/chef/provider/package.rb +16 -7
  68. data/lib/chef/provider/package/chocolatey.rb +3 -1
  69. data/lib/chef/provider/package/dnf.rb +183 -0
  70. data/lib/chef/provider/package/dnf/dnf_helper.py +91 -0
  71. data/lib/chef/provider/package/dnf/python_helper.rb +120 -0
  72. data/lib/chef/provider/package/dnf/version.rb +56 -0
  73. data/lib/chef/provider/package/easy_install.rb +1 -1
  74. data/lib/chef/provider/package/freebsd/base.rb +1 -1
  75. data/lib/chef/provider/package/freebsd/pkgng.rb +1 -1
  76. data/lib/chef/provider/package/powershell.rb +3 -3
  77. data/lib/chef/provider/package/windows.rb +1 -1
  78. data/lib/chef/provider/package/zypper.rb +1 -1
  79. data/lib/chef/provider/route.rb +186 -184
  80. data/lib/chef/provider/service/arch.rb +2 -2
  81. data/lib/chef/provider/service/freebsd.rb +1 -1
  82. data/lib/chef/provider/service/gentoo.rb +2 -2
  83. data/lib/chef/provider/service/insserv.rb +2 -2
  84. data/lib/chef/provider/service/macosx.rb +2 -2
  85. data/lib/chef/provider/service/openbsd.rb +1 -1
  86. data/lib/chef/provider/service/redhat.rb +2 -2
  87. data/lib/chef/provider/support/yum_repo.erb +10 -3
  88. data/lib/chef/provider/user.rb +17 -20
  89. data/lib/chef/provider/user/aix.rb +23 -24
  90. data/lib/chef/provider/user/dscl.rb +56 -53
  91. data/lib/chef/provider/user/linux.rb +13 -16
  92. data/lib/chef/provider/user/pw.rb +26 -30
  93. data/lib/chef/provider/user/solaris.rb +11 -12
  94. data/lib/chef/provider/user/useradd.rb +20 -22
  95. data/lib/chef/provider/user/windows.rb +19 -22
  96. data/lib/chef/provider_resolver.rb +4 -2
  97. data/lib/chef/providers.rb +1 -0
  98. data/lib/chef/resource.rb +7 -0
  99. data/lib/chef/resource/chocolatey_package.rb +1 -0
  100. data/lib/chef/resource/dnf_package.rb +64 -0
  101. data/lib/chef/resource/file/verification.rb +6 -4
  102. data/lib/chef/resource/yum_package.rb +18 -14
  103. data/lib/chef/resource/yum_repository.rb +1 -1
  104. data/lib/chef/resource_reporter.rb +11 -0
  105. data/lib/chef/resources.rb +1 -0
  106. data/lib/chef/scan_access_control.rb +4 -4
  107. data/lib/chef/util/dsc/resource_store.rb +1 -1
  108. data/lib/chef/version.rb +1 -1
  109. data/lib/chef/win32/memory.rb +1 -1
  110. data/lib/chef/win32/security.rb +2 -2
  111. data/lib/chef/win32/security/sid.rb +2 -2
  112. data/spec/functional/assets/yumrepo/chef_rpm-1.10-1.fc24.i686.rpm +0 -0
  113. data/spec/functional/assets/yumrepo/chef_rpm-1.10-1.fc24.src.rpm +0 -0
  114. data/spec/functional/assets/yumrepo/chef_rpm-1.10-1.fc24.x86_64.rpm +0 -0
  115. data/spec/functional/assets/yumrepo/chef_rpm-1.2-1.fc24.i686.rpm +0 -0
  116. data/spec/functional/assets/yumrepo/chef_rpm-1.2-1.fc24.src.rpm +0 -0
  117. data/spec/functional/assets/yumrepo/chef_rpm-1.2-1.fc24.x86_64.rpm +0 -0
  118. data/spec/functional/assets/yumrepo/repodata/313329137b55fd333b2dc66394a6661a2befa6cc535d8460d92a4a78a9c581f0-primary.sqlite.bz2 +0 -0
  119. data/spec/functional/assets/yumrepo/repodata/31ac4db5d5ac593728fcc26aef82b7b93c4cc4dbec843786b1845b939b658553-other.xml.gz +0 -0
  120. data/spec/functional/assets/yumrepo/repodata/4ac40fa3c6728c1401318e2e20a997436624e83dcf7a5f952b851ef422637773-filelists.sqlite.bz2 +0 -0
  121. data/spec/functional/assets/yumrepo/repodata/66391e53f0510b98b3f0b79f40ba1048026d9a1ef20905d9c40ba6f5411f3243-primary.xml.gz +0 -0
  122. data/spec/functional/assets/yumrepo/repodata/8b34697595fcc87928e12d24644dda9462c3857bd932861e28bc77ae1f31be16-filelists.xml.gz +0 -0
  123. data/spec/functional/assets/yumrepo/repodata/b97cca3fe14bcf06c52be4449b6108f7731239ff221111dcce8aada5467f60dc-other.sqlite.bz2 +0 -0
  124. data/spec/functional/assets/yumrepo/repodata/repomd.xml +55 -0
  125. data/spec/functional/resource/dnf_package_spec.rb +686 -0
  126. data/spec/functional/resource/dsc_script_spec.rb +1 -0
  127. data/spec/functional/resource/user/useradd_spec.rb +10 -1
  128. data/spec/integration/knife/chef_repo_path_spec.rb +2 -2
  129. data/spec/integration/recipes/recipe_dsl_spec.rb +3 -0
  130. data/spec/integration/recipes/resource_load_spec.rb +3 -3
  131. data/spec/spec_helper.rb +5 -3
  132. data/spec/support/lib/chef/provider/snakeoil.rb +1 -0
  133. data/spec/support/lib/chef/resource/cat.rb +1 -0
  134. data/spec/support/lib/chef/resource/one_two_three_four.rb +1 -0
  135. data/spec/support/lib/chef/resource/openldap_includer.rb +2 -0
  136. data/spec/support/lib/chef/resource/with_state.rb +2 -0
  137. data/spec/support/lib/chef/resource/zen_master.rb +1 -0
  138. data/spec/unit/cookbook/metadata_spec.rb +3 -3
  139. data/spec/unit/data_collector/messages/helpers_spec.rb +7 -0
  140. data/spec/unit/data_collector_spec.rb +56 -0
  141. data/spec/unit/decorator/lazy_spec.rb +1 -1
  142. data/spec/unit/environment_spec.rb +1 -1
  143. data/spec/unit/lwrp_spec.rb +3 -4
  144. data/spec/unit/node_spec.rb +23 -2
  145. data/spec/unit/platform_spec.rb +1 -0
  146. data/spec/unit/provider/group/dscl_spec.rb +29 -29
  147. data/spec/unit/provider/group/gpasswd_spec.rb +10 -10
  148. data/spec/unit/provider/group/groupadd_spec.rb +31 -30
  149. data/spec/unit/provider/group/groupmod_spec.rb +16 -16
  150. data/spec/unit/provider/group/pw_spec.rb +11 -11
  151. data/spec/unit/provider/group/suse_spec.rb +5 -5
  152. data/spec/unit/provider/group/usermod_spec.rb +15 -15
  153. data/spec/unit/provider/ifconfig/aix_spec.rb +14 -14
  154. data/spec/unit/provider/ifconfig/debian_spec.rb +10 -22
  155. data/spec/unit/provider/ifconfig/redhat_spec.rb +4 -4
  156. data/spec/unit/provider/ifconfig_spec.rb +18 -19
  157. data/spec/unit/provider/package/chocolatey_spec.rb +21 -21
  158. data/spec/unit/provider/package/msu_spec.rb +1 -1
  159. data/spec/unit/provider/route_spec.rb +21 -21
  160. data/spec/unit/provider/user/dscl_spec.rb +54 -57
  161. data/spec/unit/provider/user/linux_spec.rb +5 -5
  162. data/spec/unit/provider/user/pw_spec.rb +26 -22
  163. data/spec/unit/provider/user/windows_spec.rb +4 -4
  164. data/spec/unit/provider/user_spec.rb +19 -21
  165. data/spec/unit/provider_resolver_spec.rb +1 -0
  166. data/spec/unit/resource/chocolatey_package_spec.rb +12 -0
  167. data/spec/unit/resource/dnf_package_spec.rb +99 -0
  168. data/spec/unit/resource/remote_file_spec.rb +2 -2
  169. data/spec/unit/resource/yum_package_spec.rb +20 -0
  170. data/spec/unit/resource_reporter_spec.rb +24 -0
  171. data/spec/unit/resource_spec.rb +2 -0
  172. data/spec/unit/runner_spec.rb +1 -0
  173. data/tasks/bin/bundle-platform +1 -1
  174. data/tasks/gemfile_util.rb +2 -2
  175. data/tasks/templates/prerelease.md.erb +1 -10
  176. data/tasks/templates/release.md.erb +1 -9
  177. metadata +24 -5
  178. data/lib/chef/platform/handler_map.rb +0 -40
@@ -0,0 +1,91 @@
1
+ #!/usr/bin/env python3
2
+ # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
3
+
4
+ import sys
5
+ import dnf
6
+ import hawkey
7
+ import signal
8
+ import os
9
+ import json
10
+
11
+ base = None
12
+
13
+ def get_sack():
14
+ global base
15
+ if base is None:
16
+ base = dnf.Base()
17
+ base.read_all_repos()
18
+ base.fill_sack()
19
+ return base.sack
20
+
21
+ # FIXME: leaks memory and does not work
22
+ def flushcache():
23
+ try:
24
+ os.remove('/var/cache/dnf/@System.solv')
25
+ except OSError:
26
+ pass
27
+ get_sack().load_system_repo(build_cache=True)
28
+
29
+ def query(command):
30
+ sack = get_sack()
31
+
32
+ subj = dnf.subject.Subject(command['provides'])
33
+ q = subj.get_best_query(sack, with_provides=True)
34
+
35
+ if command['action'] == "whatinstalled":
36
+ q = q.installed()
37
+
38
+ if command['action'] == "whatavailable":
39
+ q = q.available()
40
+
41
+ if 'epoch' in command:
42
+ q = q.filterm(epoch=int(command['epoch']))
43
+ if 'version' in command:
44
+ q = q.filterm(version__glob=command['version'])
45
+ if 'release' in command:
46
+ q = q.filterm(release__glob=command['release'])
47
+
48
+ if 'arch' in command:
49
+ q = q.filterm(arch__glob=command['arch'])
50
+
51
+ # only apply the default arch query filter if it returns something
52
+ archq = q.filter(arch=[ 'noarch', hawkey.detect_arch() ])
53
+ if len(archq.run()) > 0:
54
+ q = archq
55
+
56
+ pkgs = dnf.query.latest_limit_pkgs(q, 1)
57
+
58
+ if not pkgs:
59
+ sys.stdout.write('{} nil nil\n'.format(command['provides'].split().pop(0)))
60
+ else:
61
+ # make sure we picked the package with the highest version
62
+ pkgs.sort
63
+ pkg = pkgs.pop()
64
+ sys.stdout.write('{} {}:{}-{} {}\n'.format(pkg.name, pkg.epoch, pkg.version, pkg.release, pkg.arch))
65
+
66
+ # the design of this helper is that it should try to be 'brittle' and fail hard and exit in order
67
+ # to keep process tables clean. additional error handling should probably be added to the retry loop
68
+ # on the ruby side.
69
+ def exit_handler(signal, frame):
70
+ sys.exit(0)
71
+
72
+ signal.signal(signal.SIGINT, exit_handler)
73
+ signal.signal(signal.SIGHUP, exit_handler)
74
+ signal.signal(signal.SIGPIPE, exit_handler)
75
+ signal.signal(signal.SIGCHLD, exit_handler)
76
+
77
+ while 1:
78
+ # kill self if we get orphaned (tragic)
79
+ ppid = os.getppid()
80
+ if ppid == 1:
81
+ sys.exit(0)
82
+ line = sys.stdin.readline()
83
+ command = json.loads(line)
84
+ if command['action'] == "whatinstalled":
85
+ query(command)
86
+ elif command['action'] == "whatavailable":
87
+ query(command)
88
+ elif command['action'] == "flushcache":
89
+ flushcache()
90
+ else:
91
+ raise RuntimeError("bad command")
@@ -0,0 +1,120 @@
1
+ #
2
+ # Copyright:: Copyright 2016, Chef Software, Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require "chef/provider/package/dnf/version"
19
+ require "timeout"
20
+
21
+ class Chef
22
+ class Provider
23
+ class Package
24
+ class Dnf < Chef::Provider::Package
25
+ class PythonHelper
26
+ include Singleton
27
+ extend Chef::Mixin::Which
28
+
29
+ attr_accessor :stdin
30
+ attr_accessor :stdout
31
+ attr_accessor :stderr
32
+ attr_accessor :wait_thr
33
+
34
+ DNF_HELPER = ::File.expand_path(::File.join(::File.dirname(__FILE__), "dnf_helper.py")).freeze
35
+ DNF_COMMAND = "#{which("python3")} #{DNF_HELPER}"
36
+
37
+ def start
38
+ ENV["PYTHONUNBUFFERED"] = "1"
39
+ @stdin, @stdout, @stderr, @wait_thr = Open3.popen3(DNF_COMMAND)
40
+ end
41
+
42
+ def reap
43
+ unless wait_thr.nil?
44
+ Process.kill("KILL", wait_thr.pid) rescue nil
45
+ stdin.close unless stdin.nil?
46
+ stdout.close unless stdout.nil?
47
+ stderr.close unless stderr.nil?
48
+ wait_thr.value # this calls waitpit()
49
+ end
50
+ end
51
+
52
+ def check
53
+ start if stdin.nil?
54
+ end
55
+
56
+ # i couldn't figure out how to decompose an evr on the python side, it seems reasonably
57
+ # painless to do it in ruby (generally massaging nevras in the ruby side is HIGHLY
58
+ # discouraged -- this is an "every rule has an exception" exception -- any additional
59
+ # functionality should probably trigger moving this regexp logic into python)
60
+ def add_version(hash, version)
61
+ epoch = nil
62
+ if version =~ /(\S+):(\S+)/
63
+ epoch, version = $1, $2
64
+ end
65
+ if version =~ /(\S+)-(\S+)/
66
+ version, release = $1, $2
67
+ end
68
+ hash["epoch"] = epoch unless epoch.nil?
69
+ hash["release"] = release unless release.nil?
70
+ hash["version"] = version
71
+ end
72
+
73
+ def build_query(action, provides, version, arch)
74
+ hash = { "action" => action }
75
+ hash["provides"] = provides
76
+ add_version(hash, version) unless version.nil?
77
+ hash["arch" ] = arch unless arch.nil?
78
+ FFI_Yajl::Encoder.encode(hash)
79
+ end
80
+
81
+ def parse_response(output)
82
+ array = output.split.map { |x| x == "nil" ? nil : x }
83
+ array.each_slice(3).map { |x| Version.new(*x) }.first
84
+ end
85
+
86
+ # @returns Array<Version>
87
+ def query(action, provides, version = nil, arch = nil)
88
+ with_helper do
89
+ json = build_query(action, provides, version, arch)
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
97
+ end
98
+ end
99
+
100
+ def restart
101
+ reap
102
+ start
103
+ end
104
+
105
+ def with_helper
106
+ max_retries ||= 5
107
+ Timeout.timeout(600) do
108
+ check
109
+ yield
110
+ end
111
+ rescue EOFError, Errno::EPIPE, Timeout::Error, Errno::ESRCH => e
112
+ raise e unless ( max_retries -= 1 ) > 0
113
+ restart
114
+ retry
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,56 @@
1
+ #
2
+ # Copyright:: Copyright 2016, Chef Software, Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ class Chef
19
+ class Provider
20
+ class Package
21
+ class Dnf < Chef::Provider::Package
22
+
23
+ # helper class to assist in passing around name/version/arch triples
24
+ class Version
25
+ attr_accessor :name
26
+ attr_accessor :version
27
+ attr_accessor :arch
28
+
29
+ def initialize(name, version, arch)
30
+ @name = name
31
+ @version = version
32
+ @arch = arch
33
+ end
34
+
35
+ def to_s
36
+ "#{name}-#{version}.#{arch}"
37
+ end
38
+
39
+ def version_with_arch
40
+ "#{version}.#{arch}" unless version.nil?
41
+ end
42
+
43
+ def matches_name_and_arch?(other)
44
+ other.version == version && other.arch == arch
45
+ end
46
+
47
+ def ==(other)
48
+ name == other.name && version == other.version && arch == other.arch
49
+ end
50
+
51
+ alias_method :eql?, :==
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -122,7 +122,7 @@ class Chef
122
122
 
123
123
  def remove_package(name, version)
124
124
  Chef.deprecated(:easy_install, "The easy_install package provider is deprecated and will be removed in Chef 13.")
125
- run_command(:command => "#{easy_install_binary_path }#{expand_options(@new_resource.options)} -m #{name}")
125
+ run_command(:command => "#{easy_install_binary_path}#{expand_options(@new_resource.options)} -m #{name}")
126
126
  end
127
127
 
128
128
  def purge_package(name, version)
@@ -58,7 +58,7 @@ class Chef
58
58
  def makefile_variable_value(variable, dir = nil)
59
59
  options = dir ? { :cwd => dir } : {}
60
60
  make_v = shell_out_with_timeout!("make -V #{variable}", options.merge!(:env => nil, :returns => [0, 1]))
61
- make_v.exitstatus.zero? ? make_v.stdout.strip.split($\).first : nil # $\ is the line separator, i.e. newline.
61
+ make_v.exitstatus == 0 ? make_v.stdout.strip.split($\).first : nil # $\ is the line separator, i.e. newline.
62
62
  end
63
63
  end
64
64
 
@@ -64,7 +64,7 @@ class Chef
64
64
  end
65
65
 
66
66
  pkg_query = shell_out_with_timeout!("pkg rquery#{expand_options(options)} '%v' #{@new_resource.package_name}", :env => nil)
67
- pkg_query.exitstatus.zero? ? pkg_query.stdout.strip.split(/\n/).last : nil
67
+ pkg_query.exitstatus == 0 ? pkg_query.stdout.strip.split(/\n/).last : nil
68
68
  end
69
69
 
70
70
  def repo_regex
@@ -60,7 +60,7 @@ class Chef
60
60
  # Removes the package for the version passed and if no version is passed, then all installed versions of the package are removed
61
61
  def remove_package(names, versions)
62
62
  names.each_with_index do |name, index|
63
- if versions && versions[index] != nil
63
+ if versions && !versions[index].nil?
64
64
  powershell_out( "Uninstall-Package '#{name}' -Force -ForceBootstrap -RequiredVersion #{versions[index]}", { :timeout => @new_resource.timeout })
65
65
  else
66
66
  version = "0"
@@ -78,7 +78,7 @@ class Chef
78
78
  def build_candidate_versions
79
79
  versions = []
80
80
  new_resource.package_name.each_with_index do |name, index|
81
- if new_resource.version && new_resource.version[index] != nil
81
+ if new_resource.version && !new_resource.version[index].nil?
82
82
  version = powershell_out("(Find-Package '#{name}' -RequiredVersion #{new_resource.version[index]} -ForceBootstrap -Force | select version | Format-Table -HideTableHeaders | Out-String).Trim()", { :timeout => @new_resource.timeout }).stdout.strip()
83
83
  else
84
84
  version = powershell_out("(Find-Package '#{name}' -ForceBootstrap -Force | select version | Format-Table -HideTableHeaders | Out-String).Trim()", { :timeout => @new_resource.timeout }).stdout.strip()
@@ -95,7 +95,7 @@ class Chef
95
95
  def build_current_versions
96
96
  version_list = []
97
97
  new_resource.package_name.each_with_index do |name, index|
98
- if new_resource.version && new_resource.version[index] != nil
98
+ if new_resource.version && !new_resource.version[index].nil?
99
99
  version = powershell_out("(Get-Package -Name '#{name}' -RequiredVersion #{new_resource.version[index]} -ForceBootstrap -Force | select version | Format-Table -HideTableHeaders | Out-String).Trim()", { :timeout => @new_resource.timeout }).stdout.strip()
100
100
  else
101
101
  version = powershell_out("(Get-Package -Name '#{name}' -ForceBootstrap -Force | select version | Format-Table -HideTableHeaders | Out-String).Trim()", { :timeout => @new_resource.timeout }).stdout.strip()
@@ -262,7 +262,7 @@ class Chef
262
262
  if source_location.nil?
263
263
  inferred_registry_type == :msi
264
264
  else
265
- ::File.extname(source_location).casecmp(".msi").zero?
265
+ ::File.extname(source_location).casecmp(".msi") == 0
266
266
  end
267
267
  end
268
268
  end
@@ -144,7 +144,7 @@ class Chef
144
144
  end
145
145
  end
146
146
 
147
- def gpg_checks()
147
+ def gpg_checks
148
148
  case Chef::Config[:zypper_check_gpg]
149
149
  when true
150
150
  ""
@@ -21,209 +21,211 @@ require "chef/mixin/command"
21
21
  require "chef/provider"
22
22
  require "ipaddr"
23
23
 
24
- class Chef::Provider::Route < Chef::Provider
25
- include Chef::Mixin::Command
26
-
27
- provides :route
28
-
29
- attr_accessor :is_running
30
-
31
- MASK = { "0.0.0.0" => "0",
32
- "128.0.0.0" => "1",
33
- "192.0.0.0" => "2",
34
- "224.0.0.0" => "3",
35
- "240.0.0.0" => "4",
36
- "248.0.0.0" => "5",
37
- "252.0.0.0" => "6",
38
- "254.0.0.0" => "7",
39
- "255.0.0.0" => "8",
40
- "255.128.0.0" => "9",
41
- "255.192.0.0" => "10",
42
- "255.224.0.0" => "11",
43
- "255.240.0.0" => "12",
44
- "255.248.0.0" => "13",
45
- "255.252.0.0" => "14",
46
- "255.254.0.0" => "15",
47
- "255.255.0.0" => "16",
48
- "255.255.128.0" => "17",
49
- "255.255.192.0" => "18",
50
- "255.255.224.0" => "19",
51
- "255.255.240.0" => "20",
52
- "255.255.248.0" => "21",
53
- "255.255.252.0" => "22",
54
- "255.255.254.0" => "23",
55
- "255.255.255.0" => "24",
56
- "255.255.255.128" => "25",
57
- "255.255.255.192" => "26",
58
- "255.255.255.224" => "27",
59
- "255.255.255.240" => "28",
60
- "255.255.255.248" => "29",
61
- "255.255.255.252" => "30",
62
- "255.255.255.254" => "31",
63
- "255.255.255.255" => "32" }
64
-
65
- def hex2ip(hex_data)
66
- # Cleanup hex data
67
- hex_ip = hex_data.to_s.downcase.gsub(/[^0-9a-f]/, "")
68
-
69
- # Check hex data format (IP is a 32bit integer, so should be 8 chars long)
70
- return nil if hex_ip.length != hex_data.length || hex_ip.length != 8
71
-
72
- # Extract octets from hex data
73
- octets = hex_ip.scan(/../).reverse.collect { |octet| [octet].pack("H2").unpack("C").first }
74
-
75
- # Validate IP
76
- ip = octets.join(".")
77
- begin
78
- IPAddr.new(ip, Socket::AF_INET).to_s
79
- rescue ArgumentError
80
- Chef::Log.debug("Invalid IP address data: hex=#{hex_ip}, ip=#{ip}")
81
- return nil
82
- end
83
- end
84
-
85
- def whyrun_supported?
86
- true
87
- end
24
+ class Chef
25
+ class Provider
26
+ class Route < Chef::Provider
27
+ include Chef::Mixin::Command
28
+
29
+ provides :route
30
+
31
+ attr_accessor :is_running
32
+
33
+ MASK = { "0.0.0.0" => "0",
34
+ "128.0.0.0" => "1",
35
+ "192.0.0.0" => "2",
36
+ "224.0.0.0" => "3",
37
+ "240.0.0.0" => "4",
38
+ "248.0.0.0" => "5",
39
+ "252.0.0.0" => "6",
40
+ "254.0.0.0" => "7",
41
+ "255.0.0.0" => "8",
42
+ "255.128.0.0" => "9",
43
+ "255.192.0.0" => "10",
44
+ "255.224.0.0" => "11",
45
+ "255.240.0.0" => "12",
46
+ "255.248.0.0" => "13",
47
+ "255.252.0.0" => "14",
48
+ "255.254.0.0" => "15",
49
+ "255.255.0.0" => "16",
50
+ "255.255.128.0" => "17",
51
+ "255.255.192.0" => "18",
52
+ "255.255.224.0" => "19",
53
+ "255.255.240.0" => "20",
54
+ "255.255.248.0" => "21",
55
+ "255.255.252.0" => "22",
56
+ "255.255.254.0" => "23",
57
+ "255.255.255.0" => "24",
58
+ "255.255.255.128" => "25",
59
+ "255.255.255.192" => "26",
60
+ "255.255.255.224" => "27",
61
+ "255.255.255.240" => "28",
62
+ "255.255.255.248" => "29",
63
+ "255.255.255.252" => "30",
64
+ "255.255.255.254" => "31",
65
+ "255.255.255.255" => "32" }.freeze
66
+
67
+ def hex2ip(hex_data)
68
+ # Cleanup hex data
69
+ hex_ip = hex_data.to_s.downcase.gsub(/[^0-9a-f]/, "")
70
+
71
+ # Check hex data format (IP is a 32bit integer, so should be 8 chars long)
72
+ return nil if hex_ip.length != hex_data.length || hex_ip.length != 8
73
+
74
+ # Extract octets from hex data
75
+ octets = hex_ip.scan(/../).reverse.collect { |octet| [octet].pack("H2").unpack("C").first }
76
+
77
+ # Validate IP
78
+ ip = octets.join(".")
79
+ begin
80
+ IPAddr.new(ip, Socket::AF_INET).to_s
81
+ rescue ArgumentError
82
+ Chef::Log.debug("Invalid IP address data: hex=#{hex_ip}, ip=#{ip}")
83
+ return nil
84
+ end
85
+ end
88
86
 
89
- def load_current_resource
90
- self.is_running = false
87
+ def whyrun_supported?
88
+ true
89
+ end
91
90
 
92
- # cidr or quad dot mask
93
- if @new_resource.netmask
94
- new_ip = IPAddr.new("#{@new_resource.target}/#{@new_resource.netmask}")
95
- else
96
- new_ip = IPAddr.new(@new_resource.target)
97
- end
91
+ def load_current_resource
92
+ self.is_running = false
93
+
94
+ # cidr or quad dot mask
95
+ new_ip = if new_resource.netmask
96
+ IPAddr.new("#{new_resource.target}/#{new_resource.netmask}")
97
+ else
98
+ IPAddr.new(new_resource.target)
99
+ end
100
+
101
+ # For linux, we use /proc/net/route file to read proc table info
102
+ return if node[:os] != "linux"
103
+
104
+ route_file = ::File.open("/proc/net/route", "r")
105
+
106
+ # Read all routes
107
+ while (line = route_file.gets)
108
+ # Get all the fields for a route
109
+ _, destination, gateway, _, _, _, _, mask = line.split
110
+
111
+ # Convert hex-encoded values to quad-dotted notation (e.g. 0064A8C0 => 192.168.100.0)
112
+ destination = hex2ip(destination)
113
+ gateway = hex2ip(gateway)
114
+ mask = hex2ip(mask)
115
+
116
+ # Skip formatting lines (header, etc)
117
+ next unless destination && gateway && mask
118
+ Chef::Log.debug("#{new_resource} system has route: dest=#{destination} mask=#{mask} gw=#{gateway}")
119
+
120
+ # check if what were trying to configure is already there
121
+ # use an ipaddr object with ip/mask this way we can have
122
+ # a new resource be in cidr format (i don't feel like
123
+ # expanding bitmask by hand.
124
+ #
125
+ running_ip = IPAddr.new("#{destination}/#{mask}")
126
+ Chef::Log.debug("#{new_resource} new ip: #{new_ip.inspect} running ip: #{running_ip.inspect}")
127
+ self.is_running = true if running_ip == new_ip && gateway == new_resource.gateway
128
+ end
98
129
 
99
- # For linux, we use /proc/net/route file to read proc table info
100
- if node[:os] == "linux"
101
- route_file = ::File.open("/proc/net/route", "r")
102
-
103
- # Read all routes
104
- while (line = route_file.gets)
105
- # Get all the fields for a route
106
- iface, destination, gateway, flags, refcnt, use, metric, mask, mtu, window, irtt = line.split
107
-
108
- # Convert hex-encoded values to quad-dotted notation (e.g. 0064A8C0 => 192.168.100.0)
109
- destination = hex2ip(destination)
110
- gateway = hex2ip(gateway)
111
- mask = hex2ip(mask)
112
-
113
- # Skip formatting lines (header, etc)
114
- next unless destination && gateway && mask
115
- Chef::Log.debug("#{@new_resource} system has route: dest=#{destination} mask=#{mask} gw=#{gateway}")
116
-
117
- # check if what were trying to configure is already there
118
- # use an ipaddr object with ip/mask this way we can have
119
- # a new resource be in cidr format (i don't feel like
120
- # expanding bitmask by hand.
121
- #
122
- running_ip = IPAddr.new("#{destination}/#{mask}")
123
- Chef::Log.debug("#{@new_resource} new ip: #{new_ip.inspect} running ip: #{running_ip.inspect}")
124
- self.is_running = true if running_ip == new_ip && gateway == @new_resource.gateway
130
+ route_file.close
125
131
  end
126
132
 
127
- route_file.close
128
- end
129
- end
133
+ def action_add
134
+ # check to see if load_current_resource found the route
135
+ if is_running
136
+ Chef::Log.debug("#{new_resource} route already active - nothing to do")
137
+ else
138
+ command = generate_command(:add)
139
+ converge_by("run #{command.join(' ')} to add route") do
140
+ shell_out_compact!(command)
141
+ Chef::Log.info("#{new_resource} added")
142
+ end
143
+ end
130
144
 
131
- def action_add
132
- # check to see if load_current_resource found the route
133
- if is_running
134
- Chef::Log.debug("#{@new_resource} route already active - nothing to do")
135
- else
136
- command = generate_command(:add)
137
- converge_by ("run #{ command } to add route") do
138
- run_command( :command => command )
139
- Chef::Log.info("#{@new_resource} added")
145
+ # for now we always write the file (ugly but its what it is)
146
+ generate_config
140
147
  end
141
- end
142
148
 
143
- #for now we always write the file (ugly but its what it is)
144
- generate_config
145
- end
149
+ def action_delete
150
+ if is_running
151
+ command = generate_command(:delete)
152
+ converge_by("run #{command.join(' ')} to delete route ") do
153
+ shell_out_compact!(command)
154
+ Chef::Log.info("#{new_resource} removed")
155
+ end
156
+ else
157
+ Chef::Log.debug("#{new_resource} route does not exist - nothing to do")
158
+ end
146
159
 
147
- def action_delete
148
- if is_running
149
- command = generate_command(:delete)
150
- converge_by ("run #{ command } to delete route ") do
151
- run_command( :command => command )
152
- Chef::Log.info("#{@new_resource} removed")
160
+ # for now we always write the file (ugly but its what it is)
161
+ generate_config
153
162
  end
154
- else
155
- Chef::Log.debug("#{@new_resource} route does not exist - nothing to do")
156
- end
157
-
158
- #for now we always write the file (ugly but its what it is)
159
- generate_config
160
- end
161
163
 
162
- def generate_config
163
- conf = Hash.new
164
- case node[:platform]
165
- when "centos", "redhat", "fedora"
166
- # walk the collection
167
- run_context.resource_collection.each do |resource|
168
- if resource.is_a? Chef::Resource::Route
169
- # default to eth0
170
- if resource.device
171
- dev = resource.device
172
- else
173
- dev = "eth0"
164
+ def generate_config
165
+ conf = {}
166
+ case node[:platform]
167
+ when "centos", "redhat", "fedora"
168
+ # walk the collection
169
+ run_context.resource_collection.each do |resource|
170
+ next unless resource.is_a? Chef::Resource::Route
171
+ # default to eth0
172
+ dev = if resource.device
173
+ resource.device
174
+ else
175
+ "eth0"
176
+ end
177
+
178
+ conf[dev] = "" if conf[dev].nil?
179
+ case @action
180
+ when :add
181
+ conf[dev] << config_file_contents(:add, target: resource.target, netmask: resource.netmask, gateway: resource.gateway) if resource.action == [:add]
182
+ when :delete
183
+ # need to do this for the case when the last route on an int
184
+ # is removed
185
+ conf[dev] << config_file_contents(:delete)
186
+ end
174
187
  end
175
-
176
- conf[dev] = String.new if conf[dev].nil?
177
- case @action
178
- when :add
179
- conf[dev] << config_file_contents(:add, :target => resource.target, :netmask => resource.netmask, :gateway => resource.gateway) if resource.action == [:add]
180
- when :delete
181
- # need to do this for the case when the last route on an int
182
- # is removed
183
- conf[dev] << config_file_contents(:delete)
188
+ conf.each do |k, v|
189
+ network_file_name = "/etc/sysconfig/network-scripts/route-#{k}"
190
+ converge_by("write route route.#{k}\n#{conf[k]} to #{network_file_name}") do
191
+ network_file = ::File.new(network_file_name, "w")
192
+ network_file.puts(conf[k])
193
+ Chef::Log.debug("#{new_resource} writing route.#{k}\n#{conf[k]}")
194
+ network_file.close
195
+ end
184
196
  end
185
197
  end
186
198
  end
187
- conf.each do |k, v|
188
- network_file_name = "/etc/sysconfig/network-scripts/route-#{k}"
189
- converge_by ("write route route.#{k}\n#{conf[k]} to #{ network_file_name }") do
190
- network_file = ::File.new(network_file_name, "w")
191
- network_file.puts(conf[k])
192
- Chef::Log.debug("#{@new_resource} writing route.#{k}\n#{conf[k]}")
193
- network_file.close
199
+
200
+ def generate_command(action)
201
+ target = new_resource.target
202
+ target = "#{target}/#{MASK[new_resource.netmask.to_s]}" if new_resource.netmask
203
+
204
+ case action
205
+ when :add
206
+ command = [ "ip", "route", "replace", target ]
207
+ command += [ "via", new_resource.gateway ] if new_resource.gateway
208
+ command += [ "dev", new_resource.device ] if new_resource.device
209
+ when :delete
210
+ command = [ "ip", "route", "delete", target ]
211
+ command += [ "via", new_resource.gateway ] if new_resource.gateway
194
212
  end
195
- end
196
- end
197
- end
198
213
 
199
- def generate_command(action)
200
- common_route_items = ""
201
- common_route_items << "/#{MASK[@new_resource.netmask.to_s]}" if @new_resource.netmask
202
- common_route_items << " via #{@new_resource.gateway} " if @new_resource.gateway
203
-
204
- case action
205
- when :add
206
- command = "ip route replace #{@new_resource.target}"
207
- command << common_route_items
208
- command << " dev #{@new_resource.device} " if @new_resource.device
209
- when :delete
210
- command = "ip route delete #{@new_resource.target}"
211
- command << common_route_items
212
- end
214
+ command
215
+ end
213
216
 
214
- return command
215
- end
217
+ def config_file_contents(action, options = {})
218
+ content = ""
219
+ case action
220
+ when :add
221
+ content << (options[:target]).to_s
222
+ content << "/#{options[:netmask]}" if options[:netmask]
223
+ content << " via #{options[:gateway]}" if options[:gateway]
224
+ content << "\n"
225
+ end
216
226
 
217
- def config_file_contents(action, options = {})
218
- content = ""
219
- case action
220
- when :add
221
- content << "#{options[:target]}"
222
- content << "/#{options[:netmask]}" if options[:netmask]
223
- content << " via #{options[:gateway]}" if options[:gateway]
224
- content << "\n"
227
+ content
228
+ end
225
229
  end
226
-
227
- return content
228
230
  end
229
231
  end