Check if /var/lib/ceph/nss exists before creation

mkdir() throws an exception if the directory already exists, so we should check
for it's existance before creation as hooks should be idempotent.

This occurred in practice when the install hook had to be re-run, following a
previous failure due to juju API timeout.  It would also occur if the keystone
relation was re-built, so that case is also fixed.

Change-Id: I4052cda5bb20f76ab592ed7817bdc1e5b5b2138d
Closes-Bug: #1563667
This commit is contained in:
Trent Lloyd 2016-03-30 13:11:58 +08:00
parent c29fc43d1e
commit b0338f7283

View File

@ -130,7 +130,8 @@ def install():
execd_preinstall()
enable_pocket('multiverse')
install_packages()
os.makedirs(NSS_DIR)
if not os.path.exists(NSS_DIR):
os.makedirs(NSS_DIR)
if not os.path.exists('/etc/ceph'):
os.makedirs('/etc/ceph')
@ -157,7 +158,8 @@ def setup_keystone_certs(unit=None, rid=None):
from keystoneclient.v2_0 import client
certs_path = '/var/lib/ceph/nss'
mkdir(certs_path)
if not os.path.exists(certs_path):
mkdir(certs_path)
rdata = relation_get(unit=unit, rid=rid)
auth_protocol = rdata.get('auth_protocol', 'http')