chef 12.11.18-universal-mingw32 → 12.12.13-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -4
  3. data/Rakefile +3 -2
  4. data/VERSION +1 -1
  5. data/acceptance/Gemfile.lock +22 -23
  6. data/acceptance/data-collector/test/integration/default/serverspec/default_spec.rb +2 -41
  7. data/lib/chef/application/solo.rb +7 -0
  8. data/lib/chef/chef_fs/file_system/multiplexed_dir.rb +1 -1
  9. data/lib/chef/data_collector.rb +79 -43
  10. data/lib/chef/data_collector/messages.rb +4 -33
  11. data/lib/chef/data_collector/messages/helpers.rb +2 -2
  12. data/lib/chef/data_collector/resource_report.rb +21 -11
  13. data/lib/chef/decorator/unchain.rb +43 -0
  14. data/lib/chef/exceptions.rb +5 -0
  15. data/lib/chef/http.rb +5 -5
  16. data/lib/chef/knife/cookbook_create.rb +4 -0
  17. data/lib/chef/knife/cookbook_site_download.rb +8 -1
  18. data/lib/chef/knife/cookbook_site_install.rb +8 -0
  19. data/lib/chef/knife/cookbook_site_list.rb +8 -1
  20. data/lib/chef/knife/cookbook_site_search.rb +8 -1
  21. data/lib/chef/knife/cookbook_site_share.rb +8 -1
  22. data/lib/chef/knife/cookbook_site_show.rb +14 -3
  23. data/lib/chef/knife/cookbook_site_unshare.rb +8 -1
  24. data/lib/chef/knife/core/bootstrap_context.rb +1 -1
  25. data/lib/chef/knife/supermarket_download.rb +33 -0
  26. data/lib/chef/knife/supermarket_install.rb +33 -0
  27. data/lib/chef/knife/supermarket_list.rb +33 -0
  28. data/lib/chef/knife/supermarket_search.rb +33 -0
  29. data/lib/chef/knife/supermarket_share.rb +33 -0
  30. data/lib/chef/knife/supermarket_show.rb +33 -0
  31. data/lib/chef/knife/supermarket_unshare.rb +33 -0
  32. data/lib/chef/node.rb +13 -32
  33. data/lib/chef/node/attribute.rb +123 -70
  34. data/lib/chef/node/attribute_collections.rb +9 -130
  35. data/lib/chef/node/common_api.rb +124 -0
  36. data/lib/chef/node/immutable_collections.rb +27 -2
  37. data/lib/chef/property.rb +6 -2
  38. data/lib/chef/provider.rb +4 -5
  39. data/lib/chef/provider/batch.rb +1 -1
  40. data/lib/chef/provider/directory.rb +3 -1
  41. data/lib/chef/provider/package/openbsd.rb +1 -1
  42. data/lib/chef/provider/package/rubygems.rb +9 -3
  43. data/lib/chef/provider/package/windows/exe.rb +2 -5
  44. data/lib/chef/provider/powershell_script.rb +1 -1
  45. data/lib/chef/provider/remote_directory.rb +2 -0
  46. data/lib/chef/resource.rb +22 -17
  47. data/lib/chef/resource_builder.rb +9 -4
  48. data/lib/chef/shell.rb +1 -1
  49. data/lib/chef/version.rb +1 -1
  50. data/spec/data/run_context/cookbooks/circular-dep1/attributes/default.rb +2 -4
  51. data/spec/data/run_context/cookbooks/circular-dep2/attributes/default.rb +2 -3
  52. data/spec/data/run_context/cookbooks/dependency1/attributes/aa_first.rb +2 -2
  53. data/spec/data/run_context/cookbooks/dependency1/attributes/default.rb +2 -2
  54. data/spec/data/run_context/cookbooks/dependency1/attributes/zz_last.rb +2 -3
  55. data/spec/data/run_context/cookbooks/dependency2/attributes/default.rb +2 -3
  56. data/spec/data/run_context/cookbooks/no-default-attr/attributes/server.rb +2 -3
  57. data/spec/data/run_context/cookbooks/test-with-circular-deps/attributes/default.rb +2 -3
  58. data/spec/data/run_context/cookbooks/test-with-deps/attributes/default.rb +2 -3
  59. data/spec/functional/assets/chocolatey_feed/test-A.1.0.nupkg +0 -0
  60. data/spec/functional/assets/chocolatey_feed/test-A.1.5.nupkg +0 -0
  61. data/spec/functional/assets/chocolatey_feed/test-A.2.0.nupkg +0 -0
  62. data/spec/functional/assets/chocolatey_feed/test-B.1.0.nupkg +0 -0
  63. data/spec/functional/resource/dsc_script_spec.rb +1 -0
  64. data/spec/functional/resource/package_spec.rb +1 -1
  65. data/spec/functional/resource/template_spec.rb +3 -3
  66. data/spec/functional/shell_spec.rb +1 -1
  67. data/spec/integration/knife/client_bulk_delete_spec.rb +130 -0
  68. data/spec/integration/knife/client_create_spec.rb +69 -0
  69. data/spec/integration/knife/client_delete_spec.rb +63 -0
  70. data/spec/integration/knife/client_key_create_spec.rb +65 -0
  71. data/spec/integration/knife/client_key_delete_spec.rb +42 -0
  72. data/spec/integration/knife/client_key_list_spec.rb +60 -0
  73. data/spec/integration/knife/client_key_show_spec.rb +44 -0
  74. data/spec/integration/knife/client_list_spec.rb +48 -0
  75. data/spec/integration/knife/client_show_spec.rb +36 -0
  76. data/spec/integration/knife/cookbook_bulk_delete_spec.rb +64 -0
  77. data/spec/integration/knife/cookbook_download_spec.rb +95 -0
  78. data/spec/integration/knife/cookbook_list_spec.rb +54 -0
  79. data/spec/integration/knife/cookbook_show_spec.rb +159 -0
  80. data/spec/integration/knife/cookbook_upload_spec.rb +90 -0
  81. data/spec/integration/knife/data_bag_create_spec.rb +58 -0
  82. data/spec/integration/knife/data_bag_delete_spec.rb +58 -0
  83. data/spec/integration/knife/data_bag_from_file_spec.rb +115 -0
  84. data/spec/integration/knife/data_bag_list_spec.rb +43 -0
  85. data/spec/integration/knife/data_bag_show_spec.rb +53 -0
  86. data/spec/integration/knife/environment_compare_spec.rb +74 -0
  87. data/spec/integration/knife/environment_create_spec.rb +40 -0
  88. data/spec/integration/knife/environment_delete_spec.rb +36 -0
  89. data/spec/integration/knife/environment_from_file_spec.rb +115 -0
  90. data/spec/integration/knife/environment_list_spec.rb +41 -0
  91. data/spec/integration/knife/environment_show_spec.rb +56 -0
  92. data/spec/integration/knife/node_bulk_delete_spec.rb +51 -0
  93. data/spec/integration/knife/node_create_spec.rb +46 -0
  94. data/spec/integration/knife/node_delete_spec.rb +47 -0
  95. data/spec/integration/knife/node_environment_set_spec.rb +42 -0
  96. data/spec/integration/knife/node_from_file_spec.rb +58 -0
  97. data/spec/integration/knife/node_list_spec.rb +44 -0
  98. data/spec/integration/knife/node_run_list_add_spec.rb +53 -0
  99. data/spec/integration/knife/node_run_list_remove_spec.rb +35 -0
  100. data/spec/integration/knife/node_run_list_set_spec.rb +40 -0
  101. data/spec/integration/knife/node_show_spec.rb +35 -0
  102. data/spec/integration/knife/role_bulk_delete_spec.rb +51 -0
  103. data/spec/integration/knife/role_create_spec.rb +40 -0
  104. data/spec/integration/knife/role_delete_spec.rb +47 -0
  105. data/spec/integration/knife/role_from_file_spec.rb +95 -0
  106. data/spec/integration/knife/role_list_spec.rb +44 -0
  107. data/spec/integration/knife/role_show_spec.rb +50 -0
  108. data/spec/support/shared/integration/knife_support.rb +10 -3
  109. data/spec/unit/application/solo_spec.rb +7 -0
  110. data/spec/unit/cookbook_version_spec.rb +4 -4
  111. data/spec/unit/data_collector/messages/helpers_spec.rb +3 -7
  112. data/spec/unit/data_collector/messages_spec.rb +28 -45
  113. data/spec/unit/data_collector_spec.rb +40 -47
  114. data/spec/unit/knife/cookbook_create_spec.rb +1 -0
  115. data/spec/unit/knife/cookbook_site_download_spec.rb +1 -0
  116. data/spec/unit/knife/node_environment_set_spec.rb +0 -24
  117. data/spec/unit/knife/node_run_list_set_spec.rb +0 -25
  118. data/spec/unit/node/attribute_spec.rb +7 -9
  119. data/spec/unit/node/immutable_collections_spec.rb +4 -0
  120. data/spec/unit/node/vivid_mash_spec.rb +344 -0
  121. data/spec/unit/node_spec.rb +115 -26
  122. data/spec/unit/provider/directory_spec.rb +11 -1
  123. data/spec/unit/provider/package/windows/exe_spec.rb +14 -9
  124. data/spec/unit/provider/powershell_script_spec.rb +4 -4
  125. data/spec/unit/provider/remote_directory_spec.rb +15 -0
  126. data/spec/unit/recipe_spec.rb +31 -6
  127. data/spec/unit/run_context_spec.rb +2 -2
  128. data/spec/unit/shell/shell_session_spec.rb +1 -1
  129. data/tasks/dependencies.rb +0 -2
  130. metadata +55 -786
  131. data/acceptance/.bundle/config +0 -2
  132. data/acceptance/basics/.kitchen/logs/chef-current-install-ubuntu-1404.log +0 -2
  133. data/acceptance/basics/.kitchen/logs/kitchen.log +0 -3
  134. data/acceptance/fips/.kitchen/logs/fips-integration-centos-6.log +0 -3
  135. data/acceptance/fips/.kitchen/logs/fips-integration-windows-2012r2.log +0 -3
  136. data/acceptance/fips/.kitchen/logs/fips-unit-functional-centos-6.log +0 -3
  137. data/acceptance/fips/.kitchen/logs/fips-unit-functional-windows-2012r2.log +0 -3
  138. data/acceptance/fips/.kitchen/logs/kitchen.log +0 -6
  139. data/acceptance/trivial/.kitchen/logs/chef-current-install-windows-2012r2.log +0 -2
  140. data/acceptance/trivial/.kitchen/logs/kitchen.log +0 -3
  141. data/acceptance/windows-service/.kitchen/logs/chef-windows-service-windows-2012r2.log +0 -2
  142. data/acceptance/windows-service/.kitchen/logs/kitchen.log +0 -3
