コード例 #1
0
ファイル: test_rules.py プロジェクト: williamwang0/MusicGen
 def test_validate_port_has_binding_host(self):
     with self.port() as port:
         core_plugin = directory.get_plugin()
         port['port']['binding:host_id'] = 'host'
         core_plugin.update_port(self.context, port['port']['id'], port)
         validator = rules.TrunkPortValidator(port['port']['id'])
         self.assertTrue(validator.is_bound(self.context))
コード例 #2
0
ファイル: plugin.py プロジェクト: zhhuabj/neutron
 def delete_trunk(self, context, trunk_id):
     """Delete the specified trunk."""
     with db_api.CONTEXT_WRITER.using(context):
         trunk = self._get_trunk(context, trunk_id)
         rules.trunk_can_be_managed(context, trunk)
         trunk_port_validator = rules.TrunkPortValidator(trunk.port_id)
         if trunk_port_validator.can_be_trunked_or_untrunked(context):
             # NOTE(status_police): when a trunk is deleted, the logical
             # object disappears from the datastore, therefore there is no
             # status transition involved. If PRECOMMIT failures occur,
             # the trunk remains in the status where it was.
             try:
                 trunk.delete()
             except Exception as e:
                 with excutils.save_and_reraise_exception():
                     LOG.warning('Trunk driver raised exception when '
                                 'deleting trunk port %s: %s', trunk_id,
                                 str(e))
             payload = events.DBEventPayload(context, resource_id=trunk_id,
                                             states=(trunk,))
             registry.publish(resources.TRUNK, events.PRECOMMIT_DELETE,
                              self, payload=payload)
         else:
             LOG.info('Trunk driver does not consider trunk %s '
                      'untrunkable', trunk_id)
             raise trunk_exc.TrunkInUse(trunk_id=trunk_id)
     registry.publish(resources.TRUNK, events.AFTER_DELETE, self,
                      payload=events.DBEventPayload(
                          context, resource_id=trunk_id,
                          states=(trunk,)))
コード例 #3
0
ファイル: plugin.py プロジェクト: hookk/neutron
 def delete_trunk(self, context, trunk_id):
     """Delete the specified trunk."""
     with db_api.autonested_transaction(context.session):
         trunk = self._get_trunk(context, trunk_id)
         rules.trunk_can_be_managed(context, trunk)
         trunk_port_validator = rules.TrunkPortValidator(trunk.port_id)
         if trunk_port_validator.can_be_trunked_or_untrunked(context):
             # NOTE(status_police): when a trunk is deleted, the logical
             # object disappears from the datastore, therefore there is no
             # status transition involved. If PRECOMMIT failures occur,
             # the trunk remains in the status where it was.
             trunk.delete()
             payload = callbacks.TrunkPayload(context,
                                              trunk_id,
                                              original_trunk=trunk)
             registry.notify(resources.TRUNK,
                             events.PRECOMMIT_DELETE,
                             self,
                             payload=payload)
         else:
             raise trunk_exc.TrunkInUse(trunk_id=trunk_id)
     registry.notify(resources.TRUNK,
                     events.AFTER_DELETE,
                     self,
                     payload=payload)
コード例 #4
0
ファイル: trunk_vpp.py プロジェクト: Ebrink/networking-vpp
 def delete_trunk(self, context, trunk_id):
     """Delete the trunk port."""
     LOG.debug("Deleting trunk_id %s", trunk_id)
     deleted_from_db = False
     with db_context_writer.using(context):
         trunk = self._get_trunk(context, trunk_id)
         rules.trunk_can_be_managed(context, trunk)
         trunk_port_validator = rules.TrunkPortValidator(trunk.port_id)
         if not trunk_port_validator.is_bound(context):
             trunk.delete()
             deleted_from_db = True
             payload = callbacks.TrunkPayload(context,
                                              trunk_id,
                                              original_trunk=trunk)
             registry.notify(trunk_const.TRUNK,
                             events.PRECOMMIT_DELETE,
                             self,
                             payload=payload)
         else:
             raise trunk_exc.TrunkInUse(trunk_id=trunk_id)
     if deleted_from_db:
         registry.notify(trunk_const.TRUNK,
                         events.AFTER_DELETE,
                         self,
                         payload=payload)
コード例 #5
0
 def test_validate_port_cannot_be_trunked_raises(self):
     with self.port() as port, \
          mock.patch.object(rules.TrunkPortValidator,
                            "can_be_trunked", return_value=False), \
          testtools.ExpectedException(trunk_exc.ParentPortInUse):
         validator = rules.TrunkPortValidator(port['port']['id'])
         validator.validate(self.context)
