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

Support Windows 2016 #291

Merged
merged 7 commits into from
Feb 7, 2017
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
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ language: ruby
cache: bundler
sudo: false
rvm:
- 2.0.0
- 2.1
- 2.2
- 2.2.6
- 2.3.1
- ruby-head
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ gem "winrm-fs"
gem "activesupport", "~> 4.0"

group :test do
gem "rake"
gem "rake", "< 12"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for this particular pin?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rake 12 isn't compatible with rubocop 0.28, which is pinned by finstyle 1.4.0.

And the gemspec file says

style and complexity libraries are tightly version pinned as newer releases may introduce new and undesireable style choices which would be immediately enforced in CI

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tried updating to finstyle 1.5.0. It still isn't compatible with rake 12, and it picks up 11 more style offences :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're moving away from finstyle and I didn't realize this repo was still on it so new things to do

gem "pry"
end

Expand Down
48 changes: 29 additions & 19 deletions lib/kitchen/driver/aws/standard_platform/windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ def username
#
# "windows" -> [nil, nil, nil]
# Windows_Server-*-R*_RTM-, Windows_Server-*-R*_SP*-,
# Windows_Server-*-RTM-, Windows_Server-*-SP*-
# Windows_Server-*-RTM-, Windows_Server-*-SP*-,
# Windows_Server-*-
# "windows-2012" -> [2012, 0, nil]
# Windows_Server-2012-RTM-, Windows_Server-2012-SP*-
# "windows-2012r2" -> [2012, 2, nil]
Expand All @@ -29,6 +30,8 @@ def username
# Windows_Server-2012-R2_SP1-
# "windows-2012r2rtm" -> [2012, 2, 0]
# Windows_Server-2012-R2_RTM-
# "windows-2016" -> [2016, 0, nil]
# Windows_Server-2016-
def image_search
search = {
"owner-alias" => "amazon",
Expand Down Expand Up @@ -75,6 +78,7 @@ def self.from_image(driver, image)
# 2012r2sp4 -> [ 2012, 2, 4 ]
# 2012sp4 -> [ 2012, 0, 4 ]
# 2012rtm -> [ 2012, 0, 0 ]
# 2016 -> [ 2016, 0, nil ]
def windows_version_parts
version = self.version
if version
Expand Down Expand Up @@ -106,29 +110,35 @@ def windows_version_parts

private

def windows_name_filter
def windows_name_filter # rubocop:disable Metrics/MethodLength
major, revision, service_pack = windows_version_parts

case revision
when nil
revision_strings = ["", "R*_"]
when 0
revision_strings = [""]
if major == 2016
"Windows_Server-2016-English-Full-Base-*"
else
revision_strings = ["R#{revision}_"]
end
case revision
when nil
revision_strings = ["", "R*_"]
when 0
revision_strings = [""]
else
revision_strings = ["R#{revision}_"]
end

case service_pack
when nil
revision_strings = revision_strings.flat_map { |r| ["#{r}RTM", "#{r}SP*"] }
when 0
revision_strings = revision_strings.map { |r| "#{r}RTM" }
else
revision_strings = revision_strings.map { |r| "#{r}SP#{service_pack}" }
end
case service_pack
when nil
revision_strings = revision_strings.flat_map { |r| ["#{r}RTM", "#{r}SP*"] }
when 0
revision_strings = revision_strings.map { |r| "#{r}RTM" }
else
revision_strings = revision_strings.map { |r| "#{r}SP#{service_pack}" }
end

revision_strings.map do |r|
"Windows_Server-#{major || "*"}-#{r}-English-*-Base-*"
name_filter = revision_strings.map do |r|
"Windows_Server-#{major || "*"}-#{r}-English-*-Base-*"
end
name_filter << "Windows_Server-*-English-Full-Base-*" if major.nil?
name_filter
end
end
end
Expand Down
7 changes: 6 additions & 1 deletion lib/kitchen/driver/ec2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -518,10 +518,15 @@ def default_windows_user_data
EOH
end

if actual_platform.version =~ /2016/
logfile_name = 'C:\\ProgramData\\Amazon\\EC2-Windows\\Launch\\Log\\kitchen-ec2.log'
else
logfile_name = 'C:\\Program Files\\Amazon\\Ec2ConfigService\\Logs\\kitchen-ec2.log'
end
# Returning the fully constructed PowerShell script to user_data
Kitchen::Util.outdent!(<<-EOH)
<powershell>
$logfile="C:\\Program Files\\Amazon\\Ec2ConfigService\\Logs\\kitchen-ec2.log"
$logfile=#{logfile_name}
# Allow script execution
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force
#PS Remoting and & winrm.cmd basic config
Expand Down
14 changes: 11 additions & 3 deletions spec/kitchen/driver/ec2/image_selection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ def new_instance(platform_name: "blarghle")
Windows_Server-*-RTM-English-*-Base-*
Windows_Server-*-SP*-English-*-Base-*
Windows_Server-*-R*_RTM-English-*-Base-*
Windows_Server-*-R*_SP*-English-*-Base-*] }
Windows_Server-*-R*_SP*-English-*-Base-*
Windows_Server-*-English-Full-Base-*] }
],
"windows-2008" => [
{ :name => "owner-alias", :values => %w[amazon] },
Expand Down Expand Up @@ -267,7 +268,8 @@ def new_instance(platform_name: "blarghle")
Windows_Server-*-RTM-English-*-Base-*
Windows_Server-*-SP*-English-*-Base-*
Windows_Server-*-R*_RTM-English-*-Base-*
Windows_Server-*-R*_SP*-English-*-Base-*] },
Windows_Server-*-R*_SP*-English-*-Base-*
Windows_Server-*-English-Full-Base-*] },
{ :name => "architecture", :values => %w[x86_64] }
],
"windows-2012r2-x86_64" => [
Expand All @@ -283,14 +285,20 @@ def new_instance(platform_name: "blarghle")
Windows_Server-*-RTM-English-*-Base-*
Windows_Server-*-SP*-English-*-Base-*
Windows_Server-*-R*_RTM-English-*-Base-*
Windows_Server-*-R*_SP*-English-*-Base-*] }
Windows_Server-*-R*_SP*-English-*-Base-*
Windows_Server-*-English-Full-Base-*] }
],
"windows-server-2012r2-x86_64" => [
{ :name => "owner-alias", :values => %w[amazon] },
{ :name => "name", :values => %w[
Windows_Server-2012-R2_RTM-English-*-Base-*
Windows_Server-2012-R2_SP*-English-*-Base-*] },
{ :name => "architecture", :values => %w[x86_64] }
],
"windows-2016" => [
{ :name => "owner-alias", :values => %w[amazon] },
{ :name => "name", :values => %w[
Windows_Server-2016-English-Full-Base-*] }
]
}