@@ -145,7 +145,9 @@ class Chef
145
145
  if ::File.exists?(@new_resource.path)
146
146
  converge_by("delete existing directory #{@new_resource.path}") do
147
147
  if @new_resource.recursive == true
148
- FileUtils.rm_rf(@new_resource.path)
148
+ # we don't use rm_rf here because it masks all errors, including
149
+ # IO errors or permission errors that would prvent the deletion
150
+ FileUtils.rm_r(@new_resource.path)
149
151
  Chef::Log.info("#{@new_resource} deleted #{@new_resource.path} recursively")
150
152
  else
151
153
  ::Dir.delete(@new_resource.path)
@@ -127,7 +127,7 @@ class Chef
127
127
  end
128
128
 
129
129
  def pkg_path
130
- ENV["PKG_PATH"] || "http://ftp.OpenBSD.org/pub/#{node.kernel.name}/#{node.kernel.release}/packages/#{node.kernel.machine}/"
130
+ ENV["PKG_PATH"] || "http://ftp.OpenBSD.org/pub/#{node["kernel"]["name"]}/#{node["kernel"]["release"]}/packages/#{node["kernel"]["machine"]}/"
131
131
  end
132
132
 
133
133
  end
@@ -431,17 +431,23 @@ class Chef
431
431
  end
