def test_security_group_get_port_from_device(self):
        with self.network() as n:
            with self.subnet(n):
                with self.security_group() as sg:
                    security_group_id = sg['security_group']['id']
                    res = self._create_port(self.fmt, n['network']['id'])
                    port = self.deserialize(self.fmt, res)
                    fixed_ips = port['port']['fixed_ips']
                    data = {'port': {'fixed_ips': fixed_ips,
                                     'name': port['port']['name'],
                                     ext_sg.SECURITYGROUPS:
                                     [security_group_id]}}

                    req = self.new_update_request('ports', data,
                                                  port['port']['id'])
                    if res.status_int >= 400:
                        raise webob.exc.HTTPClientError(code=res.status_int)
                    res = self.deserialize(self.fmt,
                                           req.get_response(self.api))
                    port_id = res['port']['id']
                    device_id = port_id[:8]
                    port_dict = mlnx_db.get_port_from_device(device_id)
                    self.assertEqual(port_id, port_dict['id'])
                    self.assertEqual([security_group_id],
                                     port_dict[ext_sg.SECURITYGROUPS])
                    self.assertEqual([], port_dict['security_group_rules'])
                    self.assertEqual([fixed_ips[0]['ip_address']],
                                     port_dict['fixed_ips'])
                    self._delete('ports', port['port']['id'])
    def get_port_from_device(cls, device):
        """Get port according to device.

        To maintain compatibility with Linux Bridge L2 Agent for DHCP/L3
        services get device either by linux bridge plugin
        device name convention or by mac address
        """
        port = db.get_port_from_device(device[cls.TAP_PREFIX_LEN:])
        if port:
            port['device'] = device
        else:
            port = db.get_port_from_device_mac(device)
        return port
Exemple #3
0
    def get_port_from_device(cls, device):
        """Get port according to device.

        To maintain compatibility with Linux Bridge L2 Agent for DHCP/L3
        services get device either by linux bridge plugin
        device name convention or by mac address
        """
        port = db.get_port_from_device(device[cls.TAP_PREFIX_LEN:])
        if port:
            port['device'] = device
        else:
            port = db.get_port_from_device_mac(device)
        return port
 def update_device_down(self, rpc_context, **kwargs):
     """Device no longer exists on agent."""
     agent_id = kwargs.get("agent_id")
     device = kwargs.get("device")
     LOG.debug(_("Device %(device)s no longer exists on %(agent_id)s"), {"device": device, "agent_id": agent_id})
     port = db.get_port_from_device(device)
     if port:
         entry = {"device": device, "exists": True}
         if port["status"] != q_const.PORT_STATUS_DOWN:
             # Set port status to DOWN
             db.set_port_status(port["id"], q_const.PORT_STATUS_DOWN)
     else:
         entry = {"device": device, "exists": False}
         LOG.debug(_("%s can not be found in database"), device)
     return entry
 def update_device_down(self, rpc_context, **kwargs):
     """Device no longer exists on agent."""
     agent_id = kwargs.get('agent_id')
     device = kwargs.get('device')
     LOG.debug(_("Device %(device)s no longer exists on %(agent_id)s"),
               {'device': device, 'agent_id': agent_id})
     port = db.get_port_from_device(device)
     if port:
         entry = {'device': device,
                  'exists': True}
         # Set port status to DOWN
         db.set_port_status(port['id'], q_const.PORT_STATUS_DOWN)
     else:
         entry = {'device': device,
                  'exists': False}
         LOG.debug(_("%s can not be found in database"), device)
     return entry
Exemple #6
0
 def update_device_down(self, rpc_context, **kwargs):
     """Device no longer exists on agent."""
     agent_id = kwargs.get('agent_id')
     device = kwargs.get('device')
     LOG.debug(_("Device %(device)s no longer exists on %(agent_id)s"), {
         'device': device,
         'agent_id': agent_id
     })
     port = db.get_port_from_device(device)
     if port:
         entry = {'device': device, 'exists': True}
         # Set port status to DOWN
         db.set_port_status(port['id'], q_const.PORT_STATUS_DOWN)
     else:
         entry = {'device': device, 'exists': False}
         LOG.debug(_("%s can not be found in database"), device)
     return entry
 def test_security_group_get_port_from_device_with_no_port(self):
     port_dict = mlnx_db.get_port_from_device('bad_device_id')
     self.assertEqual(None, port_dict)