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

Adding knife-windows options #354

Merged
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
56 changes: 28 additions & 28 deletions knife-ec2.gemspec
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
# -*- encoding: utf-8 -*-
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
require 'knife-ec2/version'

Gem::Specification.new do |s|
s.name = 'knife-ec2'
s.version = Knife::Ec2::VERSION
s.authors = ['Adam Jacob', 'Seth Chisamore']
s.email = ['adam@opscode.com', 'schisamo@opscode.com']
s.homepage = 'https://github.com/opscode/knife-ec2'
s.summary = "EC2 Support for Chef's Knife Command"
s.description = s.summary
s.license = 'Apache-2.0'

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }

s.add_dependency 'fog', '~> 1.29.0'
s.add_dependency 'knife-windows', '>= 0.8.2'

s.add_development_dependency 'chef', '~> 12.0', '>= 12.2.1'
s.add_development_dependency 'rspec', '~> 3.0'
s.add_development_dependency 'rake', '~> 10.1'
s.add_development_dependency 'sdoc', '~> 0.3'

s.require_paths = ['lib']
end
# -*- encoding: utf-8 -*-
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
require 'knife-ec2/version'
Gem::Specification.new do |s|
s.name = 'knife-ec2'
s.version = Knife::Ec2::VERSION
s.authors = ['Adam Jacob', 'Seth Chisamore']
s.email = ['adam@opscode.com', 'schisamo@opscode.com']
s.homepage = 'https://github.com/opscode/knife-ec2'
s.summary = "EC2 Support for Chef's Knife Command"
s.description = s.summary
s.license = 'Apache-2.0'
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
s.add_dependency 'fog', '~> 1.29.0'
s.add_dependency 'knife-windows', '~> 1.0.0.rc.1'
s.add_development_dependency 'chef', '~> 12.0', '>= 12.2.1'
s.add_development_dependency 'rspec', '~> 3.0'
s.add_development_dependency 'rake', '~> 10.1'
s.add_development_dependency 'sdoc', '~> 0.3'
s.require_paths = ['lib']
end
7 changes: 6 additions & 1 deletion lib/chef/knife/ec2_server_create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
require 'chef/knife/ec2_base'
require 'chef/knife/s3_source'
require 'chef/knife/winrm_base'
require 'chef/knife/bootstrap_windows_base'

class Chef
class Knife
class Ec2ServerCreate < Knife

include Knife::Ec2Base
include Knife::WinrmBase
include Knife::BootstrapWindowsBase
deps do
require 'tempfile'
require 'fog'
Expand Down Expand Up @@ -678,6 +680,7 @@ def bootstrap_for_windows_node(server, fqdn)
bootstrap.config[:ca_trust_file] = locate_config_value(:ca_trust_file)
bootstrap.config[:winrm_port] = locate_config_value(:winrm_port)
bootstrap.config[:auth_timeout] = locate_config_value(:auth_timeout)
bootstrap.config[:winrm_ssl_verify_mode] = locate_config_value(:winrm_ssl_verify_mode)
elsif locate_config_value(:bootstrap_protocol) == 'ssh'
bootstrap = Chef::Knife::BootstrapWindowsSsh.new
bootstrap.config[:ssh_user] = locate_config_value(:ssh_user)
Expand All @@ -690,6 +693,9 @@ def bootstrap_for_windows_node(server, fqdn)
exit 1
end
bootstrap.name_args = [fqdn]
bootstrap.config[:msi_url] = locate_config_value(:msi_url)
bootstrap.config[:install_as_service] = locate_config_value(:install_as_service)
bootstrap.config[:session_timeout] = locate_config_value(:session_timeout)
bootstrap.config[:chef_node_name] = config[:chef_node_name] || server.id
bootstrap_common_params(bootstrap)
end
Expand Down Expand Up @@ -1166,7 +1172,6 @@ def windows_password

def load_winrm_deps
require 'winrm'
require 'em-winrm'
require 'chef/knife/winrm'
require 'chef/knife/bootstrap_windows_winrm'
require 'chef/knife/bootstrap_windows_ssh'
Expand Down
33 changes: 27 additions & 6 deletions spec/unit/ec2_server_create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
:instance_id => 'test_spot_instance_id',
:state => 'open',
:key_name => 'ssh_key_name',
:availability_zone => nil,
:availability_zone => nil,
:flavor_id => 'm1.small',
:image_id => 'image' }

