def test_delete_busy(self, mock_delete): err = exception.EResourceBusy(type='profile', id='FAKE_ID') mock_delete.side_effect = err self.assertRaises(exception.EResourceBusy, pb.Profile.delete, self.ctx, 'FAKE_ID') mock_delete.assert_called_once_with(self.ctx, 'FAKE_ID')
def profile_delete(context, profile_id): 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.EResourceBusy(type='profile', id=profile_id) # used by any nodes? nodes = session.query(models.Node).filter_by(profile_id=profile_id) if nodes.count() > 0: raise exception.EResourceBusy(type='profile', id=profile_id) session.delete(profile)
def action_delete(context, action_id): 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.EResourceBusy(type='action', id=action_id) session.delete(action)
def policy_delete(context, policy_id): 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.EResourceBusy(type='policy', id=policy_id) session.delete(policy)
def test_policy_delete_policy_in_use(self, mock_find, mock_delete): x_obj = mock.Mock(id='POLICY_ID') mock_find.return_value = x_obj err = exc.EResourceBusy(type='policy', id='POLICY_ID') mock_delete.side_effect = err req = orpo.PolicyDeleteRequest(identity='POLICY_ID') ex = self.assertRaises(rpc.ExpectedException, self.svc.policy_delete, self.ctx, req.obj_to_primitive()) self.assertEqual(exc.ResourceInUse, ex.exc_info[0]) self.assertEqual( _("The policy 'POLICY_ID' cannot be deleted: " "still attached to some clusters."), str(ex.exc_info[1])) mock_find.assert_called_once_with(self.ctx, 'POLICY_ID') mock_delete.assert_called_once_with(self.ctx, 'POLICY_ID')
def test_profile_delete_profile_in_use(self, mock_find, mock_delete): self._setup_fakes() x_obj = mock.Mock(id='PROFILE_ID', type='TestProfile-1.0') mock_find.return_value = x_obj err = exc.EResourceBusy(type='profile', id='PROFILE_ID') mock_delete.side_effect = err req = vorp.ProfileDeleteRequest(identity='PROFILE_ID') ex = self.assertRaises(rpc.ExpectedException, self.svc.profile_delete, self.ctx, req.obj_to_primitive()) self.assertEqual(exc.ResourceInUse, ex.exc_info[0]) self.assertEqual( "The profile 'PROFILE_ID' cannot be deleted: " "still referenced by some clusters and/or nodes.", six.text_type(ex.exc_info[1])) mock_find.assert_called_once_with(self.ctx, 'PROFILE_ID') mock_delete.assert_called_once_with(self.ctx, 'PROFILE_ID')
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.EResourceBusy(type='action', id='FAKE_ID') mock_delete.side_effect = ex req = orao.ActionDeleteRequest(identity='ACTION_ID') ex = self.assertRaises(rpc.ExpectedException, self.eng.action_delete, self.ctx, req.obj_to_primitive()) self.assertEqual(exc.ResourceInUse, ex.exc_info[0]) self.assertEqual( "The action 'ACTION_ID' cannot be deleted: still " "in one of WAITING, RUNNING or SUSPENDED state.", six.text_type(ex.exc_info[1])) mock_find.assert_called_once_with(self.ctx, 'ACTION_ID') mock_delete.assert_called_once_with(self.ctx, 'FAKE_ID')