432
432
 
433
433
  def current_version
434
- #raise 'todo'
434
+ # rubygems 2.6.3 ensures that gem lists are sorted newest first
435
+ pos = if Gem::Version.new(Gem::VERSION) >= Gem::Version.new("2.6.3")
436
+ :first
437
+ else
438
+ :last
439
+ end
440
+
435
441
  # If one or more matching versions are installed, the newest of them
436
442
  # is the current version
437
443
  if !matching_installed_versions.empty?
438
- gemspec = matching_installed_versions.last
444
+ gemspec = matching_installed_versions.send(pos)
439
445
  logger.debug { "#{@new_resource} found installed gem #{gemspec.name} version #{gemspec.version} matching #{gem_dependency}" }
440
446
  gemspec
441
447
  # If no version matching the requirements exists, the latest installed
442
448
  # version is the current version.
443
449
  elsif !all_installed_versions.empty?
444
- gemspec = all_installed_versions.last
450
+ gemspec = all_installed_versions.send(pos)
445
451
  logger.debug { "#{@new_resource} newest installed version of gem #{gemspec.name} is #{gemspec.version}" }
446
452
  gemspec
447
453
  else
@@ -78,12 +78,9 @@ class Chef
78
78
  private
79
79
 
80
80
  def uninstall_command(uninstall_string)
