@@ -776,6 +776,146 @@ def test_remove_subnet_required_options(self):
776776 self .assertIsNone (result )
777777
778778
779+ class TestAddExtraRoutesToRouter (TestRouter ):
780+
781+ _router = network_fakes .FakeRouter .create_one_router ()
782+
783+ def setUp (self ):
784+ super (TestAddExtraRoutesToRouter , self ).setUp ()
785+ self .network .add_extra_routes_to_router = mock .Mock (
786+ return_value = self ._router )
787+ self .cmd = router .AddExtraRoutesToRouter (self .app , self .namespace )
788+ self .network .find_router = mock .Mock (return_value = self ._router )
789+
790+ def test_add_no_extra_route (self ):
791+ arglist = [
792+ self ._router .id ,
793+ ]
794+ verifylist = [
795+ ('router' , self ._router .id ),
796+ ]
797+ parsed_args = self .check_parser (self .cmd , arglist , verifylist )
798+
799+ result = self .cmd .take_action (parsed_args )
800+
801+ self .network .add_extra_routes_to_router .assert_called_with (
802+ self ._router , body = {'router' : {'routes' : []}})
803+ self .assertEqual (2 , len (result ))
804+
805+ def test_add_one_extra_route (self ):
806+ arglist = [
807+ self ._router .id ,
808+ '--route' , 'destination=dst1,gateway=gw1' ,
809+ ]
810+ verifylist = [
811+ ('router' , self ._router .id ),
812+ ('routes' , [{'destination' : 'dst1' , 'gateway' : 'gw1' }]),
813+ ]
814+ parsed_args = self .check_parser (self .cmd , arglist , verifylist )
815+
816+ result = self .cmd .take_action (parsed_args )
817+
818+ self .network .add_extra_routes_to_router .assert_called_with (
819+ self ._router , body = {'router' : {'routes' : [
820+ {'destination' : 'dst1' , 'nexthop' : 'gw1' },
821+ ]}})
822+ self .assertEqual (2 , len (result ))
823+
824+ def test_add_multiple_extra_routes (self ):
825+ arglist = [
826+ self ._router .id ,
827+ '--route' , 'destination=dst1,gateway=gw1' ,
828+ '--route' , 'destination=dst2,gateway=gw2' ,
829+ ]
830+ verifylist = [
831+ ('router' , self ._router .id ),
832+ ('routes' , [
833+ {'destination' : 'dst1' , 'gateway' : 'gw1' },
834+ {'destination' : 'dst2' , 'gateway' : 'gw2' },
835+ ]),
836+ ]
837+ parsed_args = self .check_parser (self .cmd , arglist , verifylist )
838+
839+ result = self .cmd .take_action (parsed_args )
840+
841+ self .network .add_extra_routes_to_router .assert_called_with (
842+ self ._router , body = {'router' : {'routes' : [
843+ {'destination' : 'dst1' , 'nexthop' : 'gw1' },
844+ {'destination' : 'dst2' , 'nexthop' : 'gw2' },
845+ ]}})
846+ self .assertEqual (2 , len (result ))
847+
848+
849+ class TestRemoveExtraRoutesFromRouter (TestRouter ):
850+
851+ _router = network_fakes .FakeRouter .create_one_router ()
852+
853+ def setUp (self ):
854+ super (TestRemoveExtraRoutesFromRouter , self ).setUp ()
855+ self .network .remove_extra_routes_from_router = mock .Mock (
856+ return_value = self ._router )
857+ self .cmd = router .RemoveExtraRoutesFromRouter (self .app , self .namespace )
858+ self .network .find_router = mock .Mock (return_value = self ._router )
859+
860+ def test_remove_no_extra_route (self ):
861+ arglist = [
862+ self ._router .id ,
863+ ]
864+ verifylist = [
865+ ('router' , self ._router .id ),
866+ ]
867+ parsed_args = self .check_parser (self .cmd , arglist , verifylist )
868+
869+ result = self .cmd .take_action (parsed_args )
870+
871+ self .network .remove_extra_routes_from_router .assert_called_with (
872+ self ._router , body = {'router' : {'routes' : []}})
873+ self .assertEqual (2 , len (result ))
874+
875+ def test_remove_one_extra_route (self ):
876+ arglist = [
877+ self ._router .id ,
878+ '--route' , 'destination=dst1,gateway=gw1' ,
879+ ]
880+ verifylist = [
881+ ('router' , self ._router .id ),
882+ ('routes' , [{'destination' : 'dst1' , 'gateway' : 'gw1' }]),
883+ ]
884+ parsed_args = self .check_parser (self .cmd , arglist , verifylist )
885+
886+ result = self .cmd .take_action (parsed_args )
887+
888+ self .network .remove_extra_routes_from_router .assert_called_with (
889+ self ._router , body = {'router' : {'routes' : [
890+ {'destination' : 'dst1' , 'nexthop' : 'gw1' },
891+ ]}})
892+ self .assertEqual (2 , len (result ))
893+
894+ def test_remove_multiple_extra_routes (self ):
895+ arglist = [
896+ self ._router .id ,
897+ '--route' , 'destination=dst1,gateway=gw1' ,
898+ '--route' , 'destination=dst2,gateway=gw2' ,
899+ ]
900+ verifylist = [
901+ ('router' , self ._router .id ),
902+ ('routes' , [
903+ {'destination' : 'dst1' , 'gateway' : 'gw1' },
904+ {'destination' : 'dst2' , 'gateway' : 'gw2' },
905+ ]),
906+ ]
907+ parsed_args = self .check_parser (self .cmd , arglist , verifylist )
908+
909+ result = self .cmd .take_action (parsed_args )
910+
911+ self .network .remove_extra_routes_from_router .assert_called_with (
912+ self ._router , body = {'router' : {'routes' : [
913+ {'destination' : 'dst1' , 'nexthop' : 'gw1' },
914+ {'destination' : 'dst2' , 'nexthop' : 'gw2' },
915+ ]}})
916+ self .assertEqual (2 , len (result ))
917+
918+
779919class TestSetRouter (TestRouter ):
780920
781921 # The router to set.
0 commit comments