From 0ecc33223cdc6a7a1b162cb93ca622df013f9b8e Mon Sep 17 00:00:00 2001 From: Chris MacNaughton Date: Wed, 1 Apr 2020 12:56:11 +0200 Subject: [PATCH] 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 --- hooks/charmhelpers/contrib/openstack/vaultlocker.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/hooks/charmhelpers/contrib/openstack/vaultlocker.py b/hooks/charmhelpers/contrib/openstack/vaultlocker.py index 866a2697..4690f6b0 100644 --- a/hooks/charmhelpers/contrib/openstack/vaultlocker.py +++ b/hooks/charmhelpers/contrib/openstack/vaultlocker.py @@ -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