chef 13.2.20 → 13.3.42

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +1 -1
  3. data/Gemfile +2 -8
  4. data/README.md +6 -2
  5. data/Rakefile +0 -11
  6. data/VERSION +1 -1
  7. data/acceptance/Gemfile.lock +1 -1
  8. data/acceptance/data-collector/.acceptance/data-collector-test/files/default/api.rb +34 -18
  9. data/acceptance/data-collector/.acceptance/data-collector-test/recipes/default.rb +6 -0
  10. data/lib/chef/cookbook/metadata.rb +2 -2
  11. data/lib/chef/deprecation/warnings.rb +3 -1
  12. data/lib/chef/exceptions.rb +1 -1
  13. data/lib/chef/http.rb +9 -10
  14. data/lib/chef/http/api_versions.rb +2 -0
  15. data/lib/chef/http/http_request.rb +3 -0
  16. data/lib/chef/knife/core/bootstrap_context.rb +1 -0
  17. data/lib/chef/knife/core/status_presenter.rb +1 -1
  18. data/lib/chef/knife/ssh.rb +4 -0
  19. data/lib/chef/provider/apt_preference.rb +99 -0
  20. data/lib/chef/provider/execute.rb +3 -2
  21. data/lib/chef/provider/http_request.rb +14 -0
  22. data/lib/chef/provider/mount/aix.rb +49 -8
  23. data/lib/chef/provider/package/windows/registry_uninstall_entry.rb +1 -1
  24. data/lib/chef/provider/package/zypper.rb +5 -5
  25. data/lib/chef/provider/service/systemd.rb +12 -11
  26. data/lib/chef/provider/support/zypper_repo.erb +17 -0
  27. data/lib/chef/provider/systemd_unit.rb +3 -2
  28. data/lib/chef/provider/windows_task.rb +92 -71
  29. data/lib/chef/provider/zypper_repository.rb +81 -0
  30. data/lib/chef/providers.rb +2 -0
  31. data/lib/chef/resource/apt_preference.rb +36 -0
  32. data/lib/chef/resource/execute.rb +12 -2
  33. data/lib/chef/resource/http_request.rb +1 -1
  34. data/lib/chef/resource/zypper_repository.rb +51 -0
  35. data/lib/chef/resources.rb +2 -0
  36. data/lib/chef/search/query.rb +6 -1
  37. data/lib/chef/server_api_versions.rb +21 -2
  38. data/lib/chef/version.rb +3 -4
  39. data/lib/chef/win32/api/file.rb +1 -0
  40. data/lib/chef/win32/file.rb +2 -0
  41. data/lib/chef/win32/version.rb +6 -0
  42. data/spec/functional/knife/ssh_spec.rb +1 -1
  43. data/spec/functional/resource/execute_spec.rb +2 -2
  44. data/spec/spec_helper.rb +8 -1
  45. data/spec/unit/cookbook/metadata_spec.rb +3 -3
  46. data/spec/unit/http/api_versions_spec.rb +6 -3
  47. data/spec/unit/knife/bootstrap_spec.rb +4 -0
  48. data/spec/unit/knife/cookbook_show_spec.rb +3 -3
  49. data/spec/unit/knife/ssh_spec.rb +7 -1
  50. data/spec/unit/knife/status_spec.rb +2 -0
  51. data/spec/unit/provider/apt_preference_spec.rb +87 -0
  52. data/spec/unit/provider/apt_update_spec.rb +7 -7
  53. data/spec/unit/provider/dsc_resource_spec.rb +2 -2
  54. data/spec/unit/provider/execute_spec.rb +32 -14
  55. data/spec/unit/provider/mount/aix_spec.rb +33 -1
  56. data/spec/unit/provider/package/rubygems_spec.rb +1 -1
  57. data/spec/unit/provider/package/windows/registry_uninstall_entry_spec.rb +56 -3
  58. data/spec/unit/provider/package/windows_spec.rb +1 -1
  59. data/spec/unit/provider/package/zypper_spec.rb +43 -0
  60. data/spec/unit/provider/script_spec.rb +1 -1
  61. data/spec/unit/provider/service/systemd_service_spec.rb +23 -21
  62. data/spec/unit/provider/systemd_unit_spec.rb +42 -41
  63. data/spec/unit/provider/windows_task_spec.rb +40 -0
  64. data/spec/unit/resource/apt_preference_spec.rb +41 -0
  65. data/spec/unit/resource/execute_spec.rb +21 -1
  66. data/spec/unit/resource/powershell_script_spec.rb +2 -2
  67. data/spec/unit/resource/zypper_repository_spec.rb +65 -0
  68. data/spec/unit/search/query_spec.rb +13 -18
  69. data/spec/unit/server_api_spec.rb +75 -1
  70. data/spec/unit/server_api_versions_spec.rb +22 -0
  71. data/spec/unit/win32/link_spec.rb +73 -0
  72. data/tasks/dependencies.rb +0 -1
  73. metadata +13 -6
  74. data/tasks/changelog.rb +0 -37
  75. data/tasks/version.rb +0 -41
