From d46c886f6790c736aa473fdf47b112a4561390f2 Mon Sep 17 00:00:00 2001 From: Nelvin Driz Date: Sun, 1 Apr 2012 22:06:27 +0800 Subject: [PATCH] [openstack|compute] Update Mocks for Security Groups and Volumes Signed-off-by: Nelvin Driz --- lib/fog/openstack/compute.rb | 17 ++------ .../requests/compute/list_security_groups.rb | 42 +++++++++---------- .../requests/compute/list_volumes.rb | 10 ++--- 3 files changed, 27 insertions(+), 42 deletions(-) diff --git a/lib/fog/openstack/compute.rb b/lib/fog/openstack/compute.rb index 774dbe3bf..6b9779fbd 100644 --- a/lib/fog/openstack/compute.rb +++ b/lib/fog/openstack/compute.rb @@ -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 diff --git a/lib/fog/openstack/requests/compute/list_security_groups.rb b/lib/fog/openstack/requests/compute/list_security_groups.rb index 13d5e2d2a..9ac0f2343 100644 --- a/lib/fog/openstack/requests/compute/list_security_groups.rb +++ b/lib/fog/openstack/requests/compute/list_security_groups.rb @@ -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 diff --git a/lib/fog/openstack/requests/compute/list_volumes.rb b/lib/fog/openstack/requests/compute/list_volumes.rb index f4198bdd3..9a45fba43 100644 --- a/lib/fog/openstack/requests/compute/list_volumes.rb +++ b/lib/fog/openstack/requests/compute/list_volumes.rb @@ -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