mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[OpenStack|Network] Add tests for security_groups and security_group_rules methods
This commit is contained in:
parent
d4d53d0892
commit
525a35ae1d
6 changed files with 186 additions and 0 deletions
27
tests/openstack/models/network/security_group_rule_tests.rb
Normal file
27
tests/openstack/models/network/security_group_rule_tests.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
Shindo.tests('Fog::Network[:openstack] | security_group_rule model', ['openstack']) do
|
||||
|
||||
@secgroup = Fog::Network[:openstack].security_groups.create({:name => "fogsecgroup"})
|
||||
attributes = {:security_group_id => @secgroup.id, :direction => "ingress"}
|
||||
model_tests(Fog::Network[:openstack].security_group_rules, attributes, true)
|
||||
|
||||
tests('success') do
|
||||
tests('#create').succeeds do
|
||||
attributes = {
|
||||
:security_group_id => @secgroup.id,
|
||||
:direction => "ingress",
|
||||
:protocol => "tcp",
|
||||
:port_range_min => 22,
|
||||
:port_range_max => 22,
|
||||
:remote_ip_prefix => "0.0.0.0/0"
|
||||
}
|
||||
@secgrouprule = Fog::Network[:openstack].security_group_rules.create(attributes)
|
||||
@secgrouprule.wait_for { ready? } unless Fog.mocking?
|
||||
!@secgrouprule.id.nil?
|
||||
end
|
||||
|
||||
tests('#destroy').succeeds do
|
||||
@secgrouprule.destroy
|
||||
end
|
||||
end
|
||||
@secgroup.destroy
|
||||
end
|
25
tests/openstack/models/network/security_group_rules_tests.rb
Normal file
25
tests/openstack/models/network/security_group_rules_tests.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
Shindo.tests('Fog::Network[:openstack] | security_group_rules collection', ['openstack']) do
|
||||
|
||||
@secgroup = Fog::Network[:openstack].security_groups.create({:name => "my_secgroup"})
|
||||
attributes = {:security_group_id => @secgroup.id, :direction => "ingress"}
|
||||
collection_tests(Fog::Network[:openstack].security_group_rules, attributes, true)
|
||||
|
||||
tests('success') do
|
||||
attributes = {
|
||||
:security_group_id => @secgroup.id,
|
||||
:direction => "ingress",
|
||||
:protocol => "tcp",
|
||||
:port_range_min => 22,
|
||||
:port_range_max => 22,
|
||||
:remote_ip_prefix => "0.0.0.0/0"
|
||||
}
|
||||
@secgrouprule = Fog::Network[:openstack].security_group_rules.create(attributes)
|
||||
|
||||
tests('#all(filter)').succeeds do
|
||||
secgrouprule = Fog::Network[:openstack].security_group_rules.all({:direction => "ingress"})
|
||||
secgrouprule.first.direction == "ingress"
|
||||
end
|
||||
@secgrouprule.destroy
|
||||
end
|
||||
@secgroup.destroy
|
||||
end
|
17
tests/openstack/models/network/security_group_tests.rb
Normal file
17
tests/openstack/models/network/security_group_tests.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
Shindo.tests('Fog::Network[:openstack] | security_group model', ['openstack']) do
|
||||
|
||||
model_tests(Fog::Network[:openstack].security_groups, {:name => "fogsecgroup"}, true)
|
||||
|
||||
tests('success') do
|
||||
tests('#create').succeeds do
|
||||
attributes = {:name => "my_secgroup", :description => "my sec group desc"}
|
||||
@secgroup = Fog::Network[:openstack].security_groups.create(attributes)
|
||||
@secgroup.wait_for { ready? } unless Fog.mocking?
|
||||
!@secgroup.id.nil?
|
||||
end
|
||||
|
||||
tests('#destroy').succeeds do
|
||||
@secgroup.destroy
|
||||
end
|
||||
end
|
||||
end
|
16
tests/openstack/models/network/security_groups_tests.rb
Normal file
16
tests/openstack/models/network/security_groups_tests.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
Shindo.tests('Fog::Network[:openstack] | security_groups collection', ['openstack']) do
|
||||
|
||||
attributes = {:name => "my_secgroup", :description => "my sec group desc"}
|
||||
collection_tests(Fog::Network[:openstack].security_groups, attributes, true)
|
||||
|
||||
tests('success') do
|
||||
attributes = {:name => "fogsecgroup", :description => "fog sec group desc"}
|
||||
@secgroup = Fog::Network[:openstack].security_groups.create(attributes)
|
||||
|
||||
tests('#all(filter)').succeeds do
|
||||
secgroup = Fog::Network[:openstack].security_groups.all({:name => "fogsecgroup"})
|
||||
secgroup.first.name == "fogsecgroup"
|
||||
end
|
||||
@secgroup.destroy
|
||||
end
|
||||
end
|
|
@ -0,0 +1,58 @@
|
|||
Shindo.tests('Fog::Network[:openstack] | security_grouprule requests', ['openstack']) do
|
||||
|
||||
@security_group_rule_format = {
|
||||
"id" => String,
|
||||
"remote_group_id" => Fog::Nullable::String,
|
||||
"direction" => String,
|
||||
"remote_ip_prefix" => Fog::Nullable::String,
|
||||
"protocol" => Fog::Nullable::String,
|
||||
"ethertype" => String,
|
||||
"port_range_max" => Fog::Nullable::Integer,
|
||||
"port_range_min" => Fog::Nullable::Integer,
|
||||
"security_group_id" => String,
|
||||
"tenant_id" => String
|
||||
}
|
||||
|
||||
tests('success') do
|
||||
attributes = {:name => "my_security_group", :description => "tests group"}
|
||||
data = Fog::Network[:openstack].create_security_group(attributes).body["security_group"]
|
||||
@sec_group_id = data["id"]
|
||||
@sec_group_rule_id = nil
|
||||
|
||||
tests("#create_security_group_rule(#{@sec_group_id}, 'ingress', attributes)").formats(@security_group_rule_format) do
|
||||
attributes = {
|
||||
:remote_ip_prefix => "0.0.0.0/0",
|
||||
:protocol => "tcp",
|
||||
:port_range_min => 22,
|
||||
:port_range_max => 22
|
||||
}
|
||||
data = Fog::Network[:openstack].create_security_group_rule(@sec_group_id, 'ingress', attributes).body["security_group_rule"]
|
||||
@sec_group_rule_id = data["id"]
|
||||
data
|
||||
end
|
||||
|
||||
tests("#get_security_group_rule('#{@sec_group_rule_id}')").formats(@security_group_rule_format) do
|
||||
Fog::Network[:openstack].get_security_group_rule(@sec_group_rule_id).body["security_group_rule"]
|
||||
end
|
||||
|
||||
tests("#list_security_group_rules").formats("security_group_rules" => [@security_group_rule_format]) do
|
||||
Fog::Network[:openstack].list_security_group_rules.body
|
||||
end
|
||||
|
||||
tests("#delete_security_group_rule('#{@sec_group_rule_id}')").succeeds do
|
||||
Fog::Network[:openstack].delete_security_group_rule(@sec_group_rule_id)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
tests('failure') do
|
||||
tests('#get_security_group_rule(0)').raises(Fog::Network::OpenStack::NotFound) do
|
||||
Fog::Network[:openstack].get_security_group_rule(0)
|
||||
end
|
||||
|
||||
tests('#delete_security_group_rule(0)').raises(Fog::Network::OpenStack::NotFound) do
|
||||
Fog::Network[:openstack].delete_security_group_rule(0)
|
||||
end
|
||||
end
|
||||
Fog::Network[:openstack].delete_security_group(@sec_group_id)
|
||||
end
|
43
tests/openstack/requests/network/security_group_tests.rb
Normal file
43
tests/openstack/requests/network/security_group_tests.rb
Normal file
|
@ -0,0 +1,43 @@
|
|||
Shindo.tests('Fog::Network[:openstack] | security_group requests', ['openstack']) do
|
||||
|
||||
@security_group_format = {
|
||||
"id" => String,
|
||||
"name" => String,
|
||||
"description" => String,
|
||||
"tenant_id" => String,
|
||||
"security_group_rules" => [Hash]
|
||||
}
|
||||
|
||||
tests('success') do
|
||||
@sec_group_id = nil
|
||||
|
||||
tests("#create_security_group('fog_security_group', 'tests group')").formats(@security_group_format) do
|
||||
attributes = {:name => "fog_security_group", :description => "tests group"}
|
||||
data = Fog::Network[:openstack].create_security_group(attributes).body["security_group"]
|
||||
@sec_group_id = data["id"]
|
||||
data
|
||||
end
|
||||
|
||||
tests("#get_security_group('#{@sec_group_id}')").formats(@security_group_format) do
|
||||
Fog::Network[:openstack].get_security_group(@sec_group_id).body["security_group"]
|
||||
end
|
||||
|
||||
tests("#list_security_groups").formats('security_groups' => [@security_group_format]) do
|
||||
Fog::Network[:openstack].list_security_groups.body
|
||||
end
|
||||
|
||||
tests("#delete_security_group('#{@sec_group_id}')").succeeds do
|
||||
Fog::Network[:openstack].delete_security_group(@sec_group_id)
|
||||
end
|
||||
end
|
||||
|
||||
tests('failure') do
|
||||
tests("#get_security_group(0)").raises(Fog::Network::OpenStack::NotFound) do
|
||||
Fog::Network[:openstack].get_security_group(0)
|
||||
end
|
||||
|
||||
tests("#delete_security_group(0)").raises(Fog::Network::OpenStack::NotFound) do
|
||||
Fog::Network[:openstack].delete_security_group(0)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue