Skip to content

Commit 2bc6349

Browse files
author
Uwe Schwaeke
committed
feat(database): add SQLite as a second backend (SPEC-028)
Introduce a backend-neutral database contract in internal/database whose method sets mirror pgx's, so the 736 call sites change types only. The database.url scheme selects the backend at startup: postgres:// keeps the existing pgxpool implementation and passes SQL through untouched, while sqlite:///absolute/path opens one WAL-mode file (synchronous=FULL, 0600, immediate transactions) for a single node — VXLAN is refused. SQLite support: - modernc.org/sqlite (pure Go, CGO-free); golang-migrate database/sqlite and source/iofs. - A translation layer rewrites the PostgreSQL SQL the code already writes: casts, = ANY($n), LIMIT NULL, FOR UPDATE and ~, and registers now(), gen_random_uuid() and no-op advisory locks. Times, JSON, lists and []byte are converted at the boundary. TestSQLConstructs fails the build on any construct only PostgreSQL runs. - Migrations live in one folder read through a per-backend view; SQLite starts at a generated baseline (073). Migration 074 adds volumes/snapshots.reserved_by on both backends, and TestSchemaParity proves the 72 tables match. Behavioural changes forced by holding one file per node: - No transaction is held across storage, libvirt, network or HTTP work. Cinder volume and snapshot creates reserve a creating row, build the backing outside any transaction, then finalise; a per-node startup sweep sets creates interrupted by a crash to error and reclaims their files. - Nova rechecks binding quota under an advisory lock and answers 403 (Quota exceeded) instead of 413, matching upstream Nova. Go 1.27.2. Adds a host-testing runbook and contracts under docs/specs/028-sqlite-database-layer/. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Uwe Schwaeke <uwe.schwaeke@sap.com>
1 parent 3585f84 commit 2bc6349

238 files changed

Lines changed: 16327 additions & 1696 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/ci.yml‎

Lines changed: 118 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Set up Go
2020
uses: actions/setup-go@v6
2121
with:
22-
go-version: '1.27.2'
22+
go-version: 'stable'
2323

2424
- name: Cache Go modules
2525
uses: actions/cache@v5
@@ -37,8 +37,8 @@ jobs:
3737
SIZE=$(stat --format=%s bin/lightstack 2>/dev/null || stat -f%z bin/lightstack)
3838
SIZE_MB=$(($SIZE / 1048576))
3939
echo "Binary size: ${SIZE_MB}MB"
40-
if [ $SIZE -gt 68157440 ]; then
41-
echo "❌ Binary too large: ${SIZE_MB}MB (max 65MB)"
40+
if [ $SIZE -gt 104857600 ]; then
41+
echo "❌ Binary too large: ${SIZE_MB}MB (max 100MB)"
4242
exit 1
4343
fi
4444
echo "✅ Binary size OK: ${SIZE_MB}MB"
@@ -57,7 +57,7 @@ jobs:
5757
name: Unit Tests
5858
runs-on: ubuntu-latest
5959
needs: build
60-
timeout-minutes: 10
60+
timeout-minutes: 20
6161

6262
# Postgres service so DB-backed unit tests (e.g. keystone admin bootstrap,
6363
# SPEC-007 WS-2) run instead of skipping. Tests connect via LIGHTSTACK_TEST_DB_URL.
@@ -83,7 +83,7 @@ jobs:
8383
- name: Set up Go
8484
uses: actions/setup-go@v6
8585
with:
86-
go-version: '1.27.2'
86+
go-version: 'stable'
8787

8888
- name: Cache Go modules
8989
uses: actions/cache@v5
@@ -98,6 +98,13 @@ jobs:
9898
env:
9999
LIGHTSTACK_TEST_DB_URL: postgres://lightstack:secret@localhost:5432/lightstack_test?sslmode=disable
100100

