~teknico/charm-helpers/lint-fixes

« back to all changes in this revision

Viewing changes to charmhelpers/contrib/hahelpers/ceph.py

  • Committer: Adam Gandelman
  • Date: 2013-08-13 16:53:12 UTC
  • mfrom: (66.1.4 ceph-wait-for-device)
  • Revision ID: adamg@canonical.com-20130813165312-pvaj0g0zprqffrzj
[ahasenack] Wait in a limited loop for the ceph device to become available.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
import commands
12
12
import os
13
13
import shutil
 
14
import time
14
15
 
15
16
from subprocess import (
16
17
    check_call,
24
25
    related_units,
25
26
    log,
26
27
    INFO,
 
28
    ERROR
27
29
)
28
30
 
29
31
from charmhelpers.core.host import (
179
181
    return fs in [f for m, f in mounts()]
180
182
 
181
183
 
182
 
def make_filesystem(blk_device, fstype='ext4'):
183
 
    log('ceph: Formatting block device %s as filesystem %s.' %
184
 
        (blk_device, fstype), level=INFO)
185
 
    cmd = ['mkfs', '-t', fstype, blk_device]
186
 
    check_call(cmd)
 
184
def make_filesystem(blk_device, fstype='ext4', timeout=10):
 
185
    count = 0
 
186
    e_noent = os.errno.ENOENT
 
187
    while not os.path.exists(blk_device):
 
188
        if count >= timeout:
 
189
            log('ceph: gave up waiting on block device %s' % blk_device,
 
190
                level=ERROR)
 
191
            raise IOError(e_noent, os.strerror(e_noent), blk_device)
 
192
        log('ceph: waiting for block device %s to appear' % blk_device,
 
193
            level=INFO)
 
194
        count += 1
 
195
        time.sleep(1)
 
196
    else:
 
197
        log('ceph: Formatting block device %s as filesystem %s.' %
 
198
            (blk_device, fstype), level=INFO)
 
199
        check_call(['mkfs', '-t', fstype, blk_device])
187
200
 
188
201
 
189
202
def place_data_on_ceph(service, blk_device, data_src_dst, fstype='ext4'):