chef 12.17.44 → 12.18.31

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
@@ -1548,6 +1548,13 @@ class Chef
1548
1548
  #
1549
1549
  # Returns the class with the given resource_name.
1550
1550
  #
1551
+ # NOTE: Chef::Resource.resource_matching_short_name(:package) returns
1552
+ # Chef::Resource::Package, while on rhel the API call
1553
+ # Chef::Resource.resource_for_node(:package, node) will return
1554
+ # Chef::Resource::YumPackage -- which is probably what you really
1555
+ # want. This API should most likely be removed or changed to call
1556
+ # resource_for_node.
1557
+ #
1551
1558
  # ==== Parameters
1552
1559
  # short_name<Symbol>:: short_name of the resource (ie :directory)
1553
1560
  #
@@ -34,6 +34,7 @@ class Chef
34
34
  property :package_name, [String, Array], coerce: proc { |x| [x].flatten }
35
35
 
36
36
  property :version, [String, Array], coerce: proc { |x| [x].flatten }
37
+ property :returns, [Integer, Array], default: [ 0 ], desired_state: false
37
38
  end
38
39
  end
39
40
  end
@@ -0,0 +1,64 @@
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/resource/package"
19
+
20
+ class Chef
21
+ class Resource
22
+ class DnfPackage < Chef::Resource::Package
23
+ extend Chef::Mixin::Which
24
+
25
+ resource_name :dnf_package
26
+
27
+ allowed_actions :install, :upgrade, :remove, :purge, :reconfig, :lock, :unlock, :flush_cache
28
+
29
+ provides :package, os: "linux", platform_family: %w{rhel fedora} do
30
+ which("dnf")
31
+ end
32
+
33
+ provides :dnf_package
34
+
35
+ # Install a specific arch
36
+ property :arch, [String, Array], coerce: proc { |x| [x].flatten }
37
+
38
+ # Flush the in-memory available/installed cache, this does not flush the dnf caches on disk
39
+ property :flush_cache,
40
+ Hash,
41
+ default: { before: false, after: false },
42
+ coerce: proc { |v|
43
+ if v.is_a?(Hash)
44
+ v
45
+ elsif v.is_a?(Array)
46
+ v.each_with_object({}) { |arg, obj| obj[arg] = true }
47
+ elsif v.is_a?(TrueClass) || v.is_a?(FalseClass)
48
+ { before: v, after: v }
49
+ elsif v == :before
50
+ { before: true, after: false }
51
+ elsif v == :after
52
+ { after: true, before: false }
53
+ end
54
+ }
55
+
56
+ def allow_downgrade(arg = nil)
57
+ if !arg.nil?
58
+ Chef.deprecated(:dnf_package_allow_downgrade, "the allow_downgrade property on the dnf_package provider is not used, DNF supports downgrades by default.")
59
+ end
60
+ false
61
+ end
62
+ end
63
+ end
64
+ end
@@ -108,10 +108,12 @@ class Chef
108
108
  def verify_command(path, opts)
109
109
  # First implementation interpolated `file`; docs & RFC claim `path`
110
110
  # is interpolated. Until `file` can be deprecated, interpolate both.
111
- Chef.deprecated(:verify_file,
112
- "%{file} is deprecated in verify command and will not be "\
113
- "supported in Chef 13. Please use %{path} instead."
114
- ) if @command.include?("%{file}")
111
+ if @command.include?("%{file}")
112
+ Chef.deprecated(:verify_file,
113
+ "%{file} is deprecated in verify command and will not be "\
114
+ "supported in Chef 13. Please use %{path} instead."
115
+ )
116
+ end
115
117
  command = @command % { :file => path, :path => path }
116
118
  interpreter = Chef::GuardInterpreter.for_resource(@parent_resource, command, @command_opts)
117
119
  interpreter.evaluate
@@ -17,7 +17,6 @@
17
17
  #
18
18
 
19
19
  require "chef/resource/package"
20
- require "chef/provider/package/yum"
21
20
 
22
21
  class Chef
23
22
  class Resource
@@ -27,22 +26,27 @@ class Chef
27
26
 
28
27
  # Install a specific arch
29
28
  property :arch, [ String, Array ]
30
- # the {} on the proc here is because rspec chokes if it's do...end
29
+
31
30
  property :flush_cache,
32
- Hash,
33
- default: { before: false, after: false },
34
- coerce: proc { |v|
35
- if v.is_a?(Array)
36
- v.each_with_object({}) { |arg, obj| obj[arg] = true }
37
- elsif v.any?
38
- v
39
- else
40
- { before: v, after: v }
41
- end
42
- }
31
+ Hash,
32
+ default: { before: false, after: false },
33
+ coerce: proc { |v|
34
+ if v.is_a?(Hash)
35
+ v
36
+ elsif v.is_a?(Array)
37
+ v.each_with_object({}) { |arg, obj| obj[arg] = true }
38
+ elsif v.is_a?(TrueClass) || v.is_a?(FalseClass)
39
+ { before: v, after: v }
40
+ elsif v == :before
41
+ { before: true, after: false }
42
+ elsif v == :after
43
+ { after: true, before: false }
44
+ end
45
+ }
46
+
43
47
  property :allow_downgrade, [ true, false ], default: false
44
- property :yum_binary, String
45
48
 
49
+ property :yum_binary, String
46
50
  end
47
51
  end
48
52
  end
@@ -25,7 +25,7 @@ class Chef
25
25
  provides :yum_repository
26
26
 
27
27
  # http://linux.die.net/man/5/yum.conf
28
- property :baseurl, String, regex: /.*/
28
+ property :baseurl, [String, Array], regex: /.*/
29
29
  property :cost, String, regex: /^\d+$/
