lib/kitchen/driver/ec2.rb in kitchen-ec2-1.3.2 vs lib/kitchen/driver/ec2.rb in kitchen-ec2-1.4.0

- old
+ new

@@ -21,10 +21,11 @@ require "kitchen" require_relative "ec2_version" require_relative "aws/client" require_relative "aws/instance_generator" require_relative "aws/standard_platform" +require_relative "aws/standard_platform/amazon" require_relative "aws/standard_platform/centos" require_relative "aws/standard_platform/debian" require_relative "aws/standard_platform/rhel" require_relative "aws/standard_platform/fedora" require_relative "aws/standard_platform/freebsd" @@ -46,19 +47,19 @@ kitchen_driver_api_version 2 plugin_version Kitchen::Driver::EC2_VERSION - default_config :region, ENV["AWS_REGION"] || "us-east-1" + default_config :region, ENV["AWS_REGION"] || "us-east-1" default_config :shared_credentials_profile, nil - default_config :availability_zone, nil + default_config :availability_zone, nil default_config :instance_type do |driver| driver.default_instance_type end default_config :ebs_optimized, false default_config :security_group_ids, nil - default_config :tags, "created-by" => "test-kitchen" + default_config :tags, "created-by" => "test-kitchen" default_config :user_data do |driver| if driver.windows_os? driver.default_windows_user_data end end @@ -81,11 +82,11 @@ default_config :interface, nil default_config :http_proxy, ENV["HTTPS_PROXY"] || ENV["HTTP_PROXY"] default_config :retry_limit, 3 default_config :tenancy, "default" default_config :instance_initiated_shutdown_behavior, nil - default_config :ssl_verify_peer, true + default_config :ssl_verify_peer, true def initialize(*args, &block) super # AWS Ruby SDK loading isn't thread safe, so as soon as we know we're # going to use EC2, autoload it. Seems to have been fixed in Ruby 2.3+ @@ -204,14 +205,22 @@ :on => ::Aws::EC2::Errors::InvalidInstanceIDNotFound ) do |r, _| info("Attempting to tag the instance, #{r} retries") tag_server(server) + # Get information about the AMI (image) used to create the image. + image_data = ec2.client.describe_images({ :image_ids => [server.image_id] })[0][0] + state[:server_id] = server.id info("EC2 instance <#{state[:server_id]}> created.") - wait_until_volumes_ready(server, state) - tag_volumes(server) + + # instance-store backed images do not have attached volumes, so only + # wait for the volumes to be ready if the instance EBS-backed. + if image_data.root_device_type == "ebs" + wait_until_volumes_ready(server, state) + tag_volumes(server) + end wait_until_ready(server, state) end if windows_os? && instance.transport[:username] =~ /administrator/i && @@ -219,11 +228,11 @@ # 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.") + info("EC2 instance <#{state[:server_id]}> ready (hostname: #{state[:hostname]}).") instance.transport.connection(state).wait_until_ready create_ec2_json(state) debug("ec2:create '#{state[:hostname]}'") end @@ -370,11 +379,11 @@ def create_spot_request request_duration = config[:retryable_tries] * config[:retryable_sleep] request_data = { :spot_price => config[:spot_price].to_s, :launch_specification => instance_generator.ec2_instance_data, - :valid_until => Time.now + request_duration + :valid_until => Time.now + request_duration, } if config[:block_duration_minutes] request_data[:block_duration_minutes] = config[:block_duration_minutes] end @@ -489,11 +498,11 @@ INTERFACE_TYPES = { "dns" => "public_dns_name", "public" => "public_ip_address", "private" => "private_ip_address", - "private_dns" => "private_dns_name" + "private_dns" => "private_dns_name", } # # Lookup hostname of provided server. If interface_type is provided use # that interface to lookup hostname. Otherwise, try ordered list of @@ -555,29 +564,36 @@ EOH end if actual_platform.version =~ /2016/ logfile_name = 'C:\\ProgramData\\Amazon\\EC2-Windows\\Launch\\Log\\kitchen-ec2.log' + disk_init = 'C:\\ProgramData\\Amazon\\EC2-Windows\\Launch\\Scripts\\InitializeDisks.ps1' else logfile_name = 'C:\\Program Files\\Amazon\\Ec2ConfigService\\Logs\\kitchen-ec2.log' + disk_init = "" end # Returning the fully constructed PowerShell script to user_data Kitchen::Util.outdent!(<<-EOH) <powershell> - $logfile=#{logfile_name} + $logfile="#{logfile_name}" + # EC2Launch doesn't init extra disks by default + #{disk_init} # Allow script execution Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force #PS Remoting and & winrm.cmd basic config - Enable-PSRemoting -Force -SkipNetworkProfileCheck + $enableArgs=@{Force=$true} + $command=Get-Command Enable-PSRemoting + if($command.Parameters.Keys -contains "skipnetworkprofilecheck"){ + $enableArgs.skipnetworkprofilecheck=$true + } + Enable-PSRemoting @enableArgs & winrm.cmd set winrm/config '@{MaxTimeoutms="1800000"}' >> $logfile & winrm.cmd set winrm/config/winrs '@{MaxMemoryPerShellMB="1024"}' >> $logfile & winrm.cmd set winrm/config/winrs '@{MaxShellsPerUser="50"}' >> $logfile - #Server settings - support username/password login - & winrm.cmd set winrm/config/service/auth '@{Basic="true"}' >> $logfile - & winrm.cmd set winrm/config/service '@{AllowUnencrypted="true"}' >> $logfile & winrm.cmd set winrm/config/winrs '@{MaxMemoryPerShellMB="1024"}' >> $logfile #Firewall Config & netsh advfirewall firewall set rule name="Windows Remote Management (HTTP-In)" profile=public protocol=tcp localport=5985 remoteip=localsubnet new remoteip=any >> $logfile + Set-ItemProperty -Name LocalAccountTokenFilterPolicy -Path HKLM:\\software\\Microsoft\\Windows\\CurrentVersion\\Policies\\system -Value 1 #{custom_admin_script} </powershell> EOH end # rubocop:enable Metrics/MethodLength, Metrics/LineLength