@@ -616,3 +616,81 @@ def test_show_all_options(self):
616616 ref_columns , ref_data = self ._get_common_cols_data (self ._port )
617617 self .assertEqual (ref_columns , columns )
618618 self .assertEqual (ref_data , data )
619+
620+
621+ class TestUnsetPort (TestPort ):
622+
623+ def setUp (self ):
624+ super (TestUnsetPort , self ).setUp ()
625+ self ._testport = network_fakes .FakePort .create_one_port (
626+ {'fixed_ips' : [{'subnet_id' : '042eb10a-3a18-4658-ab-cf47c8d03152' ,
627+ 'ip_address' : '0.0.0.1' },
628+ {'subnet_id' : '042eb10a-3a18-4658-ab-cf47c8d03152' ,
629+ 'ip_address' : '1.0.0.0' }],
630+ 'binding:profile' : {'batman' : 'Joker' , 'Superman' : 'LexLuthor' }})
631+ self .fake_subnet = network_fakes .FakeSubnet .create_one_subnet (
632+ {'id' : '042eb10a-3a18-4658-ab-cf47c8d03152' })
633+ self .network .find_subnet = mock .Mock (return_value = self .fake_subnet )
634+ self .network .find_port = mock .Mock (return_value = self ._testport )
635+ self .network .update_port = mock .Mock (return_value = None )
636+ # Get the command object to test
637+ self .cmd = port .UnsetPort (self .app , self .namespace )
638+
639+ def test_unset_port_parameters (self ):
640+ arglist = [
641+ '--fixed-ip' ,
642+ 'subnet=042eb10a-3a18-4658-ab-cf47c8d03152,ip-address=1.0.0.0' ,
643+ '--binding-profile' , 'Superman' ,
644+ self ._testport .name ,
645+ ]
646+ verifylist = [
647+ ('fixed_ip' , [{
648+ 'subnet' : '042eb10a-3a18-4658-ab-cf47c8d03152' ,
649+ 'ip-address' : '1.0.0.0' }]),
650+ ('binding_profile' , ['Superman' ]),
651+ ]
652+
653+ parsed_args = self .check_parser (self .cmd , arglist , verifylist )
654+ result = self .cmd .take_action (parsed_args )
655+
656+ attrs = {
657+ 'fixed_ips' : [{
658+ 'subnet_id' : '042eb10a-3a18-4658-ab-cf47c8d03152' ,
659+ 'ip_address' : '0.0.0.1' }],
660+ 'binding:profile' : {'batman' : 'Joker' }
661+ }
662+ self .network .update_port .assert_called_once_with (
663+ self ._testport , ** attrs )
664+ self .assertIsNone (result )
665+
666+ def test_unset_port_fixed_ip_not_existent (self ):
667+ arglist = [
668+ '--fixed-ip' , 'ip-address=1.0.0.1' ,
669+ '--binding-profile' , 'Superman' ,
670+ self ._testport .name ,
671+ ]
672+ verifylist = [
673+ ('fixed_ip' , [{'ip-address' : '1.0.0.1' }]),
674+ ('binding_profile' , ['Superman' ]),
675+ ]
676+
677+ parsed_args = self .check_parser (self .cmd , arglist , verifylist )
678+ self .assertRaises (exceptions .CommandError ,
679+ self .cmd .take_action ,
680+ parsed_args )
681+
682+ def test_unset_port_binding_profile_not_existent (self ):
683+ arglist = [
684+ '--fixed-ip' , 'ip-address=1.0.0.0' ,
685+ '--binding-profile' , 'Neo' ,
686+ self ._testport .name ,
687+ ]
688+ verifylist = [
689+ ('fixed_ip' , [{'ip-address' : '1.0.0.0' }]),
690+ ('binding_profile' , ['Neo' ]),
691+ ]
692+
693+ parsed_args = self .check_parser (self .cmd , arglist , verifylist )
694+ self .assertRaises (exceptions .CommandError ,
695+ self .cmd .take_action ,
696+ parsed_args )
0 commit comments