30
30
  property :clean_headers, [TrueClass, FalseClass], default: false # deprecated
31
31
  property :clean_metadata, [TrueClass, FalseClass], default: true
@@ -198,6 +198,17 @@ class Chef
198
198
  def resource_completed(new_resource)
199
199
  if @pending_update && !nested_resource?(new_resource)
200
200
  @pending_update.finish
201
+
202
+ # Verify if the resource has sensitive data
203
+ # and create a new blank resource with only
204
+ # the name so we can report it back without
205
+ # sensitive data
206
+ if @pending_update.new_resource.sensitive
207
+ klass = @pending_update.new_resource.class
208
+ resource_name = @pending_update.new_resource.name
209
+ @pending_update.new_resource = klass.new(resource_name)
210
+ end
211
+
201
212
  @updated_resources << @pending_update
202
213
  @pending_update = nil
203
214
  end
@@ -31,6 +31,7 @@ require "chef/resource/deploy"
31
31
  require "chef/resource/deploy_revision"
32
32
  require "chef/resource/directory"
33
33
  require "chef/resource/dpkg_package"
34
+ require "chef/resource/dnf_package"
34
35
  require "chef/resource/dsc_script"
35
36
  require "chef/resource/dsc_resource"
36
37
  require "chef/resource/easy_install_package"
@@ -70,7 +70,7 @@ class Chef
70
70
  when Integer
71
71
  stat.uid
72
72
  else
73
- Chef::Log.error("The `owner` parameter of the #@new_resource resource is set to an invalid value (#{new_resource.owner.inspect})")
73
+ Chef::Log.error("The `owner` parameter of the #{@new_resource} resource is set to an invalid value (#{new_resource.owner.inspect})")
74
74
  raise ArgumentError, "cannot resolve #{new_resource.owner.inspect} to uid, owner must be a string or integer"
75
75
  end
76
76
  end
@@ -97,7 +97,7 @@ class Chef
97
97
  when Integer
98
98
  stat.gid
99
99
  else
100
- Chef::Log.error("The `group` parameter of the #@new_resource resource is set to an invalid value (#{new_resource.owner.inspect})")
100
+ Chef::Log.error("The `group` parameter of the #{@new_resource} resource is set to an invalid value (#{new_resource.owner.inspect})")
101
101
  raise ArgumentError, "cannot resolve #{new_resource.group.inspect} to gid, group must be a string or integer"
102
102
  end
103
103
  end
@@ -121,8 +121,8 @@ class Chef
121
121
  when String, Integer, nil
122
122
  "0#{(stat.mode & 07777).to_s(8)}"
123
123
  else
124
- Chef::Log.error("The `mode` parameter of the #@new_resource resource is set to an invalid value (#{new_resource.mode.inspect})")
125
- raise ArgumentError, "Invalid value #{new_resource.mode.inspect} for `mode` on resource #@new_resource"
124
+ Chef::Log.error("The `mode` parameter of the #{@new_resource} resource is set to an invalid value (#{new_resource.mode.inspect})")
125
+ raise ArgumentError, "Invalid value #{new_resource.mode.inspect} for `mode` on resource #{@new_resource}"
126
126
  end
127
127
  end
128
128
 
@@ -74,7 +74,7 @@ class Chef
74
74
  found = rs.find_all do |r|
75
75
  name_matches = r["Name"].casecmp(name) == 0
76
76
  if name_matches
77
- module_name == nil || (r["Module"] && r["Module"]["Name"].casecmp(module_name) == 0)
77
+ module_name.nil? || (r["Module"] && r["Module"]["Name"].casecmp(module_name) == 0)
78
78
  else
79
79
  false
80
80
  end
@@ -21,7 +21,7 @@
21
21
 
22
22
  class Chef
23
23
  CHEF_ROOT = File.expand_path("../..", __FILE__)
24
- VERSION = "12.17.44"
24
+ VERSION = "12.18.31"
25
25
  end
26
26
 
27
27
  #
@@ -35,7 +35,7 @@ class Chef
35
35
  Chef::ReservedNames::Win32::Error.raise!
36
36
  end
37
37
  # If a block is passed, handle freeing the memory at the end
38
- if block != nil
38
+ if !block.nil?
39
39
  begin
40
40
  yield result
41
41
  ensure
@@ -551,7 +551,7 @@ class Chef
551
551
  def set_security_descriptor_dacl(security_descriptor, acl, defaulted = false, present = nil)
552
552
  security_descriptor = security_descriptor.pointer if security_descriptor.respond_to?(:pointer)
553
553
  acl = acl.pointer if acl.respond_to?(:pointer)
554
- present = !security_descriptor.null? if present == nil
554
+ present = !security_descriptor.null? if present.nil?
555
555
 
556
556
  unless SetSecurityDescriptorDacl(security_descriptor, present, acl, defaulted)
557
557
  Chef::ReservedNames::Win32::Error.raise!
@@ -579,7 +579,7 @@ class Chef
579
579
  def self.set_security_descriptor_sacl(security_descriptor, acl, defaulted = false, present = nil)
580
580
  security_descriptor = security_descriptor.pointer if security_descriptor.respond_to?(:pointer)
581
581
  acl = acl.pointer if acl.respond_to?(:pointer)
582
- present = !security_descriptor.null? if present == nil
582
+ present = !security_descriptor.null? if present.nil?
583
583
 
584
584
  unless SetSecurityDescriptorSacl(security_descriptor, present, acl, defaulted)
585
585
  Chef::ReservedNames::Win32::Error.raise!
@@ -50,7 +50,7 @@ class Chef
50
50
  end
51
51
 
52
52
  def ==(other)
53
- other != nil && Chef::ReservedNames::Win32::Security.equal_sid(self, other)
53
+ !other.nil? && Chef::ReservedNames::Win32::Security.equal_sid(self, other)
54
54
  end
