コード例 #1
0
ファイル: test_glance_manage.py プロジェクト: yebinama/glance
 def test_purge_command_fk_constraint_failure(self, purge_deleted_rows):
     purge_deleted_rows.side_effect = db_exception.DBReferenceError(
         'fake_table', 'fake_constraint', 'fake_key', 'fake_key_table')
     exit = self.assertRaises(SystemExit, self.commands.purge, 10, 100)
     self.assertEqual(
         "Purge command failed, check glance-manage logs"
         " for more details.", exit.code)
コード例 #2
0
 def test__allocate_hosting_port_returns_none_if_binding_fails(self):
     with self.router() as r, self.port() as p1:
         r_id = r['router']['id']
         p1_id = p1['port']['id']
         self._router_interface_action('add', r_id, None, p1_id)
         plugging_drv_mock = mock.MagicMock()
         plugging_drv_mock.allocate_hosting_port.return_value = {
             'allocated_port_id': p1_id,
             'allocated_vlan': 10
         }
         adm_ctx = bc.context.get_admin_context()
         p1_db = self._core_plugin._get_port(adm_ctx, p1_id)
         ctx_mock = mock.MagicMock()
         ctx_mock.session = mock.MagicMock()
         ctx_mock.session.begin = adm_ctx.session.begin
         ctx_mock.session.add = mock.MagicMock()
         ctx_mock.session.add.side_effect = db_exc.DBReferenceError(
             'cisco_port_mappings',
             'foreign key constraint',
             p1_id,
             'ports',
             inner_exception=inner_db_exc.IntegrityError("Invalid insert",
                                                         params="",
                                                         orig=None))
         res = self.l3_plugin._allocate_hosting_port(
             ctx_mock, r_id, p1_db, 'fake_hd_id', plugging_drv_mock)
         self.assertIsNone(res)
コード例 #3
0
 def test_set_port_status_concurrent_delete(self):
     exc = os_db_exc.DBReferenceError('', '', '', '')
     with self.network(set_context=True, tenant_id='test') as net1, \
         self.subnet(network=net1) as subnet1, \
         self.port(subnet=subnet1, set_context=True,
                   tenant_id='test') as port1, \
         mock.patch('neutron.db.provisioning_blocks.'
                    'add_provisioning_component',
                    side_effect=exc) as apc:
         self.mech_driver.set_port_status_down(port1['port']['id'])
         apc.assert_called_once_with(mock.ANY, port1['port']['id'],
                                     resources.PORT,
                                     provisioning_blocks.L2_AGENT_ENTITY)
コード例 #4
0
    def test_save_fkey_constraint_fail(self, mock_update):
        fake_updated_at = datetime.datetime(2015, 1, 1)
        nwinfo = network_model.NetworkInfo.hydrate([{'address': 'foo'}])
        nwinfo_json = nwinfo.json()
        new_info_cache = fake_info_cache.copy()
        new_info_cache['id'] = 1
        new_info_cache['updated_at'] = fake_updated_at
        new_info_cache['network_info'] = nwinfo_json

        # We should see InstanceNotFound raised for fkey=instance_uuid
        mock_update.side_effect = db_exc.DBReferenceError(
            'table', 'constraint', 'instance_uuid', 'key_table')

        obj = instance_info_cache.InstanceInfoCache(context=self.context)
        obj.instance_uuid = uuids.info_instance
        obj.network_info = nwinfo_json
        self.assertRaises(exception.InstanceNotFound, obj.save)

        # We should see the original exception raised for any other fkey
        mock_update.side_effect = db_exc.DBReferenceError(
            'table', 'constraint', 'otherkey', 'key_table')
        self.assertRaises(db_exc.DBReferenceError, obj.save)
コード例 #5
0
ファイル: test_deployable.py プロジェクト: sainusahib/cyborg
    def _test_save_objectfield_fk_constraint_fails(self, foreign_key,
                                                   expected_exception):

        error = db_exc.DBReferenceError('table', 'constraint', foreign_key,
                                        'key_table')
        # Prevent lazy-loading any fields, results in InstanceNotFound
        deployable = fake_deployable.fake_deployable_obj(self.context)
        fields_with_save_methods = [field for field in deployable.fields
                                    if hasattr(deployable, '_save_%s' % field)]
        for field in fields_with_save_methods:
            @mock.patch.object(deployable, '_save_%s' % field)
            @mock.patch.object(deployable, 'obj_attr_is_set')
            def _test(mock_is_set, mock_save_field):
                mock_is_set.return_value = True
                mock_save_field.side_effect = error
                deployable.obj_reset_changes(fields=[field])
                deployable._changed_fields.add(field)
                self.assertRaises(expected_exception, deployable.save)
                deployable.obj_reset_changes(fields=[field])
            _test()
コード例 #6
0
def _foreign_key_error(integrity_error, match, engine_name, is_disconnect):
    """Filter for foreign key errors."""

    try:
        table = match.group("table")
    except IndexError:
        table = None
    try:
        constraint = match.group("constraint")
    except IndexError:
        constraint = None
    try:
        key = match.group("key")
    except IndexError:
        key = None
    try:
        key_table = match.group("key_table")
    except IndexError:
        key_table = None

    raise exception.DBReferenceError(table, constraint, key, key_table,
                                     integrity_error)
コード例 #7
0
def _raise_DBReferenceError(*args, **kwargs):
    args = [mock.Mock(unsafe=True)] * 4
    e = exception.DBReferenceError(*args)
    raise e
コード例 #8
0
 def test_create_port_catch_db_reference_error(self):
     self._test__port_action_with_failures(exc=db_exc.DBReferenceError(
         'a', 'b', 'c', 'd'),
                                           action='create_port')