mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[aws|cloud_formation] cleanup + tests
This commit is contained in:
parent
c96ca14a9e
commit
9257518c18
13 changed files with 247 additions and 25 deletions
|
@ -17,6 +17,7 @@ module Fog
|
|||
class Mock
|
||||
|
||||
def initialize(options={})
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -7,7 +7,7 @@ module Fog
|
|||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'StackId'
|
||||
when 'RequestId', 'StackId'
|
||||
@response[name] = @value
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,16 +7,20 @@ module Fog
|
|||
|
||||
def reset
|
||||
@event = {}
|
||||
@response = { 'Events' => [] }
|
||||
@response = { 'StackEvents' => [] }
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'EventId', 'StackId', 'StackName', 'LogicalResourceId', 'PhysicalResourceId', 'ResourceType', 'Timestamp', 'ResourceStatus', 'ResourceStatusReason'
|
||||
when 'EventId', 'LogicalResourceId', 'PhysicalResourceId', 'ResourceProperties', 'ResourceStatus', 'ResourceStatusReason', 'ResourceType', 'StackId', 'StackName'
|
||||
@event[name] = @value
|
||||
when 'member'
|
||||
@response['Events'] << @event
|
||||
@response['StackEvents'] << @event
|
||||
@event = {}
|
||||
when 'RequestId'
|
||||
@response[name] = @value
|
||||
when 'Timestamp'
|
||||
@event[name] = Time.parse(@value)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -7,16 +7,20 @@ module Fog
|
|||
|
||||
def reset
|
||||
@resource = {}
|
||||
@response = { 'Resources' => [] }
|
||||
@response = { 'StackResources' => [] }
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'StackId', 'StackName', 'LogicalResourceId', 'PhysicalResourceId', 'ResourceType', 'TimeStamp', 'ResourceStatus'
|
||||
when 'StackId', 'StackName', 'LogicalResourceId', 'PhysicalResourceId', 'ResourceType', 'ResourceStatus'
|
||||
@resource[name] = @value
|
||||
when 'member'
|
||||
@response['Resources'] << @resource
|
||||
@response['StackResources'] << @resource
|
||||
@resource = {}
|
||||
when 'RequestId'
|
||||
@response[name] = @value
|
||||
when 'Timestamp'
|
||||
@resource[name] = Time.parse(@value)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -45,11 +45,22 @@ module Fog
|
|||
end
|
||||
else
|
||||
case name
|
||||
when 'StackName', 'StackId', 'CreationTime', 'StackStatus', 'DisableRollback'
|
||||
@stack[name] = @value
|
||||
when 'member'
|
||||
@response['Stacks'] << @stack
|
||||
@stack = { 'Outputs' => [], 'Parameters' => [] }
|
||||
when 'RequestId'
|
||||
@response[name] = @value
|
||||
when 'CreationTime'
|
||||
@stack[name] = Time.parse(@value)
|
||||
when 'DisableRollback'
|
||||
case @value
|
||||
when 'false'
|
||||
@stack[name] = false
|
||||
when 'true'
|
||||
@stack[name] = true
|
||||
end
|
||||
when 'StackName', 'StackId', 'StackStatus'
|
||||
@stack[name] = @value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,7 +7,7 @@ module Fog
|
|||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'TemplateBody'
|
||||
when 'RequestId', 'TemplateBody'
|
||||
@response[name] = @value
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,10 +5,43 @@ module Fog
|
|||
|
||||
class ValidateTemplate < Fog::Parsers::Base
|
||||
|
||||
def reset
|
||||
@parameter = {}
|
||||
@response = { 'Parameters' => [] }
|
||||
end
|
||||
|
||||
def start_element(name, attrs = [])
|
||||
super
|
||||
case name
|
||||
when 'Parameters'
|
||||
@in_parameters = true
|
||||
end
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'TemplateParameter', 'Description'
|
||||
when 'DefaultValue', 'ParameterKey'
|
||||
@parameter[name] = @value
|
||||
when 'Description'
|
||||
if @in_parameters
|
||||
@parameter[name] = @value
|
||||
else
|
||||
@response[name] = @value
|
||||
end
|
||||
when 'RequestId'
|
||||
@response[name] = @value
|
||||
when 'member'
|
||||
@response['Parameters'] << @parameter
|
||||
@parameter = {}
|
||||
when 'NoEcho'
|
||||
case @value
|
||||
when 'false'
|
||||
@parameter[name] = false
|
||||
when 'true'
|
||||
@parameter[name] = true
|
||||
end
|
||||
when 'Parameters'
|
||||
@in_parameters = false
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -9,10 +9,14 @@ module Fog
|
|||
#
|
||||
# ==== Parameters
|
||||
# * stack_name<~String>: name of the stack to create
|
||||
# * options<~Hash>
|
||||
# * options<~Hash>:
|
||||
# * TemplateBody<~String>: structure containing the template body
|
||||
# or
|
||||
# or (one of the two Template parameters is required)
|
||||
# * TemplateURL<~String>: URL of file containing the template body
|
||||
# * DisableRollback<~Boolean>: Controls rollback on stack creation failure, defaults to false
|
||||
# * NotificationARNs<~Array>: List of SNS topics to publish events to
|
||||
# * Parameters<~Hash>: Hash of providers to supply to template
|
||||
# * TimeoutInMinutes<~Integer>: Minutes to wait before status is set to CREATE_FAILED
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
|
@ -23,11 +27,42 @@ module Fog
|
|||
# http://docs.amazonwebservices.com/AWSCloudFormation/latest/APIReference/API_CreateStack.html
|
||||
#
|
||||
def create_stack(stack_name, options = {})
|
||||
params = {
|
||||
'StackName' => stack_name,
|
||||
}
|
||||
|
||||
if options['DisableRollback']
|
||||
params['DisableRollback'] = options['DisableRollback']
|
||||
end
|
||||
|
||||
if options['NotificationARNs']
|
||||
params.merge!(AWS.indexed_param("NotificationARNs.member", [*options['NotificationARNs']]))
|
||||
end
|
||||
|
||||
if options['Parameters']
|
||||
options['Parameters'].keys.each_with_index do |key, index|
|
||||
index += 1 # params are 1-indexed
|
||||
params.merge!({
|
||||
"Parameters.member.#{index}.ParameterKey" => key,
|
||||
"Parameters.member.#{index}.ParameterValue" => options['Parameters'][key]
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
if options['TemplateBody']
|
||||
params['TemplateBody'] = options['TemplateBody']
|
||||
elsif options['TemplateURL']
|
||||
params['TemplateURL'] = options['TemplateURL']
|
||||
end
|
||||
|
||||
if options['TimeoutInMinutes']
|
||||
params['TimeoutInMinutes'] = options['TimeoutInMinutes']
|
||||
end
|
||||
|
||||
request({
|
||||
'Action' => 'CreateStack',
|
||||
'StackName' => stack_name,
|
||||
:parser => Fog::Parsers::AWS::CloudFormation::CreateStack.new
|
||||
}.merge!(options))
|
||||
}.merge!(params))
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -8,14 +8,14 @@ module Fog
|
|||
# Describe stack events
|
||||
#
|
||||
# ==== Parameters
|
||||
# * stack_name<~String>: stack name to return events for
|
||||
# * options<~Hash>:
|
||||
# * StackName<~String>: only return events related to this stack name
|
||||
# * NextToken<~String>: identifies the start of the next list of events, if there is one
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'Events'<~Array> - Matching resources
|
||||
# * 'StackEvents'<~Array> - Matching resources
|
||||
# * event<~Hash>:
|
||||
# * 'EventId'<~String> -
|
||||
# * 'StackId'<~String> -
|
||||
|
@ -23,16 +23,17 @@ module Fog
|
|||
# * 'LogicalResourceId'<~String> -
|
||||
# * 'PhysicalResourceId'<~String> -
|
||||
# * 'ResourceType'<~String> -
|
||||
# * 'Timestamp'<~String> -
|
||||
# * 'Timestamp'<~Time> -
|
||||
# * 'ResourceStatus'<~String> -
|
||||
# * 'ResourceStatusReason'<~String> -
|
||||
#
|
||||
# ==== See Also
|
||||
# http://docs.amazonwebservices.com/AWSCloudFormation/latest/APIReference/API_DescribeStackEvents.html
|
||||
#
|
||||
def describe_stack_events(options = {})
|
||||
def describe_stack_events(stack_name, options = {})
|
||||
request({
|
||||
'Action' => 'DescribeStackEvents',
|
||||
'StackName' => stack_name,
|
||||
:parser => Fog::Parsers::AWS::CloudFormation::DescribeStackEvents.new
|
||||
}.merge!(options))
|
||||
end
|
||||
|
|
|
@ -9,21 +9,22 @@ module Fog
|
|||
#
|
||||
# ==== Parameters
|
||||
# * options<~Hash>:
|
||||
# * 'PhysicalResourceId'<~String>: name or unique identifier that corresponds to a physical instance ID
|
||||
# or (one of PhysicalResourceId and StackName is required)
|
||||
# * 'StackName'<~String>: only return events related to this stack name
|
||||
# * 'LogicalResourceId'<~String>: logical name of the resource as specified in the template
|
||||
# * 'PhysicalResourceId'<~String>: name or unique identifier that corresponds to a physical instance ID
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'Resources'<~Array> - Matching resources
|
||||
# * 'StackResources'<~Array> - Matching resources
|
||||
# * resource<~Hash>:
|
||||
# * 'StackId'<~String> -
|
||||
# * 'StackName'<~String> -
|
||||
# * 'LogicalResourceId'<~String> -
|
||||
# * 'PhysicalResourceId'<~String> -
|
||||
# * 'ResourceType'<~String> -
|
||||
# * 'Timestamp'<~String> -
|
||||
# * 'Timestamp'<~Time> -
|
||||
# * 'ResourceStatus'<~String> -
|
||||
#
|
||||
# ==== See Also
|
||||
|
|
|
@ -3,7 +3,7 @@ module Fog
|
|||
class CloudFormation
|
||||
class Real
|
||||
|
||||
require 'fog/aws/parsers/cloud_formation/get_template'
|
||||
require 'fog/aws/parsers/cloud_formation/validate_template'
|
||||
|
||||
# Describe stacks
|
||||
#
|
||||
|
@ -23,8 +23,8 @@ module Fog
|
|||
#
|
||||
def validate_template(options = {})
|
||||
request({
|
||||
'Action' => 'GetTemplate',
|
||||
:parser => Fog::Parsers::AWS::CloudFormation::GetTemplate.new
|
||||
'Action' => 'ValidateTemplate',
|
||||
:parser => Fog::Parsers::AWS::CloudFormation::ValidateTemplate.new
|
||||
}.merge!(options))
|
||||
end
|
||||
|
||||
|
|
|
@ -36,6 +36,8 @@ class AWS < Fog::Bin
|
|||
hash[key] = case key
|
||||
when :cdn
|
||||
Fog::CDN.new(:provider => 'AWS')
|
||||
when :cloud_formation
|
||||
Fog::AWS::CloudFormation.new
|
||||
when :compute
|
||||
Fog::Compute.new(:provider => 'AWS')
|
||||
when :dns
|
||||
|
|
130
tests/aws/requests/cloud_formation/stack_tests.rb
Normal file
130
tests/aws/requests/cloud_formation/stack_tests.rb
Normal file
|
@ -0,0 +1,130 @@
|
|||
Shindo.tests('AWS::CloudFormation | stack requests', ['aws', 'cloudformation']) do
|
||||
|
||||
@validate_template_format = {
|
||||
'Description' => String,
|
||||
'Parameters' => [
|
||||
{
|
||||
'DefaultValue' => Fog::Nullable::String,
|
||||
'Description' => String,
|
||||
'NoEcho' => Fog::Boolean,
|
||||
'ParameterKey' => String,
|
||||
}
|
||||
],
|
||||
'RequestId' => String
|
||||
}
|
||||
|
||||
@create_stack_format = {
|
||||
'RequestId' => String,
|
||||
'StackId' => String
|
||||
}
|
||||
|
||||
@get_template_format = {
|
||||
'RequestId' => String,
|
||||
'TemplateBody' => String
|
||||
}
|
||||
|
||||
@describe_stacks_format = {
|
||||
'RequestId' => String,
|
||||
'Stacks' => [
|
||||
{
|
||||
'CreationTime' => Time,
|
||||
'DisableRollback' => Fog::Boolean,
|
||||
'Outputs' => [
|
||||
{
|
||||
'OutputKey' => String,
|
||||
'OutputValue' => String
|
||||
}
|
||||
],
|
||||
'Parameters' => [
|
||||
{
|
||||
'ParameterKey' => String,
|
||||
'ParameterValue' => String,
|
||||
}
|
||||
],
|
||||
'StackId' => String,
|
||||
'StackName' => String,
|
||||
'StackStatus' => String,
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@describe_stack_events_format = {
|
||||
'RequestId' => String,
|
||||
'StackEvents' => [
|
||||
{
|
||||
'EventId' => String,
|
||||
'LogicalResourceId' => String,
|
||||
'PhysicalResourceId' => String,
|
||||
'ResourceProperties' => String,
|
||||
'ResourceStatus' => String,
|
||||
'ResourceStatusReason' => String,
|
||||
'ResourceType' => String,
|
||||
'StackId' => String,
|
||||
'StackName' => String,
|
||||
'Timestamp' => Time
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@describe_stack_resources_format = {
|
||||
'RequestId' => String,
|
||||
'StackResources' => [
|
||||
{
|
||||
'LogicalResourceId' => String,
|
||||
'PhysicalResourceId' => String,
|
||||
'ResourceStatus' => String,
|
||||
'ResourceType' => String,
|
||||
'StackId' => String,
|
||||
'StackName' => String,
|
||||
'Timestamp' => Time
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
tests('success') do
|
||||
|
||||
@stack_name = 'fogstack' << Time.now.to_i.to_s
|
||||
@keypair = AWS[:compute].key_pairs.create(:name => 'cloudformation')
|
||||
@template_url = 'https://s3.amazonaws.com/cloudformation-templates-us-east-1/EC2InstanceSample-1.0.0.template'
|
||||
|
||||
tests("validate_template('TemplateURL' => '#{@template_url}')").formats(@validate_template_format) do
|
||||
AWS[:cloud_formation].validate_template('TemplateURL' => @template_url).body
|
||||
end
|
||||
|
||||
tests("create_stack('#{@stack_name}', 'TemplateURL' => '#{@template_url}', Parameters => {'KeyName' => 'cloudformation'})").formats(@create_stack_format) do
|
||||
AWS[:cloud_formation].create_stack(
|
||||
@stack_name,
|
||||
'TemplateURL' => @template_url,
|
||||
'Parameters' => {'KeyName' => 'cloudformation'}
|
||||
).body
|
||||
end
|
||||
|
||||
tests("get_template('#{@stack_name})").formats(@get_template_format) do
|
||||
AWS[:cloud_formation].get_template(@stack_name).body
|
||||
end
|
||||
|
||||
tests("describe_stacks").formats(@describe_stacks_format) do
|
||||
AWS[:cloud_formation].describe_stacks.body
|
||||
end
|
||||
|
||||
tests("describe_stack_events('#{@stack_name}')").formats(@describe_stack_events_format) do
|
||||
AWS[:cloud_formation].describe_stack_events(@stack_name).body
|
||||
end
|
||||
|
||||
tests("describe_stack_resources('StackName' => '#{@stack_name}')").formats(@describe_stack_resources_format) do
|
||||
AWS[:cloud_formation].describe_stack_resources('StackName' => @stack_name).body
|
||||
end
|
||||
|
||||
tests("delete_stack('#{@stack_name}')").succeeds do
|
||||
AWS[:cloud_formation].delete_stack(@stack_name)
|
||||
end
|
||||
|
||||
@keypair.destroy
|
||||
|
||||
end
|
||||
|
||||
tests('failure') do
|
||||
|
||||
end
|
||||
|
||||
end
|
Loading…
Add table
Reference in a new issue