@@ -0,0 +1,81 @@
1
+ #
2
+ # Author:: Tim Smith (<tsmith@chef.io>)
3
+ # Copyright:: Copyright (c) 2017, Chef Software 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/resource"
20
+ require "chef/dsl/declare_resource"
21
+ require "chef/mixin/which"
22
+ require "chef/provider/noop"
23
+ require "shellwords"
24
+
25
+ class Chef
26
+ class Provider
27
+ class ZypperRepository < Chef::Provider
28
+
29
+ extend Chef::Mixin::Which
30
+
31
+ provides :zypper_repository do
32
+ which "zypper"
33
+ end
34
+
35
+ def load_current_resource
36
+ end
37
+
38
+ action :create do
39
+ declare_resource(:template, "/etc/zypp/repos.d/#{escaped_repo_name}.repo") do
40
+ if template_available?(new_resource.source)
41
+ source new_resource.source
42
+ else
43
+ source ::File.expand_path("../support/zypper_repo.erb", __FILE__)
44
+ local true
45
+ end
46
+ sensitive new_resource.sensitive
47
+ variables(config: new_resource)
48
+ mode new_resource.mode
49
+ notifies :refresh, new_resource, :immediately if new_resource.refresh_cache
50
+ end
51
+ end
52
+
53
+ action :delete do
54
+ declare_resource(:execute, "zypper removerepo #{escaped_repo_name}") do
55
+ only_if "zypper lr #{escaped_repo_name}"
56
+ end
57
+ end
58
+
59
+ action :refresh do
60
+ declare_resource(:execute, "zypper refresh #{escaped_repo_name}") do
61
+ only_if "zypper lr #{escaped_repo_name}"
62
+ end
63
+ end
64
+
65
+ alias_method :action_add, :action_create
66
+ alias_method :action_remove, :action_delete
67
+
68
+ # zypper repos are allowed to have spaces in the names
69
+ def escaped_repo_name
70
+ Shellwords.escape(new_resource.repo_name)
71
+ end
72
+
73
+ def template_available?(path)
74
+ !path.nil? && run_context.has_template_in_cookbook?(new_resource.cookbook_name, path)
75
+ end
76
+
77
+ end
78
+ end
79
+ end
80
+
81
+ Chef::Provider::Noop.provides :zypper_repository
@@ -17,6 +17,7 @@
17
17
  #
18
18
 
19
19
  require "chef/provider/apt_update"
20
+ require "chef/provider/apt_preference"
20
21
  require "chef/provider/apt_repository"
21
22
  require "chef/provider/batch"
22
23
  require "chef/provider/cookbook_file"
@@ -59,6 +60,7 @@ require "chef/provider/user"
59
60
  require "chef/provider/whyrun_safe_ruby_block"
60
61
  require "chef/provider/yum_repository"
61
62
  require "chef/provider/windows_task"
63
+ require "chef/provider/zypper_repository"
62
64
 
63
65
  require "chef/provider/env/windows"
64
66
 
@@ -0,0 +1,36 @@
1
+ #
2
+ # Author:: Tim Smith (<tsmith@chef.io>)
3
+ # Copyright:: 2016-2017, Chef Software, 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/resource"
20
+
21
+ class Chef
22
+ class Resource
23
+ class AptPreference < Chef::Resource
24
+ resource_name :apt_preference
25
+ provides :apt_preference
26
+
27
+ property :package_name, String, name_property: true, regex: [/^([a-z]|[A-Z]|[0-9]|_|-|\.|\*|\+)+$/]
28
+ property :glob, String
29
+ property :pin, String, required: true
30
+ property :pin_priority, [String, Integer], required: true
31
+
32
+ default_action :add
33
+ allowed_actions :add, :remove
34
+ end
35
+ end
36
+ end
@@ -132,6 +132,8 @@ class Chef
132
132
 
