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)
 def test_get_bnp_phys_switch_port_by_id(self):
     """Test get_bnp_phys_switch_port_by_id method."""
     swport = self._get_bnp_phys_switchport_dict()
     db.add_bnp_phys_switch_port(self.ctx, swport)
     port = db.get_bnp_phys_switch_ports_by_switch_id(self.ctx,
                                                      swport['switch_id'])
     new_swport = db.get_bnp_phys_switch_port_by_id(self.ctx,
                                                    port[0]['id'])
     self.assertEqual(port[0]['id'], new_swport['id'])
 def test_update_bnp_phys_swport_status(self):
     """Test update_bnp_phys_swport_status method."""
     port_dict = self._get_bnp_phys_switchport_dict()
     db.add_bnp_phys_switch_port(self.ctx, port_dict)
     db.update_bnp_phys_swport_status(self.ctx,
                                      port_dict['switch_id'],
                                      port_dict['interface_name'],
                                      "DOWN")
     port_updt = self.ctx.session.query(models.BNPPhysicalSwitchPort).all()
     self.assertEqual(port_updt[0]['port_status'], "DOWN")
 def _add_physical_port(self, context, switch_id, ports):
     for port in ports:
         port['switch_id'] = switch_id
         status = const.PORT_STATUS[port['port_status']]
         port['port_status'] = status
         db.add_bnp_phys_switch_port(context, port)
 def test_add_bnp_phys_switch_port(self):
     """Test add_bnp_phys_switch_port method."""
     port_dict = self._get_bnp_phys_switchport_dict()
     db.add_bnp_phys_switch_port(self.ctx, port_dict)
     count = self.ctx.session.query(models.BNPPhysicalSwitchPort).count()
     self.assertEqual(1, count)