コード例 #6
0
ファイル: trunk_vpp.py プロジェクト: Ebrink/networking-vpp
 def validate_trunk(self, context, trunk):
     """Validate the input trunk data and return a valid trunk object."""
     trunk_details = trunk
     trunk_validator = rules.TrunkPortValidator(trunk['port_id'])
     trunk_details['port_id'] = trunk_validator.validate(context)
     trunk_details['sub_ports'] = self.validate_subports(
         context, trunk['sub_ports'], trunk)
     return trunk_details
コード例 #7
0
ファイル: test_rules.py プロジェクト: williamwang0/MusicGen
 def test_check_not_in_use_raises(self):
     with self.port() as port:
         core_plugin = directory.get_plugin()
         port['port']['device_id'] = 'foo_device_id'
         core_plugin.update_port(self.context, port['port']['id'], port)
         validator = rules.TrunkPortValidator(port['port']['id'])
         self.assertRaises(n_exc.PortInUse,
                           validator.check_not_in_use, self.context)
コード例 #8
0
ファイル: test_rules.py プロジェクト: zjtheone/neutron
 def test_validate_port_has_binding_host(self):
     with self.port() as port:
         core_plugin = manager.NeutronManager.get_plugin()
         port['port']['binding:host_id'] = 'host'
         core_plugin.update_port(self.context, port['port']['id'], port)
         validator = rules.TrunkPortValidator(port['port']['id'])
         self.assertRaises(trunk_exc.ParentPortInUse, validator.validate,
                           self.context)
コード例 #9
0
ファイル: test_rules.py プロジェクト: zjtheone/neutron
 def test_validate_port_has_device_owner_compute(self):
     with self.port() as port:
         core_plugin = manager.NeutronManager.get_plugin()
         device_owner = n_const.DEVICE_OWNER_COMPUTE_PREFIX + 'test'
         port['port']['device_owner'] = device_owner
         core_plugin.update_port(self.context, port['port']['id'], port)
         validator = rules.TrunkPortValidator(port['port']['id'])
         self.assertRaises(trunk_exc.ParentPortInUse, validator.validate,
                           self.context)
コード例 #10
0
ファイル: plugin.py プロジェクト: zainubwahid/neutron
    def validate(self, context, trunk):
        """Return a valid trunk or raises an error if unable to do so."""
        trunk_details = trunk

        trunk_validator = rules.TrunkPortValidator(trunk['port_id'])
        trunk_details['port_id'] = trunk_validator.validate(context)

        subports_validator = rules.SubPortsValidator(
            self._segmentation_types, trunk['sub_ports'], trunk['port_id'])
        trunk_details['sub_ports'] = subports_validator.validate(context)
        return trunk_details
コード例 #11
0
ファイル: test_rules.py プロジェクト: williamwang0/MusicGen
 def test_validate_port_parent_in_use_by_trunk(self):
     with self.port() as trunk_parent:
         trunk = {'port_id': trunk_parent['port']['id'],
                  'tenant_id': 'test_tenant',
                  'sub_ports': []}
         self.trunk_plugin.create_trunk(
             self.context, {trunk_api.ALIAS: trunk})
         validator = rules.TrunkPortValidator(trunk_parent['port']['id'])
         self.assertRaises(trunk_exc.ParentPortInUse,
                           validator.validate,
                           self.context)
コード例 #12
0
 def test_can_be_trunked_returns_false(self):
     # need to trigger a driver registration
     fakes.FakeDriverCanTrunkBoundPort.create()
     self.trunk_plugin = trunk_plugin.TrunkPlugin()
     directory.add_plugin('trunk', self.trunk_plugin)
     with self.port() as port:
         core_plugin = directory.get_plugin()
         port['port']['binding:host_id'] = 'host'
         core_plugin.update_port(self.context, port['port']['id'], port)
         validator = rules.TrunkPortValidator(port['port']['id'])
         # port cannot be trunked because of binding mismatch
         self.assertFalse(validator.can_be_trunked(self.context))
コード例 #13
0
 def test_can_be_trunked_returns_false(self):
     # need to trigger a driver registration
     fakes.FakeDriverCanTrunkBoundPort.create()
     self.trunk_plugin = trunk_plugin.TrunkPlugin()
     with self.port() as port, \
             mock.patch.object(manager.NeutronManager,
                               "get_service_plugins") as f:
         f.return_value = {'trunk': self.trunk_plugin}
         core_plugin = manager.NeutronManager.get_plugin()
         port['port']['binding:host_id'] = 'host'
         core_plugin.update_port(self.context, port['port']['id'], port)
         validator = rules.TrunkPortValidator(port['port']['id'])
         # port cannot be trunked because of binding mismatch
         self.assertFalse(validator.can_be_trunked(self.context))
