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'])
                    res = self.deserialize(self.fmt,
                                           req.get_response(self.api))
                    port_id = res['port']['id']
                    device_id = port_id[:8]
                    port_dict = lb_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'])
Beispiel #2
0
    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'])
                    res = self.deserialize(self.fmt,
                                           req.get_response(self.api))
                    port_id = res['port']['id']
                    device_id = port_id[:8]
                    port_dict = lb_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'])
Beispiel #3
0
 def update_device_up(self, rpc_context, **kwargs):
     """Device is up on agent"""
     agent_id = kwargs.get('agent_id')
     device = kwargs.get('device')
     LOG.debug(_("Device %(device)s up %(agent_id)s"),
               locals())
     port = db.get_port_from_device(device[self.TAP_PREFIX_LEN:])
     if port:
         if port['status'] != q_const.PORT_STATUS_ACTIVE:
             # Set port status to ACTIVE
             db.set_port_status(port['id'], q_const.PORT_STATUS_ACTIVE)
     else:
         LOG.debug(_("%s can not be found in database"), device)
Beispiel #4
0
 def update_device_down(self, rpc_context, **kwargs):
     """Device no longer exists on agent"""
     # (TODO) garyk - live migration and port status
     agent_id = kwargs.get('agent_id')
     device = kwargs.get('device')
     LOG.debug("Device %s no longer exists on %s", device, agent_id)
     port = db.get_port_from_device(device[self.TAP_PREFIX_LEN:])
     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
Beispiel #5
0
 def update_device_down(self, rpc_context, **kwargs):
     """Device no longer exists on agent"""
     # (TODO) garyk - live migration and port status
     agent_id = kwargs.get('agent_id')
     device = kwargs.get('device')
     LOG.debug("Device %s no longer exists on %s", device, agent_id)
     port = db.get_port_from_device(device[self.TAP_PREFIX_LEN:])
     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
Beispiel #6
0
 def get_device_details(self, rpc_context, **kwargs):
     """Agent requests device details"""
     agent_id = kwargs.get('agent_id')
     device = kwargs.get('device')
     LOG.debug("Device %s details requested from %s", device, agent_id)
     port = db.get_port_from_device(device[self.TAP_PREFIX_LEN:])
     if port:
         binding = db.get_network_binding(db_api.get_session(),
                                          port['network_id'])
         entry = {'device': device,
                  'physical_network': binding.physical_network,
                  'vlan_id': binding.vlan_id,
                  'network_id': port['network_id'],
                  'port_id': port['id'],
                  'admin_state_up': port['admin_state_up']}
         # Set the port status to UP
         db.set_port_status(port['id'], q_const.PORT_STATUS_ACTIVE)
     else:
         entry = {'device': device}
         LOG.debug("%s can not be found in database", device)
     return entry
 def get_device_details(self, rpc_context, **kwargs):
     """Agent requests device details"""
     agent_id = kwargs.get('agent_id')
     device = kwargs.get('device')
     LOG.debug("Device %s details requested from %s", device, agent_id)
     port = db.get_port_from_device(device[self.TAP_PREFIX_LEN:])
     if port:
         binding = db.get_network_binding(db_api.get_session(),
                                          port['network_id'])
         entry = {'device': device,
                  'physical_network': binding.physical_network,
                  'vlan_id': binding.vlan_id,
                  'network_id': port['network_id'],
                  'port_id': port['id'],
                  'admin_state_up': port['admin_state_up']}
         # Set the port status to UP
         db.set_port_status(port['id'], constants.PORT_STATUS_ACTIVE)
     else:
         entry = {'device': device}
         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 = lb_db.get_port_from_device('bad_device_id')
     self.assertEqual(None, port_dict)
Beispiel #9
0
 def test_security_group_get_port_from_device_with_no_port(self):
     port_dict = lb_db.get_port_from_device('bad_device_id')
     self.assertEqual(None, port_dict)
Beispiel #10
0
 def get_port_from_device(cls, device):
     port = db.get_port_from_device(device[cls.TAP_PREFIX_LEN :])
     if port:
         port["device"] = device
     return port
Beispiel #11
0
 def get_port_from_device(cls, device):
     port = db.get_port_from_device(device[cls.TAP_PREFIX_LEN:])
     if port:
         port['device'] = device
     return port