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

[rackspace|auto_scale] adding tests

This commit is contained in:
Kyle Rames 2013-10-02 13:18:23 -05:00
parent 81bd48c417
commit 4af85578ae
9 changed files with 164 additions and 37 deletions

View file

@ -14,6 +14,22 @@ Shindo.tests('Fog::Rackspace::AutoScale | group', ['rackspace', 'rackspace_autos
tests('#policies').succeeds do
@instance.policies
end
tests('#launch_config').succeeds do
@instance.launch_config
end
tests('#group_config').succeeds do
@instance.group_config
end
tests('#state').succeeds do
@instance.state
end
tests('deactive scaling group').succeeds do
deactive_auto_scale_group(@instance)
end
end
end

View file

@ -8,6 +8,10 @@ Shindo.tests('Fog::Rackspace::AutoScale | groups', ['rackspace', 'rackspace_auto
:launch_config => LAUNCH_CONFIG_OPTIONS
}
collection_tests(service.groups, options, false)
collection_tests(service.groups, options, false) do
tests('deactive scaling group').succeeds do
deactive_auto_scale_group(@instance)
end
end
end

View file

@ -2,22 +2,24 @@ Shindo.tests('Fog::Rackspace::AutoScale | policies', ['rackspace', 'rackspace_au
pending if Fog.mocking?
service = Fog::Rackspace::AutoScale.new :rackspace_region => :ord
group = service.groups.create({
:policies => POLICIES_OPTIONS,
:group_config => GROUP_CONFIG_OPTIONS,
:launch_config => LAUNCH_CONFIG_OPTIONS
})
options = {
:name => "policy 2",
:change => 5,
:cooldown => 100,
:type => 'webhook'
}
begin
group = service.groups.create({
:policies => POLICIES_OPTIONS,
:group_config => GROUP_CONFIG_OPTIONS,
:launch_config => LAUNCH_CONFIG_OPTIONS
})
options = {
:name => "policy 2",
:change => 5,
:cooldown => 100,
:type => 'webhook'
}
collection_tests(group.policies, options, false)
ensure
group.destroy
deactive_auto_scale_group(group)
group.destroy if group
end
end

View file

@ -13,18 +13,22 @@ Shindo.tests('Fog::Rackspace::AutoScale | policy', ['rackspace', 'rackspace_auto
options = {
:name => "policy 2",
:change => 5,
:change => 1,
:cooldown => 100,
:type => 'webhook',
:group => group
}
model_tests(group.policies, options, false) do
tests('#execute').succeeds do
@instance.execute
end
tests('#webhooks').succeeds do
@instance.webhooks
end
end
ensure
deactive_auto_scale_group(group)
group.destroy if group
end

View file

@ -28,9 +28,14 @@ Shindo.tests('Fog::Rackspace::AutoScale | webhook', ['rackspace', 'rackspace_aut
:policy => policy
}
model_tests(policy.webhooks, options, false)
model_tests(policy.webhooks, options, false) do
tests('#execution_url').succeeds do
@instance.execution_url
end
end
ensure
policy.destroy if policy
deactive_auto_scale_group(group)
group.destroy if group
end

View file

@ -21,6 +21,7 @@ Shindo.tests('Fog::Rackspace::AutoScale | webhooks', ['rackspace', 'rackspace_au
collection_tests(policy.webhooks, options, false)
ensure
policy.destroy if policy
deactive_auto_scale_group(group)
group.destroy if group
end

View file

@ -3,24 +3,70 @@ Shindo.tests('Fog::Rackspace::AutoScale | config_tests', ['rackspace', 'rackspac
pending if Fog.mocking?
service = Fog::Rackspace::AutoScale.new :rackspace_region => :ord
@group = service.create_group(LAUNCH_CONFIG_OPTIONS, GROUP_CONFIG_OPTIONS, POLICIES_OPTIONS).body['group']
@group_id = @group['id']
begin
@group = service.create_group(LAUNCH_CONFIG_OPTIONS, GROUP_CONFIG_OPTIONS, POLICIES_OPTIONS).body['group']
@group_id = @group['id']
tests('success') do
tests('#get group config').formats({"groupConfiguration" => GROUP_CONFIG_FORMAT}) do
service.get_group_config(@group_id).body
end
tests('#update group config').formats(204) do
data = service.update_group_config(@group_id, {
'maxEntities' => 7,
'minEntities' => 1,
'metadata' => {},
'name' => 'foo',
'cooldown' => 20}).data
data[:status]
tests('success') do
tests('#get_group_config').formats({"groupConfiguration" => GROUP_CONFIG_FORMAT}) do
service.get_group_config(@group_id).body
end
tests('#update_group_config').returns(204) do
data = service.update_group_config(@group_id, {
'maxEntities' => 0,
'minEntities' => 0,
'metadata' => {},
'name' => 'foo',
'cooldown' => 20})
data.status
end
tests('#get_launch_config').formats(LAUNCH_CONFIG_FORMAT) do
service.get_launch_config(@group_id).body["launchConfiguration"]
end
tests('#update_launch_config').returns(204) do
data = service.update_launch_config(@group_id, {
"args" => {
"loadBalancers" => [
{
"port" => 8000,
"loadBalancerId" => 9099
}
],
"server" => {
"name" => "autoscale_server",
"imageRef" => "0d589460-f177-4b0f-81c1-8ab8903ac7d8",
"flavorRef" => "2",
"OS-DCF =>diskConfig" => "AUTO",
"metadata" => {
"build_config" => "core",
"meta_key_1" => "meta_value_1",
"meta_key_2" => "meta_value_2"
},
"networks" => [
{
"uuid" => "11111111-1111-1111-1111-111111111111"
},
{
"uuid" => "00000000-0000-0000-0000-000000000000"
}
],
"personality" => [
{
"path" => "/root/.csivh",
"contents" => "VGhpcyBpcyBhIHRlc3QgZmlsZS4="
}
]
}
},
"type" => "launch_server"
})
data.status
end
end
ensure
service.delete_group(@group_id)
end
tests('failure') do
tests('#update group config').raises(Fog::Rackspace::AutoScale::BadRequest) do
service.update_group_config(@group_id, {})

View file

@ -9,14 +9,26 @@ Shindo.tests('Fog::Rackspace::AutoScale | group_tests', ['rackspace', 'rackspace
@group_id = response['group']['id']
response
end
tests('#get group').formats(GET_GROUP_HEADERS_FORMAT) do
service.get_group(@group_id).data[:headers]
tests('#list_groups').formats(LIST_GROUPS_FORMAT) do
service.list_groups.body
end
tests('#get group').succeeds do
[200, 204].include? service.get_group(@group_id).status
end
tests('#get group - body').formats(GROUP_FORMAT) do
service.get_group(@group_id).body
end
tests('#delete group').formats(GROUP_DELETE_DATA_FORMAT) do
service.delete_group(@group_id).data
tests('#get_group_state').formats(GROUP_STATE_FORMAT) do
service.get_group_state(@group_id).body
end
tests('#pause_group_state') do
pending
end
tests('#resume_group_state') do
pending
end
tests('#delete group').returns(204) do
service.delete_group(@group_id).status
end
end

View file

@ -1,5 +1,34 @@
### FORMATS
LIST_GROUPS_FORMAT =
{ "groups_links"=>[],
"groups"=> [
{
"paused"=> Fog::Boolean,
"desiredCapacity"=> Integer,
"links"=>[{"href"=> String, "rel"=> String}],
"active"=>[],
"pendingCapacity"=> Integer,
"activeCapacity"=> Integer,
"id"=> String,
"name"=> String
}
]
}
GROUP_STATE_FORMAT = {
"group" => {
"paused"=> Fog::Boolean,
"desiredCapacity" => Integer,
"links"=>[{"href" => String, "rel"=> String}],
"active"=>[],
"pendingCapacity" => Integer,
"activeCapacity" => Integer,
"id" => String,
"name"=> String
}
}
GET_GROUP_HEADERS_FORMAT = {
"Content-Type"=>String,
"Via"=>String,
@ -142,7 +171,7 @@ LAUNCH_CONFIG_OPTIONS = {
}
GROUP_CONFIG_OPTIONS = {
"maxEntities" => 10,
"maxEntities" => 3,
"cooldown" => 360,
"name" => "testscalinggroup198547",
"minEntities" => 0,
@ -177,4 +206,12 @@ GROUP_OPTIONS = {
WEBHOOK_OPTIONS = {
"name" => "webhook name",
"metadata" => {'foo' => 'bar'}
}
}
def deactive_auto_scale_group(group)
return unless group
config = group.group_config
config.min_entities = 0
config.max_entities = 0
config.save
end