133
133
  property :sensitive, [ TrueClass, FalseClass ], default: false, coerce: proc { |x| password ? true : x }
134
134
 
135
+ property :elevated, [ TrueClass, FalseClass ], default: false
136
+
135
137
  def self.set_guard_inherited_attributes(*inherited_attributes)
136
138
  @class_inherited_attributes = inherited_attributes
137
139
  end
@@ -149,21 +151,29 @@ class Chef
149
151
  end
150
152
 
151
153
  def after_created
152
- validate_identity_platform(user, password, domain)
154
+ validate_identity_platform(user, password, domain, elevated)
153
155
  identity = qualify_user(user, password, domain)
154
156
  domain(identity[:domain])
155
157
  user(identity[:user])
156
158
  end
157
159
 
158
- def validate_identity_platform(specified_user, password = nil, specified_domain = nil)
160
+ def validate_identity_platform(specified_user, password = nil, specified_domain = nil, elevated = false)
159
161
  if node[:platform_family] == "windows"
160
162
  if specified_user && password.nil?
161
163
  raise ArgumentError, "A value for `password` must be specified when a value for `user` is specified on the Windows platform"
162
164
  end
165
+
166
+ if elevated && !specified_user && !password
167
+ raise ArgumentError, "`elevated` option should be passed only with `username` and `password`."
168
+ end
163
169
  else
164
170
  if password || specified_domain
165
171
  raise Exceptions::UnsupportedPlatform, "Values for `domain` and `password` are only supported on the Windows platform"
166
172
  end
173
+
174
+ if elevated
175
+ raise Exceptions::UnsupportedPlatform, "Value for `elevated` is only supported on the Windows platform"
176
+ end
167
177
  end
168
178
  end
169
179
 
@@ -27,7 +27,7 @@ class Chef
27
27
  identity_attr :url
28
28
 
29
29
  default_action :get
30
- allowed_actions :get, :put, :post, :delete, :head, :options
30
+ allowed_actions :get, :patch, :put, :post, :delete, :head, :options
31
31
 
32
32
  def initialize(name, run_context = nil)
33
33
  super
@@ -0,0 +1,51 @@
1
+ #
2
+ # Author:: Tim Smith (<tsmith@chef.io>)
3
+ # Copyright:: Copyright (c) 2017 Chef Software, 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/resource"
20
+
21
+ class Chef
22
+ class Resource
23
+ class ZypperRepository < Chef::Resource
24
+ resource_name :zypper_repository
25
+ provides :zypper_repo
26
+
27
+ property :repo_name, String, name_property: true
28
+ property :description, String
29
+ property :type, String, default: "NONE"
30
+ property :enabled, [true, false], default: true
31
+ property :autorefresh, [true, false], default: true
32
+ property :gpgcheck, [true, false], default: true
33
+ property :gpgkey, String
34
+ property :baseurl, String
35
+ property :mirrorlist, String
36
+ property :path, String
37
+ property :priority, Integer, default: 99
38
+ property :keeppackages, [true, false], default: false
39
+ property :mode, default: "0644"
40
+ property :refresh_cache, [true, false], default: true
41
+ property :source, String, regex: /.*/
42
+
43
+ default_action :create
44
+ allowed_actions :create, :remove, :add, :refresh
45
+
46
+ # provide compatibility with the zypper cookbook
47
+ alias_method :key, :gpgkey
48
+ alias_method :uri, :baseurl
49
+ end
50
+ end
51
+ end
@@ -17,6 +17,7 @@
17
17
  #
18
18
 
19
19
  require "chef/resource/apt_package"
20
+ require "chef/resource/apt_preference"
20
21
  require "chef/resource/apt_repository"
21
22
  require "chef/resource/apt_update"
22
23
  require "chef/resource/bash"
@@ -95,6 +96,7 @@ require "chef/resource/yum_repository"
95
96
  require "chef/resource/lwrp_base"
96
97
  require "chef/resource/bff_package"
97
98
  require "chef/resource/zypper_package"
99
+ require "chef/resource/zypper_repository"
98
100
  require "chef/resource/cab_package"
