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

[openstack|compute] Update Mocks for Security Groups and Volumes

Signed-off-by: Nelvin Driz <nelvindriz@live.com>
This commit is contained in:
Nelvin Driz 2012-04-01 22:06:27 +08:00
parent c9b04b47c9
commit d46c886f67
3 changed files with 27 additions and 42 deletions

View file

@ -180,26 +180,15 @@ module Fog
def initialize(options={}) def initialize(options={})
@openstack_username = options[:openstack_username] @openstack_username = options[:openstack_username]
@openstack_tenant = options[:openstack_tenant]
@data ||= { :users => {}}
unless @data[:users].find {|u| u['name'] == options[:openstack_username]}
id = Fog::Mock.random_numbers(6).to_s
@data[:users][id] = {
'id' => id,
'name' => options[:openstack_username],
'email' => "#{options[:openstack_username]}@mock.com",
'tenantId' => Fog::Mock.random_numbers(6).to_s,
'enabled' => true
}
end
end end
def data def data
self.class.data[@openstack_username] self.class.data["#{@openstack_username}-#{@openstack_tenant}"]
end end
def reset_data def reset_data
self.class.data.delete(@openstack_username) self.class.data.delete("#{@openstack_username}-#{@openstack_tenant}")
end end
def credentials def credentials

View file

@ -18,54 +18,50 @@ module Fog
response = Excon::Response.new response = Excon::Response.new
response.status = 200 response.status = 200
response.headers = { response.headers = {
"X-Compute-Request-Id" => "req-63a90344-7c4d-42e2-936c-fd748bced1b3", "X-Compute-Request-Id" => "req-#{Fog::Mock.random_base64(36)}",
"Content-Type" => "application/json", "Content-Type" => "application/json",
"Content-Length" => "667",
"Date" => Date.new "Date" => Date.new
} }
response.body = { self.data[:security_groups] ||= [
"security_groups" => [{ { "rules" => [
"rules" => [{ { "from_port" => 44,
"from_port" => 44,
"group" => {}, "group" => {},
"ip_protocol" => "tcp", "ip_protocol" => "tcp",
"to_port" => 55, "to_port" => 55,
"parent_group_id" => 1, "parent_group_id" => 1,
"ip_range" => {"cidr"=>"10.10.10.10/24"}, "ip_range" => {"cidr"=>"10.10.10.10/24"},
"id"=>1 "id" => Fog::Mock.random_base64(36)
}, },
{ { "from_port" => 2,
"from_port" => 2,
"group" => {}, "group" => {},
"ip_protocol" => "tcp", "ip_protocol" => "tcp",
"to_port" => 3, "to_port" => 3,
"parent_group_id" => 1, "parent_group_id" => 1,
"ip_range" => {"cidr"=>"10.10.10.10/24"}, "ip_range" => {"cidr"=>"10.10.10.10/24"},
"id" => 2 "id" => Fog::Mock.random_base64(36)
}], } ],
"tenant_id" => "d5183375ab0343f3a0b4b05f547aefc2", "tenant_id" => @openstack_tenant,
"id" => 1, "id" => Fog::Mock.random_base64(36),
"name" => "default", "name" => "default",
"description" => "default" "description" => "default"
}, },
{ {
"rules" => [{ "rules" => [
"from_port" => 44, { "from_port" => 44,
"group" => {}, "group" => {},
"ip_protocol" => "tcp", "ip_protocol" => "tcp",
"to_port" => 55, "to_port" => 55,
"parent_group_id" => 2, "parent_group_id" => 2,
"ip_range" => { "ip_range" => { "cidr"=>"10.10.10.10/24" },
"cidr"=>"10.10.10.10/24" "id"=> Fog::Mock.random_base64(36)
}, } ],
"id"=>3 "tenant_id" => @openstack_tenant,
}], "id" => Fog::Mock.random_base64(36),
"tenant_id" => "d5183375ab0343f3a0b4b05f547aefc2",
"id" => 2,
"name" => "test", "name" => "test",
"description" => "this is a test" "description" => "this is a test"
} }
]} ]
response.body = { 'security_groups' => self.data[:security_groups] }
response response
end end
end # mock end # mock

View file

@ -20,12 +20,11 @@ module Fog
def list_volumes(detailed=true) def list_volumes(detailed=true)
response = Excon::Response.new response = Excon::Response.new
response.status = 200 response.status = 200
response.body = { self.data[:volumes] ||= [
"volumes" => [
{ "status" => "available", { "status" => "available",
"displayDescription" => "", "displayDescription" => "",
"availabilityZone" => "nova", "availabilityZone" => "nova",
"displayName" => "WD", "displayName" => "test 1",
"attachments" => [{}], "attachments" => [{}],
"volumeType" => nil, "volumeType" => nil,
"snapshotId" => nil, "snapshotId" => nil,
@ -36,7 +35,7 @@ module Fog
{ "status" => "available", { "status" => "available",
"displayDescription" => "", "displayDescription" => "",
"availabilityZone" => "nova", "availabilityZone" => "nova",
"displayName" => "test", "displayName" => "test 2",
"attachments" => [{}], "attachments" => [{}],
"volumeType" => nil, "volumeType" => nil,
"snapshotId" => nil, "snapshotId" => nil,
@ -44,7 +43,8 @@ module Fog
"id" => 8, "id" => 8,
"createdAt" => "2012-03-30 16:14:55.582717", "createdAt" => "2012-03-30 16:14:55.582717",
"metadata" => {} } "metadata" => {} }
] } ]
response.body = { 'volumes' => self.data[:volumes] }
response response
end end
end end