From eadd0231a741245d83fdfd1234016d7565226c53 Mon Sep 17 00:00:00 2001 From: Wesley Beary Date: Mon, 28 Sep 2009 20:00:49 -0700 Subject: [PATCH] fixes/specs for security_group(s) --- lib/fog/aws/ec2.rb | 2 + lib/fog/aws/models/ec2/security_group.rb | 4 +- lib/fog/aws/models/ec2/security_groups.rb | 2 +- spec/aws/models/ec2/security_group_spec.rb | 84 +++++++++++++++++++++ spec/aws/models/ec2/security_groups_spec.rb | 71 +++++++++++++++++ 5 files changed, 160 insertions(+), 3 deletions(-) create mode 100644 spec/aws/models/ec2/security_group_spec.rb create mode 100644 spec/aws/models/ec2/security_groups_spec.rb diff --git a/lib/fog/aws/ec2.rb b/lib/fog/aws/ec2.rb index e55149aa6..525ceb402 100644 --- a/lib/fog/aws/ec2.rb +++ b/lib/fog/aws/ec2.rb @@ -30,6 +30,8 @@ module Fog load "fog/aws/models/ec2/addresses.rb" load "fog/aws/models/ec2/key_pair.rb" load "fog/aws/models/ec2/key_pairs.rb" + load "fog/aws/models/ec2/security_group.rb" + load "fog/aws/models/ec2/security_groups.rb" load "fog/aws/models/ec2/snapshot.rb" load "fog/aws/models/ec2/snapshots.rb" load "fog/aws/models/ec2/volume.rb" diff --git a/lib/fog/aws/models/ec2/security_group.rb b/lib/fog/aws/models/ec2/security_group.rb index ac3af4236..f795463d5 100644 --- a/lib/fog/aws/models/ec2/security_group.rb +++ b/lib/fog/aws/models/ec2/security_group.rb @@ -15,12 +15,12 @@ module Fog end def reload - new_attributes = security_groups.all(@public_ip).first.attributes + new_attributes = security_groups.get(@group_name).attributes merge_attributes(new_attributes) end def save - data = connection.create_create_security_group(@group_name, @group_description).body + data = connection.create_security_group(@group_name, @group_description).body true end diff --git a/lib/fog/aws/models/ec2/security_groups.rb b/lib/fog/aws/models/ec2/security_groups.rb index b73fe0692..69c92aa78 100644 --- a/lib/fog/aws/models/ec2/security_groups.rb +++ b/lib/fog/aws/models/ec2/security_groups.rb @@ -16,7 +16,7 @@ module Fog end def all(group_name = []) - data = connection.describe_security_groups(group_name) + data = connection.describe_security_groups(group_name).body security_groups = Fog::AWS::EC2::SecurityGroups.new({ :connection => connection, :group_name => group_name diff --git a/spec/aws/models/ec2/security_group_spec.rb b/spec/aws/models/ec2/security_group_spec.rb new file mode 100644 index 000000000..9e38beace --- /dev/null +++ b/spec/aws/models/ec2/security_group_spec.rb @@ -0,0 +1,84 @@ +require File.dirname(__FILE__) + '/../../../spec_helper' + +describe 'Fog::AWS::EC2::SecurityGroup' do + + describe "#initialize" do + + it "should remap attributes from parser" #do + # address = Fog::AWS::EC2::SecurityGroup.new( + # 'instanceId' => 'i-00000000', + # 'publicIp' => '0.0.0.0' + # ) + # address.instance_id.should == 'i-00000000' + # address.public_ip.should == '0.0.0.0' + # end + + end + + describe "#security_groups" do + + it "should return a Fog::AWS::EC2::SecurityGroups" do + ec2.security_groups.new.security_groups.should be_a(Fog::AWS::EC2::SecurityGroups) + end + + it "should be the security_groups the keypair is related to" do + security_groups = ec2.security_groups + security_groups.new.security_groups.should == security_groups + end + + end + + describe "#destroy" do + + it "should return true if the security_group is deleted" do + address = ec2.security_groups.create(:group_description => 'groupdescription', :group_name => 'keyname') + address.destroy.should be_true + end + + end + + describe "#reload" do + + before(:each) do + @security_group = ec2.security_groups.create(:group_description => 'groupdescription', :group_name => 'keyname') + @reloaded = @security_group.reload + end + + after(:each) do + @security_group.destroy + end + + it "should return a Fog::AWS::EC2::SecurityGroup" do + @reloaded.should be_a(Fog::AWS::EC2::SecurityGroup) + end + + it "should reset attributes to remote state" do + @security_group.attributes.should == @reloaded.attributes + end + + end + + describe "#save" do + + before(:each) do + @security_group = ec2.security_groups.new(:group_description => 'groupdescription', :group_name => 'keyname') + end + + it "should return true when it succeeds" do + @security_group.save.should be_true + @security_group.destroy + end + + it "should not exist in security_groups before save" do + @security_group.security_groups.get(@security_group.group_name).should be_nil + end + + it "should exist in buckets after save" do + @security_group.save + @security_group.security_groups.get(@security_group.group_name).should_not be_nil + @security_group.destroy + end + + end + +end diff --git a/spec/aws/models/ec2/security_groups_spec.rb b/spec/aws/models/ec2/security_groups_spec.rb new file mode 100644 index 000000000..c732a7f09 --- /dev/null +++ b/spec/aws/models/ec2/security_groups_spec.rb @@ -0,0 +1,71 @@ +require File.dirname(__FILE__) + '/../../../spec_helper' + +describe 'Fog::AWS::EC2::SecurityGroups' do + + describe "#all" do + + it "should return a Fog::AWS::EC2::SecurityGroups" do + ec2.security_groups.all.should be_a(Fog::AWS::EC2::SecurityGroups) + end + + it "should include persisted security_groups" do + security_group = ec2.security_groups.create(:group_description => 'groupdescription', :group_name => 'keyname') + ec2.security_groups.get(security_group.group_name).should_not be_nil + security_group.destroy + end + + end + + describe "#create" do + + before(:each) do + @security_group = ec2.security_groups.create(:group_description => 'groupdescription', :group_name => 'keyname') + end + + after(:each) do + @security_group.destroy + end + + it "should return a Fog::AWS::EC2::SecurityGroup" do + @security_group.should be_a(Fog::AWS::EC2::SecurityGroup) + end + + it "should exist on ec2" do + ec2.security_groups.get(@security_group.group_name).should_not be_nil + end + + end + + describe "#get" do + + it "should return a Fog::AWS::EC2::SecurityGroup if a matching security_group exists" do + security_group = ec2.security_groups.create(:group_description => 'groupdescription', :group_name => 'keyname') + get = ec2.security_groups.get(security_group.group_name) + security_group.attributes[:fingerprint].should == get.attributes[:fingerprint] + security_group.attributes[:group_name].should == get.attributes[:group_name] + security_group.destroy + end + + it "should return nil if no matching security_group exists" do + ec2.security_groups.get('notasecuritygroupname').should be_nil + end + + end + + describe "#new" do + + it "should return a Fog::AWS::EC2::SecurityGroup" do + ec2.security_groups.new(:group_description => 'groupdescription', :group_name => 'keyname').should be_a(Fog::AWS::EC2::SecurityGroup) + end + + end + + describe "#reload" do + + it "should return a Fog::AWS::EC2::SecurityGroups" do + ec2.security_groups.all.reload.should be_a(Fog::AWS::EC2::SecurityGroups) + end + + end + +end