1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Adds template retrieving into Plan

Adds following to Planning service of OpenStack:
 * get_plan_templates request
 * templates, master_template, environment and
   provider_resource_templates methods to Plan model
 * tests for get_plan_template request
 * tests for template retrieving methods of Plan model
This commit is contained in:
Petr Blaho 2015-03-11 19:19:32 +01:00
parent 9ac981ec6e
commit 1a0dff6424
5 changed files with 77 additions and 0 deletions

View file

@ -5,6 +5,9 @@ module Fog
class Planning
class Plan < Fog::Model
MASTER_TEMPLATE_NAME = 'plan.yaml'
ENVIRONMENT_NAME = 'environment.yaml'
identity :uuid
attribute :description
@ -19,6 +22,24 @@ module Fog
prepare_service_value(attributes)
super
end
def templates
service.get_plan_templates(uuid).body
end
def master_template
templates[MASTER_TEMPLATE_NAME]
end
def environment
templates[ENVIRONMENT_NAME]
end
def provider_resource_templates
templates.select do |key, template|
![MASTER_TEMPLATE_NAME, ENVIRONMENT_NAME].include?(key)
end
end
end
end
end

View file

@ -28,6 +28,7 @@ module Fog
# Plan requests
request :list_plans
request :get_plan_templates
request :get_plan
class Mock

View file

@ -0,0 +1,28 @@
module Fog
module Openstack
class Planning
class Real
def get_plan_templates(plan_uuid)
request(
:expects => [200, 204],
:method => 'GET',
:path => "plans/#{plan_uuid}/templates"
)
end
end # class Real
class Mock
def get_plan_templates(plan_uuid)
response = Excon::Response.new
response.status = [200, 204][rand(1)]
response.body = {
"environment.yaml" => "... content of template file ...",
"plan.yaml" => "... content of template file ...",
"provider-compute-1.yaml" => "... content of template file ..."
}
response
end # def get_plan_templates
end # class Mock
end # class Planning
end # module Openstack
end # module Fog

View file

@ -0,0 +1,21 @@
Shindo.tests("Fog::Openstack[:planning] | plan", ['openstack']) do
@instance = Fog::Openstack[:planning].plans.first
tests('success') do
tests('#templates').succeeds do
@instance.templates
end
tests('#master_template').succeeds do
@instance.master_template
end
tests('#environment').succeeds do
@instance.environment
end
tests('#provider_resource_templates').succeeds do
@instance.provider_resource_templates
end
end
end

View file

@ -12,6 +12,8 @@ Shindo.tests('Fog::Openstack[:planning] | Planning plan requests', ['openstack']
"version" => Fog::Nullable::Integer,
}
@plan_templates_format = Hash
tests('success') do
tests('#list_plans').data_matches_schema([@plan_format]) do
plans = Fog::Openstack[:planning].list_plans.body
@ -22,5 +24,9 @@ Shindo.tests('Fog::Openstack[:planning] | Planning plan requests', ['openstack']
tests('#get_plan').data_matches_schema(@plan_format) do
Fog::Openstack[:planning].get_plan(@instance['uuid']).body
end
tests('#get_plan_templates').data_matches_schema(@plan_templates_format) do
Fog::Openstack[:planning].get_plan_templates(@instance['uuid']).body
end
end
end