Skip to content
Closed
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
8 changes: 7 additions & 1 deletion lib/fog/openstack/orchestration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class OpenStack < Fog::Service
request :update_stack
request :delete_stack
request :list_stacks
request :describe_stack
request :get_template
request :list_stack_resources

class Mock
attr_reader :auth_token
Expand All @@ -30,7 +33,10 @@ class Mock
def self.data
@data ||= Hash.new do |hash, key|
hash[key] = {
:stacks => {}
:stacks => {},
:stack_details => {},
:resources => {},
:templates => {}
}
end
end
Expand Down
24 changes: 24 additions & 0 deletions lib/fog/openstack/requests/orchestration/create_stack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,30 @@ def create_stack(stack_name, options = {})
'updated_time' => Time.now
}

self.data[:stack_details][stack_name] ||= {}
self.data[:stack_details][stack_name][stack_id] = stack.merge ({
'parameters' => options[:parameters],
'output' => [],
'disable_rollback' => options[:disable_rollback]
})

self.data[:templates][stack_name] ||= {}
self.data[:templates][stack_name][stack_id] = options[:template_body]

self.data[:resources][stack_name] ||= {}
self.data[:resources][stack_name][stack_id] = [
{ 'resource_name' => 'my_instance',
'links' => [],
'logical_resource_id' => 'my_instance',
'resource_status_reason' => 'state changed',
'updated_time' => Time.now,
'required_by' => [],
'resource_status' => 'CREATE_COMPLETE',
'physical_resource_id' => Fog::Mock.random_hex(32),
'resource_type' => 'OS::Nova::Server'
}
]

response = Excon::Response.new
response.status = 201
response.body = {
Expand Down
32 changes: 32 additions & 0 deletions lib/fog/openstack/requests/orchestration/describe_stack.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module Fog
module Orchestration
class OpenStack
class Real
# Describe a specified stack
#
# @param stack_name [String] stack name to get details from
# @param stack_id [String] the unique identifier for the stack
#
# @return [Excon::Response]

def describe_stack(stack_name, stack_id)
request(
:expects => 200,
:path => "stacks/#{stack_name}/#{stack_id}",
:method => 'GET'
)
end
end

class Mock
def describe_stack(stack_name, stack_id)
stack = self.data[:stack_details][stack_name][stack_id]
Excon::Response.new(
:body => { 'stack' => stack },
:status => 200
)
end
end
end
end
end
34 changes: 34 additions & 0 deletions lib/fog/openstack/requests/orchestration/get_template.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module Fog
module Orchestration
class OpenStack
class Real
# Get the template for a specified stack
#
# @param stack_name [String] stack name to get template from
# @param stack_id [String] the unique identifier for the stack
#
# @return [Excon::Response]
# * body [Hash]:
# * TemplateBody [String] -
#
def get_template(stack_name, stack_id)
request(
:expects => 200,
:path => "stacks/#{stack_name}/#{stack_id}/template",
:method => 'GET'
)
end
end

class Mock
def get_template(stack_name, stack_id)
template = self.data[:templates][stack_name][stack_id]
Excon::Response.new(
:body => template,
:status => 200
)
end
end
end
end
end
36 changes: 36 additions & 0 deletions lib/fog/openstack/requests/orchestration/list_stack_resources.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module Fog
module Orchestration
class OpenStack
class Real
# List resources from a specified stack
#
# @param stack_name [String] stack name to get resources from
# @param stack_id [String] the unique identifier for the stack
# @param options [Hash]
# * nested_depth - also includes resources from nested stacks up to nested_depth
# levels of recursion.
#
# @return [Excon::Response]

def list_stack_resources(stack_name, stack_id, options = {})
request(
:expects => 200,
:path => "stacks/#{stack_name}/#{stack_id}/resources",
:method => 'GET',
:query => options
)
end
end

class Mock
def list_stack_resources(stack_name, stack_id, options = {})
resources = self.data[:resources][stack_name][stack_id]
Excon::Response.new(
:body => { 'resources' => resources },
:status => 200
)
end
end
end
end
end
44 changes: 38 additions & 6 deletions tests/openstack/requests/orchestration/stack_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,53 @@
'links' => Array,
}

@stack_details_format = @stack_format.merge ({
'parameters' => Fog::Nullable::Hash,
'output' => Array,
'disable_rollback' => Fog::Nullable::Boolean
})

@resource_format = {
'links' => Array,
'resource_name' => String,
'resource_type' => String,
'physical_resource_id' => String,
'logical_resource_id' => String,
'resource_status' => String,
'resource_status_reason' => String,
'updated_time' => Time,
'required_by' => Array,
}

tests('success') do
tests('#create_stack("teststack")').formats(@create_format) do
Fog::Orchestration[:openstack].create_stack("teststack").body
stack_name = "teststack"
stack = nil
tests("#create_stack(#{stack_name})").formats(@create_format) do
stack = Fog::Orchestration[:openstack].create_stack(stack_name).body
end

tests('#list_stacks').formats({'stacks' => [@stack_format]}) do
Fog::Orchestration[:openstack].list_stacks.body
end

tests('#update_stack("teststack")').formats({}) do
Fog::Orchestration[:openstack].update_stack("teststack").body
tests("#update_stack(#{stack_name})").formats({}) do
Fog::Orchestration[:openstack].update_stack(stack_name).body
end

tests("#delete_stack(#{stack_name}, #{stack['id']})").formats({}) do
Fog::Orchestration[:openstack].delete_stack(stack_name, stack["id"]).body
end

tests("#describe_stack(#{stack_name}, #{stack['id']})").formats({'stack' => @stack_details_format}) do
Fog::Orchestration[:openstack].describe_stack(stack_name, stack["id"]).body
end

tests("#list_stack_resources(#{stack_name}, #{stack['id']})").formats({'resources' => [@resource_format]}) do
Fog::Orchestration[:openstack].list_stack_resources(stack_name, stack["id"]).body
end

tests('#delete_stack("teststack", "id")').formats({}) do
Fog::Orchestration[:openstack].delete_stack("teststack", "id").body
tests("#get_template(#{stack_name}, #{stack['id']})").formats({}) do
Fog::Orchestration[:openstack].get_template(stack_name, stack["id"]).body
end
end
end