Skip to content

Commit

Permalink
test: include MySQL/MariaDB in FT test set
Browse files Browse the repository at this point in the history
Signed-off-by: Kairo Araujo <[email protected]>
  • Loading branch information
kairoaraujo committed Aug 5, 2024
1 parent b0b01b5 commit dfb244a
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 19 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,18 @@ jobs:
api_version: ${{ needs.set-component-versions.outputs.api_version }}
cli_version: ${{ needs.set-component-versions.outputs.cli_version }}

functional-tests-mysql:
needs: set-component-versions
name: FT Deploy MySQL Server
uses: ./.github/workflows/functional-tests.yml
with:
docker_compose: docker-compose-mysql.yml
api_version: ${{ needs.set-component-versions.outputs.api_version }}
cli_version: ${{ needs.set-component-versions.outputs.cli_version }}

prepare-rc:
runs-on: ubuntu-latest
needs: [functional-tests-local, functional-tests-local-redis, functional-tests-aws]
needs: [functional-tests-local, functional-tests-local-redis, functional-tests-aws, functional-tests-mysql]
outputs:
release_id: ${{ steps.gh-release.outputs.id }}
steps:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/functional-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:

- name: Bootstrap/Setup RSTUF DAS and run Functional Tests
run: |
make ft-das CLI_VERSION=${{ inputs.cli_version }} PYTEST_GROUP=${{ matrix.pytest-group }}
make ft-das CLI_VERSION=${{ inputs.cli_version }} PYTEST_GROUP=${{ matrix.pytest-group }} DC=${{ inputs.docker_compose }}
functional-das-slow:
name: "DAS Slow"
Expand All @@ -101,7 +101,7 @@ jobs:

- name: Bootstrap/Setup RSTUF DAS and run Functional Tests
run: |
make ft-das CLI_VERSION=${{ inputs.cli_version }} PYTEST_GROUP=none SLOW="yes"
make ft-das CLI_VERSION=${{ inputs.cli_version }} PYTEST_GROUP=none SLOW="yes" DC=${{ inputs.docker_compose }}
functional-signed:
name: "Signed"
Expand Down Expand Up @@ -130,7 +130,7 @@ jobs:

- name: Bootstrap/Setup RSTUF full Signed and run Functional Tests
run: |
make ft-signed CLI_VERSION=${{ inputs.cli_version }} PYTEST_GROUP=${{ matrix.pytest-group }}
make ft-signed CLI_VERSION=${{ inputs.cli_version }} PYTEST_GROUP=${{ matrix.pytest-group }} DC=${{ inputs.docker_compose }}
functional-signed-slow:
name: "Signed Slow"
Expand All @@ -156,4 +156,4 @@ jobs:

- name: Bootstrap/Setup RSTUF full Signed and run Functional Tests
run: |
make ft-signed CLI_VERSION=${{ inputs.cli_version }} PYTEST_GROUP=none SLOW="yes"
make ft-signed CLI_VERSION=${{ inputs.cli_version }} PYTEST_GROUP=none SLOW="yes" DC=${{ inputs.docker_compose }}
11 changes: 10 additions & 1 deletion .github/workflows/review-approved.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,13 @@ jobs:
with:
docker_compose: docker-compose-aws.yml
api_version: dev
cli_version: dev
cli_version: dev

functional-tests-mysql:
name: Deploy MySQL Server as DB
if: github.event.review.state == 'approved'
uses: ./.github/workflows/functional-tests.yml
with:
docker_compose: docker-compose-mysql.yml
api_version: dev
cli_version: dev
23 changes: 12 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
.PHONY: build-dev run-dev stop clean purge reformat tests requirements coverage docs
ifeq ($(DC),)
DC := docker-compose.yml
endif

build-dev:
docker build -t repository-service-tuf-worker:dev .
Expand All @@ -7,23 +10,21 @@ run-dev: export API_VERSION = dev
run-dev:
$(MAKE) build-dev
docker pull ghcr.io/repository-service-tuf/repository-service-tuf-api:dev
ifneq ($(DC),)
docker compose -f docker-compose-$(DC).yml up --remove-orphans
else
docker compose -f docker-compose.yml up --remove-orphans
endif

docker compose -f $(DC) up --remove-orphans



db-migration:
if [ -z "$(M)" ]; then echo "Use: make db-migration M=\'message here\'"; exit 1; fi
docker compose run --rm --entrypoint='alembic revision --autogenerate -m "$(M)"' repository-service-tuf-worker

stop:
docker compose down -v
docker compose -f $(DC) down -v

clean:
$(MAKE) stop
docker compose rm --force
docker compose -f $(DC) rm --force
docker rm repository-service-tuf-worker-localstack-1 -f
rm -rf ./data
rm -rf ./data_test
Expand Down Expand Up @@ -73,18 +74,18 @@ ft-das:
ifeq ($(GITHUB_ACTION),)
$(MAKE) clone-umbrella
endif
docker compose run --env UMBRELLA_PATH=rstuf-umbrella --rm rstuf-ft-runner bash rstuf-umbrella/tests/functional/scripts/run-ft-das.sh $(CLI_VERSION) $(PYTEST_GROUP) $(SLOW)
docker compose -f $(DC) run --env UMBRELLA_PATH=rstuf-umbrella --rm rstuf-ft-runner bash rstuf-umbrella/tests/functional/scripts/run-ft-das.sh $(CLI_VERSION) $(PYTEST_GROUP) $(SLOW)