101+
# The same tests on SQLite. Every package gets a fresh file of its own next to the one
102+
# named here (dbtest.URL), so packages running in parallel never share one.
103+
- name: Run unit tests on SQLite
104+
run: go test -race -count=1 $(go list ./... | grep -v '/test/contract')
105+
env:
106+
LIGHTSTACK_TEST_DB_URL: sqlite://${{ runner.temp }}/ls-test/t.db
107+
101108
- name: Upload coverage to Codecov
102109
uses: codecov/codecov-action@v7
103110
with:
@@ -118,7 +125,7 @@ jobs:
118125
- name: Set up Go
119126
uses: actions/setup-go@v6
120127
with:
121-
go-version: '1.27.2'
128+
go-version: 'stable'
122129

123130
- name: Cache Go modules
124131
uses: actions/cache@v5
@@ -158,6 +165,8 @@ jobs:
158165
run: |
159166
cd test/contract && go test -v ./... -count=1 -timeout=10m 2>&1 | tee /tmp/contract_test_output.txt
160167
env:
168+
# The fixtures the API cannot create are seeded straight into the server's database.
169+
LIGHTSTACK_DB_URL: "postgres://lightstack:secret@localhost:5432/lightstack?sslmode=disable"
161170
OS_AUTH_URL: "http://localhost:35357/v3"
162171
OS_USERNAME: "admin"
163172
OS_PASSWORD: "secret"
@@ -212,6 +221,99 @@ jobs:
212221
if: always()
213222
run: docker compose -f deployments/docker-compose.yml down -v
214223

224+
contract-tests-sqlite:
225+
name: Contract Tests (SQLite)
226+
runs-on: ubuntu-latest
227+
needs: build
228+
timeout-minutes: 20
229+
env:
230+
OS_AUTH_URL: http://localhost:35357/v3
231+
OS_USERNAME: admin
232+
OS_PASSWORD: secret
233+
OS_PROJECT_NAME: default
234+
OS_USER_DOMAIN_NAME: Default
235+
OS_PROJECT_DOMAIN_NAME: Default
236+
237+
steps:
238+
- name: Checkout code
239+
uses: actions/checkout@v6
240+
241+
# The `runner` context is not available in a job-level `env`, so name the database
242+
# here: read by the server and by the contract tests' fixture seeding (contract.Seed).
243+
- name: Name the SQLite database
244+
run: echo "LIGHTSTACK_DB_URL=sqlite://$RUNNER_TEMP/ls/db/lightstack.db" >> "$GITHUB_ENV"
245+
246+
- name: Set up Go
247+
uses: actions/setup-go@v6
248+
with:
249+
go-version: 'stable'
250+
251+
- name: Cache Go modules
252+
uses: actions/cache@v5
253+
with:
254+
path: ~/go/pkg/mod
255+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
256+
restore-keys: |
257+
${{ runner.os }}-go-
258+
259+
- name: Build
260+
run: make build
261+
262+
- name: Install volume and cloud-init tooling
263+
# storage_mode: local shells out to qemu-img, and cloud-init ISOs need genisoimage.
264+
# The Docker image the Postgres contract job runs bundles both (Dockerfile: qemu-img,
265+
# cdrkit); this job runs the raw binary, so install them on the runner. Without them a
266+
# volume create fails, the test gets an empty volume id, and follow-up actions fail the
267+
# volume_metadata foreign key.
268+
run: sudo apt-get update && sudo apt-get install -y --no-install-recommends qemu-utils genisoimage
269+
270+
# A stub-libvirt, stub-network server on a fresh SQLite file: no database service at all.
271+
- name: Start lightstack on SQLite
272+
run: |
273+
mkdir -p "$RUNNER_TEMP/ls/state"
274+
# LIGHTSTACK_DB_URL (set above) overrides database.url at load, so the file keeps
275+
# its default; only state_path is redirected out of /var/lib.
276+
sed -e "s|^# state_path: .*|state_path: $RUNNER_TEMP/ls/state|" \
277+
config/lightstack.yaml > "$RUNNER_TEMP/ls/lightstack.yaml"
278+
nohup ./bin/lightstack --config "$RUNNER_TEMP/ls/lightstack.yaml" --migrations migrations \
279+
> "$RUNNER_TEMP/ls/lightstack.log" 2>&1 &
280+
env:
281+
LIGHTSTACK_JWT_SECRET: ci-contract-tests-only
282+
LIGHTSTACK_ENDPOINT_HOST: localhost
283+
# Tests name the instance they ask the metadata service about (see the Compose file).
284+
LIGHTSTACK_METADATA_TRUST_INSTANCE_HEADER: "true"
285+
286+
- name: Wait for lightstack to be ready
287+
run: timeout 60 bash -c 'until ./bin/lightstack healthcheck; do sleep 2; done'
288+
289+
- name: Install OpenStack CLI
290+
run: python3 -m pip install python-openstackclient
291+
292+
- name: Run contract tests
293+
run: cd test/contract && go test ./... -count=1 -timeout=10m
294+
295+
- name: Run quick integration tests
296+
run: ./test/quick_test.sh
297+
298+
- name: Server log
299+
if: always()
300+
# Surface every error line from the whole log first — a failing request's cause scrolls past
301+
# a 300-line tail — then tail the end, which also shows a startup log.Fatalf (plain text the
302+
# level filter would hide).
303+
run: |
304+
echo "=== error lines (whole log) ==="
305+
grep -F '"level":"error"' "$RUNNER_TEMP/ls/lightstack.log" || echo "(none)"
306+
echo "=== last 300 lines ==="
307+
tail -n 300 "$RUNNER_TEMP/ls/lightstack.log" || true
308+
309+
- name: Upload server log
310+
if: failure()
311+
uses: actions/upload-artifact@v7
312+
with:
313+
name: sqlite-contract-lightstack-log
314+
path: ${{ runner.temp }}/ls/lightstack.log
315+
if-no-files-found: warn
316+
215317
integration-tests:
216318
name: Integration Tests
217319
runs-on: ubuntu-latest
@@ -339,7 +441,9 @@ jobs:
339441
bash "$RUNNER_TEMP/get-helm-3"
340442
fi
341443
if ! helm plugin list 2>/dev/null | grep -q '^unittest'; then
342-
helm plugin install https://github.com/helm-unittest/helm-unittest
444+
# helm-unittest ships no provenance file; recent Helm refuses an
445+
# unverified plugin unless verification is explicitly skipped.
446+
helm plugin install https://github.com/helm-unittest/helm-unittest --verify=false
343447
fi
344448
helm version --short
345449
@@ -386,7 +490,7 @@ jobs:
386490
status-check:
387491
name: CI Status
388492
runs-on: ubuntu-latest
389-
needs: [build, unit-tests, contract-tests, integration-tests, dco-check, rgw-integration-tests, helm-check]
493+
needs: [build, unit-tests, contract-tests, contract-tests-sqlite, integration-tests, dco-check, rgw-integration-tests, helm-check]
390494
if: always()
391495

