@@ -767,3 +767,109 @@ def test_show_all_options(self):
767767
768768 self .assertEqual (self .columns , columns )
769769 self .assertEqual (self .data , data )
770+
771+
772+ class TestUnsetSubnet (TestSubnet ):
773+
774+ def setUp (self ):
775+ super (TestUnsetSubnet , self ).setUp ()
776+ self ._testsubnet = network_fakes .FakeSubnet .create_one_subnet (
777+ {'dns_nameservers' : ['8.8.8.8' ,
778+ '8.8.8.4' ],
779+ 'host_routes' : [{'destination' : '10.20.20.0/24' ,
780+ 'nexthop' : '10.20.20.1' },
781+ {'destination' : '10.30.30.30/24' ,
782+ 'nexthop' : '10.30.30.1' }],
783+ 'allocation_pools' : [{'start' : '8.8.8.100' ,
784+ 'end' : '8.8.8.150' },
785+ {'start' : '8.8.8.160' ,
786+ 'end' : '8.8.8.170' }], })
787+ self .network .find_subnet = mock .Mock (return_value = self ._testsubnet )
788+ self .network .update_subnet = mock .Mock (return_value = None )
789+ # Get the command object to test
790+ self .cmd = subnet_v2 .UnsetSubnet (self .app , self .namespace )
791+
792+ def test_unset_subnet_params (self ):
793+ arglist = [
794+ '--dns-nameserver' , '8.8.8.8' ,
795+ '--host-route' , 'destination=10.30.30.30/24,gateway=10.30.30.1' ,
796+ '--allocation-pool' , 'start=8.8.8.100,end=8.8.8.150' ,
797+ self ._testsubnet .name ,
798+ ]
799+ verifylist = [
800+ ('dns_nameservers' , ['8.8.8.8' ]),
801+ ('host_routes' , [{
802+ "destination" : "10.30.30.30/24" , "gateway" : "10.30.30.1" }]),
803+ ('allocation_pools' , [{
804+ 'start' : '8.8.8.100' , 'end' : '8.8.8.150' }]),
805+ ]
806+
807+ parsed_args = self .check_parser (self .cmd , arglist , verifylist )
808+ result = self .cmd .take_action (parsed_args )
809+
810+ attrs = {
811+ 'dns_nameservers' : ['8.8.8.4' ],
812+ 'host_routes' : [{
813+ "destination" : "10.20.20.0/24" , "nexthop" : "10.20.20.1" }],
814+ 'allocation_pools' : [{'start' : '8.8.8.160' , 'end' : '8.8.8.170' }],
815+ }
816+ self .network .update_subnet .assert_called_once_with (
817+ self ._testsubnet , ** attrs )
818+ self .assertIsNone (result )
819+
820+ def test_unset_subnet_wrong_host_routes (self ):
821+ arglist = [
822+ '--dns-nameserver' , '8.8.8.8' ,
823+ '--host-route' , 'destination=10.30.30.30/24,gateway=10.30.30.2' ,
824+ '--allocation-pool' , 'start=8.8.8.100,end=8.8.8.150' ,
825+ self ._testsubnet .name ,
826+ ]
827+ verifylist = [
828+ ('dns_nameservers' , ['8.8.8.8' ]),
829+ ('host_routes' , [{
830+ "destination" : "10.30.30.30/24" , "gateway" : "10.30.30.2" }]),
831+ ('allocation_pools' , [{
832+ 'start' : '8.8.8.100' , 'end' : '8.8.8.150' }]),
833+ ]
834+
835+ parsed_args = self .check_parser (self .cmd , arglist , verifylist )
836+ self .assertRaises (exceptions .CommandError ,
837+ self .cmd .take_action , parsed_args )
838+
839+ def test_unset_subnet_wrong_allocation_pool (self ):
840+ arglist = [
841+ '--dns-nameserver' , '8.8.8.8' ,
842+ '--host-route' , 'destination=10.30.30.30/24,gateway=10.30.30.1' ,
843+ '--allocation-pool' , 'start=8.8.8.100,end=8.8.8.156' ,
844+ self ._testsubnet .name ,
845+ ]
846+ verifylist = [
847+ ('dns_nameservers' , ['8.8.8.8' ]),
848+ ('host_routes' , [{
849+ "destination" : "10.30.30.30/24" , "gateway" : "10.30.30.1" }]),
850+ ('allocation_pools' , [{
851+ 'start' : '8.8.8.100' , 'end' : '8.8.8.156' }]),
852+ ]
853+
854+ parsed_args = self .check_parser (self .cmd , arglist , verifylist )
855+ self .assertRaises (exceptions .CommandError ,
856+ self .cmd .take_action , parsed_args )
857+
858+ def test_unset_subnet_wrong_dns_nameservers (self ):
859+ arglist = [
860+ '--dns-nameserver' , '8.8.8.1' ,
861+ '--host-route' , 'destination=10.30.30.30/24,gateway=10.30.30.1' ,
862+ '--allocation-pool' , 'start=8.8.8.100,end=8.8.8.150' ,
863+ self ._testsubnet .name ,
864+ ]
865+ verifylist = [
866+ ('dns_nameservers' , ['8.8.8.1' ]),
867+ ('host_routes' , [{
868+ "destination" : "10.30.30.30/24" , "gateway" : "10.30.30.1" }]),
869+ ('allocation_pools' , [{
870+ 'start' : '8.8.8.100' , 'end' : '8.8.8.150' }]),
871+ ]
872+
873+ parsed_args = self .check_parser (self .cmd , arglist , verifylist )
874+ self .assertRaises (exceptions .CommandError ,
875+ self .cmd .take_action , parsed_args )
0 commit comments