Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve speed of readiness detection for Windows instances #582

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
25 changes: 12 additions & 13 deletions lib/kitchen/driver/ec2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,6 @@ def create(state)
wait_until_ready(server, state)
end

if windows_os? &&
instance.transport[:username] =~ /administrator/i &&
instance.transport[:password].nil?
# If we're logging into the administrator user and a password isn't
# supplied, try to fetch it from the AWS instance
fetch_windows_admin_password(server, state)
end

info("EC2 instance <#{state[:server_id]}> ready (hostname: #{state[:hostname]}).")
instance.transport.connection(state).wait_until_ready
attach_network_interface(state) unless config[:elastic_network_interface_id].nil?
Expand Down Expand Up @@ -536,12 +528,19 @@ def wait_until_ready(server, state)
state[:hostname] = hostname(aws_instance, nil)
end
if ready && windows_os?
output = server.console_output.output
unless output.nil?
output = Base64.decode64(output)
debug "Console output: --- \n#{output}"
if instance.transport[:username] =~ /administrator/i &&
instance.transport[:password].nil?
# If we're logging into the administrator user and a password isn't
xorima marked this conversation as resolved.
Show resolved Hide resolved
# supplied, try to fetch it from the AWS instance
fetch_windows_admin_password(server, state)
else
output = server.console_output.output
unless output.nil?
output = Base64.decode64(output)
debug "Console output: --- \n#{output}"
end
ready = !!(output =~ /Windows is Ready to use/)
end
ready = !!(output =~ /Windows is Ready to use/)
end
ready
end
Expand Down
44 changes: 40 additions & 4 deletions spec/kitchen/driver/ec2_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,46 @@
expect(driver.wait_until_ready(server, state)).to eq(true)
end
end

context "when windows instance" do
let(:hostname) { "windows" }

before do
expect(aws_instance).to receive(:exists?).and_return(true)
expect(aws_instance).to receive_message_chain("state.name").and_return("running")
expect(driver).to receive(:windows_os?).and_return(true)
end

context "does define a username/password" do
before do
expect(transport).to receive(:[]).with(:username).and_return("foo")
end

context "console output is ready" do
it "returns true" do
# base64 encoded `Windows is Ready to use`
expect(server).to receive_message_chain("console_output.output").and_return("V2luZG93cyBpcyBSZWFkeSB0byB1c2U=")
expect(driver.wait_until_ready(server, state)).to eq(true)
end
end

context "console output is not ready" do
it "returns false" do
expect(server).to receive_message_chain("console_output.output").and_return("")
expect(driver.wait_until_ready(server, state)).to eq(false)
end
end
end

context "does not define a username/password" do
it "returns true" do
expect(transport).to receive(:[]).with(:username).and_return("administrator")
expect(transport).to receive(:[]).with(:password).and_return(nil)
expect(driver).to receive(:fetch_windows_admin_password).with(server, state)
expect(driver.wait_until_ready(server, state)).to eq(true)
end
end
end
end

describe "#fetch_windows_admin_password" do
Expand Down Expand Up @@ -482,11 +522,7 @@

context "instance is a windows machine" do
before do
expect(driver).to receive(:windows_os?).and_return(true)
expect(transport).to receive(:[]).with(:username).and_return("administrator")
expect(transport).to receive(:[]).with(:password).and_return(nil)
expect(driver).to receive(:submit_server).and_return(server)
expect(driver).to receive(:fetch_windows_admin_password).with(server, state)
end

include_examples "common create"
Expand Down