ft-das-local:
docker compose run --env UMBRELLA_PATH=rstuf-umbrella --rm rstuf-ft-runner bash rstuf-umbrella/tests/functional/scripts/run-ft-das.sh $(CLI_VERSION)
docker compose -f $(DC) run --env UMBRELLA_PATH=rstuf-umbrella --rm rstuf-ft-runner bash rstuf-umbrella/tests/functional/scripts/run-ft-das.sh $(CLI_VERSION)


ft-signed:
# Use "GITHUB_ACTION" to identify if we are running from a GitHub action.
ifeq ($(GITHUB_ACTION),)
$(MAKE) clone-umbrella
endif
docker compose run --env UMBRELLA_PATH=rstuf-umbrella --rm rstuf-ft-runner bash rstuf-umbrella/tests/functional/scripts/run-ft-signed.sh $(CLI_VERSION) $(PYTEST_GROUP) $(SLOW)
docker compose -f $(DC) run --env UMBRELLA_PATH=rstuf-umbrella --rm rstuf-ft-runner bash rstuf-umbrella/tests/functional/scripts/run-ft-signed.sh $(CLI_VERSION) $(PYTEST_GROUP) $(SLOW)

ft-signed-local:
docker compose run --env UMBRELLA_PATH=rstuf-umbrella --rm rstuf-ft-runner bash rstuf-umbrella/tests/functional/scripts/run-ft-signed.sh $(CLI_VERSION)
docker compose -f $(DC) run --env UMBRELLA_PATH=rstuf-umbrella --rm rstuf-ft-runner bash rstuf-umbrella/tests/functional/scripts/run-ft-signed.sh $(CLI_VERSION)
7 changes: 7 additions & 0 deletions docker-compose-aws.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,10 @@ services:
condition: service_healthy
tty: true
stdin_open: true

rstuf-ft-runner:
image: python:3.10-slim-buster
command: python -V
working_dir: /rstuf-runner
volumes:
- ./:/rstuf-runner
9 changes: 9 additions & 0 deletions docker-compose-mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,12 @@ services:
condition: service_healthy
tty: true
stdin_open: true

rstuf-ft-runner:
image: python:3.10-slim-buster
command: python -V
working_dir: /rstuf-runner
environment:
- PERFORMANCE=false
volumes:
- ./:/rstuf-runner
7 changes: 7 additions & 0 deletions docker-compose-redis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,10 @@ services:
condition: service_healthy
tty: true
stdin_open: true

rstuf-ft-runner:
image: python:3.10-slim-buster
command: python -V
working_dir: /rstuf-runner
volumes:
- ./:/rstuf-runner
61 changes: 59 additions & 2 deletions tests/unit/tuf_repository_service_worker/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,58 @@ def test__get_role_for_artifact_path_no_role_for_target(self, test_repo):

def test__update_task(self, test_repo, mocked_datetime):
test_repo._db = pretend.stub(
refresh=pretend.call_recorder(lambda *a: None)
refresh=pretend.call_recorder(lambda *a: None),
bind=pretend.stub(
url=pretend.stub(
drivername="mysql+pymysql",
)
),
commit=pretend.call_recorder(lambda: None),
)

fake_target = pretend.stub(published=True)
fake_bin_targets = {
"bin-e": [fake_target],
"bin-f": [fake_target, fake_target],
}
fake_update_state = pretend.call_recorder(lambda *a, **kw: None)
fake_subtask = pretend.stub(status=states.SUCCESS)
result = test_repo._update_task(
fake_bin_targets, fake_update_state, fake_subtask
)

assert result is None
assert test_repo._db.refresh.calls == [
pretend.call(fake_target),
pretend.call(fake_target),
pretend.call(fake_target),
]
assert test_repo._db.commit.calls == [pretend.call(), pretend.call()]
assert fake_update_state.calls == [
pretend.call(
state="RUNNING",
meta={
"details": {
"published_roles": ["bin-e"],
"roles_to_publish": "['bin-e', 'bin-f']",
},
"message": "Publishing",
"last_update": mocked_datetime.now(),
"exc_type": None,
"exc_message": None,
},
),
]

def test__update_task_when_postgresql(self, test_repo, mocked_datetime):
test_repo._db = pretend.stub(
refresh=pretend.call_recorder(lambda *a: None),
bind=pretend.stub(
url=pretend.stub(
drivername="postgresql",
)
),
commit=pretend.call_recorder(lambda: None),
)

fake_target = pretend.stub(published=True)
Expand All @@ -1179,6 +1230,7 @@ def test__update_task(self, test_repo, mocked_datetime):
pretend.call(fake_target),
pretend.call(fake_target),
]
assert test_repo._db.commit.calls == [] # No commit for PostgreSQL
assert fake_update_state.calls == [
pretend.call(
state="RUNNING",
Expand All @@ -1197,7 +1249,12 @@ def test__update_task(self, test_repo, mocked_datetime):

def test__update_task_subtask_failure(self, test_repo, mocked_datetime):
test_repo._db = pretend.stub(
refresh=pretend.call_recorder(lambda *a: None)
refresh=pretend.call_recorder(lambda *a: None),
bind=pretend.stub(
url=pretend.stub(
drivername="postgresql",
)
),
)

fake_target = pretend.stub(published=True)
Expand Down

0 comments on commit dfb244a

Please sign in to comment.