Skip to content

Commit

Permalink
test: Debug restore in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
robin-nitrokey committed Nov 17, 2023
1 parent ee7c7ca commit 15a2ae2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ jobs:
run: |
. venv/bin/activate
make test
- name: Upload artifacts
uses: actions/upload-artifact@v3
if: ${{ failure() }}
with:
name: backup
path: backupNethsm.bin
- name: upload coverage
uses: codecov/codecov-action@v3
with:
Expand Down
23 changes: 16 additions & 7 deletions tests/test_nethsm_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,22 @@ def test_state_restore(nethsm: NetHSM) -> None:
system_time = datetime.datetime.now(datetime.timezone.utc)
assert nethsm.get_state().value == "Unprovisioned"

try:
with open(C.FILENAME_BACKUP, "rb") as f:
nethsm.restore(f, C.BACKUP_PASSPHRASE, system_time)
nethsm.unlock(C.UNLOCK_PASSPHRASE)
except OSError as e:
print(e, type(e))
assert False
successful_try = None
last_exception = None
for i in range(10):
try:
with open(C.FILENAME_BACKUP, "rb") as f:
nethsm.restore(f, C.BACKUP_PASSPHRASE, system_time)
successful_try = i
except nethsm.ApiException as e:
last_exception = e
continue

if successful_try != 0:
print(f"successful try: {successful_try}")
raise last_exception

nethsm.unlock(C.UNLOCK_PASSPHRASE)

assert nethsm.list_keys() == [C.KEY_ID_GENERATED]

Expand Down

0 comments on commit 15a2ae2

Please sign in to comment.