Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
require:
- chefstyle
- cookstyle/chefstyle

AllCops:
TargetRubyVersion: 3.1
Expand Down
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ group :debug do
gem "pry"
end

group :chefstyle do
gem "chefstyle", "2.2.3"
group :cookstyle do
gem "cookstyle", "~> 8.7"
end
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:test)

begin
require "chefstyle"
require "cookstyle/chefstyle"
require "rubocop/rake_task"
RuboCop::RakeTask.new(:style) do |task|
task.options += ["--display-cop-names", "--no-color"]
end
rescue LoadError
puts "chefstyle is not available. (sudo) gem install chefstyle to do style checking."
puts "cookstyle/chefstyle is not available. (sudo) gem install cookstyle to do style checking."
end

task default: %i{test style}
17 changes: 10 additions & 7 deletions lib/kitchen/driver/gce.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class Gce < Kitchen::Driver::Base
default_config :use_private_ip, false
default_config :wait_time, 600
default_config :refresh_rate, 2
default_config :winpass_timeout, nil
default_config :guest_accelerators, []
default_config :metadata, {}
default_config :labels, {}
Expand Down Expand Up @@ -271,13 +272,15 @@ def update_windows_password(server_name)

info("Resetting the Windows password for user #{username} on #{server_name}...")

state[:password] = GoogleComputeWindowsPassword.new(
project:,
zone:,
opts = {
project: project,
zone: zone,
instance_name: server_name,
email: config[:email],
username:
).new_password
email: config[:email],
username: username,
}
opts[:timeout] = config[:winpass_timeout] unless config[:winpass_timeout].nil?
state[:password] = GoogleComputeWindowsPassword.new(**opts).new_password

info("Password reset complete on #{server_name} complete.")
end
Expand Down Expand Up @@ -527,7 +530,7 @@ def boot_disk_source_image
end

def image_url(image = image_name)
return "projects/#{image_project}/global/images/#{image}" if image_exist?(image)
"projects/#{image_project}/global/images/#{image}" if image_exist?(image)
end

def image_name_for_family(image_family)
Expand Down
36 changes: 35 additions & 1 deletion spec/kitchen/driver/gce_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -395,13 +395,47 @@

allow(driver).to receive(:state).and_return(state)
expect(transport).to receive(:config).and_return(username: "test_username")
expect(driver).to receive(:config).and_return(email: "test_email")
allow(driver).to receive(:config).and_return(email: "test_email", winpass_timeout: nil)
expect(driver).to receive(:winrm_transport?).and_return(true)
expect(GoogleComputeWindowsPassword).to receive(:new).with(winpass_config).and_return(winpass)
expect(winpass).to receive(:new_password).and_return("password123")
driver.update_windows_password("server_1")
expect(state[:password]).to eq("password123")
end

it "passes the winpass_timeout config to gcewinpass when set" do
state = {}
winpass = double("winpass")

allow(driver).to receive(:state).and_return(state)
expect(transport).to receive(:config).and_return(username: "test_username")
allow(driver).to receive(:config).and_return(email: "test_email", winpass_timeout: 300)
expect(driver).to receive(:winrm_transport?).and_return(true)
expect(GoogleComputeWindowsPassword).to receive(:new).with(
hash_including(timeout: 300)
).and_return(winpass)
expect(winpass).to receive(:new_password).and_return("password123")
driver.update_windows_password("server_1")
end

it "does not pass timeout when winpass_timeout is not set in config" do
state = {}
winpass = double("winpass")

allow(driver).to receive(:state).and_return(state)
expect(transport).to receive(:config).and_return(username: "test_username")
allow(driver).to receive(:config).and_return(email: "test_email", winpass_timeout: nil)
expect(driver).to receive(:winrm_transport?).and_return(true)
expect(GoogleComputeWindowsPassword).to receive(:new).with(
hash_not_including(:timeout)
).and_return(winpass)
expect(winpass).to receive(:new_password).and_return("password123")
driver.update_windows_password("server_1")
end

it "defaults winpass_timeout config to nil" do
expect(driver.send(:config)[:winpass_timeout]).to be_nil
end
end

describe "#check_api_call" do
Expand Down
Loading