def _update_switch_ports(self, context, switch_id, ports, db_switch_ports):
     port_ifname_map = {}
     db_swport_ifname_map = {}
     for port in ports:
         port_ifname_map[port['interface_name']] = const.PORT_STATUS[
             port['port_status']]
     for sw_port in db_switch_ports:
         db_swport_ifname_map[
             sw_port['interface_name']] = sw_port['port_status']
     for port_ifname in port_ifname_map.keys():
         if port_ifname in db_swport_ifname_map.keys():
             if port_ifname_map[port_ifname] != db_swport_ifname_map[
                port_ifname]:
                 db.update_bnp_phys_swport_status(
                     context, switch_id,
                     port_ifname, port_ifname_map[port_ifname])
             port_ifname_map.pop(port_ifname)
             db_swport_ifname_map.pop(port_ifname)
         elif port_ifname not in db_swport_ifname_map.keys():
             for port in ports:
                 if port['interface_name'] == port_ifname:
                     ifindex = port['ifindex']
                     break
             phys_port = {'switch_id': switch_id,
                          'port_status': port_ifname_map[port_ifname],
                          'interface_name': port_ifname,
                          'ifindex': ifindex}
             db.add_bnp_phys_switch_port(context, phys_port)
             port_ifname_map.pop(port_ifname)
     if db_swport_ifname_map:
         for swport_ifname in db_swport_ifname_map:
             db.delete_bnp_phys_switch_ports_by_name(context, switch_id,
                                                     swport_ifname)
 def test_delete_bnp_phys_switch_ports_by_name(self):
     """Test delete_bnp_phys_switch_ports_by_name method."""
     swport_dict = self._get_bnp_phys_switchport_dict()
     db.add_bnp_phys_switch_port(self.ctx, swport_dict)
     db.delete_bnp_phys_switch_ports_by_name(self.ctx,
                                             swport_dict['switch_id'],
                                             swport_dict['interface_name'])
     count = self.ctx.session.query(models.BNPPhysicalSwitchPort).count()
     self.assertEqual(0, count)