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={})
@openstack_username = options[:openstack_username]
@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
@openstack_tenant = options[:openstack_tenant]
end
def data
self.class.data[@openstack_username]
self.class.data["#{@openstack_username}-#{@openstack_tenant}"]
end
def reset_data
self.class.data.delete(@openstack_username)
self.class.data.delete("#{@openstack_username}-#{@openstack_tenant}")
end
def credentials

View file

@ -18,54 +18,50 @@ module Fog
response = Excon::Response.new
response.status = 200
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-Length" => "667",
"Date" => Date.new
}
response.body = {
"security_groups" => [{
"rules" => [{
"from_port" => 44,
self.data[:security_groups] ||= [
{ "rules" => [
{ "from_port" => 44,
"group" => {},
"ip_protocol" => "tcp",
"to_port" => 55,
"parent_group_id" => 1,
"ip_range" => {"cidr"=>"10.10.10.10/24"},
"id"=>1
"id" => Fog::Mock.random_base64(36)
},
{
"from_port" => 2,
{ "from_port" => 2,
"group" => {},
"ip_protocol" => "tcp",
"to_port" => 3,
"parent_group_id" => 1,
"ip_range" => {"cidr"=>"10.10.10.10/24"},
"id" => 2
}],
"tenant_id" => "d5183375ab0343f3a0b4b05f547aefc2",
"id" => 1,
"id" => Fog::Mock.random_base64(36)
} ],
"tenant_id" => @openstack_tenant,
"id" => Fog::Mock.random_base64(36),
"name" => "default",
"description" => "default"
},
{
"rules" => [{
"from_port" => 44,
"rules" => [
{ "from_port" => 44,
"group" => {},
"ip_protocol" => "tcp",
"to_port" => 55,
"parent_group_id" => 2,
"ip_range" => {
"cidr"=>"10.10.10.10/24"
},
"id"=>3
}],
"tenant_id" => "d5183375ab0343f3a0b4b05f547aefc2",
"id" => 2,
"ip_range" => { "cidr"=>"10.10.10.10/24" },
"id"=> Fog::Mock.random_base64(36)
} ],
"tenant_id" => @openstack_tenant,
"id" => Fog::Mock.random_base64(36),
"name" => "test",
"description" => "this is a test"
}
]}
]
response.body = { 'security_groups' => self.data[:security_groups] }
response
end
end # mock

View file

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