392496
steps:
@@ -395,6 +499,7 @@ jobs:
395499
echo "Build: ${{ needs.build.result }}"
396500
echo "Unit Tests: ${{ needs.unit-tests.result }}"
397501
echo "Contract Tests: ${{ needs.contract-tests.result }}"
502+
echo "Contract Tests (SQLite): ${{ needs.contract-tests-sqlite.result }}"
398503
echo "Integration Tests: ${{ needs.integration-tests.result }}"
399504
echo "SAP Sign-off: ${{ needs.dco-check.result }}"
400505
echo "RGW Integration Tests: ${{ needs.rgw-integration-tests.result }}"
@@ -417,6 +522,11 @@ jobs:
417522
exit 1
418523
fi
419524
525+
if [ "${{ needs.contract-tests-sqlite.result }}" != "success" ]; then
526+
echo "❌ Contract or quick tests failed on SQLite"
527+
exit 1
528+
fi
529+
420530
if [ "${{ needs.integration-tests.result }}" != "success" ]; then
421531
echo "❌ Integration tests failed"
422532
exit 1

‎.github/workflows/security.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
- name: Set up Go
2525
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
2626
with:
27-
go-version: '1.27.2'
27+
go-version: 'stable'
2828
cache: true
2929

3030
- name: Scan Go code and pinned development tool

0 commit comments

Comments
 (0)