Be more defensive when checking Vault

When relations are departing during a unit removal, the relation
to Vault can loose enough data that the vault-relation-departed hook
raises an exception. The checks for Vault readiness should be more
defensive to ensure that charms can successfully depart their relations

Depends-On https://github.com/juju/charm-helpers/pull/445
Closes-Bug: #1868282

Change-Id: I0b6226f0f3500aef7304f8e8b38d06daebfd0c20
This commit is contained in:
Chris MacNaughton 2020-04-01 12:56:11 +02:00 committed by Chris MacNaughton (icey)
parent cb0f757f18
commit 0ecc33223c

View File

@ -140,9 +140,16 @@ def vault_relation_complete(backend=None):
:ptype backend: string
:returns: whether the relation to vault is complete
:rtype: bool"""
vault_kv = VaultKVContext(secret_backend=backend or VAULTLOCKER_BACKEND)
vault_kv()
return vault_kv.complete
try:
import hvac
except ImportError:
return False
try:
vault_kv = VaultKVContext(secret_backend=backend or VAULTLOCKER_BACKEND)
vault_kv()
return vault_kv.complete
except hvac.exceptions.InvalidRequest:
return False
# TODO: contrib a high level unwrap method to hvac that works