81
- uninstall_string.delete!('"')
81
+ uninstall_string = "\"#{uninstall_string}\"" if ::File.exist?(uninstall_string)
82
82
  uninstall_string = [
83
- %q{/d"},
84
- ::File.dirname(uninstall_string),
85
- %q{" },
86
- ::File.basename(uninstall_string),
83
+ uninstall_string,
87
84
  expand_options(new_resource.options),
88
85
  " ",
89
86
  unattended_flags,
@@ -36,7 +36,7 @@ class Chef
36
36
  end
37
37
 
38
38
  def command
39
- basepath = is_forced_32bit ? wow64_directory : run_context.node.kernel.os_info.system_directory
39
+ basepath = is_forced_32bit ? wow64_directory : run_context.node["kernel"]["os_info"]["system_directory"]
40
40
 
41
41
  # Powershell.exe is always in "v1.0" folder (for backwards compatibility)
42
42
  interpreter_path = Chef::Util::PathHelper.join(basepath, "WindowsPowerShell", "v1.0", interpreter)
@@ -209,6 +209,8 @@ class Chef
209
209
  def cookbook_file_resource(target_path, relative_source_path)
210
210
  res = Chef::Resource::CookbookFile.new(target_path, run_context)
211
211
  res.cookbook_name = resource_cookbook
212
+ # Set the sensitivity level
213
+ res.sensitive(new_resource.sensitive)
212
214
  res.source(::File.join(source, relative_source_path))
213
215
  if Chef::Platform.windows? && files_rights
214
216
  files_rights.each_pair do |permission, *args|
@@ -1529,23 +1529,6 @@ class Chef
1529
1529
  Chef::ResourceResolver.resolve(short_name, canonical: true)
1530
1530
  end
1531
1531
 
1532
- # @api private
1533
- def self.register_deprecated_lwrp_class(resource_class, class_name)
1534
- if Chef::Resource.const_defined?(class_name, false)
1535
- Chef::Log.warn "#{class_name} already exists! Deprecation class overwrites #{resource_class}"
1536
- Chef::Resource.send(:remove_const, class_name)
1537
- end
1538
-
1539
- if !Chef::Config[:treat_deprecation_warnings_as_errors]
1540
- Chef::Resource.const_set(class_name, resource_class)
1541
- deprecated_constants[class_name.to_sym] = resource_class
1542
- end
1543
- end
1544
-
1545
- def self.deprecated_constants
1546
- @deprecated_constants ||= {}
1547
- end
1548
-
1549
1532
  # @api private
1550
1533
  def lookup_provider_constant(name, action = :nothing)
1551
1534
  begin
@@ -1559,6 +1542,27 @@ class Chef
1559
1542
  end
1560
1543
  end
1561
1544
 
1545
+ module DeprecatedLWRPClass
1546
+
1547
+ # @api private
1548
+ def register_deprecated_lwrp_class(resource_class, class_name)
1549
+ if Chef::Resource.const_defined?(class_name, false)
1550
+ Chef::Log.warn "#{class_name} already exists! Deprecation class overwrites #{resource_class}"
1551
+ Chef::Resource.send(:remove_const, class_name)
1552
+ end
1553
+
1554
+ if !Chef::Config[:treat_deprecation_warnings_as_errors]
1555
+ Chef::Resource.const_set(class_name, resource_class)
1556
+ Chef::Resource.deprecated_constants[class_name.to_sym] = resource_class
1557
+ end
1558
+ end
1559
+
1560
+ def deprecated_constants
1561
+ raise "Deprecated constants should be called only on Chef::Resource" unless self == Chef::Resource
1562
+ @deprecated_constants ||= {}
1563
+ end
1564
+ end
1565
+
1562
1566
  private
1563
1567
 
1564
1568
  def self.remove_canonical_dsl
@@ -1569,6 +1573,7 @@ class Chef
1569
1573
  end
1570
1574
  end
1571
1575
  end
1576
+ extend DeprecatedLWRPClass
1572
1577
  end
1573
1578
  end
1574
1579
 
@@ -104,7 +104,11 @@ class Chef
104
104
  end
105
105
 
106
106
  def is_trivial_resource?(resource)
107
- identicalish_resources?(resource_class.new(name, run_context), resource)
107
+ trivial_resource = resource_class.new(name, run_context)
108
+ # force un-lazy the name property on the created trivial resource
109
+ name_property = resource_class.properties.find { |sym, p| p.name_property? }
110
+ trivial_resource.send(name_property[0]) unless name_property.nil?
111
+ identicalish_resources?(trivial_resource, resource)
108
112
  end
109
113
 
110
114
  # this is an equality test specific to checking for 3694 cloning warnings
@@ -124,9 +128,10 @@ class Chef
124
128
  end
125
129
 
126
130
  def emit_cloned_resource_warning
127
- Chef::Log.warn("Cloning resource attributes for #{resource} from prior resource (CHEF-3694)")
128
- Chef::Log.warn("Previous #{prior_resource}: #{prior_resource.source_line}") if prior_resource.source_line
129
- Chef::Log.warn("Current #{resource}: #{resource.source_line}") if resource.source_line
131
+ message = "Cloning resource attributes for #{resource} from prior resource (CHEF-3694)"
132
+ message << "\nPrevious #{prior_resource}: #{prior_resource.source_line}" if prior_resource.source_line
133
+ message << "\nCurrent #{resource}: #{resource.source_line}" if resource.source_line
134
+ Chef.log_deprecation(message)
130
135
  end
131
136
 
132
137
  def emit_harmless_cloning_debug
@@ -148,7 +148,7 @@ module Shell
148
148
  end
149
149
 
150
150
  def self.greeting
151
- " #{Etc.getlogin}@#{Shell.session.node.fqdn}"
151
+ " #{Etc.getlogin}@#{Shell.session.node["fqdn"]}"
152
152
  rescue NameError, ArgumentError
153
153
  ""
154
154
  end
@@ -21,7 +21,7 @@
21
21
 
22
22
  class Chef
23
23
  CHEF_ROOT = File.expand_path("../..", __FILE__)
24
- VERSION = "12.11.18"
24
+ VERSION = "12.12.13"
25
25
  end
26
26
 
27
27
  #
@@ -1,4 +1,2 @@
1
- set_unless[:attr_load_order] = []
2
- set[:attr_load_order] << "circular-dep1::default"
3
-
4
-
1
+ normal_unless[:attr_load_order] = []
2
+ normal[:attr_load_order] << "circular-dep1::default"
@@ -1,3 +1,2 @@
1
- set_unless[:attr_load_order] = []
2
- set[:attr_load_order] << "circular-dep2::default"
3
-
1
+ normal_unless[:attr_load_order] = []
2
+ normal[:attr_load_order] << "circular-dep2::default"
@@ -1,2 +1,2 @@
1
- set_unless[:attr_load_order] = []
2
- set[:attr_load_order] << "dependency1::aa_first"
1
+ normal_unless[:attr_load_order] = []
2
+ normal[:attr_load_order] << "dependency1::aa_first"
@@ -1,2 +1,2 @@
1
- set_unless[:attr_load_order] = []
2
- set[:attr_load_order] << "dependency1::default"
1
+ normal_unless[:attr_load_order] = []
2
+ normal[:attr_load_order] << "dependency1::default"
@@ -1,3 +1,2 @@
1
- set_unless[:attr_load_order] = []
2
- set[:attr_load_order] << "dependency1::zz_last"
3
-
1
+ normal_unless[:attr_load_order] = []
2
+ normal[:attr_load_order] << "dependency1::zz_last"
@@ -1,3 +1,2 @@
1
- set_unless[:attr_load_order] = []
2
- set[:attr_load_order] << "dependency2::default"
3
-
1
+ normal_unless[:attr_load_order] = []
2
+ normal[:attr_load_order] << "dependency2::default"
@@ -1,3 +1,2 @@
1
- set_unless[:attr_load_order] = []
2
- set[:attr_load_order] << "no-default-attr::server"
3
-
1
+ normal_unless[:attr_load_order] = []
2
+ normal[:attr_load_order] << "no-default-attr::server"
@@ -1,3 +1,2 @@
1
- set_unless[:attr_load_order] = []
2
- set[:attr_load_order] << "test-with-circular-deps::default"
3
-
1
+ normal_unless[:attr_load_order] = []
2
+ normal[:attr_load_order] << "test-with-circular-deps::default"
@@ -1,3 +1,2 @@
1
- set_unless[:attr_load_order] = []
2
- set[:attr_load_order] << "test-with-deps::default"
3
-
1
+ normal_unless[:attr_load_order] = []
2
+ normal[:attr_load_order] << "test-with-deps::default"
@@ -469,6 +469,7 @@ EOF
469
469
  end
470
470
 
471
471
  it "allows the use of ps_credential" do
472
+ skip("Skipped until we can adjust the test cert to meet the WMF 5 cert requirements.")
472
473
  expect(user_exists?(dsc_user)).to eq(false)
473
474
  powershell_script_resource.run_action(:run)
474
475
  expect(File).to exist(configuration_data_path)
@@ -260,7 +260,7 @@ describe Chef::Resource::Package, metadata do
260
260
  end
261
261
 
262
262
  before do
263
- node.set[:preseed_value] = "FROM TEMPLATE"
263
+ node.normal[:preseed_value] = "FROM TEMPLATE"
264
264
  end
265
265
 
266
266
  it "preseeds the package, then installs it" do
@@ -110,7 +110,7 @@ describe Chef::Resource::Template do
110
110
 
111
111
  context "using single helper syntax referencing @node" do
112
112
  before do
113
- node.set[:helper_test_attr] = "value from helper method"
113
+ node.normal[:helper_test_attr] = "value from helper method"
114
114
  resource.helper(:helper_method) { "#{@node[:helper_test_attr]}" }
115
115
  end
116
116
 
@@ -131,7 +131,7 @@ describe Chef::Resource::Template do
131
131
 
132
132
  context "using an inline block referencing @node" do
133
133
  before do
134
- node.set[:helper_test_attr] = "value from helper method"
134
+ node.normal[:helper_test_attr] = "value from helper method"
135
135
 
136
136
  resource.helpers do
137
137
  def helper_method
@@ -168,7 +168,7 @@ describe Chef::Resource::Template do
168
168
  end
169
169
 
170
170
  before do
171
- node.set[:helper_test_attr] = "value from helper method"
171
+ node.normal[:helper_test_attr] = "value from helper method"
172
172
 
173
173
  resource.helpers(ExampleModuleReferencingATNode)
174
174
  end
@@ -137,7 +137,7 @@ describe Shell do
137
137
 
138
138
  it "sets the override_runlist from the command line" do
139
139
  output, exitstatus = run_chef_shell_with("-o 'override::foo,override::bar'") do |out, keyboard|
140
- show_recipes_code = %q[puts "#{node.recipes.inspect}"]
140
+ show_recipes_code = %q[puts "#{node["recipes"].inspect}"]
141
141
  keyboard.puts(show_recipes_code)
142
142
  read_until(out, show_recipes_code)
143
143
  end
@@ -0,0 +1,130 @@
1
+ #
2
+ # Copyright:: Copyright 2013-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
+ require "support/shared/integration/integration_helper"
18
+ require "support/shared/context/config"
19
+
20
+ describe "knife client bulk delete", :workstation do
21
+ include IntegrationSupport
22
+ include KnifeSupport
23
+
24
+ include_context "default config options"
25
+
26
+ when_the_chef_server "has some clients" do
27
+ before do
28
+ client "concat", {}
29
+ client "cons", {}
30
+ client "car", {}
31
+ client "cdr", {}
32
+ client "cat", {}
33
+ end
34
+
35
+ it "deletes all matching clients" do
36
+ knife("client bulk delete ^ca.*", input: "Y").should_succeed <<EOM
37
+ The following clients will be deleted:
38
+
39
+ car cat
40
+
41
+ Are you sure you want to delete these clients? (Y/N) Deleted client car
42
+ Deleted client cat
43
+ EOM
44
+
45
+ knife("client list").should_succeed <<EOM
46
+ cdr
47
+ chef-validator
48
+ chef-webui
49
+ concat
50
+ cons
51
+ EOM
52
+ end
53
+
54
+ it "deletes all matching clients when unanchored" do
55
+ knife("client bulk delete ca.*", input: "Y").should_succeed <<EOM
56
+ The following clients will be deleted:
57
+
58
+ car cat concat
59
+
60
+ Are you sure you want to delete these clients? (Y/N) Deleted client car
61
+ Deleted client cat
62
+ Deleted client concat
63
+ EOM
64
+
65
+ knife("client list").should_succeed <<EOM
66
+ cdr
67
+ chef-validator
68
+ chef-webui
69
+ cons
70
+ EOM
71
+ end
72
+ end
73
+
74
+ when_the_chef_server "has a validator client" do
75
+ before do
76
+ client "cons", {}
77
+ client "car", {}
78
+ client "car-validator", { validator: true }
79
+ client "cdr", {}
80
+ client "cat", {}
81
+ end
82
+
83
+ it "refuses to delete a validator normally" do
84
+ knife("client bulk delete ^ca.*", input: "Y").should_succeed <<EOM
85
+ The following clients are validators and will not be deleted:
86
+
87
+ car-validator
88
+
89
+ You must specify --delete-validators to delete the validator clients
90
+ The following clients will be deleted:
91
+
92
+ car cat
93
+
94
+ Are you sure you want to delete these clients? (Y/N) Deleted client car
95
+ Deleted client cat
96
+ EOM
97
+
98
+ knife("client list").should_succeed <<EOM
99
+ car-validator
100
+ cdr
101
+ chef-validator
102
+ chef-webui
103
+ cons
104
+ EOM
105
+ end
106
+
107
+ it "deletes a validator when told to" do
108
+ knife("client bulk delete ^ca.* -D", input: "Y\nY").should_succeed <<EOM
109
+ The following validators will be deleted:
110
+
111
+ car-validator
112
+
113
+ Are you sure you want to delete these validators? (Y/N) Deleted client car-validator
114
+ The following clients will be deleted:
115
+
116
+ car cat
117
+
118
+ Are you sure you want to delete these clients? (Y/N) Deleted client car
119
+ Deleted client cat
120
+ EOM
121
+
122
+ knife("client list").should_succeed <<EOM
123
+ cdr
124
+ chef-validator
125
+ chef-webui
126
+ cons
127
+ EOM
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,69 @@
1
+ #
2
+ # Copyright:: Copyright 2013-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
+ require "support/shared/integration/integration_helper"
18
+ require "support/shared/context/config"
19
+ require "openssl"
20
+
21
+ describe "knife client create", :workstation do
22
+ include IntegrationSupport
23
+ include KnifeSupport
24
+
25
+ include_context "default config options"
26
+
27
+ let(:out) { "Created client[bah]\n" }
28
+
29
+ when_the_chef_server "is empty" do
30
+ it "creates a new client" do
31
+ knife("client create -k bah").should_succeed stderr: out
32
+ end
33
+
34
+ it "creates a new validator client" do
35
+ knife("client create -k --validator bah").should_succeed stderr: out
36
+ knife("client show bah").should_succeed <<EOM
37
+ admin: false
38
+ chef_type: client
39
+ name: bah
40
+ validator: true
41
+ EOM
42
+ end
43
+
44
+ it "refuses to add an existing client" do
45
+ pending "Knife client create must not blindly overwrite an existing client"
46
+ knife("client create -k bah").should_succeed stderr: out
47
+ expect { knife("client create -k bah") }.to raise_error(Net::HTTPServerException)
48
+ end
49
+
50
+ it "saves the private key to a file" do
51
+ Dir.mktmpdir do |tgt|
52
+ knife("client create -f #{tgt}/bah.pem bah").should_succeed stderr: out
53
+ expect(File).to exist("#{tgt}/bah.pem")
54
+ end
55
+ end
56
+
57
+ it "reads the public key from a file" do
58
+ Dir.mktmpdir do |tgt|
59
+ key = OpenSSL::PKey::RSA.generate(1024)
60
+ File.open("#{tgt}/public.pem", "w") { |pub| pub.write(key.public_key.to_pem) }
61
+ knife("client create -p #{tgt}/public.pem bah").should_succeed stderr: out
62
+ end
63
+ end
64
+
65
+ it "refuses to run if conflicting options are passed" do
66
+ knife("client create -p public.pem --prevent-keygen blah").should_fail stderr: "FATAL: You cannot pass --public-key and --prevent-keygen\n", stdout: /^USAGE.*/
67
+ end
68
+ end
69
+ end