From 2c25fae5f1221f81f657b551c9b54df8e5a5d2f0 Mon Sep 17 00:00:00 2001 From: Wesley Beary Date: Thu, 20 Aug 2009 19:25:52 -0700 Subject: [PATCH] use the new more persistent data store for mocks --- lib/fog/aws/requests/ec2/allocate_address.rb | 2 +- lib/fog/aws/requests/ec2/create_key_pair.rb | 4 ++-- lib/fog/aws/requests/ec2/create_security_group.rb | 4 ++-- lib/fog/aws/requests/ec2/create_volume.rb | 2 +- lib/fog/aws/requests/ec2/delete_key_pair.rb | 2 +- lib/fog/aws/requests/ec2/delete_security_group.rb | 4 ++-- lib/fog/aws/requests/ec2/delete_volume.rb | 6 +++--- lib/fog/aws/requests/ec2/describe_addresses.rb | 6 +++--- lib/fog/aws/requests/ec2/describe_key_pairs.rb | 6 +++--- lib/fog/aws/requests/ec2/describe_security_groups.rb | 6 +++--- lib/fog/aws/requests/ec2/describe_volumes.rb | 12 ++++++------ lib/fog/aws/requests/ec2/release_address.rb | 2 +- ...e_snapshot_spec.rb => describe_snapshots_spec.rb} | 0 13 files changed, 28 insertions(+), 28 deletions(-) rename spec/aws/requests/ec2/{describe_snapshot_spec.rb => describe_snapshots_spec.rb} (100%) diff --git a/lib/fog/aws/requests/ec2/allocate_address.rb b/lib/fog/aws/requests/ec2/allocate_address.rb index dd8e5171c..e88865975 100644 --- a/lib/fog/aws/requests/ec2/allocate_address.rb +++ b/lib/fog/aws/requests/ec2/allocate_address.rb @@ -35,7 +35,7 @@ else 'instanceId' => '', 'publicIp' => public_ip } - @data[:addresses][public_ip] = data + Fog::AWS::EC2.data[:addresses][public_ip] = data response.body = { 'publicIp' => public_ip, 'requestId' => Fog::AWS::Mock.request_id diff --git a/lib/fog/aws/requests/ec2/create_key_pair.rb b/lib/fog/aws/requests/ec2/create_key_pair.rb index 54da43e7d..97202d42f 100644 --- a/lib/fog/aws/requests/ec2/create_key_pair.rb +++ b/lib/fog/aws/requests/ec2/create_key_pair.rb @@ -35,14 +35,14 @@ else def create_key_pair(key_name) response = Fog::Response.new - unless @data[:key_pairs][key_name] + unless Fog::AWS::EC2.data[:key_pairs][key_name] response.status = 200 data = { 'keyFingerprint' => Fog::AWS::Mock.key_fingerprint, 'keyMaterial' => Fog::AWS::Mock.key_material, 'keyName' => key_name } - @data[:key_pairs][key_name] = data + Fog::AWS::EC2.data[:key_pairs][key_name] = data response.body = { 'requestId' => Fog::AWS::Mock.request_id }.merge!(data) diff --git a/lib/fog/aws/requests/ec2/create_security_group.rb b/lib/fog/aws/requests/ec2/create_security_group.rb index 0e204b665..1721f87fd 100644 --- a/lib/fog/aws/requests/ec2/create_security_group.rb +++ b/lib/fog/aws/requests/ec2/create_security_group.rb @@ -35,14 +35,14 @@ else def create_security_group(name, description) response = Fog::Response.new - unless @data[:security_groups][name] + unless Fog::AWS::EC2.data[:security_groups][name] data = { 'GroupDescription' => description, 'GroupName' => name, 'ipPermissions' => [], 'OwnerId' => Fog::AWS::Mock.owner_id } - @data[:security_groups][name] = data + Fog::AWS::EC2.data[:security_groups][name] = data response.body = { 'requestId' => Fog::AWS::Mock.request_id, 'return' => true diff --git a/lib/fog/aws/requests/ec2/create_volume.rb b/lib/fog/aws/requests/ec2/create_volume.rb index de6e20582..2d7a7af92 100644 --- a/lib/fog/aws/requests/ec2/create_volume.rb +++ b/lib/fog/aws/requests/ec2/create_volume.rb @@ -52,7 +52,7 @@ else 'status' => 'creating', 'volumeId' => volume_id } - @data[:volumes][volume_id] = data + Fog::AWS::EC2.data[:volumes][volume_id] = data response.body = { 'requestId' => Fog::AWS::Mock.request_id }.merge!(data.reject {|key,value| !['availabilityZone','createTime','size','snapshotId','status','volumeId'].include?(key) }) diff --git a/lib/fog/aws/requests/ec2/delete_key_pair.rb b/lib/fog/aws/requests/ec2/delete_key_pair.rb index 461e1cb3b..acca06a3b 100644 --- a/lib/fog/aws/requests/ec2/delete_key_pair.rb +++ b/lib/fog/aws/requests/ec2/delete_key_pair.rb @@ -33,7 +33,7 @@ else def delete_key_pair(key_name) response = Fog::Response.new - @data[:key_pairs].delete(key_name) + Fog::AWS::EC2.data[:key_pairs].delete(key_name) response.status = 200 response.body = { 'requestId' => Fog::AWS::Mock.request_id, diff --git a/lib/fog/aws/requests/ec2/delete_security_group.rb b/lib/fog/aws/requests/ec2/delete_security_group.rb index cfc86e436..4b18ad67d 100644 --- a/lib/fog/aws/requests/ec2/delete_security_group.rb +++ b/lib/fog/aws/requests/ec2/delete_security_group.rb @@ -32,8 +32,8 @@ else class EC2 def delete_security_group(name) response = Fog::Response.new - if @data[:security_groups][name] - @data[:security_groups].delete(name) + if Fog::AWS::EC2.data[:security_groups][name] + Fog::AWS::EC2.data[:security_groups].delete(name) response.status = 200 response.body = { 'requestId' => Fog::AWS::Mock.request_id, diff --git a/lib/fog/aws/requests/ec2/delete_volume.rb b/lib/fog/aws/requests/ec2/delete_volume.rb index 2df4e3b5f..a735c7ece 100644 --- a/lib/fog/aws/requests/ec2/delete_volume.rb +++ b/lib/fog/aws/requests/ec2/delete_volume.rb @@ -33,13 +33,13 @@ else def delete_volume(volume_id) response = Fog::Response.new - if volume = @data[:volumes][volume_id] - @data[:deleted_at][volume['volumeId']] = Time.now + if volume = Fog::AWS::EC2.data[:volumes][volume_id] + Fog::AWS::EC2.data[:deleted_at][volume['volumeId']] = Time.now volume['status'] = 'deleting' response.status = 200 response.body = { 'requestId' => Fog::AWS::Mock.request_id, - 'return' => true + 'return' => true } else response.status = 400 diff --git a/lib/fog/aws/requests/ec2/describe_addresses.rb b/lib/fog/aws/requests/ec2/describe_addresses.rb index 077eeed59..69f0b69db 100644 --- a/lib/fog/aws/requests/ec2/describe_addresses.rb +++ b/lib/fog/aws/requests/ec2/describe_addresses.rb @@ -34,12 +34,12 @@ else class EC2 def describe_addresses(public_ip = []) - public_ip = [*public_ip] response = Fog::Response.new + public_ip = [*public_ip] if public_ip != [] - addresses_set = @data[:addresses].reject {|key, value| !public_ip.include?(key)}.values + addresses_set = Fog::AWS::EC2.data[:addresses].reject {|key, value| !public_ip.include?(key)}.values else - addresses_set = @data[:addresses].values + addresses_set = Fog::AWS::EC2.data[:addresses].values end if public_ip.length == 0 || public_ip.length == addresses_set.length response.status = 200 diff --git a/lib/fog/aws/requests/ec2/describe_key_pairs.rb b/lib/fog/aws/requests/ec2/describe_key_pairs.rb index aa1e8ca96..4d9058610 100644 --- a/lib/fog/aws/requests/ec2/describe_key_pairs.rb +++ b/lib/fog/aws/requests/ec2/describe_key_pairs.rb @@ -34,12 +34,12 @@ else class EC2 def describe_key_pairs(key_name = []) - key_name = [*key_name] response = Fog::Response.new + key_name = [*key_name] if key_name != [] - key_set = @data[:key_pairs].reject {|key, value| !key_name.include?(key)}.values + key_set = Fog::AWS::EC2.data[:key_pairs].reject {|key, value| !key_name.include?(key)}.values else - key_set = @data[:key_pairs].values + key_set = Fog::AWS::EC2.data[:key_pairs].values end if key_name.length == 0 || key_name.length == key_set.length response.status = 200 diff --git a/lib/fog/aws/requests/ec2/describe_security_groups.rb b/lib/fog/aws/requests/ec2/describe_security_groups.rb index d22279b34..e003b1345 100644 --- a/lib/fog/aws/requests/ec2/describe_security_groups.rb +++ b/lib/fog/aws/requests/ec2/describe_security_groups.rb @@ -44,12 +44,12 @@ else class EC2 def describe_security_groups(group_name = []) - group_name = [*group_name] response = Fog::Response.new + group_name = [*group_name] if group_name != [] - security_group_info = @data[:security_groups].reject {|key, value| !group_name.include?(key)}.values + security_group_info = Fog::AWS::EC2.data[:security_groups].reject {|key, value| !group_name.include?(key)}.values else - security_group_info = @data[:security_groups].values + security_group_info = Fog::AWS::EC2.data[:security_groups].values end if group_name.length == 0 || group_name.length == security_group_info.length response.status = 200 diff --git a/lib/fog/aws/requests/ec2/describe_volumes.rb b/lib/fog/aws/requests/ec2/describe_volumes.rb index 48255ca15..7024c5681 100644 --- a/lib/fog/aws/requests/ec2/describe_volumes.rb +++ b/lib/fog/aws/requests/ec2/describe_volumes.rb @@ -43,12 +43,12 @@ else class EC2 def describe_volumes(volume_id = []) - volume_id = [*volume_id] response = Fog::Response.new + volume_id = [*volume_id] if volume_id != [] - volume_set = @data[:volumes].reject {|key,value| !volume_id.include?(key)}.values + volume_set = Fog::AWS::EC2.data[:volumes].reject {|key,value| !volume_id.include?(key)}.values else - volume_set = @data[:volumes].values + volume_set = Fog::AWS::EC2.data[:volumes].values end volume_set.each do |volume| @@ -58,9 +58,9 @@ else volume['status'] = 'available' end when 'deleting' - if Time.now - @data[:deleted_at][volume['volumeId']] > 2 - @data[:deleted_at].delete(volume['volumeId']) - @data[:volumes].delete(volume['volumeId']) + if Time.now - Fog::AWS::EC2.data[:deleted_at][volume['volumeId']] > 2 + Fog::AWS::EC2.data[:deleted_at].delete(volume['volumeId']) + Fog::AWS::EC2.data[:volumes].delete(volume['volumeId']) end end end diff --git a/lib/fog/aws/requests/ec2/release_address.rb b/lib/fog/aws/requests/ec2/release_address.rb index 509f390ef..b08a3ac60 100644 --- a/lib/fog/aws/requests/ec2/release_address.rb +++ b/lib/fog/aws/requests/ec2/release_address.rb @@ -30,7 +30,7 @@ else def release_address(public_ip) response = Fog::Response.new - if (address = @data[:addresses].delete(public_ip)) + if (address = Fog::AWS::EC2.data[:addresses].delete(public_ip)) response.status = 200 response.body = { 'requestId' => Fog::AWS::Mock.request_id, diff --git a/spec/aws/requests/ec2/describe_snapshot_spec.rb b/spec/aws/requests/ec2/describe_snapshots_spec.rb similarity index 100% rename from spec/aws/requests/ec2/describe_snapshot_spec.rb rename to spec/aws/requests/ec2/describe_snapshots_spec.rb