forked from netbox-community/Device-Type-Library-Import
-
Notifications
You must be signed in to change notification settings - Fork 0
Migrate read queries from REST to GraphQL with simplified preload #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,34 @@ | ||
| NETBOX_URL= | ||
| NETBOX_TOKEN= | ||
| REPO_URL=https://github.com/netbox-community/devicetype-library.git | ||
| NETBOX_TOKEN=XXXXXXXXX-xxxxxxxxx | ||
| NETBOX_URL=https://netbox.example.org | ||
|
|
||
| REPO_BRANCH=master | ||
| REPO_URL=https://github.com/netbox-community/devicetype-library.git | ||
|
|
||
| # SSL options — choose one approach if your NetBox uses a self-signed or private CA: | ||
| # | ||
| # Option A (recommended): point requests at your CA bundle so the certificate | ||
| # is validated properly. Set REQUESTS_CA_BUNDLE to the path of your PEM-encoded | ||
| # CA certificate or bundle file. This is a standard requests/urllib3 variable | ||
| # and is also respected by most Python HTTP clients. | ||
| # REQUESTS_CA_BUNDLE=/etc/ssl/certs/my-internal-ca.pem | ||
| # | ||
| # Option B (insecure – dev/test only): disable certificate verification entirely. | ||
| # IGNORE_SSL_ERRORS=False is the secure default; set to True only for local/dev use. | ||
| # WARNING: This bypasses all certificate validation and exposes connections to | ||
| # man-in-the-middle attacks. Never enable in production environments. | ||
| IGNORE_SSL_ERRORS=False | ||
| #REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt # you should enable this if you are running on a linux system | ||
|
|
||
| # Optional: restrict import to specific device type slugs | ||
| #SLUGS=c9300-48u isr4431 isr4331 | ||
|
|
||
| # Performance tuning — adjust for your NetBox instance size and network | ||
| # Number of items per GraphQL page (default: 5000). | ||
| # Values up to 25000 have been tested successfully on a default NetBox | ||
| # instance with minimal extra latency. Most NetBox installs cap | ||
| # MAX_PAGE_SIZE at 1000 by default; the client detects server-side | ||
| # clamping and paginates accordingly. | ||
| #GRAPHQL_PAGE_SIZE=5000 | ||
|
|
||
| # Number of threads for concurrent component preloading (default: 8). | ||
| # Reduce on smaller instances to lower load; increase for faster imports. | ||
| #PRELOAD_THREADS=8 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| # SPDX-License-Identifier: MIT | ||
| name: Weekly test against NetBox main | ||
|
|
||
| on: | ||
| schedule: | ||
| - cron: '0 6 * * 1' # Every Monday at 06:00 UTC | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
marcinpsk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| jobs: | ||
| integration-test: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| services: | ||
| postgres: | ||
| image: postgres:16 | ||
| env: | ||
| POSTGRES_DB: netbox | ||
| POSTGRES_USER: netbox | ||
| POSTGRES_PASSWORD: netbox | ||
| options: >- | ||
| --health-cmd pg_isready | ||
| --health-interval 10s | ||
| --health-timeout 5s | ||
| --health-retries 5 | ||
| ports: | ||
| - 5432:5432 | ||
|
|
||
| redis: | ||
| image: redis:7 | ||
| options: >- | ||
| --health-cmd "redis-cli ping" | ||
| --health-interval 10s | ||
| --health-timeout 5s | ||
| --health-retries 5 | ||
| ports: | ||
| - 6379:6379 | ||
|
|
||
| steps: | ||
| - name: Checkout importer | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| path: importer | ||
|
|
||
| - name: Install uv | ||
| uses: astral-sh/setup-uv@v7 | ||
| with: | ||
| enable-cache: true | ||
|
|
||
| - name: Checkout NetBox main | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| repository: netbox-community/netbox | ||
| path: netbox | ||
| ref: main | ||
|
|
||
| - name: Install NetBox dependencies | ||
| run: pip install -r netbox/requirements.txt | ||
|
|
||
| - name: Configure NetBox | ||
| run: | | ||
| cat > netbox/netbox/configuration.py << 'EOF' | ||
| ALLOWED_HOSTS = ['*'] | ||
| DATABASE = { | ||
| 'NAME': 'netbox', | ||
| 'USER': 'netbox', | ||
| 'PASSWORD': 'netbox', | ||
| 'HOST': 'localhost', | ||
| 'PORT': '5432', | ||
| 'CONN_MAX_AGE': 300, | ||
| 'ENGINE': 'django.db.backends.postgresql', | ||
| } | ||
| REDIS = { | ||
| 'tasks': {'HOST': 'localhost', 'PORT': 6379, 'DATABASE': 0, 'SSL': False}, | ||
| 'caching': {'HOST': 'localhost', 'PORT': 6379, 'DATABASE': 1, 'SSL': False}, | ||
| } | ||
| SECRET_KEY = 'test-secret-key-not-for-production-1234567890123456' # checkov:skip=CKV_SECRET_6 | ||
| API_TOKEN_PEPPERS = {0: 'a' * 64} # checkov:skip=CKV_SECRET_6 | ||
| DEBUG = True | ||
| LOGIN_REQUIRED = False | ||
| EOF | ||
|
|
||
| - name: Run NetBox migrations | ||
| working-directory: netbox/netbox | ||
| run: python manage.py migrate --no-input | ||
|
|
||
| - name: Create admin user and API token | ||
| working-directory: netbox/netbox | ||
| run: | | ||
| DJANGO_SUPERUSER_PASSWORD=admin python manage.py createsuperuser \ | ||
| --username=admin --email=admin@example.com --no-input | ||
| TOKEN=$(python manage.py shell -c " | ||
| from django.apps import apps | ||
| Token = apps.get_model('users', 'Token') | ||
| from django.contrib.auth import get_user_model | ||
| user = get_user_model().objects.get(username='admin') | ||
| t = Token.objects.create(user=user) | ||
| print(t.key) | ||
| ") | ||
| echo "NETBOX_TOKEN=$TOKEN" >> "$GITHUB_ENV" | ||
| echo "Created API token" | ||
|
|
||
| - name: Start NetBox dev server | ||
| working-directory: netbox/netbox | ||
| run: | | ||
| rm -f /tmp/netbox.log && touch /tmp/netbox.log | ||
| python manage.py runserver 0.0.0.0:8000 >> /tmp/netbox.log 2>&1 & | ||
| echo $! > /tmp/netbox.pid | ||
| # Wait up to 60 s for NetBox to respond | ||
| for i in $(seq 1 30); do | ||
| if curl -sf http://localhost:8000/api/ > /dev/null 2>&1; then | ||
| echo "NetBox is ready (attempt $i)" | ||
| break | ||
| fi | ||
| echo "Waiting for NetBox... ($i/30)" | ||
| sleep 2 | ||
| done | ||
| curl -sf http://localhost:8000/api/ > /dev/null || { echo "NetBox did not start"; exit 1; } | ||
|
|
||
| - name: Install importer dependencies | ||
| working-directory: importer | ||
| run: uv sync | ||
|
|
||
| - name: Set up test-fixtures git repo | ||
| run: | | ||
| mkdir -p /tmp/test-fixtures/device-types/TestVendor | ||
| mkdir -p /tmp/test-fixtures/module-types/TestVendor | ||
| mkdir -p /tmp/test-fixtures/elevation-images/TestVendor | ||
| cp importer/tests/fixtures/device-types/TestVendor/*.yaml \ | ||
| /tmp/test-fixtures/device-types/TestVendor/ | ||
| cp importer/tests/fixtures/module-types/TestVendor/*.yaml \ | ||
| /tmp/test-fixtures/module-types/TestVendor/ | ||
| cp importer/tests/fixtures/elevation-images/TestVendor/*.png \ | ||
| /tmp/test-fixtures/elevation-images/TestVendor/ | ||
| cd /tmp/test-fixtures | ||
| git init -b main | ||
| git config user.email "ci@test.local" | ||
| git config user.name "CI" | ||
| git add . | ||
| git commit -m "test fixtures" | ||
|
|
||
| - name: Run integration tests | ||
| working-directory: importer | ||
| env: | ||
| NETBOX_URL: http://localhost:8000 | ||
| NETBOX_TOKEN: ${{ env.NETBOX_TOKEN }} | ||
| REPO_URL: file:///tmp/test-fixtures | ||
| REPO_BRANCH: main | ||
| run: uv run python tests/integration/test_import.py | ||
|
|
||
| - name: Print NetBox version on failure | ||
| if: failure() | ||
| run: | | ||
| curl -s http://localhost:8000/api/status/ | python3 -m json.tool || true | ||
| echo "--- NetBox server log ---" | ||
| cat /tmp/netbox.log 2>/dev/null | tail -50 || true | ||
marcinpsk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -104,7 +104,7 @@ celerybeat.pid | |
| # Environments | ||
| .env* | ||
| !.env.example | ||
| !.envrc | ||
| !.envrc.example | ||
| .venv | ||
| env/ | ||
| venv/ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.