From 5691e7e4af910009aa00f1590a1309e0749bc368 Mon Sep 17 00:00:00 2001 From: Sachin Jain Date: Wed, 1 Jul 2026 10:30:08 +0530 Subject: [PATCH 1/4] Add configurable winpass_timeout for Windows password reset Fixes an issue where the Windows password reset operation would timeout with 'Timeout::Error: Timeout while waiting for password agent to perform password reset' on instances that take longer to initialize the password agent. Added a new 'winpass_timeout' configuration option (defaults to nil) that allows users to specify a custom timeout (in seconds) for the gcewinpass password reset operation. When not set, the default timeout from gcewinpass is used, preserving backward compatibility. Usage in kitchen.yml: driver: winpass_timeout: 300 Fixes: https://github.com/test-kitchen/kitchen-google/issues/117 Signed-off-by: Sachin Jain --- lib/kitchen/driver/gce.rb | 13 +++++++----- spec/kitchen/driver/gce_spec.rb | 36 ++++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/lib/kitchen/driver/gce.rb b/lib/kitchen/driver/gce.rb index a38aa61..da9527f 100644 --- a/lib/kitchen/driver/gce.rb +++ b/lib/kitchen/driver/gce.rb @@ -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, {} @@ -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 + 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 diff --git a/spec/kitchen/driver/gce_spec.rb b/spec/kitchen/driver/gce_spec.rb index 03a979b..a589721 100644 --- a/spec/kitchen/driver/gce_spec.rb +++ b/spec/kitchen/driver/gce_spec.rb @@ -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 From f7549c8d6093b100200898c0f269dc3d35b77915 Mon Sep 17 00:00:00 2001 From: Sachin Jain Date: Thu, 2 Jul 2026 14:48:24 +0530 Subject: [PATCH 2/4] Replace chefstyle with cookstyle Switch linting dependency from chefstyle to cookstyle (~> 8.7) and update Rakefile to use cookstyle/chefstyle require pattern, aligning with other test-kitchen plugins (e.g. kitchen-ec2). Signed-off-by: Sachin Jain --- Gemfile | 4 ++-- Rakefile | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 64a208e..3901fa9 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/Rakefile b/Rakefile index 2dc6a2f..cfbbc30 100644 --- a/Rakefile +++ b/Rakefile @@ -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} From 3024f411c0f4273dafc6d55657ddaea3492e837c Mon Sep 17 00:00:00 2001 From: Sachin Jain Date: Thu, 2 Jul 2026 14:54:18 +0530 Subject: [PATCH 3/4] Update .rubocop.yml to use cookstyle/chefstyle require Signed-off-by: Sachin Jain --- .rubocop.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.rubocop.yml b/.rubocop.yml index 8fd406e..ea9207d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,6 +1,6 @@ --- require: - - chefstyle + - cookstyle/chefstyle AllCops: TargetRubyVersion: 3.1 From 26774caee27dd7574482060460ce09237d5b60c5 Mon Sep 17 00:00:00 2001 From: Sachin Jain Date: Thu, 2 Jul 2026 14:58:21 +0530 Subject: [PATCH 4/4] Auto-correct cookstyle offenses Fix 5 auto-correctable offenses detected by cookstyle: - Layout/HashAlignment: align hash keys in update_windows_password - Style/RedundantReturn: remove redundant return in image_url Signed-off-by: Sachin Jain --- lib/kitchen/driver/gce.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/kitchen/driver/gce.rb b/lib/kitchen/driver/gce.rb index da9527f..14348bd 100644 --- a/lib/kitchen/driver/gce.rb +++ b/lib/kitchen/driver/gce.rb @@ -273,11 +273,11 @@ def update_windows_password(server_name) info("Resetting the Windows password for user #{username} on #{server_name}...") opts = { - project: project, - zone: zone, + project: project, + zone: zone, instance_name: server_name, - email: config[:email], - username: username, + email: config[:email], + username: username, } opts[:timeout] = config[:winpass_timeout] unless config[:winpass_timeout].nil? state[:password] = GoogleComputeWindowsPassword.new(**opts).new_password @@ -530,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)