chef 17.1.35-universal-mingw32 → 17.4.38-universal-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +6 -4
- data/chef.gemspec +1 -0
- data/lib/chef/action_collection.rb +6 -26
- data/lib/chef/application/base.rb +15 -0
- data/lib/chef/application.rb +4 -2
- data/lib/chef/client.rb +7 -1
- data/lib/chef/compliance/default_attributes.rb +5 -3
- data/lib/chef/compliance/reporter/automate.rb +1 -1
- data/lib/chef/compliance/runner.rb +16 -2
- data/lib/chef/cookbook_version.rb +26 -4
- data/lib/chef/data_collector/run_end_message.rb +1 -1
- data/lib/chef/data_collector.rb +0 -1
- data/lib/chef/deprecated.rb +14 -4
- data/lib/chef/dsl/render_helpers.rb +44 -0
- data/lib/chef/dsl/secret.rb +64 -0
- data/lib/chef/dsl/toml.rb +116 -0
- data/lib/chef/dsl/universal.rb +5 -0
- data/lib/chef/dsl.rb +1 -0
- data/lib/chef/event_dispatch/base.rb +2 -1
- data/lib/chef/exceptions.rb +23 -0
- data/lib/chef/formatters/doc.rb +14 -13
- data/lib/chef/formatters/error_mapper.rb +2 -2
- data/lib/chef/formatters/minimal.rb +6 -5
- data/lib/chef/handler/slow_report.rb +66 -0
- data/lib/chef/handler.rb +46 -8
- data/lib/chef/http.rb +5 -5
- data/lib/chef/json_compat.rb +1 -1
- data/lib/chef/node.rb +20 -19
- data/lib/chef/policy_builder/policyfile.rb +88 -45
- data/lib/chef/provider/execute.rb +1 -1
- data/lib/chef/provider/file.rb +2 -2
- data/lib/chef/provider/group/dscl.rb +1 -1
- data/lib/chef/provider/launchd.rb +6 -6
- data/lib/chef/provider/lwrp_base.rb +1 -1
- data/lib/chef/provider/package/habitat.rb +168 -0
- data/lib/chef/provider/package/powershell.rb +5 -0
- data/lib/chef/provider/subversion.rb +4 -4
- data/lib/chef/provider/support/yum_repo.erb +1 -1
- data/lib/chef/provider/support/zypper_repo.erb +4 -2
- data/lib/chef/provider/systemd_unit.rb +17 -16
- data/lib/chef/provider/user/mac.rb +3 -3
- data/lib/chef/provider/yum_repository.rb +27 -43
- data/lib/chef/provider/zypper_repository.rb +30 -34
- data/lib/chef/provider.rb +26 -1
- data/lib/chef/provider_resolver.rb +8 -2
- data/lib/chef/providers.rb +1 -0
- data/lib/chef/resource/alternatives.rb +5 -5
- data/lib/chef/resource/apt_preference.rb +2 -2
- data/lib/chef/resource/apt_repository.rb +2 -2
- data/lib/chef/resource/apt_update.rb +4 -4
- data/lib/chef/resource/build_essential.rb +1 -1
- data/lib/chef/resource/chef_client_config.rb +10 -5
- data/lib/chef/resource/chef_client_cron.rb +3 -3
- data/lib/chef/resource/chef_client_launchd.rb +3 -3
- data/lib/chef/resource/chef_client_scheduled_task.rb +15 -15
- data/lib/chef/resource/chef_client_systemd_timer.rb +3 -3
- data/lib/chef/resource/chef_client_trusted_certificate.rb +2 -2
- data/lib/chef/resource/chef_handler.rb +2 -2
- data/lib/chef/resource/chef_sleep.rb +1 -1
- data/lib/chef/resource/chef_vault_secret.rb +2 -2
- data/lib/chef/resource/chocolatey_feature.rb +2 -2
- data/lib/chef/resource/chocolatey_source.rb +1 -1
- data/lib/chef/resource/cron/cron_d.rb +4 -6
- data/lib/chef/resource/cron_access.rb +1 -1
- data/lib/chef/resource/dmg_package.rb +1 -1
- data/lib/chef/resource/dsc_resource.rb +1 -1
- data/lib/chef/resource/execute.rb +5 -5
- data/lib/chef/resource/gem_package.rb +2 -1
- data/lib/chef/resource/group.rb +4 -4
- data/lib/chef/resource/habitat/_habitat_shared.rb +28 -0
- data/lib/chef/resource/habitat/habitat_package.rb +129 -0
- data/lib/chef/resource/habitat/habitat_sup.rb +329 -0
- data/lib/chef/resource/habitat/habitat_sup_systemd.rb +67 -0
- data/lib/chef/resource/habitat/habitat_sup_windows.rb +90 -0
- data/lib/chef/resource/habitat_config.rb +107 -0
- data/lib/chef/resource/habitat_install.rb +247 -0
- data/lib/chef/resource/habitat_service.rb +451 -0
- data/lib/chef/resource/habitat_user_toml.rb +92 -0
- data/lib/chef/resource/homebrew_cask.rb +18 -7
- data/lib/chef/resource/homebrew_package.rb +1 -1
- data/lib/chef/resource/homebrew_tap.rb +4 -3
- data/lib/chef/resource/homebrew_update.rb +2 -2
- data/lib/chef/resource/hostname.rb +49 -7
- data/lib/chef/resource/inspec_waiver_file_entry.rb +8 -7
- data/lib/chef/resource/kernel_module.rb +6 -6
- data/lib/chef/resource/launchd.rb +3 -3
- data/lib/chef/resource/locale.rb +1 -1
- data/lib/chef/resource/lwrp_base.rb +1 -1
- data/lib/chef/resource/macos_userdefaults.rb +2 -2
- data/lib/chef/resource/ohai_hint.rb +2 -6
- data/lib/chef/resource/openbsd_package.rb +17 -0
- data/lib/chef/resource/openssl_dhparam.rb +1 -2
- data/lib/chef/resource/openssl_ec_private_key.rb +1 -3
- data/lib/chef/resource/openssl_ec_public_key.rb +1 -3
- data/lib/chef/resource/openssl_rsa_private_key.rb +1 -3
- data/lib/chef/resource/openssl_rsa_public_key.rb +1 -3
- data/lib/chef/resource/openssl_x509_certificate.rb +1 -4
- data/lib/chef/resource/openssl_x509_crl.rb +1 -3
- data/lib/chef/resource/openssl_x509_request.rb +1 -3
- data/lib/chef/resource/osx_profile.rb +3 -3
- data/lib/chef/resource/plist.rb +1 -1
- data/lib/chef/resource/powershell_package_source.rb +2 -4
- data/lib/chef/resource/reboot.rb +38 -9
- data/lib/chef/resource/remote_directory.rb +2 -2
- data/lib/chef/resource/remote_file.rb +1 -1
- data/lib/chef/resource/rhsm_errata.rb +0 -2
- data/lib/chef/resource/rhsm_errata_level.rb +1 -5
- data/lib/chef/resource/rhsm_repo.rb +15 -0
- data/lib/chef/resource/rhsm_subscription.rb +5 -5
- data/lib/chef/resource/ruby_block.rb +100 -0
- data/lib/chef/resource/scm/subversion.rb +1 -1
- data/lib/chef/resource/ssh_known_hosts_entry.rb +4 -7
- data/lib/chef/resource/sudo.rb +2 -6
- data/lib/chef/resource/support/HabService.dll.config.erb +19 -0
- data/lib/chef/resource/support/client.erb +8 -1
- data/lib/chef/resource/support/sup.toml.erb +179 -0
- data/lib/chef/resource/swap_file.rb +2 -6
- data/lib/chef/resource/sysctl.rb +2 -2
- data/lib/chef/resource/systemd_unit.rb +3 -3
- data/lib/chef/resource/timezone.rb +1 -1
- data/lib/chef/resource/user_ulimit.rb +2 -2
- data/lib/chef/resource/windows_ad_join.rb +2 -2
- data/lib/chef/resource/windows_audit_policy.rb +2 -2
- data/lib/chef/resource/windows_auto_run.rb +2 -2
- data/lib/chef/resource/windows_certificate.rb +1 -1
- data/lib/chef/resource/windows_defender.rb +163 -0
- data/lib/chef/resource/windows_defender_exclusion.rb +125 -0
- data/lib/chef/resource/windows_dfs_folder.rb +2 -2
- data/lib/chef/resource/windows_dfs_namespace.rb +2 -2
- data/lib/chef/resource/windows_dns_record.rb +2 -2
- data/lib/chef/resource/windows_dns_zone.rb +2 -2
- data/lib/chef/resource/windows_feature.rb +3 -3
- data/lib/chef/resource/windows_feature_dism.rb +3 -5
- data/lib/chef/resource/windows_feature_powershell.rb +3 -3
- data/lib/chef/resource/windows_firewall_profile.rb +2 -2
- data/lib/chef/resource/windows_firewall_rule.rb +20 -6
- data/lib/chef/resource/windows_font.rb +1 -1
- data/lib/chef/resource/windows_pagefile.rb +103 -64
- data/lib/chef/resource/windows_path.rb +2 -2
- data/lib/chef/resource/windows_printer.rb +80 -61
- data/lib/chef/resource/windows_printer_port.rb +48 -65
- data/lib/chef/resource/windows_security_policy.rb +2 -2
- data/lib/chef/resource/windows_share.rb +2 -2
- data/lib/chef/resource/windows_shortcut.rb +1 -1
- data/lib/chef/resource/windows_task.rb +1 -1
- data/lib/chef/resource/windows_uac.rb +3 -5
- data/lib/chef/resource/windows_update_settings.rb +259 -0
- data/lib/chef/resource/windows_user_privilege.rb +2 -2
- data/lib/chef/resource/windows_workgroup.rb +2 -2
- data/lib/chef/resource/yum_package.rb +11 -15
- data/lib/chef/resource/zypper_package.rb +4 -4
- data/lib/chef/resource/zypper_repository.rb +28 -8
- data/lib/chef/resource.rb +13 -17
- data/lib/chef/resource_inspector.rb +6 -2
- data/lib/chef/resource_reporter.rb +0 -1
- data/lib/chef/resources.rb +12 -1
- data/lib/chef/secret_fetcher/aws_secrets_manager.rb +65 -0
- data/lib/chef/secret_fetcher/azure_key_vault.rb +78 -0
- data/lib/chef/secret_fetcher/base.rb +76 -0
- data/lib/chef/secret_fetcher/example.rb +46 -0
- data/lib/chef/secret_fetcher.rb +55 -0
- data/lib/chef/version.rb +1 -1
- data/spec/functional/mixin/from_file_spec.rb +1 -1
- data/spec/functional/resource/windows_hostname_spec.rb +91 -0
- data/spec/functional/resource/windows_pagefile_spec.rb +98 -0
- data/spec/integration/compliance/compliance_spec.rb +1 -0
- data/spec/integration/recipes/recipe_dsl_spec.rb +1 -1
- data/spec/integration/recipes/resource_action_spec.rb +6 -6
- data/spec/support/shared/unit/provider/file.rb +2 -8
- data/spec/unit/compliance/runner_spec.rb +46 -2
- data/spec/unit/cookbook_version_spec.rb +52 -0
- data/spec/unit/data_collector_spec.rb +47 -1
- data/spec/unit/dsl/render_helpers_spec.rb +102 -0
- data/spec/unit/dsl/secret_spec.rb +71 -0
- data/spec/unit/formatters/doc_spec.rb +1 -1
- data/spec/unit/handler_spec.rb +8 -2
- data/spec/unit/policy_builder/dynamic_spec.rb +0 -5
- data/spec/unit/policy_builder/policyfile_spec.rb +144 -56
- data/spec/unit/provider/apt_update_spec.rb +3 -1
- data/spec/unit/provider/mount/aix_spec.rb +1 -1
- data/spec/unit/provider/package/powershell_spec.rb +74 -12
- data/spec/unit/provider/zypper_repository_spec.rb +3 -10
- data/spec/unit/provider_spec.rb +23 -0
- data/spec/unit/resource/homebrew_cask_spec.rb +29 -11
- data/spec/unit/resource/rhsm_subscription_spec.rb +50 -3
- data/spec/unit/resource/systemd_unit_spec.rb +1 -1
- data/spec/unit/resource/windows_defender_exclusion_spec.rb +62 -0
- data/spec/unit/resource/windows_defender_spec.rb +71 -0
- data/spec/unit/resource/windows_firewall_rule_spec.rb +12 -7
- data/spec/unit/resource/windows_pagefile_spec.rb +4 -9
- data/spec/unit/resource/windows_update_settings_spec.rb +64 -0
- data/spec/unit/resource/zypper_repository_spec.rb +1 -1
- data/spec/unit/resource_spec.rb +19 -8
- data/spec/unit/secret_fetcher/aws_secrets_manager_spec.rb +70 -0
- data/spec/unit/secret_fetcher/azure_key_vault_spec.rb +70 -0
- data/spec/unit/secret_fetcher_spec.rb +82 -0
- metadata +55 -7
@@ -0,0 +1,76 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Marc Paradise (<marc@chef.io>)
|
3
|
+
# Copyright:: Copyright (c) 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_relative "../exceptions"
|
20
|
+
|
21
|
+
class Chef
|
22
|
+
# == Chef::SecretFetcher
|
23
|
+
# An abstract base class that defines the methods required to implement
|
24
|
+
# a Secret Fetcher.
|
25
|
+
class SecretFetcher
|
26
|
+
class Base
|
27
|
+
attr_reader :config
|
28
|
+
# Note that this is only available in the context of a recipe.
|
29
|
+
# Since that's the only place it's intended to be used, that's probably OK.
|
30
|
+
attr_reader :run_context
|
31
|
+
|
32
|
+
# Initialize a new SecretFetcher::Base
|
33
|
+
#
|
34
|
+
# @param config [Hash] Configuration hash. Expected configuration keys and values
|
35
|
+
# will vary based on implementation, and are validated in `validate!`.
|
36
|
+
def initialize(config, run_context)
|
37
|
+
@config = config
|
38
|
+
@run_context = run_context
|
39
|
+
end
|
40
|
+
|
41
|
+
# Fetch the named secret by invoking implementation-specific [Chef::SecretFetcher::Base#do_fetch]
|
42
|
+
#
|
43
|
+
# @param name [Object] the name or identifier of the secret.
|
44
|
+
# @param version [Object] Optional version of the secret to fetch.
|
45
|
+
# @note - the name parameter will probably see a narrowing of type as we learn more about different integrations.
|
46
|
+
# @return [Object] the fetched secret
|
47
|
+
# @raise [Chef::Exceptions::Secret::MissingSecretName] when secret name is not provided
|
48
|
+
# @raise [Chef::Exceptions::Secret::FetchFailed] when the underlying attempt to fetch the secret fails.
|
49
|
+
def fetch(name, version = nil)
|
50
|
+
raise Chef::Exceptions::Secret::MissingSecretName.new if name.to_s == ""
|
51
|
+
|
52
|
+
do_fetch(name, version)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Validate that the instance is correctly configured.
|
56
|
+
# @raise [Chef::Exceptions::Secret::ConfigurationInvalid] if it is not.
|
57
|
+
def validate!; end
|
58
|
+
|
59
|
+
# Called to fetch the secret identified by 'identifer'. Implementations
|
60
|
+
# should expect that `validate!` has been invoked before `do_fetch`.
|
61
|
+
#
|
62
|
+
# @param identifier [Object] Unique identifier of the secret to be retrieved.
|
63
|
+
# When invoked via DSL, this is pre-verified to be not nil/not empty string.
|
64
|
+
# The expected data type and form can vary by implementation.
|
65
|
+
# @param version [Object] Optional version of the secret to be retrieved. If not
|
66
|
+
# provided, implementations are expected to fetch the most recent version of the
|
67
|
+
# secret by default.
|
68
|
+
#
|
69
|
+
# @return [Object] The secret as returned from the implementation. The data type
|
70
|
+
# will vary implementation.
|
71
|
+
#
|
72
|
+
# @raise [Chef::Exceptions::Secret::FetchFailed] if the secret could not be fetched
|
73
|
+
def do_fetch(identifier, version); raise NotImplementedError.new; end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Marc Paradise (<marc@chef.io>)
|
3
|
+
# Copyright:: Copyright (c) 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_relative "base"
|
20
|
+
|
21
|
+
class Chef
|
22
|
+
# == Chef::SecretFetcher::Example
|
23
|
+
# A simple implementation of a secrets fetcher.
|
24
|
+
# It expects to be initialized with a hash of
|
25
|
+
# keys and secret values.
|
26
|
+
#
|
27
|
+
# Usage Example:
|
28
|
+
#
|
29
|
+
# fetcher = SecretFetcher.for_service(:example, "secretkey1" => { "secret" => "lives here" })
|
30
|
+
# fetcher.fetch("secretkey1")
|
31
|
+
class SecretFetcher
|
32
|
+
class Example < Base
|
33
|
+
def validate!
|
34
|
+
if config.class != Hash
|
35
|
+
raise Chef::Exceptions::Secret::ConfigurationInvalid.new("The Example fetcher requires a hash of secrets")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def do_fetch(identifier, version)
|
40
|
+
raise Chef::Exceptions::Secret::FetchFailed.new("Secret #{identifier}) not found.") unless config.key?(identifier)
|
41
|
+
|
42
|
+
config[identifier]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Marc Paradise (<marc@chef.io>)
|
3
|
+
# Copyright:: Copyright (c) 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_relative "exceptions"
|
20
|
+
|
21
|
+
class Chef
|
22
|
+
class SecretFetcher
|
23
|
+
|
24
|
+
SECRET_FETCHERS = %i{example aws_secrets_manager azure_key_vault}.freeze
|
25
|
+
|
26
|
+
# Returns a configured and validated instance
|
27
|
+
# of a [Chef::SecretFetcher::Base] for the given
|
28
|
+
# service and configuration.
|
29
|
+
#
|
30
|
+
# @param service [Symbol] the identifier for the service that will support this request. Must be in
|
31
|
+
# SECRET_FETCHERS
|
32
|
+
# @param config [Hash] configuration that the secrets service requires
|
33
|
+
# @param run_context [Chef::RunContext] the run context this is being invoked from
|
34
|
+
def self.for_service(service, config, run_context)
|
35
|
+
fetcher = case service
|
36
|
+
when :example
|
37
|
+
require_relative "secret_fetcher/example"
|
38
|
+
Chef::SecretFetcher::Example.new(config, run_context)
|
39
|
+
when :aws_secrets_manager
|
40
|
+
require_relative "secret_fetcher/aws_secrets_manager"
|
41
|
+
Chef::SecretFetcher::AWSSecretsManager.new(config, run_context)
|
42
|
+
when :azure_key_vault
|
43
|
+
require_relative "secret_fetcher/azure_key_vault"
|
44
|
+
Chef::SecretFetcher::AzureKeyVault.new(config, run_context)
|
45
|
+
when nil, ""
|
46
|
+
raise Chef::Exceptions::Secret::MissingFetcher.new(SECRET_FETCHERS)
|
47
|
+
else
|
48
|
+
raise Chef::Exceptions::Secret::InvalidFetcherService.new("Unsupported secret service: #{service}", SECRET_FETCHERS)
|
49
|
+
end
|
50
|
+
fetcher.validate!
|
51
|
+
fetcher
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
data/lib/chef/version.rb
CHANGED
@@ -0,0 +1,91 @@
|
|
1
|
+
# Author: John McCrae (john.mccrae@progress.com)
|
2
|
+
# Copyright:: Copyright (c) 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 "chef/mixin/powershell_exec"
|
20
|
+
require "chef/resource/hostname"
|
21
|
+
|
22
|
+
describe Chef::Resource::Hostname, :windows_only do
|
23
|
+
include Chef::Mixin::PowershellExec
|
24
|
+
|
25
|
+
def get_domain_status
|
26
|
+
powershell_exec!("(Get-WmiObject -Class Win32_ComputerSystem).PartofDomain").result
|
27
|
+
end
|
28
|
+
|
29
|
+
let(:new_hostname) { "New-Hostname" }
|
30
|
+
let(:local_domain_user) { "'mydomain\\Groucho'" }
|
31
|
+
let(:local_domain_password) { "'P@ssw0rd'" }
|
32
|
+
let(:local_windows_reboot) { false }
|
33
|
+
let(:domain_status) { get_domain_status }
|
34
|
+
|
35
|
+
let(:run_context) do
|
36
|
+
node = Chef::Node.new
|
37
|
+
node.consume_external_attrs(OHAI_SYSTEM.data, {}) # node[:languages][:powershell][:version]
|
38
|
+
node.automatic["os"] = "windows"
|
39
|
+
node.automatic["platform"] = "windows"
|
40
|
+
node.automatic["platform_version"] = "6.1"
|
41
|
+
node.automatic["kernel"][:machine] = :x86_64 # Only 64-bit architecture is supported
|
42
|
+
empty_events = Chef::EventDispatch::Dispatcher.new
|
43
|
+
Chef::RunContext.new(node, {}, empty_events)
|
44
|
+
end
|
45
|
+
|
46
|
+
subject do
|
47
|
+
new_resource = Chef::Resource::Hostname.new("oldhostname", run_context)
|
48
|
+
new_resource.hostname = "Grendel"
|
49
|
+
new_resource.windows_reboot = false
|
50
|
+
new_resource
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "Changing machine names" do
|
54
|
+
context "The system can be renamed without a user or password when in a Workgroup" do
|
55
|
+
let(:hostname) { "Cucumber" }
|
56
|
+
it "does change" do
|
57
|
+
subject.run_action(:set)
|
58
|
+
expect(subject).to be_updated_by_last_action
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "Mocking being joined to a domain" do
|
63
|
+
before do
|
64
|
+
allow(subject).to receive(:is_domain_joined?) { true }
|
65
|
+
end
|
66
|
+
context "the system gets renamed when in a domain" do
|
67
|
+
let(:hostname) { "Gherkin" }
|
68
|
+
it "does change the domain account" do
|
69
|
+
subject.windows_reboot true
|
70
|
+
subject.domain_user local_domain_user
|
71
|
+
subject.domain_password local_domain_password
|
72
|
+
subject.run_action(:set)
|
73
|
+
expect(subject).to be_updated_by_last_action
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "testing for error handling" do
|
79
|
+
before do
|
80
|
+
allow(subject).to receive(:is_domain_joined?) { true }
|
81
|
+
end
|
82
|
+
context "when a node is renamed while in a domain" do
|
83
|
+
it "and fails because of missing credentials" do
|
84
|
+
subject.windows_reboot true
|
85
|
+
subject.domain_user local_domain_user
|
86
|
+
expect { subject.run_action(:set) }.to raise_error(RuntimeError)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
# Author: John McCrae (john.mccrae@progress.com)
|
2
|
+
# Copyright:: Copyright (c) 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 "chef/mixin/powershell_exec"
|
20
|
+
|
21
|
+
describe Chef::Resource::WindowsPagefile, :windows_only do
|
22
|
+
include Chef::Mixin::PowershellExec
|
23
|
+
|
24
|
+
let(:c_path) { "c:\\" }
|
25
|
+
let(:e_path) { "e:\pagefile.sys" }
|
26
|
+
|
27
|
+
let(:run_context) do
|
28
|
+
node = Chef::Node.new
|
29
|
+
node.consume_external_attrs(OHAI_SYSTEM.data, {}) # node[:languages][:powershell][:version]
|
30
|
+
node.automatic["os"] = "windows"
|
31
|
+
node.automatic["platform"] = "windows"
|
32
|
+
node.automatic["platform_version"] = "6.1"
|
33
|
+
node.automatic["kernel"][:machine] = :x86_64 # Only 64-bit architecture is supported
|
34
|
+
empty_events = Chef::EventDispatch::Dispatcher.new
|
35
|
+
Chef::RunContext.new(node, {}, empty_events)
|
36
|
+
end
|
37
|
+
|
38
|
+
subject do
|
39
|
+
new_resource = Chef::Resource::WindowsPagefile.new("pagefile", run_context)
|
40
|
+
new_resource
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "Setting Up Pagefile Management" do
|
44
|
+
context "Disable Automatic Management" do
|
45
|
+
it "Disables Automatic Management" do
|
46
|
+
subject.path c_path
|
47
|
+
subject.automatic_managed false
|
48
|
+
subject.run_action(:set)
|
49
|
+
expect(subject).to be_updated_by_last_action
|
50
|
+
end
|
51
|
+
|
52
|
+
it "Enable Automatic Management " do
|
53
|
+
subject.path c_path
|
54
|
+
subject.automatic_managed true
|
55
|
+
subject.run_action(:set)
|
56
|
+
expect(subject).to be_updated_by_last_action
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "Creating a new Pagefile" do
|
62
|
+
context "Create new pagefile" do
|
63
|
+
it "Creates a new pagefile on a different drive that doesn't exist" do
|
64
|
+
subject.path e_path
|
65
|
+
expect { subject.run_action(:set) }.to raise_error(RuntimeError)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "Update a pagefile" do
|
70
|
+
it "Changes a pagefile to use custom sizes" do
|
71
|
+
subject.path c_path
|
72
|
+
subject.initial_size 20000
|
73
|
+
subject.maximum_size 80000
|
74
|
+
subject.run_action(:set)
|
75
|
+
expect(subject).to be_updated_by_last_action
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "Deleting a Pagefile and Resetting to Automatically Managed" do
|
81
|
+
context "delete the pagefile on disk" do
|
82
|
+
it "deletes the pagefile located at the given path" do
|
83
|
+
subject.path c_path
|
84
|
+
subject.run_action(:delete)
|
85
|
+
expect(subject).to be_updated_by_last_action
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context "Re-enable automatic management of pagefiles" do
|
90
|
+
it "Enable Automatic Management " do
|
91
|
+
subject.path c_path
|
92
|
+
subject.automatic_managed true
|
93
|
+
subject.run_action(:set)
|
94
|
+
expect(subject).to be_updated_by_last_action
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -9,7 +9,7 @@ class NoActionJackson < Chef::Resource
|
|
9
9
|
@foo
|
10
10
|
end
|
11
11
|
|
12
|
-
class <<self
|
12
|
+
class << self
|
13
13
|
attr_accessor :action_was
|
14
14
|
end
|
15
15
|
end
|
@@ -17,7 +17,7 @@ end
|
|
17
17
|
class WeirdActionJackson < Chef::Resource
|
18
18
|
provides :weird_action_jackson
|
19
19
|
|
20
|
-
class <<self
|
20
|
+
class << self
|
21
21
|
attr_accessor :action_was
|
22
22
|
end
|
23
23
|
|
@@ -176,7 +176,7 @@ module ResourceActionSpec
|
|
176
176
|
@blarghle
|
177
177
|
end
|
178
178
|
|
179
|
-
class <<self
|
179
|
+
class << self
|
180
180
|
attr_accessor :ran_action
|
181
181
|
attr_accessor :succeeded
|
182
182
|
attr_accessor :ruby_block_converged
|
@@ -284,7 +284,7 @@ module ResourceActionSpec
|
|
284
284
|
@bar = "#{value}alope" if value
|
285
285
|
@bar
|
286
286
|
end
|
287
|
-
class <<self
|
287
|
+
class << self
|
288
288
|
attr_accessor :load_current_resource_ran
|
289
289
|
attr_accessor :jackalope_ran
|
290
290
|
end
|
@@ -354,8 +354,8 @@ module ResourceActionSpec
|
|
354
354
|
end
|
355
355
|
|
356
356
|
it "allows overridden action to have a description separate from the action defined in the base resource" do
|
357
|
-
expect(ActionJackson.action_description(:test1)).to eql "Original description"
|
358
|
-
expect(ActionJackalope.action_description(:test1)).to eql "An old action with a new description"
|
357
|
+
expect(ActionJackson.new("ActionJackson", nil).action_description(:test1)).to eql "Original description"
|
358
|
+
expect(ActionJackalope.new("ActionJackalope", nil).action_description(:test1)).to eql "An old action with a new description"
|
359
359
|
end
|
360
360
|
|
361
361
|
it "non-overridden actions run and can access overridden and non-overridden variables (but not necessarily new ones)" do
|