コード例 #14
0
ファイル: test_rules.py プロジェクト: williamwang0/MusicGen
 def test_validate_port_id_in_use_by_unrelated_trunk(self):
     with self.port() as trunk_parent,\
              self.port() as subport:
         trunk = {'port_id': trunk_parent['port']['id'],
                  'tenant_id': 'test_tenant',
                  'sub_ports': [{'port_id': subport['port']['id'],
                                 'segmentation_type': 'vlan',
                                 'segmentation_id': 2}]}
         self.trunk_plugin.create_trunk(
             self.context, {trunk_api.ALIAS: trunk})
         validator = rules.TrunkPortValidator(subport['port']['id'])
         self.assertRaises(trunk_exc.TrunkPortInUse,
                           validator.validate,
                           self.context)
コード例 #15
0
 def test_can_be_trunked_returns_true(self):
     # need to trigger a driver registration
     fakes.FakeDriverCanTrunkBoundPort.create()
     self.trunk_plugin = trunk_plugin.TrunkPlugin()
     directory.add_plugin('trunk', self.trunk_plugin)
     with self.port() as port, \
             mock.patch.object(trunk_utils, "is_driver_compatible",
                               return_value=True) as g:
         core_plugin = directory.get_plugin()
         port['port']['binding:host_id'] = 'host'
         core_plugin.update_port(self.context, port['port']['id'], port)
         validator = rules.TrunkPortValidator(port['port']['id'])
         self.assertTrue(validator.can_be_trunked(self.context))
         self.assertTrue(g.call_count)
コード例 #16
0
 def test_can_be_trunked_raises_conflict(self):
     d1 = fakes.FakeDriver.create()
     d2 = fakes.FakeDriverWithAgent.create()
     self.trunk_plugin = trunk_plugin.TrunkPlugin()
     directory.add_plugin('trunk', self.trunk_plugin)
     self.trunk_plugin._drivers = [d1, d2]
     with self.port() as port, \
             mock.patch.object(trunk_utils, "is_driver_compatible",
                               return_value=True):
         core_plugin = directory.get_plugin()
         port['port']['binding:host_id'] = 'host'
         core_plugin.update_port(self.context, port['port']['id'], port)
         validator = rules.TrunkPortValidator(port['port']['id'])
         self.assertRaises(trunk_exc.TrunkPluginDriverConflict,
                           validator.can_be_trunked, self.context)
コード例 #17
0
    def test_delete_trunk_raise_in_use(self):
        with self.port() as port:
            fakes.FakeDriverCanTrunkBoundPort.create()
            self.trunk_plugin = trunk_plugin.TrunkPlugin()
            directory.add_plugin('trunk', self.trunk_plugin)

            trunk = self._create_test_trunk(port)
            core_plugin = directory.get_plugin()
            port['port']['binding:host_id'] = 'host'
            core_plugin.update_port(self.context, port['port']['id'], port)

            trunk_port_validator = rules.TrunkPortValidator(trunk['port_id'])
            if not trunk_port_validator.can_be_trunked_or_untrunked(
                    self.context):
                self.assertRaises(trunk_exc.TrunkInUse,
                                  self.trunk_plugin.delete_trunk, self.context,
                                  trunk['id'])
コード例 #18
0
 def delete_trunk(self, context, trunk_id):
     """Delete the specified trunk."""
     with db_api.autonested_transaction(context.session):
         trunk = self._get_trunk(context, trunk_id)
         rules.trunk_can_be_managed(context, trunk)
         trunk_port_validator = rules.TrunkPortValidator(trunk.port_id)
         if not trunk_port_validator.is_bound(context):
             trunk.delete()
             payload = callbacks.TrunkPayload(context,
                                              trunk_id,
                                              original_trunk=trunk)
             registry.notify(constants.TRUNK,
                             events.PRECOMMIT_DELETE,
                             self,
                             payload=payload)
         else:
             raise trunk_exc.TrunkInUse(trunk_id=trunk_id)
     registry.notify(constants.TRUNK,
                     events.AFTER_DELETE,
                     self,
                     payload=payload)
コード例 #19
0
ファイル: test_rules.py プロジェクト: williamwang0/MusicGen
 def test_check_not_in_use_pass(self):
     with self.port() as port:
         validator = rules.TrunkPortValidator(port['port']['id'])
         self.assertIsNone(validator.check_not_in_use(
             self.context))
コード例 #20
0
ファイル: test_rules.py プロジェクト: williamwang0/MusicGen
 def test_can_be_trunked_or_untrunked_unbound_port(self):
     with self.port() as port:
         validator = rules.TrunkPortValidator(port['port']['id'])
         self.assertTrue(
             validator.can_be_trunked_or_untrunked(self.context))
コード例 #21
0
ファイル: test_rules.py プロジェクト: williamwang0/MusicGen
 def test_validate_for_subport_calls_check(self):
     with self.port() as port:
         validator = rules.TrunkPortValidator(port['port']['id'])
         with mock.patch.object(validator, "check_not_in_use") as f:
             validator.validate(self.context, parent_port=False)
             f.assert_called_once_with(self.context)