1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[hp|network] Add router interface methods and tests to router models.

This commit is contained in:
Rupak Ganguly 2013-04-02 16:14:36 -04:00
parent e7c9ed2592
commit 0a266b8d8d
2 changed files with 49 additions and 0 deletions

View file

@ -19,6 +19,26 @@ module Fog
true
end
def add_interface(subnet_id=nil, port_id=nil, options={})
requires :id
begin
service.add_router_interface(id, subnet_id, port_id, options).body['router']
true
rescue ArgumentError, Fog::HP::Network::NotFound
false
end
end
def remove_interface(subnet_id=nil, port_id=nil, options={})
requires :id
begin
service.remove_router_interface(id, subnet_id, port_id, options).body['router']
true
rescue ArgumentError, Fog::HP::Network::NotFound
false
end
end
def save
identity ? update : create
end

View file

@ -1,5 +1,10 @@
Shindo.tests('HP::Network | networking router model', ['hp', 'networking', 'router']) do
# needed to test router_interface calls
@network = HP[:network].networks.create(:name => 'fognetwork')
@subnet = HP[:network].subnets.create({:name => 'fogsubnet', :network_id => @network.id, :cidr => '13.13.13.13/13', :ip_version => 4})
@port = HP[:network].ports.create({:name => 'fogport', :network_id => @network.id})
attributes = {:name => 'fogrouter', :admin_state_up => true}
model_tests(HP[:network].routers, attributes, true)
@ -17,10 +22,34 @@ Shindo.tests('HP::Network | networking router model', ['hp', 'networking', 'rout
@router.save
end
tests("#add_interface(#{@subnet.id}, nil) - with subnet").succeeds do
@router.add_interface(@subnet.id)
end
tests("#remove_interface(#{@subnet.id}, nil) - with subnet").succeeds do
@router.remove_interface(@subnet.id)
end
tests("#add_interface(nil, #{@port.id}) - with port").succeeds do
@router.add_interface(nil, @port.id)
end
## deletes the port as well
tests("#remove_interface(nil, #{@port.id}) - with port").succeeds do
@router.remove_interface(nil, @port.id)
end
tests("#add_interface(#{@subnet.id}, #{@port.id}) - with both").succeeds do
@router.add_interface(@subnet.id, @port.id) == false
end
tests("#add_interface(#{@subnet.id}, #{@port.id}) - with both").succeeds do
@router.remove_interface(@subnet.id, @port.id) == false
end
tests('#destroy').succeeds do
@router.destroy
end
end
@subnet.destroy
@network.destroy
end