summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn McCrae <jmccrae@chf.io>2021-05-15 09:07:48 -0700
committerJohn McCrae <jmccrae@chf.io>2021-05-15 09:07:48 -0700
commit56aae54cb6efa60a91befb31ed5d77d0a78fcc12 (patch)
treed131655b782ce693f5bfc482d8e4510d1d1cc31d
parent673faeb0ada0dc69333ed1f3a19cc4c531475581 (diff)
downloadchef-jfm/win_hostname.tar.gz
this branch is trashed, delete itjfm/win_hostname
Signed-off-by: John McCrae <jmccrae@chf.io>
-rw-r--r--Gemfile.lock10
-rw-r--r--lib/chef/resource/hostname.rb18
-rw-r--r--spec/functional/resource/windows_hostname_spec.rb42
3 files changed, 52 insertions, 18 deletions
diff --git a/Gemfile.lock b/Gemfile.lock
index 2e9a70e083..d00b07e23e 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -8,7 +8,7 @@ GIT
GIT
remote: https://github.com/chef/ohai.git
- revision: 42d1b3f55ab3beef9f0a96ee61f63cde28c268c4
+ revision: 934109b9eb3d46da996eb4780719e0ebe11ccafc
branch: master
specs:
ohai (17.1.0)
@@ -190,7 +190,7 @@ GEM
hashie (4.1.0)
httpclient (2.8.3)
iniparse (1.5.0)
- inspec-core (4.37.0)
+ inspec-core (4.37.8)
addressable (~> 2.4)
chef-telemetry (~> 1.0, >= 1.0.8)
faraday (>= 0.9.0, < 1.5)
@@ -213,8 +213,8 @@ GEM
train-core (~> 3.0)
tty-prompt (~> 0.17)
tty-table (~> 0.10)
- inspec-core-bin (4.37.0)
- inspec-core (= 4.37.0)
+ inspec-core-bin (4.37.8)
+ inspec-core (= 4.37.8)
ipaddress (0.8.3)
iso8601 (0.13.0)
json (2.5.1)
@@ -348,7 +348,7 @@ GEM
unicode-display_width (2.0.0)
unicode_utils (1.4.0)
uuidtools (2.2.0)
- webmock (3.12.2)
+ webmock (3.13.0)
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
diff --git a/lib/chef/resource/hostname.rb b/lib/chef/resource/hostname.rb
index 04ab1f0b25..a1f2087796 100644
--- a/lib/chef/resource/hostname.rb
+++ b/lib/chef/resource/hostname.rb
@@ -44,6 +44,24 @@ class Chef
ipaddress '198.51.100.2'
end
```
+
+ **Change the hostname of a Windows, Non-Domain joined node**:
+
+ ```ruby
+ hostname 'renaming a workgroup computer' do
+ hostname 'Foo'
+ end
+ ```
+
+ **Change the hostname of a Windows, Domain-joined node**:
+
+ ```ruby
+ hostname 'renaming a domain-joined computer' do
+ hostname 'Foo'
+ domain_user "Domain\\Someone"
+ domain_password 'SomePassword'
+ end
+ ```
DOC
property :hostname, String,
diff --git a/spec/functional/resource/windows_hostname_spec.rb b/spec/functional/resource/windows_hostname_spec.rb
index 97443d0e8b..f64c805beb 100644
--- a/spec/functional/resource/windows_hostname_spec.rb
+++ b/spec/functional/resource/windows_hostname_spec.rb
@@ -27,8 +27,8 @@ describe Chef::Resource::Hostname, :windows_only do
end
let(:new_hostname) { "New-Hostname" }
- let(:local_domain_user) { "DOMAIN\\Groucho" }
- let(:local_domain_password) { "P@ssw0rd" }
+ let(:local_domain_user) { "'mydomain\\Groucho'" }
+ let(:local_domain_password) { "'P@ssw0rd'" }
let(:local_windows_reboot) { false }
let(:domain_status) { get_domain_status }
@@ -45,9 +45,7 @@ describe Chef::Resource::Hostname, :windows_only do
subject do
new_resource = Chef::Resource::Hostname.new("oldhostname", run_context)
- new_resource.hostname = "foobar"
- new_resource.domain_user = "chef"
- new_resource.domain_password = "P@ssw0rd"
+ new_resource.hostname = "Grendel"
new_resource.windows_reboot = false
new_resource
end
@@ -61,14 +59,32 @@ describe Chef::Resource::Hostname, :windows_only do
end
end
- context "the system gets renamed when in a domain" do
- let(:hostname) { "Gherkin" }
- it "does change the domain account" do
- subject.windows_reboot true
- subject.domain_user local_domain_user
- subject.domain_password local_domain_password
- subject.run_action(:set)
- expect(subject).to be_updated_by_last_action
+ describe "Mocking being joined to a domain" do
+ before do
+ allow(subject).to receive(:is_domain_joined?) { true }
+ end
+ context "the system gets renamed when in a domain" do
+ let(:hostname) { "Gherkin" }
+ it "does change the domain account" do
+ subject.windows_reboot true
+ subject.domain_user local_domain_user
+ subject.domain_password local_domain_password
+ subject.run_action(:set)
+ expect(subject).to be_updated_by_last_action
+ end
+ end
+ end
+
+ describe 'testing for error handling' do
+ before do
+ allow(subject).to receive(:is_domain_joined?) { true }
+ end
+ context "when a node is renamed while in a domain" do
+ it "and fails because of missing credentials" do
+ subject.windows_reboot true
+ subject.domain_user local_domain_user
+ expect { subject.run_action(:set) }.to raise_error(RuntimeError)
+ end
end
end
end