Expand Down
29 changes: 29 additions & 0 deletions spec/kitchen/driver/ec2_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,35 @@
Kitchen::Driver::EC2_VERSION)
end

describe "default_config" do
context "Windows" do
let(:resource) { instance_double(::Aws::EC2::Resource, :image => image) }
before do
allow(driver).to receive(:windows_os?).and_return(true)
allow(client).to receive(:resource).and_return(resource)
allow(instance).to receive(:name).and_return("instance_name")
end
context "Windows 2016" do
let(:image) {
FakeImage.new(:name => "Windows_Server-2016-English-Full-Base-2017.01.11")
}
it "sets :user_data to something" do
expect(driver[:user_data]).to include
'$logfile=C:\\ProgramData\\Amazon\\EC2-Windows\\Launch\\Log\\kitchen-ec2.log'
end
end
context "Windows 2012R2" do
let(:image) {
FakeImage.new(:name => "Windows_Server-2012-R2_RTM-English-64Bit-Base-2017.01.11")
}
it "sets :user_data to something" do
expect(driver[:user_data]).to include
'$logfile=C:\\Program Files\\Amazon\\Ec2ConfigService\\Logs\\kitchen-ec2.log'
end
end
end
end

describe "#hostname" do
let(:public_dns_name) { nil }
let(:private_dns_name) { nil }
Expand Down