Skip to content

Commit 7a3570a

Browse files
DPE-2758 better messaging when no bucket + ceph testing (#332)
* improved action output and ceph integration test * WIP: ceph test with SSL support * setup microceph without ssl for now * rollback ssl support * touch microceph variables file to allow tox run * removed unused import * put microceph setup before any tox call * Include before tests * fix libs versioning and removed unnecessary change * sync patches * lint fixes from synced lib * deprecated microceph action * picking fix for github_secrets plugin name * bumped dpw on workflows * Use reusable integration test workflow * !fixup Use reusable integration test workflow --------- Co-authored-by: Carl Csaposs <[email protected]>
1 parent d7b90c3 commit 7a3570a

21 files changed

+264
-336
lines changed

.github/workflows/ci.yaml

Lines changed: 23 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,9 @@ on:
1616
jobs:
1717
lint:
1818
name: Lint
19-
uses: canonical/data-platform-workflows/.github/workflows/lint.yaml@v9.0.2
19+
uses: canonical/data-platform-workflows/.github/workflows/lint.yaml@v9.3.1
2020

2121
unit-test:
22-
strategy:
23-
fail-fast: false
24-
matrix:
25-
juju-version: ["2.9", "3.1"]
2622
name: Unit test charm
2723
runs-on: ubuntu-latest
2824
timeout-minutes: 5
@@ -35,124 +31,40 @@ jobs:
3531
pipx install poetry
3632
- name: Run tests
3733
run: tox run -e unit
38-
env:
39-
# This env var is only to indicate Juju version to "simulate" in the unit tests
40-
# No libjuju is being actually used in unit testing
41-
LIBJUJU_VERSION_SPECIFIER: ${{ matrix.juju-version }}
4234
- name: Upload Coverage to Codecov
4335
uses: codecov/codecov-action@v3
4436

4537
build:
4638
name: Build charm
47-
uses: canonical/data-platform-workflows/.github/workflows/build_charms_with_cache.yaml@v9.0.2
39+
uses: canonical/data-platform-workflows/.github/workflows/build_charms_with_cache.yaml@v9.3.1
4840
with:
4941
charmcraft-snap-channel: beta
5042

51-
gh-hosted-collect-integration-tests:
52-
name: (GH hosted) Collect integration test groups
53-
needs:
54-
- lint
55-
- unit-test
56-
runs-on: ubuntu-latest
57-
steps:
58-
- name: Checkout
59-
uses: actions/checkout@v3
60-
- name: Install tox & poetry
61-
run: |
62-
pipx install tox
63-
pipx install poetry
64-
- name: Select test stability level
65-
id: select-test-stability
66-
run: |
67-
if [[ "${{ github.event_name }}" == "schedule" ]]
68-
then
69-
echo Running unstable and stable tests
70-
echo "mark_expression=" >> "$GITHUB_OUTPUT"
71-
else
72-
echo Skipping unstable tests
73-
echo "mark_expression=not unstable" >> "$GITHUB_OUTPUT"
74-
fi
75-
- name: Collect test groups
76-
id: collect-groups
77-
run: tox run -e integration -- tests/integration -m '${{ steps.select-test-stability.outputs.mark_expression }}' --collect-groups
78-
outputs:
79-
groups: ${{ steps.collect-groups.outputs.groups }}
80-
81-
gh-hosted-integration-test:
43+
integration-test:
8244
strategy:
8345
fail-fast: false
8446
matrix:
85-
groups: ${{ fromJSON(needs.gh-hosted-collect-integration-tests.outputs.groups) }}
86-
juju-snap-channel: ["2.9/stable", "3.1/stable"]
87-
include:
88-
- juju-snap-channel: "3.1/stable"
89-
agent-version: "3.1.6"
90-
libjuju-version: "3.2.2"
91-
- juju-snap-channel: "2.9/stable"
92-
agent-version: "2.9.45"
93-
libjuju-version: "2.9.44.1"
94-
exclude:
95-
# Disabling HA tests, as long as we want to have a limited pipeline on Juju3
96-
- juju-snap-channel: "3.1/stable"
97-
groups:
98-
job_name: "high_availability/test_replication.py | group 1"
99-
- juju-snap-channel: "3.1/stable"
100-
groups:
101-
job_name: "high_availability/test_self_healing.py | group 1"
102-
- juju-snap-channel: "3.1/stable"
103-
groups:
104-
job_name: "high_availability/test_upgrade.py | group 1"
105-
- juju-snap-channel: "3.1/stable"
106-
groups:
107-
job_name: "high_availability/test_upgrade_from_stable.py | group 1"
108-
name: ${{ matrix.juju-snap-channel }} - (GH hosted) ${{ matrix.groups.job_name }}
47+
juju:
48+
- agent: 2.9.45
49+
libjuju: ^2
50+
- agent: 3.1.6
51+
name: Integration test charm | ${{ matrix.juju.agent }}
10952
needs:
11053
- lint
11154
- unit-test
11255
- build
113-
- gh-hosted-collect-integration-tests
114-
runs-on: ubuntu-latest
115-
timeout-minutes: 120
116-
steps:
117-
- name: Checkout
118-
uses: actions/checkout@v3
119-
- name: Install tox & poetry
120-
run: |
121-
pipx install tox
122-
pipx install poetry
123-
- name: Setup operator environment
124-
uses: charmed-kubernetes/actions-operator@main
125-
with:
126-
provider: microk8s
127-
channel: "1.28-strict/stable"
128-
bootstrap-options: "--agent-version ${{ matrix.agent-version }}"
129-
juju-channel: ${{ matrix.juju-snap-channel }}
130-
- name: Update python-libjuju version
131-
if: ${{ matrix.libjuju-version == '2.9.44.1' }}
132-
run: poetry add --lock --group integration juju@'${{ matrix.libjuju-version }}'
133-
- name: Download packed charm(s)
134-
uses: actions/download-artifact@v3
135-
with:
136-
name: ${{ needs.build.outputs.artifact-name }}
137-
- name: Select test stability level
138-
id: select-test-stability
139-
run: |
140-
if [[ "${{ github.event_name }}" == "schedule" ]]
141-
then
142-
echo Running unstable and stable tests
143-
echo "mark_expression=" >> "$GITHUB_OUTPUT"
144-
else
145-
echo Skipping unstable tests
146-
echo "mark_expression=not unstable" >> "$GITHUB_OUTPUT"
147-
fi
148-
- name: Run integration tests
149-
run: tox run -e integration -- "${{ matrix.groups.path_to_test_file }}" --group="${{ matrix.groups.group_number }}" -m '${{ steps.select-test-stability.outputs.mark_expression }}'
150-
env:
151-
LIBJUJU_VERSION_SPECIFIER: ${{ matrix.libjuju-version }}
152-
SECRETS_FROM_GITHUB: |
153-
{
154-
"AWS_ACCESS_KEY": "${{ secrets.AWS_ACCESS_KEY }}",
155-
"AWS_SECRET_KEY": "${{ secrets.AWS_SECRET_KEY }}",
156-
"GCP_ACCESS_KEY": "${{ secrets.GCP_ACCESS_KEY }}",
157-
"GCP_SECRET_KEY": "${{ secrets.GCP_SECRET_KEY }}",
158-
}
56+
uses: canonical/data-platform-workflows/.github/workflows/[email protected]
57+
with:
58+
artifact-name: ${{ needs.build.outputs.artifact-name }}
59+
cloud: microk8s
60+
microk8s-snap-channel: 1.28-strict/stable
61+
juju-agent-version: ${{ matrix.juju.agent }}
62+
libjuju-version-constraint: ${{ matrix.juju.libjuju }}
63+
secrets:
64+
integration-test: |
65+
{
66+
"AWS_ACCESS_KEY": "${{ secrets.AWS_ACCESS_KEY }}",
67+
"AWS_SECRET_KEY": "${{ secrets.AWS_SECRET_KEY }}",
68+
"GCP_ACCESS_KEY": "${{ secrets.GCP_ACCESS_KEY }}",
69+
"GCP_SECRET_KEY": "${{ secrets.GCP_SECRET_KEY }}",
70+
}

.github/workflows/release.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
secrets: inherit
3434
build:
3535
name: Build charm
36-
uses: canonical/data-platform-workflows/.github/workflows/build_charm_without_cache.yaml@v9.0.2
36+
uses: canonical/data-platform-workflows/.github/workflows/build_charm_without_cache.yaml@v9.3.1
3737
with:
3838
charmcraft-snap-channel: beta
3939

@@ -43,7 +43,7 @@ jobs:
4343
- lib-check
4444
- ci-tests
4545
- build
46-
uses: canonical/data-platform-workflows/.github/workflows/release_charm.yaml@v9.0.2
46+
uses: canonical/data-platform-workflows/.github/workflows/release_charm.yaml@v9.3.1
4747
with:
4848
channel: 8.0/edge
4949
artifact-name: ${{ needs.build.outputs.artifact-name }}

.github/workflows/sync_issue_to_jira.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
jobs:
1010
sync:
1111
name: Sync GitHub issue to Jira
12-
uses: canonical/data-platform-workflows/.github/workflows/sync_issue_to_jira.yaml@v9.0.2
12+
uses: canonical/data-platform-workflows/.github/workflows/sync_issue_to_jira.yaml@v9.3.1
1313
with:
1414
jira-base-url: https://warthogs.atlassian.net
1515
jira-project-key: DPE

CONTRIBUTING.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,6 @@ tox run -e unit # unit tests
4444
tox run -e integration # integration tests
4545
tox # runs 'lint' and 'unit' environments
4646
```
47-
Tests by default are using Juju 3. In case tests are to be run against Juju 3, the following
48-
environment variable should be defined with a valid `juju` Python library version:
49-
50-
```
51-
export LIBJUJU_VERSION_SPECIFIER=2.9.44.1
52-
```
5347

5448
## Build charm
5549

lib/charms/mysql/v0/backups.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ def is_unit_blocked(self) -> bool:
4848
import datetime
4949
import logging
5050
import pathlib
51-
from typing import Dict, List, Optional, Tuple
5251
import typing
52+
from typing import Dict, List, Optional, Tuple
5353

5454
from charms.data_platform_libs.v0.s3 import S3Requirer
5555
from charms.mysql.v0.mysql import (
@@ -96,7 +96,7 @@ def is_unit_blocked(self) -> bool:
9696

9797
# Increment this PATCH version before using `charmcraft publish-lib` or reset
9898
# to 0 if you are raising the major API version
99-
LIBPATCH = 6
99+
LIBPATCH = 8
100100

101101

102102
if typing.TYPE_CHECKING:
@@ -220,9 +220,11 @@ def _on_list_backups(self, event: ActionEvent) -> None:
220220
logger.info("Listing backups in the specified s3 path")
221221
backups = sorted(list_backups_in_s3_path(s3_parameters), key=lambda pair: pair[0])
222222
event.set_results({"backups": self._format_backups_list(backups)})
223-
except Exception:
224-
error_message = "Failed to retrieve backup ids from S3"
225-
logger.exception(error_message)
223+
except Exception as e:
224+
error_message = (
225+
e.message if hasattr(e, "message") else "Failed to retrieve backup ids from S3"
226+
)
227+
logger.error(error_message)
226228
event.fail(error_message)
227229

228230
# ------------------ Create Backup ------------------

lib/charms/mysql/v0/s3_helpers.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@
3131

3232
# Increment this PATCH version before using `charmcraft publish-lib` or reset
3333
# to 0 if you are raising the major API version
34-
LIBPATCH = 5
34+
LIBPATCH = 6
35+
36+
# botocore/urllib3 clutter the logs when on debug
37+
logging.getLogger("botocore").setLevel(logging.WARNING)
38+
logging.getLogger("urllib3").setLevel(logging.WARNING)
3539

3640

3741
def upload_content_to_s3(content: str, content_path: str, s3_parameters: Dict) -> bool:
@@ -55,6 +59,7 @@ def upload_content_to_s3(content: str, content_path: str, s3_parameters: Dict) -
5559
)
5660

5761
s3 = session.resource("s3", endpoint_url=s3_parameters["endpoint"])
62+
5863
bucket = s3.Bucket(s3_parameters["bucket"])
5964

6065
with tempfile.NamedTemporaryFile() as temp_file:
@@ -89,7 +94,7 @@ def _compile_backups_from_file_ids(
8994
return backups
9095

9196

92-
def list_backups_in_s3_path(s3_parameters: Dict) -> List[Tuple[str, str]]:
97+
def list_backups_in_s3_path(s3_parameters: Dict) -> List[Tuple[str, str]]: # noqa: C901
9398
"""Retrieve subdirectories in an S3 path.
9499
95100
Args:
@@ -147,9 +152,19 @@ def list_backups_in_s3_path(s3_parameters: Dict) -> List[Tuple[str, str]]:
147152

148153
return _compile_backups_from_file_ids(metadata_ids, md5_ids, log_ids)
149154
except Exception as e:
155+
try:
156+
# botocore raises dynamically generated exceptions
157+
# with a response attribute. We can use this to
158+
# set a more meaningful error message.
159+
if e.response["Error"]["Code"] == "NoSuchBucket":
160+
message = f"Bucket {s3_parameters['bucket']} does not exist"
161+
setattr(e, "message", message)
162+
raise
163+
except (KeyError, AttributeError):
164+
pass
165+
# default handling exposes exception
150166
logger.exception(
151-
f"Failed to list subdirectories in S3 bucket={s3_parameters['bucket']}, path={s3_parameters['path']}",
152-
exc_info=e,
167+
f"Failed to list subdirectories in S3 bucket={s3_parameters['bucket']}, path={s3_parameters['path']}"
153168
)
154169
raise
155170

0 commit comments

Comments
 (0)