def correct_db_restart(self):
LOG.info("<STR_LIT>")<EOL>seg_netid_dict = self.service_segs.get_seg_netid_src(fw_const.FW_CONST)<EOL>vlan_netid_dict = self.service_vlans.get_seg_netid_src(<EOL>fw_const.FW_CONST)<EOL>for netid in seg_netid_dict:<EOL><INDENT>net = self.get_network(netid)<EOL>fw_net = self.get_fw_by_netid(netid)<EOL>if not net or not fw_net:<EOL><INDENT>if netid in vlan_netid_dict:<EOL><INDENT>vlan_net = vlan_netid_dict[netid]<EOL><DEDENT>else:<EOL><INDENT>vlan_net = None<EOL><DEDENT>self.delete_os_nwk_db(netid, seg_netid_dict[netid], vlan_net)<EOL>LOG.info("<STR_LIT>"<EOL>"<STR_LIT>", net)<EOL>return<EOL><DEDENT><DEDENT>for netid in vlan_netid_dict:<EOL><INDENT>net = self.get_network(netid)<EOL>fw_net = self.get_fw_by_netid(netid)<EOL>if not net or not fw_net:<EOL><INDENT>if netid in seg_netid_dict:<EOL><INDENT>vlan_net = seg_netid_dict[netid]<EOL><DEDENT>else:<EOL><INDENT>vlan_net = None<EOL><DEDENT>self.delete_os_nwk_db(netid, vlan_net, vlan_netid_dict[netid])<EOL>LOG.info("<STR_LIT>",<EOL>net)<EOL>return<EOL><DEDENT><DEDENT>self.service_in_ip.release_subnet_no_netid()<EOL>self.service_out_ip.release_subnet_no_netid()<EOL>fw_dict = self.get_all_fw_db()<EOL>for fw_id in fw_dict:<EOL><INDENT>rtr_nwk = fw_id[<NUM_LIT:0>:<NUM_LIT:4>] + fw_const.DUMMY_SERVICE_NWK + (<EOL>fw_id[len(fw_id) - <NUM_LIT:4>:])<EOL>net_list = self.os_helper.get_network_by_name(rtr_nwk)<EOL>for net in net_list:<EOL><INDENT>net_db_item = self.get_network(net.get('<STR_LIT:id>'))<EOL>if not net_db_item:<EOL><INDENT>self.os_helper.delete_network_all_subnets(net.get('<STR_LIT:id>'))<EOL>LOG.info("<STR_LIT>",<EOL>net.get('<STR_LIT:id>'))<EOL>return<EOL><DEDENT><DEDENT>rtr_name = fw_id[<NUM_LIT:0>:<NUM_LIT:4>] + fw_const.DUMMY_SERVICE_RTR + (<EOL>fw_id[len(fw_id) - <NUM_LIT:4>:])<EOL>rtr_list = self.os_helper.get_rtr_by_name(rtr_name)<EOL>for rtr in rtr_list:<EOL><INDENT>fw_db_item = self.get_fw_by_rtrid(rtr.get('<STR_LIT:id>'))<EOL>if not fw_db_item:<EOL><INDENT>if not net_list:<EOL><INDENT>LOG.error("<STR_LIT>"<EOL>"<STR_LIT>")<EOL>return<EOL><DEDENT>fw_type = fw_dict[fw_id].get('<STR_LIT>')<EOL>if fw_type == fw_const.FW_TENANT_EDGE:<EOL><INDENT>rtr_net = net_list[<NUM_LIT:0>]<EOL>rtr_subnet_lt = (<EOL>self.os_helper.get_subnets_for_net(rtr_net))<EOL>if rtr_subnet_lt is None:<EOL><INDENT>LOG.error("<STR_LIT>"<EOL>"<STR_LIT>", rtr_net)<EOL>return<EOL><DEDENT>rtr_subnet_id = rtr_subnet_lt[<NUM_LIT:0>].get('<STR_LIT:id>')<EOL>LOG.info("<STR_LIT>",<EOL>rtr.get('<STR_LIT:id>'))<EOL>ret = self.delete_os_dummy_rtr_nwk(rtr.get('<STR_LIT:id>'),<EOL>rtr_net.get('<STR_LIT:id>'),<EOL>rtr_subnet_id)<EOL>return ret<EOL><DEDENT><DEDENT><DEDENT><DEDENT>LOG.info("<STR_LIT>")<EOL>
Ensure DB is consistent after unexpected restarts.