@@ -1090,6 +1090,49 @@ def test__cleanup_stale_sg(self):
10901090 sg_removed_mock .assert_called_once_with (1 )
10911091 delete_sg_mock .assert_called_once_with (1 )
10921092
1093+ def test__cleanup_stale_sg_members_and_ports (self ):
1094+ self ._prepare_security_group ()
1095+ self .firewall .sg_to_delete = {1 }
1096+ new_members = {constants .IPv4 : [1 ]}
1097+ self .firewall .update_security_group_members (1 , new_members )
1098+ port_dict = {'device' : 'port-id' ,
1099+ 'security_groups' : [1 ]}
1100+ self .firewall .prepare_port_filter (port_dict )
1101+ with mock .patch .object (self .firewall .conj_ip_manager ,
1102+ 'sg_removed' ) as sg_removed_mock ,\
1103+ mock .patch .object (self .firewall .sg_port_map ,
1104+ 'delete_sg' ) as delete_sg_mock :
1105+ self .firewall ._cleanup_stale_sg ()
1106+ sg_removed_mock .assert_not_called ()
1107+ delete_sg_mock .assert_not_called ()
1108+
1109+ def test__cleanup_stale_sg_just_members (self ):
1110+ self ._prepare_security_group ()
1111+ self .firewall .sg_to_delete = {1 }
1112+ new_members = {constants .IPv4 : [1 ]}
1113+ self .firewall .update_security_group_members (1 , new_members )
1114+ with mock .patch .object (self .firewall .conj_ip_manager ,
1115+ 'sg_removed' ) as sg_removed_mock ,\
1116+ mock .patch .object (self .firewall .sg_port_map ,
1117+ 'delete_sg' ) as delete_sg_mock :
1118+ self .firewall ._cleanup_stale_sg ()
1119+ sg_removed_mock .assert_not_called ()
1120+ delete_sg_mock .assert_not_called ()
1121+
1122+ def test__cleanup_stale_sg_just_ports (self ):
1123+ self ._prepare_security_group ()
1124+ self .firewall .sg_to_delete = {1 }
1125+ port_dict = {'device' : 'port-id' ,
1126+ 'security_groups' : [1 ]}
1127+ self .firewall .prepare_port_filter (port_dict )
1128+ with mock .patch .object (self .firewall .conj_ip_manager ,
1129+ 'sg_removed' ) as sg_removed_mock ,\
1130+ mock .patch .object (self .firewall .sg_port_map ,
1131+ 'delete_sg' ) as delete_sg_mock :
1132+ self .firewall ._cleanup_stale_sg ()
1133+ sg_removed_mock .assert_not_called ()
1134+ delete_sg_mock .assert_not_called ()
1135+
10931136 def test_get_ovs_port (self ):
10941137 ovs_port = self .firewall .get_ovs_port ('port_id' )
10951138 self .assertEqual (self .fake_ovs_port , ovs_port )
0 commit comments