55
55
 
56
56
  attr_reader :pointer
@@ -61,7 +61,7 @@ class Chef
61
61
 
62
62
  def account_name
63
63
  domain, name, use = account
64
- (domain != nil && domain.length > 0) ? "#{domain}\\#{name}" : name
64
+ (!domain.nil? && domain.length > 0) ? "#{domain}\\#{name}" : name
65
65
  end
66
66
 
67
67
  def size
@@ -0,0 +1,55 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <repomd xmlns="http://linux.duke.edu/metadata/repo" xmlns:rpm="http://linux.duke.edu/metadata/rpm">
3
+ <revision>1479418959</revision>
4
+ <data type="filelists">
5
+ <checksum type="sha256">8b34697595fcc87928e12d24644dda9462c3857bd932861e28bc77ae1f31be16</checksum>
6
+ <open-checksum type="sha256">9f5be999b4a535c19afc53703851577e1a325227fab651189c5c39708b9a1e38</open-checksum>
7
+ <location href="repodata/8b34697595fcc87928e12d24644dda9462c3857bd932861e28bc77ae1f31be16-filelists.xml.gz"/>
8
+ <timestamp>1479418959</timestamp>
9
+ <size>419</size>
10
+ <open-size>1127</open-size>
11
+ </data>
12
+ <data type="primary">
13
+ <checksum type="sha256">66391e53f0510b98b3f0b79f40ba1048026d9a1ef20905d9c40ba6f5411f3243</checksum>
14
+ <open-checksum type="sha256">dc25cfbf4520861130e0ba203d27cc40b183fbb7c576aac33d838fb20a68aa32</open-checksum>
15
+ <location href="repodata/66391e53f0510b98b3f0b79f40ba1048026d9a1ef20905d9c40ba6f5411f3243-primary.xml.gz"/>
16
+ <timestamp>1479418959</timestamp>
17
+ <size>859</size>
18
+ <open-size>4529</open-size>
19
+ </data>
20
+ <data type="primary_db">
21
+ <checksum type="sha256">313329137b55fd333b2dc66394a6661a2befa6cc535d8460d92a4a78a9c581f0</checksum>
22
+ <open-checksum type="sha256">720b637c782cce8604b922e9989ecfff9091e26163d643bd1b676778beb1c933</open-checksum>
23
+ <location href="repodata/313329137b55fd333b2dc66394a6661a2befa6cc535d8460d92a4a78a9c581f0-primary.sqlite.bz2"/>
24
+ <timestamp>1479418959</timestamp>
25
+ <database_version>10</database_version>
26
+ <size>2460</size>
27
+ <open-size>32768</open-size>
28
+ </data>
29
+ <data type="other_db">
30
+ <checksum type="sha256">b97cca3fe14bcf06c52be4449b6108f7731239ff221111dcce8aada5467f60dc</checksum>
31
+ <open-checksum type="sha256">938156bcfc95828cb6857e1b2790dceaef57196843a80464ba5749772fc15e83</open-checksum>
32
+ <location href="repodata/b97cca3fe14bcf06c52be4449b6108f7731239ff221111dcce8aada5467f60dc-other.sqlite.bz2"/>
33
+ <timestamp>1479418959</timestamp>
34
+ <database_version>10</database_version>
35
+ <size>967</size>
36
+ <open-size>6144</open-size>
37
+ </data>
38
+ <data type="other">
39
+ <checksum type="sha256">31ac4db5d5ac593728fcc26aef82b7b93c4cc4dbec843786b1845b939b658553</checksum>
40
+ <open-checksum type="sha256">2ea64cdb2f5ba3859af29fe67a85d61d5b4de23f3da1ee71d5af175d8d887ab6</open-checksum>
41
+ <location href="repodata/31ac4db5d5ac593728fcc26aef82b7b93c4cc4dbec843786b1845b939b658553-other.xml.gz"/>
42
+ <timestamp>1479418959</timestamp>
43
+ <size>413</size>
44
+ <open-size>1035</open-size>
45
+ </data>
46
+ <data type="filelists_db">
47
+ <checksum type="sha256">4ac40fa3c6728c1401318e2e20a997436624e83dcf7a5f952b851ef422637773</checksum>
48
+ <open-checksum type="sha256">8bc15efa19d02a5112e20c6ed1be17c5851287ddfba17aee2283ddb216dd08d7</open-checksum>
49
+ <location href="repodata/4ac40fa3c6728c1401318e2e20a997436624e83dcf7a5f952b851ef422637773-filelists.sqlite.bz2"/>
50
+ <timestamp>1479418959</timestamp>
51
+ <database_version>10</database_version>
52
+ <size>1131</size>
53
+ <open-size>7168</open-size>
54
+ </data>
55
+ </repomd>
@@ -0,0 +1,686 @@
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 "spec_helper"
19
+ require "functional/resource/base"
20
+ require "chef/mixin/shell_out"
21
+
22
+ # run this test only for following platforms.
23
+ exclude_test = !(%w{rhel fedora}.include?(ohai[:platform_family]) && File.exist?("/usr/bin/dnf"))
24
+ describe Chef::Resource::RpmPackage, :requires_root, :external => exclude_test do
25
+ include Chef::Mixin::ShellOut
26
+
27
+ def flush_cache
28
+ # needed on at least fc23/fc24 sometimes to deal with the dnf cache getting out of sync with the rpm db
29
+ FileUtils.rm_f "/var/cache/dnf/@System.solv"
30
+ Chef::Resource::DnfPackage.new("shouldnt-matter", run_context).run_action(:flush_cache)
31
+ end
32
+
33
+ def preinstall(*rpms)
34
+ rpms.each do |rpm|
35
+ shell_out!("rpm -ivh #{CHEF_SPEC_ASSETS}/yumrepo/#{rpm}")
36
+ end
37
+ flush_cache
38
+ end
39
+
40
+ before(:each) do
41
+ File.open("/etc/yum.repos.d/chef-dnf-localtesting.repo", "w+") do |f|
42
+ f.write <<-EOF
43
+ [chef-dnf-localtesting]
44
+ name=Chef DNF spec testing repo
45
+ baseurl=file://#{CHEF_SPEC_ASSETS}/yumrepo
46
+ enable=1
47
+ gpgcheck=0
48
+ EOF
49
+ end
50
+ shell_out!("rpm -qa | grep chef_rpm | xargs -r rpm -e")
51
+ end
52
+
53
+ after(:all) do
54
+ shell_out!("rpm -qa | grep chef_rpm | xargs -r rpm -e")
55
+ FileUtils.rm_f "/etc/yum.repos.d/chef-dnf-localtesting.repo"
56
+ end
57
+
58
+ let(:package_name) { "chef_rpm" }
59
+ let(:dnf_package) { Chef::Resource::DnfPackage.new(package_name, run_context) }
60
+
61
+ describe ":install" do
62
+ context "vanilla use case" do
63
+ let(:package_name) { "chef_rpm" }
64
+
65
+ it "installs if the package is not installed" do
66
+ flush_cache
67
+ dnf_package.run_action(:install)
68
+ expect(dnf_package.updated_by_last_action?).to be true
69
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
70
+ end
71
+
72
+ it "does not install if the package is installed" do
73
+ preinstall("chef_rpm-1.10-1.fc24.x86_64.rpm")
74
+ dnf_package.run_action(:install)
75
+ expect(dnf_package.updated_by_last_action?).to be false
76
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
77
+ end
78
+
79
+ it "does not install twice" do
80
+ flush_cache
81
+ dnf_package.run_action(:install)
82
+ expect(dnf_package.updated_by_last_action?).to be true
83
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
84
+ dnf_package.run_action(:install)
85
+ expect(dnf_package.updated_by_last_action?).to be false
86
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
87
+ end
88
+
89
+ it "does not install if the prior version package is installed" do
90
+ preinstall("chef_rpm-1.2-1.fc24.x86_64.rpm")
91
+ dnf_package.run_action(:install)
92
+ expect(dnf_package.updated_by_last_action?).to be false
93
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.x86_64")
94
+ end
95
+
96
+ it "does not install if the i686 package is installed" do
97
+ skip "FIXME: do nothing, or install the x86_64 version?"
98
+ preinstall("chef_rpm-1.10-1.fc24.i686.rpm")
99
+ dnf_package.run_action(:install)
100
+ expect(dnf_package.updated_by_last_action?).to be false
101
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.i686")
102
+ end
103
+
104
+ it "does not install if the prior version i686 package is installed" do
105
+ skip "FIXME: do nothing, or install the x86_64 version?"
106
+ preinstall("chef_rpm-1.2-1.fc24.i686.rpm")
107
+ dnf_package.run_action(:install)
108
+ expect(dnf_package.updated_by_last_action?).to be false
109
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.i686")
110
+ end
111
+ end
112
+
113
+ context "with versions or globs in the name" do
114
+ it "works with a version" do
115
+ flush_cache
116
+ dnf_package.package_name("chef_rpm-1.10")
117
+ dnf_package.run_action(:install)
118
+ expect(dnf_package.updated_by_last_action?).to be true
119
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
120
+ end
121
+
122
+ it "works with an older version" do
123
+ flush_cache
124
+ dnf_package.package_name("chef_rpm-1.2")
125
+ dnf_package.run_action(:install)
126
+ expect(dnf_package.updated_by_last_action?).to be true
127
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.x86_64")
128
+ end
129
+
130
+ it "works with an evr" do
131
+ flush_cache
132
+ dnf_package.package_name("chef_rpm-0:1.2-1.fc24")
133
+ dnf_package.run_action(:install)
134
+ expect(dnf_package.updated_by_last_action?).to be true
135
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.x86_64")
136
+ end
137
+
138
+ it "works with a version glob" do
139
+ flush_cache
140
+ dnf_package.package_name("chef_rpm-1*")
141
+ dnf_package.run_action(:install)
142
+ expect(dnf_package.updated_by_last_action?).to be true
143
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
144
+ end
145
+
146
+ it "works with a name glob + version glob" do
147
+ flush_cache
148
+ dnf_package.package_name("chef_rp*-1*")
149
+ dnf_package.run_action(:install)
150
+ expect(dnf_package.updated_by_last_action?).to be true
151
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
152
+ end
153
+ end
154
+
155
+ # version only matches the actual dnf version, does not work with epoch or release or combined evr
156
+ context "with version property" do
157
+ it "matches the full version" do
158
+ flush_cache
159
+ dnf_package.package_name("chef_rpm")
160
+ dnf_package.version("1.10")
161
+ dnf_package.run_action(:install)
162
+ expect(dnf_package.updated_by_last_action?).to be true
163
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
164
+ end
165
+
166
+ it "matches with a glob" do
167
+ flush_cache
168
+ dnf_package.package_name("chef_rpm")
169
+ dnf_package.version("1*")
170
+ dnf_package.run_action(:install)
171
+ expect(dnf_package.updated_by_last_action?).to be true
172
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
173
+ end
174
+
175
+ it "matches the vr" do
176
+ flush_cache
177
+ dnf_package.package_name("chef_rpm")
178
+ dnf_package.version("1.10-1.fc24")
179
+ dnf_package.run_action(:install)
180
+ expect(dnf_package.updated_by_last_action?).to be true
181
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
182
+ end
183
+
184
+ it "matches the evr" do
185
+ flush_cache
186
+ dnf_package.package_name("chef_rpm")
187
+ dnf_package.version("0:1.10-1.fc24")
188
+ dnf_package.run_action(:install)
189
+ expect(dnf_package.updated_by_last_action?).to be true
190
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
191
+ end
192
+
193
+ it "matches with a vr glob" do
194
+ pending "doesn't work on command line either"
195
+ flush_cache
196
+ dnf_package.package_name("chef_rpm")
197
+ dnf_package.version("1.10-1*")
198
+ dnf_package.run_action(:install)
199
+ expect(dnf_package.updated_by_last_action?).to be true
200
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
201
+ end
202
+
203
+ it "matches with an evr glob" do
204
+ pending "doesn't work on command line either"
205
+ flush_cache
206
+ dnf_package.package_name("chef_rpm")
207
+ dnf_package.version("0:1.10-1*")
208
+ dnf_package.run_action(:install)
209
+ expect(dnf_package.updated_by_last_action?).to be true
210
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
211
+ end
212
+ end
213
+
214
+ context "downgrades" do
215
+ it "just work with DNF" do
216
+ preinstall("chef_rpm-1.10-1.fc24.x86_64.rpm")
217
+ dnf_package.version("1.2")
218
+ dnf_package.run_action(:install)
219
+ expect(dnf_package.updated_by_last_action?).to be true
220
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.x86_64")
221
+ end
222
+
223
+ it "throws a deprecation warning with allow_downgrade" do
224
+ Chef::Config[:treat_deprecation_warnings_as_errors] = false
225
+ expect(Chef).to receive(:deprecated).with(:dnf_package_allow_downgrade, /^the allow_downgrade property on the dnf_package provider is not used/)
226
+ preinstall("chef_rpm-1.10-1.fc24.x86_64.rpm")
227
+ dnf_package.version("1.2")
228
+ dnf_package.run_action(:install)
229
+ dnf_package.allow_downgrade true
230
+ expect(dnf_package.updated_by_last_action?).to be true
231
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.x86_64")
232
+ end
233
+ end
234
+
235
+ context "with arches" do
236
+ it "installs with 64-bit arch in the name" do
237
+ flush_cache
238
+ dnf_package.package_name("chef_rpm.x86_64")
239
+ dnf_package.run_action(:install)
240
+ expect(dnf_package.updated_by_last_action?).to be true
241
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
242
+ end
243
+
244
+ it "installs with 32-bit arch in the name" do
245
+ flush_cache
246
+ dnf_package.package_name("chef_rpm.i686")
247
+ dnf_package.run_action(:install)
248
+ expect(dnf_package.updated_by_last_action?).to be true
249
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.i686")
250
+ end
251
+
252
+ it "installs with 64-bit arch in the property" do
253
+ flush_cache
254
+ dnf_package.package_name("chef_rpm")
255
+ dnf_package.arch("x86_64")
256
+ dnf_package.run_action(:install)
257
+ expect(dnf_package.updated_by_last_action?).to be true
258
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
259
+ end
260
+
261
+ it "installs with 32-bit arch in the property" do
262
+ flush_cache
263
+ dnf_package.package_name("chef_rpm")
264
+ dnf_package.arch("i686")
265
+ dnf_package.run_action(:install)
266
+ expect(dnf_package.updated_by_last_action?).to be true
267
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.i686")
268
+ end
269
+ end
270
+
271
+ context "with constraints" do
272
+ it "with nothing installed, it installs the latest version" do
273
+ flush_cache
274
+ dnf_package.package_name("chef_rpm >= 1.2")
275
+ dnf_package.run_action(:install)
276
+ expect(dnf_package.updated_by_last_action?).to be true
277
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
278
+ end
279
+
280
+ it "when it is met, it does nothing" do
281
+ preinstall("chef_rpm-1.2-1.fc24.x86_64.rpm")
282
+ dnf_package.package_name("chef_rpm >= 1.2")
283
+ dnf_package.run_action(:install)
284
+ expect(dnf_package.updated_by_last_action?).to be false
285
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.x86_64")
286
+ end
287
+
288
+ it "when it is met, it does nothing" do
289
+ preinstall("chef_rpm-1.10-1.fc24.x86_64.rpm")
290
+ dnf_package.package_name("chef_rpm >= 1.2")
291
+ dnf_package.run_action(:install)
292
+ expect(dnf_package.updated_by_last_action?).to be false
293
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
294
+ end
295
+
296
+ it "with nothing intalled, it installs the latest version" do
297
+ flush_cache
298
+ dnf_package.package_name("chef_rpm > 1.2")
299
+ dnf_package.run_action(:install)
300
+ expect(dnf_package.updated_by_last_action?).to be true
301
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
302
+ end
303
+
304
+ it "when it is not met by an installed rpm, it upgrades" do
305
+ preinstall("chef_rpm-1.2-1.fc24.x86_64.rpm")
306
+ dnf_package.package_name("chef_rpm > 1.2")
307
+ dnf_package.run_action(:install)
308
+ expect(dnf_package.updated_by_last_action?).to be true
309
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
310
+ end
311
+
312
+ it "when it is met by an installed rpm, it does nothing" do
313
+ preinstall("chef_rpm-1.10-1.fc24.x86_64.rpm")
314
+ dnf_package.package_name("chef_rpm > 1.2")
315
+ dnf_package.run_action(:install)
316
+ expect(dnf_package.updated_by_last_action?).to be false
317
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
318
+ end
319
+
320
+ it "when there is no solution to the contraint" do
321
+ flush_cache
322
+ dnf_package.package_name("chef_rpm > 2.0")
323
+ expect { dnf_package.run_action(:install) }.to raise_error(Chef::Exceptions::Package, /No candidate version available/)
324
+ end
325
+
326
+ it "when there is no solution to the contraint but an rpm is preinstalled" do
327
+ preinstall("chef_rpm-1.10-1.fc24.x86_64.rpm")
328
+ dnf_package.package_name("chef_rpm > 2.0")
329
+ expect { dnf_package.run_action(:install) }.to raise_error(Chef::Exceptions::Package, /No candidate version available/)
330
+ end
331
+ end
332
+
333
+ context "with source arguments" do
334
+ it "raises an exception when the package does not exist" do
335
+ flush_cache
336
+ dnf_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/this-file-better-not-exist.rpm")
337
+ expect { dnf_package.run_action(:install) }.to raise_error(Chef::Exceptions::Package, /No candidate version available/)
338
+ end
339
+
340
+ it "does not raise a hard exception in why-run mode when the package does not exist" do
341
+ Chef::Config[:why_run] = true
342
+ flush_cache
343
+ dnf_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/this-file-better-not-exist.rpm")
344
+ dnf_package.run_action(:install)
345
+ expect { dnf_package.run_action(:install) }.not_to raise_error
346
+ end
347
+
348
+ it "installs the package when using the source argument" do
349
+ flush_cache
350
+ dnf_package.name "something"
351
+ dnf_package.package_name "somethingelse"
352
+ dnf_package.source("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.fc24.x86_64.rpm")
353
+ dnf_package.run_action(:install)
354
+ expect(dnf_package.updated_by_last_action?).to be true
355
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.x86_64")
356
+ end
357
+
358
+ it "installs the package when the name is a path to a file" do
359
+ flush_cache
360
+ dnf_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.fc24.x86_64.rpm")
361
+ dnf_package.run_action(:install)
362
+ expect(dnf_package.updated_by_last_action?).to be true
363
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.x86_64")
364
+ end
365
+
366
+ it "does not downgrade the package with :install" do
367
+ preinstall("chef_rpm-1.10-1.fc24.x86_64.rpm")
368
+ dnf_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.fc24.x86_64.rpm")
369
+ dnf_package.run_action(:install)
370
+ expect(dnf_package.updated_by_last_action?).to be false
371
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
372
+ end
373
+
374
+ it "does not upgrade the package with :install" do
375
+ preinstall("chef_rpm-1.2-1.fc24.x86_64.rpm")
376
+ dnf_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.10-1.fc24.x86_64.rpm")
377
+ dnf_package.run_action(:install)
378
+ expect(dnf_package.updated_by_last_action?).to be false
379
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.x86_64")
380
+ end
381
+
382
+ it "is idempotent when the package is already installed" do
383
+ preinstall("chef_rpm-1.2-1.fc24.x86_64.rpm")
384
+ dnf_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.fc24.x86_64.rpm")
385
+ dnf_package.run_action(:install)
386
+ expect(dnf_package.updated_by_last_action?).to be false
387
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.x86_64")
388
+ end
389
+ end
390
+
391
+ context "with no available version" do
392
+ it "works when a package is installed" do
393
+ FileUtils.rm_f "/etc/yum.repos.d/chef-dnf-localtesting.repo"
394
+ preinstall("chef_rpm-1.2-1.fc24.x86_64.rpm")
395
+ dnf_package.run_action(:install)
396
+ expect(dnf_package.updated_by_last_action?).to be false
397
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.x86_64")
398
+ end
399
+
400
+ it "works with a local source" do
401
+ FileUtils.rm_f "/etc/yum.repos.d/chef-dnf-localtesting.repo"
402
+ flush_cache
403
+ dnf_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.fc24.x86_64.rpm")
404
+ dnf_package.run_action(:install)
405
+ expect(dnf_package.updated_by_last_action?).to be true
406
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.x86_64")
407
+ end
408
+ end
409
+
410
+ context "multipackage with arches" do
411
+ it "installs two rpms" do
412
+ flush_cache
413
+ dnf_package.package_name([ "chef_rpm.x86_64", "chef_rpm.i686" ] )
414
+ dnf_package.run_action(:install)
415
+ expect(dnf_package.updated_by_last_action?).to be true
416
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to match(/chef_rpm-1.10-1.fc24.x86_64/)
417
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to match(/chef_rpm-1.10-1.fc24.i686/)
418
+ end
419
+
420
+ it "does nothing if both are installed" do
421
+ preinstall("chef_rpm-1.10-1.fc24.x86_64.rpm", "chef_rpm-1.10-1.fc24.i686.rpm")
422
+ flush_cache
423
+ dnf_package.package_name([ "chef_rpm.x86_64", "chef_rpm.i686" ] )
424
+ dnf_package.run_action(:install)
425
+ expect(dnf_package.updated_by_last_action?).to be false
426
+ end
427
+
428
+ it "installs the second rpm if the first is installed" do
429
+ preinstall("chef_rpm-1.10-1.fc24.x86_64.rpm")
430
+ dnf_package.package_name([ "chef_rpm.x86_64", "chef_rpm.i686" ] )
431
+ dnf_package.run_action(:install)
432
+ expect(dnf_package.updated_by_last_action?).to be true
433
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to match(/chef_rpm-1.10-1.fc24.x86_64/)
434
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to match(/chef_rpm-1.10-1.fc24.i686/)
435
+ end
436
+
437
+ it "installs the first rpm if the second is installed" do
438
+ preinstall("chef_rpm-1.10-1.fc24.i686.rpm")
439
+ dnf_package.package_name([ "chef_rpm.x86_64", "chef_rpm.i686" ] )
440
+ dnf_package.run_action(:install)
441
+ expect(dnf_package.updated_by_last_action?).to be true
442
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to match(/chef_rpm-1.10-1.fc24.x86_64/)
443
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to match(/chef_rpm-1.10-1.fc24.i686/)
444
+ end
445
+
446
+ # unlikely to work consistently correct, okay to deprecate the arch-array in favor of the arch in the name
447
+ it "installs two rpms with multi-arch" do
448
+ flush_cache
449
+ dnf_package.package_name(%w{chef_rpm chef_rpm} )
450
+ dnf_package.arch(%w{x86_64 i686})
451
+ dnf_package.run_action(:install)
452
+ expect(dnf_package.updated_by_last_action?).to be true
453
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to match(/chef_rpm-1.10-1.fc24.x86_64/)
454
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to match(/chef_rpm-1.10-1.fc24.i686/)
455
+ end
456
+
457
+ # unlikely to work consistently correct, okay to deprecate the arch-array in favor of the arch in the name
458
+ it "installs the second rpm if the first is installed (muti-arch)" do
459
+ preinstall("chef_rpm-1.10-1.fc24.x86_64.rpm")
460
+ dnf_package.package_name(%w{chef_rpm chef_rpm} )
461
+ dnf_package.arch(%w{x86_64 i686})
462
+ dnf_package.run_action(:install)
463
+ expect(dnf_package.updated_by_last_action?).to be true
464
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to match(/chef_rpm-1.10-1.fc24.x86_64/)
465
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to match(/chef_rpm-1.10-1.fc24.i686/)
466
+ end
467
+
468
+ # unlikely to work consistently correct, okay to deprecate the arch-array in favor of the arch in the name
469
+ it "installs the first rpm if the second is installed (muti-arch)" do
470
+ preinstall("chef_rpm-1.10-1.fc24.x86_64.rpm")
471
+ dnf_package.package_name(%w{chef_rpm chef_rpm} )
472
+ dnf_package.arch(%w{x86_64 i686})
473
+ dnf_package.run_action(:install)
474
+ expect(dnf_package.updated_by_last_action?).to be true
475
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to match(/chef_rpm-1.10-1.fc24.x86_64/)
476
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to match(/chef_rpm-1.10-1.fc24.i686/)
477
+ end
478
+
479
+ # unlikely to work consistently correct, okay to deprecate the arch-array in favor of the arch in the name
480
+ it "does nothing if both are installed (muti-arch)" do
481
+ preinstall("chef_rpm-1.10-1.fc24.x86_64.rpm", "chef_rpm-1.10-1.fc24.i686.rpm")
482
+ dnf_package.package_name(%w{chef_rpm chef_rpm} )
483
+ dnf_package.arch(%w{x86_64 i686})
484
+ dnf_package.run_action(:install)
485
+ expect(dnf_package.updated_by_last_action?).to be false
486
+ end
487
+ end
488
+ end
489
+
490
+ describe ":upgrade" do
491
+ context "downgrades" do
492
+ it "just work with DNF" do
493
+ preinstall("chef_rpm-1.10-1.fc24.x86_64.rpm")
494
+ dnf_package.version("1.2")
495
+ dnf_package.run_action(:install)
496
+ expect(dnf_package.updated_by_last_action?).to be true
497
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.x86_64")
498
+ end
499
+
500
+ it "throws a deprecation warning with allow_downgrade" do
501
+ Chef::Config[:treat_deprecation_warnings_as_errors] = false
502
+ expect(Chef).to receive(:deprecated).with(:dnf_package_allow_downgrade, /^the allow_downgrade property on the dnf_package provider is not used/)
503
+ preinstall("chef_rpm-1.10-1.fc24.x86_64.rpm")
504
+ dnf_package.version("1.2")
505
+ dnf_package.run_action(:install)
506
+ dnf_package.allow_downgrade true
507
+ expect(dnf_package.updated_by_last_action?).to be true
508
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.x86_64")
509
+ end
510
+ end
511
+
512
+ context "with source arguments" do
513
+ it "installs the package when using the source argument" do
514
+ flush_cache
515
+ dnf_package.name "something"
516
+ dnf_package.package_name "somethingelse"
517
+ dnf_package.source("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.fc24.x86_64.rpm")
518
+ dnf_package.run_action(:upgrade)
519
+ expect(dnf_package.updated_by_last_action?).to be true
520
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.x86_64")
521
+ end
522
+
523
+ it "installs the package when the name is a path to a file" do
524
+ flush_cache
525
+ dnf_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.fc24.x86_64.rpm")
526
+ dnf_package.run_action(:upgrade)
527
+ expect(dnf_package.updated_by_last_action?).to be true
528
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.x86_64")
529
+ end
530
+
531
+ it "downgrades the package" do
532
+ preinstall("chef_rpm-1.10-1.fc24.x86_64.rpm")
533
+ dnf_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.fc24.x86_64.rpm")
534
+ dnf_package.run_action(:upgrade)
535
+ expect(dnf_package.updated_by_last_action?).to be true
536
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.x86_64")
537
+ end
538
+
539
+ it "upgrades the package" do
540
+ preinstall("chef_rpm-1.2-1.fc24.x86_64.rpm")
541
+ dnf_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.10-1.fc24.x86_64.rpm")
542
+ dnf_package.run_action(:upgrade)
543
+ expect(dnf_package.updated_by_last_action?).to be true
544
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
545
+ end
546
+
547
+ it "is idempotent when the package is already installed" do
548
+ preinstall("chef_rpm-1.2-1.fc24.x86_64.rpm")
549
+ dnf_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.fc24.x86_64.rpm")
550
+ dnf_package.run_action(:upgrade)
551
+ expect(dnf_package.updated_by_last_action?).to be false
552
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.x86_64")
553
+ end
554
+ end
555
+
556
+ context "with no available version" do
557
+ it "works when a package is installed" do
558
+ FileUtils.rm_f "/etc/yum.repos.d/chef-dnf-localtesting.repo"
559
+ preinstall("chef_rpm-1.2-1.fc24.x86_64.rpm")
560
+ dnf_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.fc24.x86_64.rpm")
561
+ dnf_package.run_action(:upgrade)
562
+ expect(dnf_package.updated_by_last_action?).to be false
563
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.x86_64")
564
+ end
565
+
566
+ it "works with a local source" do
567
+ FileUtils.rm_f "/etc/yum.repos.d/chef-dnf-localtesting.repo"
568
+ flush_cache
569
+ dnf_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.fc24.x86_64.rpm")
570
+ dnf_package.run_action(:upgrade)
571
+ expect(dnf_package.updated_by_last_action?).to be true
572
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.x86_64")
573
+ end
574
+ end
575
+ end
576
+
577
+ describe ":remove" do
578
+ context "vanilla use case" do
579
+ let(:package_name) { "chef_rpm" }
580
+ it "does nothing if the package is not installed" do
581
+ flush_cache
582
+ dnf_package.run_action(:remove)
583
+ expect(dnf_package.updated_by_last_action?).to be false
584
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("package chef_rpm is not installed")
585
+ end
586
+
587
+ it "removes the package if the package is installed" do
588
+ preinstall("chef_rpm-1.10-1.fc24.x86_64.rpm")
589
+ dnf_package.run_action(:remove)
590
+ expect(dnf_package.updated_by_last_action?).to be true
591
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("package chef_rpm is not installed")
592
+ end
593
+
594
+ it "does not remove the package twice" do
595
+ preinstall("chef_rpm-1.10-1.fc24.x86_64.rpm")
596
+ dnf_package.run_action(:remove)
597
+ expect(dnf_package.updated_by_last_action?).to be true
598
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("package chef_rpm is not installed")
599
+ dnf_package.run_action(:remove)
600
+ expect(dnf_package.updated_by_last_action?).to be false
601
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("package chef_rpm is not installed")
602
+ end
603
+
604
+ it "removes the package if the prior version package is installed" do
605
+ preinstall("chef_rpm-1.2-1.fc24.x86_64.rpm")
606
+ dnf_package.run_action(:remove)
607
+ expect(dnf_package.updated_by_last_action?).to be true
608
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("package chef_rpm is not installed")
609
+ end
610
+
611
+ it "removes the package if the i686 package is installed" do
612
+ skip "FIXME: should this be fixed or is the current behavior correct?"
613
+ preinstall("chef_rpm-1.10-1.fc24.i686.rpm")
614
+ dnf_package.run_action(:remove)
615
+ expect(dnf_package.updated_by_last_action?).to be true
616
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("package chef_rpm is not installed")
617
+ end
618
+
619
+ it "removes the package if the prior version i686 package is installed" do
620
+ skip "FIXME: should this be fixed or is the current behavior correct?"
621
+ preinstall("chef_rpm-1.2-1.fc24.i686.rpm")
622
+ dnf_package.run_action(:remove)
623
+ expect(dnf_package.updated_by_last_action?).to be true
624
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("package chef_rpm is not installed")
625
+ end
626
+ end
627
+
628
+ context "with 64-bit arch" do
629
+ let(:package_name) { "chef_rpm.x86_64" }
630
+ it "does nothing if the package is not installed" do
631
+ flush_cache
632
+ dnf_package.run_action(:remove)
633
+ expect(dnf_package.updated_by_last_action?).to be false
634
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("package chef_rpm is not installed")
635
+ end
636
+
637
+ it "removes the package if the package is installed" do
638
+ preinstall("chef_rpm-1.10-1.fc24.x86_64.rpm")
639
+ dnf_package.run_action(:remove)
640
+ expect(dnf_package.updated_by_last_action?).to be true
641
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("package chef_rpm is not installed")
642
+ end
643
+
644
+ it "removes the package if the prior version package is installed" do
645
+ preinstall("chef_rpm-1.2-1.fc24.x86_64.rpm")
646
+ dnf_package.run_action(:remove)
647
+ expect(dnf_package.updated_by_last_action?).to be true
648
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("package chef_rpm is not installed")
649
+ end
650
+
651
+ it "does nothing if the i686 package is installed" do
652
+ preinstall("chef_rpm-1.10-1.fc24.i686.rpm")
653
+ dnf_package.run_action(:remove)
654
+ expect(dnf_package.updated_by_last_action?).to be false
655
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.i686")
656
+ end
657
+
658
+ it "does nothing if the prior version i686 package is installed" do
659
+ preinstall("chef_rpm-1.2-1.fc24.i686.rpm")
660
+ dnf_package.run_action(:remove)
661
+ expect(dnf_package.updated_by_last_action?).to be false
662
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.i686")
663
+ end
664
+ end
665
+
666
+ context "with 32-bit arch" do
667
+ let(:package_name) { "chef_rpm.i686" }
668
+ it "removes only the 32-bit arch if both are installed" do
669
+ preinstall("chef_rpm-1.10-1.fc24.x86_64.rpm", "chef_rpm-1.10-1.fc24.i686.rpm")
670
+ dnf_package.run_action(:remove)
671
+ expect(dnf_package.updated_by_last_action?).to be true
672
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
673
+ end
674
+ end
675
+
676
+ context "with no available version" do
677
+ it "works when a package is installed" do
678
+ FileUtils.rm_f "/etc/yum.repos.d/chef-dnf-localtesting.repo"
679
+ preinstall("chef_rpm-1.2-1.fc24.x86_64.rpm")
680
+ dnf_package.run_action(:remove)
681
+ expect(dnf_package.updated_by_last_action?).to be true
682
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("package chef_rpm is not installed")
683
+ end
684
+ end
685
+ end
686
+ end