mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[openstack|compute] Add requests and tests for security groups
- Added tests to already existing security group requests.
This commit is contained in:
parent
e1c5155a34
commit
b7370d640e
7 changed files with 218 additions and 45 deletions
|
@ -22,11 +22,26 @@ module Fog
|
|||
end
|
||||
|
||||
class Mock
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
def create_security_group(name, description)
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.headers = {
|
||||
"X-Compute-Request-Id" => "req-c373a42c-2825-4e60-8d34-99416ea850be",
|
||||
"Content-Type" => "application/json",
|
||||
"Content-Length" => "139",
|
||||
"Date" => Date.new}
|
||||
response.body = {
|
||||
"security_groups" => [{
|
||||
"rules" => [],
|
||||
"tenant_id" => "d5183375ab0343f3a0b4b05f547aefc2",
|
||||
"id" => 999,
|
||||
"name" => name,
|
||||
"description" => description
|
||||
}]
|
||||
}
|
||||
response
|
||||
end
|
||||
end # mock
|
||||
end # openstack
|
||||
end # compute
|
||||
end # fog
|
||||
|
|
|
@ -16,9 +16,9 @@ module Fog
|
|||
}
|
||||
|
||||
request(
|
||||
:body => MultiJson.encode(data),
|
||||
:expects => 200,
|
||||
:method => 'POST',
|
||||
:body => MultiJson.encode(data),
|
||||
:path => 'os-security-group-rules.json'
|
||||
)
|
||||
end
|
||||
|
@ -26,11 +26,31 @@ module Fog
|
|||
end
|
||||
|
||||
class Mock
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
def create_security_group_rule(parent_group_id, ip_protocol, from_port, to_port, cidr, group_id=nil)
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.headers = {
|
||||
"X-Compute-Request-Id" => "req-63a90344-7c4d-42e2-936c-fd748bced1b3",
|
||||
"Content-Type" => "application/json",
|
||||
"Content-Length" => "163",
|
||||
"Date" => Date.new
|
||||
}
|
||||
response.body = {
|
||||
"security_group_rule" => {
|
||||
"from_port" => from_port,
|
||||
"group" => group_id || {},
|
||||
"ip_protocol" => ip_protocol,
|
||||
"to_port" => to_port,
|
||||
"parent_group_id" => parent_group_id,
|
||||
"ip_range" => {
|
||||
"cidr" => cidr
|
||||
},
|
||||
"id"=>1
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end # mock
|
||||
end # openstack
|
||||
end # compute
|
||||
end # fog
|
||||
|
|
|
@ -14,10 +14,18 @@ module Fog
|
|||
end
|
||||
|
||||
class Mock
|
||||
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
def delete_security_group(security_group_id)
|
||||
response = Excon::Response.new
|
||||
response.status = 202
|
||||
response.headers = {
|
||||
"Content-Type" => "text/html; charset=UTF-8",
|
||||
"Content-Length" => "0",
|
||||
"Date" => Date.new
|
||||
}
|
||||
response.body = {}
|
||||
response
|
||||
end
|
||||
end # mock
|
||||
end # openstack
|
||||
end # compute
|
||||
end #fog
|
||||
|
|
|
@ -14,10 +14,18 @@ module Fog
|
|||
end
|
||||
|
||||
class Mock
|
||||
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
def delete_security_group_rule(security_group_rule_id)
|
||||
response = Excon::Response.new
|
||||
response.status = 202
|
||||
response.headers = {
|
||||
"Content-Type" => "text/html; charset=UTF-8",
|
||||
"Content-Length" => "0",
|
||||
"Date" => Date.new
|
||||
}
|
||||
response.body = {}
|
||||
response
|
||||
end
|
||||
end # mock
|
||||
end # openstack
|
||||
end # compute
|
||||
end # fog
|
||||
|
|
|
@ -14,10 +14,36 @@ module Fog
|
|||
end
|
||||
|
||||
class Mock
|
||||
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
def get_security_group(security_group_id)
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.headers = {
|
||||
"X-Compute-Request-Id" => "req-63a90344-7c4d-42e2-936c-fd748bced1b3",
|
||||
"Content-Type" => "application/json",
|
||||
"Content-Length" => "167",
|
||||
"Date" => Date.new
|
||||
}
|
||||
response.body = {
|
||||
"security_group" => {
|
||||
"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
|
||||
}],
|
||||
"tenant_id" => "d5183375ab0343f3a0b4b05f547aefc2",
|
||||
"id"=>security_group_id,
|
||||
"name"=>"default",
|
||||
"description"=>"default"
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end # mock
|
||||
end # openstack
|
||||
end #compute
|
||||
end #fog
|
||||
|
|
|
@ -14,10 +14,61 @@ module Fog
|
|||
end
|
||||
|
||||
class Mock
|
||||
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
def list_security_groups
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.headers = {
|
||||
"X-Compute-Request-Id" => "req-63a90344-7c4d-42e2-936c-fd748bced1b3",
|
||||
"Content-Type" => "application/json",
|
||||
"Content-Length" => "667",
|
||||
"Date" => Date.new
|
||||
}
|
||||
response.body = {
|
||||
"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
|
||||
},
|
||||
{
|
||||
"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,
|
||||
"name" => "default",
|
||||
"description" => "default"
|
||||
},
|
||||
{
|
||||
"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,
|
||||
"name" => "test",
|
||||
"description" => "this is a test"
|
||||
}
|
||||
]}
|
||||
response
|
||||
end
|
||||
end # mock
|
||||
end # openstack
|
||||
end # compute
|
||||
end # fog
|
||||
|
|
45
tests/openstack/requests/compute/security_group_tests.rb
Normal file
45
tests/openstack/requests/compute/security_group_tests.rb
Normal file
|
@ -0,0 +1,45 @@
|
|||
Shindo.tests('Fog::Compute[:openstack] | security group requests', ['openstack']) do
|
||||
@security_group_format = {
|
||||
"rules" => Array,
|
||||
"tenant_id" => String,
|
||||
"id" => Integer,
|
||||
"name" => String,
|
||||
"description" => String
|
||||
}
|
||||
|
||||
@security_group_rule_format = {
|
||||
"from_port" => Integer,
|
||||
"group" => Hash,
|
||||
"ip_protocol" => String,
|
||||
"to_port" => Integer,
|
||||
"parent_group_id" => Integer,
|
||||
"ip_range" => Hash,
|
||||
"id" => Integer
|
||||
}
|
||||
|
||||
tests('success') do
|
||||
tests('#list_security_groups').formats({"security_groups" => [@security_group_format]}) do
|
||||
Fog::Compute[:openstack].list_security_groups.body
|
||||
end
|
||||
|
||||
tests('#get_security_group(security_group_id)').formats({"security_group" => @security_group_format}) do
|
||||
Fog::Compute[:openstack].get_security_group(1).body
|
||||
end
|
||||
|
||||
tests('#create_security_group(name, description)').formats({"security_groups" => [@security_group_format]}) do
|
||||
Fog::Compute[:openstack].create_security_group('test', 'this is from the test').body
|
||||
end
|
||||
|
||||
tests('#create_security_group_rule(parent_group_id, ip_protocol, from_port, to_port, cidr, group_id=nil)').formats({"security_group_rule" => @security_group_rule_format}) do
|
||||
Fog::Compute[:openstack].create_security_group_rule(1, "tcp", 2, 3, "10.10.10.10/24").body
|
||||
end
|
||||
|
||||
tests('#delete_security_group_rule(security_group_rule_id)').succeeds do
|
||||
Fog::Compute[:openstack].delete_security_group_rule(1)
|
||||
end
|
||||
|
||||
tests('#delete_security_group(security_group_id)').succeeds do
|
||||
Fog::Compute[:openstack].delete_security_group(1)
|
||||
end
|
||||
end # tests('success')
|
||||
end
|
Loading…
Reference in a new issue