def test_add_host_with_already_added_host(self): side_effect = exception.AggregateHostExists(aggregate_id="1", host="host1") with mock.patch.object(self.controller.api, 'add_host_to_aggregate', side_effect=side_effect) as mock_add: self.assertRaises(exc.HTTPConflict, eval(self.add_host), self.req, "1", body={"add_host": {"host": "host1"}}) mock_add.assert_called_once_with(self.context, "1", "host1")
def _host_add_to_db(context, aggregate_id, host): try: with db_api.api_context_manager.writer.using(context): # Check to see if the aggregate exists _aggregate_get_from_db(context, aggregate_id) host_ref = api_models.AggregateHost() host_ref.update({"host": host, "aggregate_id": aggregate_id}) host_ref.save(context.session) return host_ref except db_exc.DBDuplicateEntry: raise exception.AggregateHostExists(host=host, aggregate_id=aggregate_id)
def stub_add_host_to_aggregate(context, aggregate, host): raise exception.AggregateHostExists(aggregate_id=aggregate, host=host)