Expand Down Expand Up @@ -465,7 +465,7 @@
@aws_key = Chef::Config[:knife][:aws_ssh_key_id]
allow(@knife_ec2_create).to receive(:ami).and_return(false)
end

it "gives warning message and creates the attribute with the required name" do
expect(@knife_ec2_create.ui).to receive(:warn).with("Use of aws_ssh_key_id option in knife.rb config is deprecated, use ssh_key_name option instead.")
@knife_ec2_create.validate!
Expand All @@ -479,7 +479,7 @@
@aws_key = Chef::Config[:knife][:aws_ssh_key_id]
allow(@knife_ec2_create).to receive(:ami).and_return(false)
end

it "gives warning message and gives preference to CLI value over knife config's value" do
expect(@knife_ec2_create.ui).to receive(:warn).with("Use of aws_ssh_key_id option in knife.rb config is deprecated, use ssh_key_name option instead.")
@knife_ec2_create.validate!
Expand All @@ -492,7 +492,7 @@
Chef::Config[:knife][:ssh_key_name] = "mykey"
allow(@knife_ec2_create).to receive(:ami).and_return(false)
end

it "does nothing" do
@knife_ec2_create.validate!
end
Expand All @@ -504,7 +504,7 @@
Chef::Config[:knife][:ssh_key_name] = "mykey"
@knife_ec2_create.config[:ssh_key_name] = "ssh_key_name"
end

it "ssh-key passed over CLI gets preference over knife config value" do
server_def = @knife_ec2_create.create_server_def
expect(server_def[:key_name]).to eq(@knife_ec2_create.config[:ssh_key_name])
Expand Down Expand Up @@ -595,6 +595,7 @@
expect(Chef::Config[:knife][:hints]["ec2"]).not_to be_nil
end
end

describe "when configuring the winrm bootstrap process for windows" do
before do
allow(@knife_ec2_create).to receive(:fetch_server_fqdn).and_return("SERVERNAME")
Expand All @@ -610,6 +611,10 @@
@knife_ec2_create.config[:distro] = 'ubuntu-10.04-magic-sparkles'
@knife_ec2_create.config[:run_list] = ['role[base]']
@knife_ec2_create.config[:json_attributes] = "{'my_attributes':{'foo':'bar'}"
@knife_ec2_create.config[:winrm_ssl_verify_mode] = 'basic'
@knife_ec2_create.config[:msi_url] = 'https://opscode-omnibus-packages.s3.amazonaws.com/windows/2008r2/x86_64/chef-client-12.3.0-1.msi'
@knife_ec2_create.config[:install_as_service] = true
@knife_ec2_create.config[:session_timeout] = "90"
@bootstrap = @knife_ec2_create.bootstrap_for_windows_node(@new_ec2_server, @new_ec2_server.dns_name)
end

Expand Down Expand Up @@ -655,6 +660,22 @@
expect(@bootstrap.config[:first_boot_attributes]).to eq("{'my_attributes':{'foo':'bar'}")
end

it "should set the bootstrap 'winrm_ssl_verify_mode' correctly" do
expect(@bootstrap.config[:winrm_ssl_verify_mode]).to eq("basic")
end

it "should set the bootstrap 'msi_url' correctly" do
expect(@bootstrap.config[:msi_url]).to eq('https://opscode-omnibus-packages.s3.amazonaws.com/windows/2008r2/x86_64/chef-client-12.3.0-1.msi')
end

it "should set the bootstrap 'install_as_service' correctly" do
expect(@bootstrap.config[:install_as_service]).to eq(@knife_ec2_create.config[:install_as_service])
end

it "should set the bootstrap 'session_timeout' correctly" do
expect(@bootstrap.config[:session_timeout]).to eq(@knife_ec2_create.config[:session_timeout])
end

it "configures sets the bootstrap's run_list" do
expect(@bootstrap.config[:run_list]).to eq(['role[base]'])
end
Expand Down Expand Up @@ -725,7 +746,7 @@
@knife_ec2_create.validate!
expect(Chef::Config[:knife][:aws_access_key_id]).to eq(@access_key_id)
expect(Chef::Config[:knife][:aws_secret_access_key]).to eq(@secret_key)
end
end
end

it 'understands that file:// validation key URIs are just paths' do
Expand Down