@@ -211,12 +211,10 @@ def security_group_info_for_ports(self, context, ports):
211211 # this set will be serialized into a list by rpc code
212212 remote_address_group_info [remote_ag_id ][ethertype ] = set ()
213213 direction = rule_in_db ['direction' ]
214- stateful = self ._is_security_group_stateful (context ,
215- security_group_id )
216214 rule_dict = {
217215 'direction' : direction ,
218216 'ethertype' : ethertype ,
219- 'stateful' : stateful }
217+ }
220218
221219 for key in ('protocol' , 'port_range_min' , 'port_range_max' ,
222220 'remote_ip_prefix' , 'remote_group_id' ,
@@ -234,6 +232,13 @@ def security_group_info_for_ports(self, context, ports):
234232 if rule_dict not in sg_info ['security_groups' ][security_group_id ]:
235233 sg_info ['security_groups' ][security_group_id ].append (
236234 rule_dict )
235+
236+ # Populate the security group "stateful" flag in the SGs list of rules.
237+ for sg_id , stateful in self ._get_sgs_stateful_flag (
238+ context , sg_info ['security_groups' ].keys ()).items ():
239+ for rule in sg_info ['security_groups' ][sg_id ]:
240+ rule ['stateful' ] = stateful
241+
237242 # Update the security groups info if they don't have any rules
238243 sg_ids = self ._select_sg_ids_for_ports (context , ports )
239244 for (sg_id , ) in sg_ids :
@@ -427,13 +432,13 @@ def _select_sg_ids_for_ports(self, context, ports):
427432 """
428433 raise NotImplementedError ()
429434
430- def _is_security_group_stateful (self , context , sg_id ):
431- """Return whether the security group is stateful or not .
435+ def _get_sgs_stateful_flag (self , context , sg_id ):
436+ """Return the security groups stateful flag .
432437
433- Return True if the security group associated with the given ID
434- is stateful, else False.
438+ Returns a dictionary with the SG ID as key and the stateful flag:
439+ {sg_1: True, sg_2: False, ...}
435440 """
436- return True
441+ raise NotImplementedError ()
437442
438443
439444class SecurityGroupServerRpcMixin (SecurityGroupInfoAPIMixin ,
@@ -530,5 +535,5 @@ def _select_ips_for_remote_address_group(self, context,
530535 return ips_by_group
531536
532537 @db_api .retry_if_session_inactive ()
533- def _is_security_group_stateful (self , context , sg_id ):
534- return sg_obj .SecurityGroup .get_sg_by_id (context , sg_id ). stateful
538+ def _get_sgs_stateful_flag (self , context , sg_ids ):
539+ return sg_obj .SecurityGroup .get_sgs_stateful_flag (context , sg_ids )
0 commit comments