99
101
  require "chef/resource/powershell_package"
100
102
  require "chef/resource/msu_package"
@@ -71,6 +71,11 @@ class Chef
71
71
  args_h = args_h.reject { |k, v| k == :fuzz }
72
72
  end
73
73
 
74
+ # Set default rows parameter to 1000. This is the default in
75
+ # Chef Server, but we set it explicitly here so that we can
76
+ # confidently advance our start parameter.
77
+ args_h[:rows] ||= 1000
78
+
74
79
  response = call_rest_service(type, query: query, **args_h)
75
80
 
76
81
  if block
@@ -87,7 +92,7 @@ class Chef
87
92
  # args_h[:rows] to avoid asking the search backend for
88
93
  # overlapping pages (which could result in duplicates).
89
94
  #
90
- next_start = response["start"] + (args_h[:rows] || response["rows"].length)
95
+ next_start = response["start"] + args_h[:rows]
91
96
  unless next_start >= response["total"]
92
97
  args_h[:start] = next_start
93
98
  search(type, query, args_h, &block)
@@ -26,15 +26,34 @@ class Chef
26
26
  end
27
27
 
28
28
  def min_server_version
29
- !@versions.nil? ? Integer(@versions["min_version"]) : nil
29
+ # If we're working with a pre-api-versioning server, always claim to be zero
30
+ if @versions.nil?
31
+ unversioned? ? 0 : nil
32
+ else
33
+ Integer(@versions["min_version"])
34
+ end
30
35
  end
31
36
 
32
37
  def max_server_version
33
- !@versions.nil? ? Integer(@versions["max_version"]) : nil
38
+ # If we're working with a pre-api-versioning server, always claim to be zero
39
+ if @versions.nil?
40
+ unversioned? ? 0 : nil
41
+ else
42
+ Integer(@versions["max_version"])
43
+ end
44
+ end
45
+
46
+ def unversioned!
47
+ @unversioned = true
48
+ end
49
+
50
+ def unversioned?
51
+ @unversioned
34
52
  end
35
53
 
36
54
  def reset!
37
55
  @versions = nil
56
+ @unversioned = false
38
57
  end
39
58
  end
40
59
  end
@@ -14,16 +14,15 @@
14
14
  # limitations under the License.
15
15
 
16
16
  #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
17
- # NOTE: This file is generated by running `rake version` in the top level of
18
- # this repo. Do not edit this manually. Edit the VERSION file and run the rake
19
- # task instead.
17
+ # NOTE: This file is modified via the `.expeditor/update_version.sh` script, which
18
+ # is triggered automatically by Chef Expeditor when a Pull Request is merged.
20
19
  #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
21
20
 
22
21
  require "chef/version_string"
23
22
 
24
23
  class Chef
25
24
  CHEF_ROOT = File.expand_path("../..", __FILE__)
26
- VERSION = Chef::VersionString.new("13.2.20")
25
+ VERSION = Chef::VersionString.new("13.3.42")
27
26
  end
28
27
 
29
28
  #
@@ -67,6 +67,7 @@ class Chef
67
67
  MAX_PATH = 260
68
68
 
69
69
  SYMBOLIC_LINK_FLAG_DIRECTORY = 0x1
70
+ SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE = 0x2
70
71
 
71
72
  FILE_NAME_NORMALIZED = 0x0
72
73
  FILE_NAME_OPENED = 0x8
@@ -22,6 +22,7 @@ require "chef/win32/api/file"
22
22
  require "chef/win32/api/security"
23
23
  require "chef/win32/error"
24
24
  require "chef/win32/unicode"
25
+ require "chef/win32/version"
25
26
 
26
27
  class Chef
27
28
  module ReservedNames::Win32
@@ -60,6 +61,7 @@ class Chef
60
61
  # TODO do a check for CreateSymbolicLinkW and
61
62
  # raise NotImplemented exception on older Windows
62
63
  flags = ::File.directory?(old_name) ? SYMBOLIC_LINK_FLAG_DIRECTORY : 0
64
+ flags |= SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE if Chef::ReservedNames::Win32::Version.new.win_10_creators_or_higher?
63
65
  old_name = encode_path(old_name)
64
66
  new_name = encode_path(new_name)
65
67
  unless CreateSymbolicLinkW(new_name, old_name, flags)
