mirror of
https://github.com/fog/fog-aws.git
synced 2022-11-09 13:50:52 -05:00
describe mount target security groups
This commit is contained in:
parent
8ff47372ac
commit
95284ad4b8
7 changed files with 122 additions and 32 deletions
|
@ -24,6 +24,7 @@ module Fog
|
|||
request :delete_file_system
|
||||
request :delete_mount_target
|
||||
request :describe_file_systems
|
||||
request :describe_mount_target_security_groups
|
||||
request :describe_mount_targets
|
||||
|
||||
class Mock
|
||||
|
@ -31,8 +32,9 @@ module Fog
|
|||
@data ||= Hash.new do |hash, region|
|
||||
hash[region] = Hash.new do |region_hash, key|
|
||||
region_hash[key] = {
|
||||
:file_systems => {},
|
||||
:mount_targets => {}
|
||||
:file_systems => {},
|
||||
:mount_targets => {},
|
||||
:security_groups => {}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
@ -150,7 +152,7 @@ module Fog
|
|||
raise Fog::AWS::EFS::FileSystemInUse.slurp(error, match[:message])
|
||||
end
|
||||
raise case match[:message]
|
||||
when /invalid ((file system)|(mount target)) id/i
|
||||
when /invalid ((file system)|(mount target)|(security group)) id/i
|
||||
Fog::AWS::EFS::NotFound.slurp(error, match[:message])
|
||||
when /invalid subnet id/i
|
||||
Fog::AWS::EFS::InvalidSubnet.slurp(error, match[:message])
|
||||
|
|
|
@ -17,7 +17,6 @@ module Fog
|
|||
state == 'available'
|
||||
end
|
||||
|
||||
|
||||
def destroy
|
||||
requires :identity
|
||||
service.delete_mount_target(:id => self.identity)
|
||||
|
@ -29,15 +28,20 @@ module Fog
|
|||
service.file_systems.get(self.file_system_id)
|
||||
end
|
||||
|
||||
def security_groups
|
||||
requires :identity
|
||||
service.describe_mount_target_security_groups(self.identity).body["SecurityGroups"]
|
||||
end
|
||||
|
||||
def save
|
||||
requires :file_system_id, :subnet_id
|
||||
params = {
|
||||
:file_system_id => self.file_system_id,
|
||||
:subnet_id => self.subnet_id,
|
||||
:subnet_id => self.subnet_id
|
||||
}
|
||||
|
||||
params.merge!('IpAddress' => self.ip_address) if self.ip_address
|
||||
params.merge!('SecurityGroups' => self.security_groups) if self.security_groups
|
||||
params.merge!('SecurityGroups' => @security_groups) if @security_groups
|
||||
|
||||
merge_attributes(service.create_mount_target(params).body)
|
||||
end
|
||||
|
|
|
@ -24,9 +24,10 @@ module Fog
|
|||
|
||||
class Mock
|
||||
def create_mount_target(options={})
|
||||
response = Excon::Response.new
|
||||
file_system_id = options[:file_system_id]
|
||||
subnet_id = options[:subnet_id]
|
||||
response = Excon::Response.new
|
||||
file_system_id = options[:file_system_id]
|
||||
subnet_id = options[:subnet_id]
|
||||
security_groups = options["SecurityGroups"] || []
|
||||
|
||||
unless file_system = self.data[:file_systems][file_system_id]
|
||||
raise Fog::AWS::EFS::NotFound.new("invalid file system ID: #{file_system_id}")
|
||||
|
@ -41,6 +42,10 @@ module Fog
|
|||
raise Fog::AWS::EFS::InvalidSubnet.new("invalid subnet ID: #{subnet_id}")
|
||||
end
|
||||
|
||||
security_groups.each do |sg|
|
||||
raise Fog::AWS::EFS::NotFound.new("invalid security group ID: #{sg}") unless Fog::Compute[:aws].data[:security_groups].values.detect { |sgd| sgd["groupId"] == sg }
|
||||
end
|
||||
|
||||
id = "fsmt-#{Fog::Mock.random_letters(8)}"
|
||||
|
||||
mount_target = {
|
||||
|
@ -53,7 +58,8 @@ module Fog
|
|||
'SubnetId' => subnet.identity,
|
||||
}
|
||||
|
||||
self.data[:mount_targets][id] = mount_target
|
||||
self.data[:mount_targets][id] = mount_target
|
||||
self.data[:security_groups][id] = security_groups
|
||||
|
||||
response.body = mount_target
|
||||
response
|
||||
|
|
|
@ -26,7 +26,7 @@ module Fog
|
|||
response = Excon::Response.new
|
||||
|
||||
unless self.data[:mount_targets][id]
|
||||
raise Fog::AWS::EFS::NotFound.new("invalid file system ID: #{id}")
|
||||
raise Fog::AWS::EFS::NotFound.new("invalid mount target ID: #{id}")
|
||||
end
|
||||
|
||||
self.data[:mount_targets].delete(id)
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class EFS
|
||||
class Real
|
||||
# Describe mount target security groups
|
||||
# http://docs.aws.amazon.com/efs/latest/ug/API_DescribeMountTargetSecurityGroups.html
|
||||
# ==== Parameters
|
||||
# * MountTargetId - Id of the mount target for which you want to describe security groups
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>
|
||||
# * body<~Hash>
|
||||
|
||||
def describe_mount_target_security_groups(mount_target_id)
|
||||
request(
|
||||
:path => "mount-targets/#{mount_target_id}/security-groups"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def describe_mount_target_security_groups(mount_target_id)
|
||||
response = Excon::Response.new
|
||||
|
||||
unless self.data[:mount_targets][mount_target_id]
|
||||
raise Fog::AWS::EFS::NotFound.new("invalid mount target ID: #{mount_target_id}")
|
||||
end
|
||||
|
||||
response.body = {"SecurityGroups" => self.data[:security_groups][mount_target_id]}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,25 +1,36 @@
|
|||
Shindo.tests("AWS::EFS | mount target", ["aws", "efs"]) do
|
||||
if ENV['FILE_SYSTEM_ID']
|
||||
@file_system = Fog::AWS[:efs].file_systems.get(ENV["FILE_SYSTEM_ID"])
|
||||
else
|
||||
@file_system = Fog::AWS[:efs].file_systems.create(:creation_token => "fogtoken#{rand(999).to_s}")
|
||||
end
|
||||
|
||||
@file_system = Fog::AWS[:efs].file_systems.create(:creation_token => "fogtoken#{rand(999).to_s}")
|
||||
@file_system.wait_for { ready? }
|
||||
|
||||
if Fog.mocking?
|
||||
vpc = Fog::Compute[:aws].vpcs.create(cidr_block: "10.0.0.0/16")
|
||||
Fog::Compute[:aws].subnets.create(vpc_id: vpc.id, cidr_block: "10.0.1.0/24")
|
||||
vpc = Fog::Compute[:aws].vpcs.create(:cidr_block => "10.0.0.0/16")
|
||||
subnet = Fog::Compute[:aws].subnets.create(:vpc_id => vpc.id, :cidr_block => "10.0.1.0/24")
|
||||
else
|
||||
vpc = Fog::Compute[:aws].vpcs.first
|
||||
subnet = vpc.subnets.first
|
||||
end
|
||||
|
||||
security_group = Fog::Compute[:aws].security_groups.create(
|
||||
:vpc_id => vpc.id,
|
||||
:name => "fog#{rand(999).to_s}",
|
||||
:description => "fog#{rand(999).to_s}"
|
||||
)
|
||||
|
||||
mount_target_params = {
|
||||
:file_system_id => @file_system.identity,
|
||||
:subnet_id => Fog::Compute[:aws].vpcs.first.subnets.first.identity
|
||||
:file_system_id => @file_system.identity,
|
||||
:subnet_id => subnet.identity,
|
||||
:security_groups => [security_group.group_id],
|
||||
}
|
||||
|
||||
model_tests(Fog::AWS[:efs].mount_targets, mount_target_params, true)
|
||||
model_tests(Fog::AWS[:efs].mount_targets, mount_target_params, true) do
|
||||
@instance.wait_for { ready? }
|
||||
|
||||
unless ENV["LEAVE_FILE_SYSTEM"] = 'true'
|
||||
@file_system.destroy
|
||||
tests("#security_groups") do
|
||||
returns([security_group.group_id]) { @instance.security_groups }
|
||||
end
|
||||
end
|
||||
|
||||
@file_system.wait_for { number_of_mount_targets == 0 }
|
||||
@file_system.destroy
|
||||
security_group.destroy
|
||||
end
|
||||
|
|
|
@ -28,18 +28,29 @@ Shindo.tests('AWS::EFS | file systems', ['aws', 'efs']) do
|
|||
end
|
||||
|
||||
if Fog.mocking?
|
||||
vpc = Fog::Compute[:aws].vpcs.create(cidr_block: "10.0.0.0/16")
|
||||
Fog::Compute[:aws].subnets.create(vpc_id: vpc.id, cidr_block: "10.0.1.0/24")
|
||||
vpc = Fog::Compute[:aws].vpcs.create(:cidr_block => "10.0.0.0/16")
|
||||
Fog::Compute[:aws].subnets.create(
|
||||
:vpc_id => vpc.id,
|
||||
:cidr_block => "10.0.1.0/24"
|
||||
)
|
||||
else
|
||||
vpc = Fog::Compute[:aws].vpcs.first
|
||||
end
|
||||
|
||||
subnet_id = Fog::Compute[:aws].vpcs.first.subnets.first.identity
|
||||
security_group = Fog::Compute[:aws].security_groups.create(
|
||||
:vpc_id => vpc.id,
|
||||
:name => "fog#{suffix}",
|
||||
:description => "fog#{suffix}"
|
||||
)
|
||||
|
||||
raises(Fog::AWS::EFS::InvalidSubnet, "invalid subnet ID: foobar") do
|
||||
Fog::AWS[:efs].create_mount_target(:file_system_id => file_system_id, :subnet_id => "foobar")
|
||||
subnet_id = vpc.subnets.first.identity
|
||||
|
||||
raises(Fog::AWS::EFS::InvalidSubnet, "invalid subnet ID: foobar#{suffix}") do
|
||||
Fog::AWS[:efs].create_mount_target(:file_system_id => file_system_id, :subnet_id => "foobar#{suffix}")
|
||||
end
|
||||
|
||||
raises(Fog::AWS::EFS::NotFound, "invalid file system ID: foobar") do
|
||||
Fog::AWS[:efs].create_mount_target(:file_system_id => "foobar", :subnet_id => subnet_id)
|
||||
raises(Fog::AWS::EFS::NotFound, "invalid file system ID: foobar#{suffix}") do
|
||||
Fog::AWS[:efs].create_mount_target(:file_system_id => "foobar#{suffix}", :subnet_id => subnet_id)
|
||||
end
|
||||
|
||||
if Fog.mocking?
|
||||
|
@ -53,8 +64,20 @@ Shindo.tests('AWS::EFS | file systems', ['aws', 'efs']) do
|
|||
end
|
||||
end
|
||||
|
||||
raises(Fog::AWS::EFS::NotFound, "invalid security group ID: foobar#{suffix}") do
|
||||
Fog::AWS[:efs].create_mount_target(
|
||||
:file_system_id => file_system_id,
|
||||
:subnet_id => subnet_id,
|
||||
'SecurityGroups' => ["foobar#{suffix}"]
|
||||
)
|
||||
end
|
||||
|
||||
tests("#create_mount_target(file_system_id: #{file_system_id}, subnet_id: #{subnet_id})").formats(AWS::EFS::Formats::MOUNT_TARGET_FORMAT) do
|
||||
Fog::AWS[:efs].create_mount_target(:file_system_id => file_system_id, :subnet_id => subnet_id).body
|
||||
Fog::AWS[:efs].create_mount_target(
|
||||
:file_system_id => file_system_id,
|
||||
:subnet_id => subnet_id,
|
||||
'SecurityGroups' => [security_group.group_id]
|
||||
).body
|
||||
end
|
||||
|
||||
tests("#describe_mount_targets(file_system_id: #{file_system_id})").formats(AWS::EFS::Formats::DESCRIBE_MOUNT_TARGETS_RESULT) do
|
||||
|
@ -71,6 +94,10 @@ Shindo.tests('AWS::EFS | file systems', ['aws', 'efs']) do
|
|||
Fog::AWS[:efs].describe_mount_targets
|
||||
end
|
||||
|
||||
raises(Fog::AWS::EFS::NotFound, "invalid mount target id: foobar#{suffix}") do
|
||||
Fog::AWS[:efs].delete_mount_target(:id => "foobar#{suffix}")
|
||||
end
|
||||
|
||||
tests("#delete_mount_target(id: #{mount_target_id})") do
|
||||
returns(true) do
|
||||
result = Fog::AWS[:efs].delete_mount_target(:id => mount_target_id)
|
||||
|
@ -88,11 +115,17 @@ Shindo.tests('AWS::EFS | file systems', ['aws', 'efs']) do
|
|||
Fog::AWS[:efs].data[:file_systems][file_system_id]["NumberOfMountTargets"] = 0
|
||||
end
|
||||
|
||||
raises(Fog::AWS::EFS::NotFound, "invalid file system ID: foobar#{suffix}") do
|
||||
Fog::AWS[:efs].delete_file_system(:id => "foobar#{suffix}")
|
||||
end
|
||||
|
||||
tests("#delete_file_system") do
|
||||
returns(true) do
|
||||
result = Fog::AWS[:efs].delete_file_system(:id => file_system_id)
|
||||
result.body.empty?
|
||||
end
|
||||
end
|
||||
|
||||
security_group.destroy
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue