Esempio n. 1
0
    def test_get_segment_by_id(self):
        segment = {api.NETWORK_TYPE: "vlan", api.PHYSICAL_NETWORK: "physnet1", api.SEGMENTATION_ID: 1}

        net_segment = self._create_segments([segment])[0]
        segment_uuid = net_segment[api.ID]

        net_segment = segments_db.get_segment_by_id(self.ctx.session, segment_uuid)
        self.assertEqual(segment, net_segment)
Esempio n. 2
0
    def test_delete_network_segment(self):
        segment = {api.NETWORK_TYPE: "vlan", api.PHYSICAL_NETWORK: "physnet1", api.SEGMENTATION_ID: 1}

        net_segment = self._create_segments([segment])[0]
        segment_uuid = net_segment[api.ID]

        segments_db.delete_network_segment(self.ctx.session, segment_uuid)
        # Get segment and verify its empty
        net_segment = segments_db.get_segment_by_id(self.ctx.session, segment_uuid)
        self.assertIsNone(net_segment)
Esempio n. 3
0
    def test_get_segment_by_id(self):
        segment = {api.NETWORK_TYPE: 'vlan',
                   api.PHYSICAL_NETWORK: 'physnet1',
                   api.SEGMENTATION_ID: 1}

        net_segment = self._create_segments([segment])[0]
        segment_uuid = net_segment[api.ID]

        net_segment = segments_db.get_segment_by_id(self.ctx,
                                                    segment_uuid)
        self.assertEqual(segment, net_segment)
Esempio n. 4
0
 def _expand_segment(self, segment_id):
     for s in self.network.network_segments:
         if s['id'] == segment_id:
             return s
     # TODO(kevinbenton): eliminate the query below. The above should
     # always return since the port is bound to a network segment. Leaving
     # in for now for minimally invasive change for back-port.
     segment = segments_db.get_segment_by_id(self._plugin_context,
                                             segment_id)
     if not segment:
         LOG.warning("Could not expand segment %s", segment_id)
     return segment
Esempio n. 5
0
 def _expand_segment(self, segment_id):
     for s in self.network.network_segments:
         if s['id'] == segment_id:
             return s
     # TODO(kevinbenton): eliminate the query below. The above should
     # always return since the port is bound to a network segment. Leaving
     # in for now for minimally invasive change for back-port.
     segment = segments_db.get_segment_by_id(self._plugin_context,
                                             segment_id)
     if not segment:
         LOG.warning("Could not expand segment %s", segment_id)
     return segment
Esempio n. 6
0
    def test_delete_network_segment(self):
        segment = {api.NETWORK_TYPE: 'vlan',
                   api.PHYSICAL_NETWORK: 'physnet1',
                   api.SEGMENTATION_ID: 1}

        net_segment = self._create_segments([segment])[0]
        segment_uuid = net_segment[api.ID]

        segments_db.delete_network_segment(self.ctx, segment_uuid)
        # Get segment and verify its empty
        net_segment = segments_db.get_segment_by_id(self.ctx,
                                                    segment_uuid)
        self.assertIsNone(net_segment)
Esempio n. 7
0
 def release_dynamic_segment(self, session, segment_id):
     """Delete a dynamic segment."""
     segment = segments_db.get_segment_by_id(session, segment_id)
     if segment:
         driver = self.drivers.get(segment.get(api.NETWORK_TYPE))
         if driver:
             driver.obj.release_segment(session, segment)
             segments_db.delete_network_segment(session, segment_id)
         else:
             LOG.error(_LE("Failed to release segment '%s' because "
                           "network type is not supported."), segment)
     else:
         LOG.debug("No segment found with id %(segment_id)s", segment_id)
Esempio n. 8
0
 def release_dynamic_segment(self, session, segment_id):
     """Delete a dynamic segment."""
     segment = segments_db.get_segment_by_id(session, segment_id)
     if segment:
         driver = self.drivers.get(segment.get(api.NETWORK_TYPE))
         if driver:
             driver.obj.release_segment(session, segment)
             segments_db.delete_network_segment(session, segment_id)
         else:
             LOG.error(_LE("Failed to release segment '%s' because "
                           "network type is not supported."), segment)
     else:
         LOG.debug("No segment found with id %(segment_id)s", segment_id)
Esempio n. 9
0
 def release_dynamic_segment(self, context, segment_id):
     """Delete a dynamic segment."""
     segment = segments_db.get_segment_by_id(context, segment_id)
     if segment:
         driver = self.drivers.get(segment.get(ml2_api.NETWORK_TYPE))
         if driver:
             if isinstance(driver.obj, api.TypeDriver):
                 driver.obj.release_segment(context.session, segment)
             else:
                 driver.obj.release_segment(context, segment)
             segments_db.delete_network_segment(context, segment_id)
         else:
             LOG.error("Failed to release segment '%s' because "
                       "network type is not supported.", segment)
     else:
         LOG.debug("No segment found with id %(segment_id)s", segment_id)
 def get_segment_id(self, context, port_id, agent_hosts):
     try:
         segment = None
         if agent_hosts:
             for host_id in agent_hosts:
                 levels = db.get_binding_levels(context, port_id, host_id)
                 if levels:
                     LOG.debug('levels: %s binding host_id: %s' %
                               (levels, host_id))
                     for level in levels:
                         if level.driver in ('f5networks', 'huawei_ac_ml2'):
                             LOG.debug('level with driver f5networks')
                             segment = segments_db.get_segment_by_id(
                                 context, level.segment_id)
                             LOG.debug(
                                 'vxlan 2 vlan seg id %s: segment %s' %
                                 (level.segment_id, segment))
                             if segment:
                                 break
         return segment
     except Exception as exc:
         LOG.error("could not get segment id by port %s and host %s, %s" %
                   (port_id, agent_hosts, exc.message))
Esempio n. 11
0
 def test_get_segment_by_id_result_not_found(self):
     segment_uuid = uuidutils.generate_uuid()
     net_segment = segments_db.get_segment_by_id(self.ctx, segment_uuid)
     self.assertIsNone(net_segment)
Esempio n. 12
0
 def get_segment_by_id(self, context, segment_id):
     return segments_db.get_segment_by_id(context, segment_id)
Esempio n. 13
0
 def test_get_segment_by_id_result_not_found(self):
     segment_uuid = uuidutils.generate_uuid()
     net_segment = segments_db.get_segment_by_id(self.ctx.session,
                                                 segment_uuid)
     self.assertIsNone(net_segment)
Esempio n. 14
0
 def _expand_segment(self, segment_id):
     segment = segments_db.get_segment_by_id(self._plugin_context,
                                             segment_id)
     if not segment:
         LOG.warning(_LW("Could not expand segment %s"), segment_id)
     return segment
Esempio n. 15
0
 def _expand_segment(self, segment_id):
     segment = segments_db.get_segment_by_id(self._plugin_context,
                                             segment_id)
     if not segment:
         LOG.warning(_LW("Could not expand segment %s"), segment_id)
     return segment