@@ -784,6 +784,12 @@ def setUp(self):
784
784
super (TestSecurityGroup , self ).setUp ()
785
785
self ._ovn_client = self .mech_driver ._ovn_client
786
786
self .plugin = self .mech_driver ._plugin
787
+ self .sg_data = {
788
+ 'name' : 'testsg' ,
789
+ 'description' : 'Test Security Group' ,
790
+ 'tenant_id' : self ._tenant_id ,
791
+ 'is_default' : True ,
792
+ }
787
793
788
794
def _find_acls_for_sg (self , sg_id ):
789
795
rows = self .nb_api .db_find_rows ('ACL' ).execute (check_error = True )
@@ -800,28 +806,29 @@ def get_api_id(r):
800
806
return [r for r in rows if get_api_id (r ) in rule_ids ]
801
807
return []
802
808
809
+ def _find_acl_remote_sg (self , remote_sg_id ):
810
+ # NOTE: the ACL to be found has ethertype=IPv4 and protocol=ICMP.
811
+ sg_match = '$pg_' + remote_sg_id .replace ('-' , '_' ) + '_ip4 && icmp4'
812
+ for row in self .nb_api .db_find_rows ('ACL' ).execute (check_error = True ):
813
+ if sg_match in row .match :
814
+ return row
815
+
803
816
def test_sg_stateful_toggle_updates_ovn_acls (self ):
804
817
def check_acl_actions (sg_id , expected ):
805
818
self .assertEqual (
806
819
{expected },
807
820
set (a .action for a in self ._find_acls_for_sg (sg_id ))
808
821
)
809
822
810
- sg_data = {
811
- 'name' : 'testsg' ,
812
- 'description' : 'Test Security Group' ,
813
- 'tenant_id' : self ._tenant_id ,
814
- 'is_default' : True ,
815
- }
816
823
sg = self .plugin .create_security_group (
817
- self .context , security_group = {'security_group' : sg_data })
824
+ self .context , security_group = {'security_group' : self . sg_data })
818
825
check_acl_actions (sg ['id' ], 'allow-related' )
819
826
820
827
def update_sg (stateful ):
821
- sg_data ['stateful' ] = stateful
828
+ self . sg_data ['stateful' ] = stateful
822
829
self .plugin .update_security_group (
823
830
self .context , sg ['id' ],
824
- security_group = {'security_group' : sg_data })
831
+ security_group = {'security_group' : self . sg_data })
825
832
826
833
update_sg (False )
827
834
check_acl_actions (sg ['id' ], 'allow-stateless' )
@@ -832,6 +839,35 @@ def update_sg(stateful):
832
839
update_sg (False )
833
840
check_acl_actions (sg ['id' ], 'allow-stateless' )
834
841
842
+ def test_remove_sg_with_related_rule_remote_sg (self ):
843
+ self .sg_data ['is_default' ] = False
844
+ sg1 = self .plugin .create_security_group (
845
+ self .context , security_group = {'security_group' : self .sg_data })
846
+ sg2 = self .plugin .create_security_group (
847
+ self .context , security_group = {'security_group' : self .sg_data })
848
+ rule_data = {'direction' : constants .INGRESS_DIRECTION ,
849
+ 'ethertype' : constants .IPv4 ,
850
+ 'protocol' : constants .PROTO_NAME_ICMP ,
851
+ 'port_range_max' : None ,
852
+ 'port_range_min' : None ,
853
+ 'remote_ip_prefix' : None ,
854
+ 'tenant_id' : sg1 ['project_id' ],
855
+ 'remote_address_group_id' : None ,
856
+ 'security_group_id' : sg1 ['id' ],
857
+ 'remote_group_id' : sg2 ['id' ]}
858
+ sg_rule = {'security_group_rule' : rule_data }
859
+ rule = self .plugin .create_security_group_rule (self .context , sg_rule )
860
+ acl = self ._find_acl_remote_sg (sg2 ['id' ])
861
+ self .assertEqual (rule ['id' ],
862
+ acl .external_ids [ovn_const .OVN_SG_RULE_EXT_ID_KEY ])
863
+ acls = self ._find_acls_for_sg (sg1 ['id' ])
864
+ self .assertEqual (3 , len (acls ))
865
+
866
+ self .plugin .delete_security_group (self .context , sg2 ['id' ])
867
+ self .assertIsNone (self ._find_acl_remote_sg (sg2 ['id' ]))
868
+ acls = self ._find_acls_for_sg (sg1 ['id' ])
869
+ self .assertEqual (2 , len (acls ))
870
+
835
871
836
872
class TestProvnetPorts (base .TestOVNFunctionalBase ):
837
873
0 commit comments