@@ -30,6 +30,8 @@ class Chef
30
30
  include Chef::ReservedNames::Win32::API::Macros
31
31
  include Chef::ReservedNames::Win32::API::System
32
32
 
33
+ attr_reader :major_version, :minor_version, :build_number
34
+
33
35
  # Ruby implementation of
34
36
  # http://msdn.microsoft.com/en-us/library/ms724833(v=vs.85).aspx
35
37
  # http://msdn.microsoft.com/en-us/library/ms724358(v=vs.85).aspx
@@ -114,6 +116,10 @@ class Chef
114
116
  end
115
117
  end
116
118
 
119
+ def win_10_creators_or_higher?
120
+ windows_10? && build_number >= 15063
121
+ end
122
+
117
123
  private
118
124
 
119
125
  def get_version
@@ -304,7 +304,7 @@ describe Chef::Knife::Ssh do
304
304
  Chef::Config[:client_key] = nil
305
305
  Chef::Config[:chef_server_url] = "http://localhost:9000"
306
306
 
307
- @api.post("/search/node?q=*:*&start=0", 200) do
307
+ @api.post("/search/node?q=*:*&start=0&rows=1000", 200) do
308
308
  %({"total":1, "start":0, "rows":[{"data": {"fqdn":"the.fqdn", "config": "the_public_hostname", "knife_config": "the_public_hostname" }}]})
309
309
  end
310
310
  end
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Serdar Sutay (<serdar@chef.io>)
3
- # Copyright:: Copyright 2014-2016, Chef Software Inc.
3
+ # Copyright:: Copyright 2014-2017, Chef Software Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -51,7 +51,7 @@ describe Chef::Resource::Execute do
51
51
 
52
52
  # why_run mode doesn't disable the updated_by_last_action logic, so we really have to look at the provider action
53
53
  # to see if why_run correctly disabled the resource. It should shell_out! for the guard but not the resource.
54
- expect_any_instance_of(Chef::Provider::Execute).to receive(:shell_out!).once
54
+ expect_any_instance_of(Chef::Provider::Execute).to receive(:shell_out_with_systems_locale!).once
55
55
 
56
56
  resource.only_if guard
57
57
  resource.run_action(:run)
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Adam Jacob (<adam@chef.io>)
3
- # Copyright:: Copyright 2008-2016, Chef Software, Inc.
3
+ # Copyright:: Copyright 2008-2017, Chef Software Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -30,6 +30,8 @@ $:.unshift File.expand_path("../..", __FILE__)
30
30
  require "rubygems"
31
31
  require "rspec/mocks"
32
32
 
33
+ require "webmock/rspec"
34
+
33
35
  $:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
34
36
  $:.unshift(File.expand_path("../lib", __FILE__))
35
37
  $:.unshift(File.dirname(__FILE__))
@@ -215,6 +217,11 @@ RSpec.configure do |config|
215
217
  config.run_all_when_everything_filtered = true
216
218
 
217
219
  config.before(:each) do
220
+ # it'd be nice to run this with connections blocked or only to localhost, but we do make lots
221
+ # of real connections, so cannot. we reset it to allow connections every time to avoid
222
+ # tests setting connections to be disabled and that state leaking into other tests.
223
+ WebMock.allow_net_connect!
224
+
218
225
  Chef.reset!
219
226
 
220
227
  Chef::ChefFS::FileSystemCache.instance.reset!
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # Author:: Adam Jacob (<adam@chef.io>)
3
3
  # Author:: Seth Falcon (<seth@chef.io>)
4
- # Copyright:: Copyright 2008-2016, Chef Software, Inc.
4
+ # Copyright:: Copyright 2008-2017, Chef Software Inc.
5
5
  # License:: Apache License, Version 2.0
6
6
  #
7
7
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -98,11 +98,11 @@ describe Chef::Cookbook::Metadata do
98
98
  end
99
99
 
100
100
  it "has an empty maintainer field" do
101
- expect(metadata.maintainer).to eq(nil)
101
+ expect(metadata.maintainer).to eq("")
102
102
  end
103
103
 
104
104
  it "has an empty maintainer_email field" do
105
- expect(metadata.maintainer).to eq(nil)
105
+ expect(metadata.maintainer_email).to eq("")
106
106
  end
107
107
 
108
108
  it "has an empty platforms list" do