mirror of
https://github.com/ansible/django-ansible-base
synced 2026-07-22 20:33:56 +00:00
No description
- Python 98%
- HTML 1.5%
- Shell 0.3%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
## Description
- **What:** Add `POST /service-index/resources/bulk-update/` endpoint to
the resource registry that accepts a list of resource updates and
processes them in a single database transaction.
- **Why:** During `migrate_service_data`, each resource item triggers an
individual HTTP PATCH to set its `service_id`. For 3,962 users, this
means 3,962 sequential round-trips taking 203s. The bulk endpoint
eliminates this per-item overhead.
- **How:** A new `@action` on `ResourceViewSet` that validates a list
payload, fetches all resources in a single query, and applies updates
atomically. Also adds `bulk_update_resources()` to `ResourceAPIClient`
for callers.
## Type of Change
- [x] New feature (non-breaking change which adds functionality)
## Self-Review Checklist
- [x] I have performed a self-review of my code
- [x] I have added relevant comments to complex code sections
- [x] I have updated documentation where needed
- [x] I have considered the security impact of these changes
- [x] I have considered performance implications
- [x] I have thought about error handling and edge cases
- [x] I have tested the changes in my local environment
## Testing Instructions
### Prerequisites
- SQLite test environment (or PostgreSQL with docker)
### Steps to Test
1. Run: `DJANGO_SETTINGS_MODULE=test_app.sqlite3settings python -m
pytest test_app/tests/resource_registry/test_bulk_update.py -v`
2. All 11 tests should pass covering: service_id updates, ansible_id
renames, partially_migrated flag, mixed fields, not-found errors,
empty/invalid/oversized payloads, permission checks, and resource_data
updates.
### Expected Results
- `POST /service-index/resources/bulk-update/` accepts a JSON list (max
1000 items)
- Each item requires `ansible_id`, optional: `service_id`,
`new_ansible_id`, `is_partially_migrated`, `resource_data`
- Returns `{"updated": N, "errors": [...]}`
- All operations are atomic (single transaction)
- Permission check: requires `HasResourceRegistryPermissions` (superuser
or resource_api_actions)
## Additional Context
### Required Actions
- [x] Requires downstream repository changes
- aap-gateway: `AAP-82119/batch-resource-migration` branch uses this
endpoint
### Performance Impact
At Kyndryl scale (3,962 users, 2,288 teams, 130 orgs), this endpoint
reduces resource migration HTTP calls from ~6,400 to ~130 (one per API
page instead of one per resource item).
---
**Note:** This PR was developed with assistance from Claude AI
assistant.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Added a bulk-update API (`bulk-update`) to update multiple resources
in one request (up to 1,000 items).
* Supports changing service links, identifiers (including
`new_ansible_id`), migration status, and optionally resource content.
* Returns an `updated` count plus per-item errors, allowing partial
success.
* **Bug Fixes**
* Improved REST client behavior to always send valid request bodies,
even when the payload is empty.
* **Validation**
* Rejects malformed payloads, missing/invalid `items`, oversized
batches, items with no update fields, and duplicate identifiers within a
request.
* **Tests**
* Added comprehensive end-to-end coverage for success, partial failure,
authorization, and content rules.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
|
||
| .githooks | ||
| .github | ||
| ansible_base | ||
| compose | ||
| docs | ||
| requirements | ||
| test_app | ||
| tools | ||
| .dockerignore | ||
| .git_archival.txt | ||
| .gitattributes | ||
| .gitignore | ||
| .help_text_check.ignore | ||
| codecov.yml | ||
| docker-compose.yml | ||
| Dockerfile | ||
| LICENSE | ||
| Makefile | ||
| manage.py | ||
| MANIFEST.in | ||
| pyproject.toml | ||
| README.md | ||
| SECURITY.md | ||
| sonar-project.properties | ||
django-ansible-base
What is it?
Django-ansible-base is exactly what it says it is. A base for any Ansible application which will leverage Django.
Documentation
Docs for django-ansible-base features can be found in the docs directory.
Information about the test_app and how to start/use it can be found in test_app/README.md