예제 #1
0
 def test_delete_busy(self, mock_delete):
     err = exception.ResourceBusyError(resource_type='profile',
                                       resource_id='FAKE_ID')
     mock_delete.side_effect = err
     self.assertRaises(exception.ResourceBusyError, pb.Profile.delete,
                       self.ctx, 'FAKE_ID')
     mock_delete.assert_called_once_with(self.ctx, 'FAKE_ID')
예제 #2
0
def profile_delete(context, profile_id, force=False):
    with session_for_write() as session:
        profile = session.query(models.Profile).get(profile_id)
        if profile is None:
            return

        # used by any clusters?
        clusters = session.query(
            models.Cluster).filter_by(profile_id=profile_id)
        if clusters.count() > 0:
            raise exception.ResourceBusyError(resource_type='profile',
                                              resource_id=profile_id)

        # used by any nodes?
        nodes = session.query(models.Node).filter_by(profile_id=profile_id)
        if nodes.count() > 0:
            raise exception.ResourceBusyError(resource_type='profile',
                                              resource_id=profile_id)
        session.delete(profile)
예제 #3
0
def action_delete(context, action_id, force=False):
    with session_for_write() as session:
        action = session.query(models.Action).get(action_id)
        if not action:
            return
        if ((action.status == 'WAITING') or (action.status == 'RUNNING')
                or (action.status == 'SUSPENDED')):

            raise exception.ResourceBusyError(resource_type='action',
                                              resource_id=action_id)
        session.delete(action)
예제 #4
0
    def test_action_delete_resource_busy(self, mock_delete):
        a1 = self.eng.action_create(self.ctx, 'A', self.target, 'CUST_ACT')
        aid = a1['id']
        ex = exception.ResourceBusyError(resource_type='action',
                                         resource_id=aid)
        mock_delete.side_effect = ex

        ex = self.assertRaises(rpc.ExpectedException, self.eng.action_delete,
                               self.ctx, aid)

        self.assertEqual(exception.ResourceInUse, ex.exc_info[0])
예제 #5
0
def policy_delete(context, policy_id, force=False):
    with session_for_write() as session:
        policy = session.query(models.Policy).get(policy_id)

        if not policy:
            return

        bindings = session.query(
            models.ClusterPolicies).filter_by(policy_id=policy_id)
        if bindings.count():
            raise exception.ResourceBusyError(resource_type='policy',
                                              resource_id=policy_id)
        session.delete(policy)
예제 #6
0
    def test_action_delete_resource_busy(self, mock_find, mock_delete):
        x_obj = mock.Mock()
        x_obj.id = 'FAKE_ID'
        mock_find.return_value = x_obj
        ex = exc.ResourceBusyError(resource_type='action',
                                   resource_id='FAKE_ID')
        mock_delete.side_effect = ex

        ex = self.assertRaises(rpc.ExpectedException, self.eng.action_delete,
                               self.ctx, 'ACTION')

        self.assertEqual(exc.ResourceInUse, ex.exc_info[0])
        mock_find.assert_called_once_with(self.ctx, 'ACTION')
        mock_delete.assert_called_once_with(self.ctx, 'FAKE_ID')
예제 #7
0
    def test_profile_delete_profile_in_use(self, mock_find, mock_delete):
        x_obj = mock.Mock(id='PROFILE_ID')
        mock_find.return_value = x_obj
        err = exc.ResourceBusyError(resource_type='profile',
                                    resource_id='PROFILE_ID')
        mock_delete.side_effect = err

        ex = self.assertRaises(rpc.ExpectedException, self.eng.profile_delete,
                               self.ctx, 'FAKE_PROFILE')

        self.assertEqual(exc.ResourceInUse, ex.exc_info[0])
        self.assertEqual('The profile (PROFILE_ID) is still in use.',
                         six.text_type(ex.exc_info[1]))
        mock_find.assert_called_once_with(self.ctx, 'FAKE_PROFILE')
        mock_delete.assert_called_once_with(self.ctx, 'PROFILE_ID')