Esempio n. 1
0
 def test_ensure_ceph_storage(self):
     self._patch('pool_exists')
     self.pool_exists.return_value = False
     self._patch('create_pool')
     self._patch('rbd_exists')
     self.rbd_exists.return_value = False
     self._patch('create_rbd_image')
     self._patch('image_mapped')
     self.image_mapped.return_value = False
     self._patch('map_block_storage')
     self._patch('filesystem_mounted')
     self.filesystem_mounted.return_value = False
     self._patch('make_filesystem')
     self._patch('service_stop')
     self._patch('service_start')
     self._patch('service_running')
     self.service_running.return_value = True
     self._patch('place_data_on_block_device')
     _service = 'mysql'
     _pool = 'bar'
     _rbd_img = 'foo'
     _mount = '/var/lib/mysql'
     _services = ['mysql']
     _blk_dev = '/dev/rbd1'
     ceph_utils.ensure_ceph_storage(_service, _pool, _rbd_img, 1024, _mount,
                                    _blk_dev, 'ext4', _services, 3)
     self.create_pool.assert_called_with(_service, _pool, replicas=3)
     self.create_rbd_image.assert_called_with(_service, _pool, _rbd_img,
                                              1024)
     self.map_block_storage.assert_called_with(_service, _pool, _rbd_img)
     self.make_filesystem.assert_called_with(_blk_dev, 'ext4')
     self.service_stop.assert_called_with(_services[0])
     self.place_data_on_block_device.assert_called_with(_blk_dev, _mount)
     self.service_start.assert_called_with(_services[0])
Esempio n. 2
0
def ceph_changed():
    log('Start Ceph Relation Changed')
    auth = relation_get('auth')
    key = relation_get('key')
    use_syslog = str(config('use-syslog')).lower()
    if None in [auth, key]:
        log('Missing key or auth in relation')
        sys.exit(0)

    ceph.configure(service=SERVICE_NAME,
                   key=key,
                   auth=auth,
                   use_syslog=use_syslog)

    if is_elected_leader('res_rabbitmq_vip'):
        rbd_img = config('rbd-name')
        rbd_size = config('rbd-size')
        sizemb = int(rbd_size.split('G')[0]) * 1024
        blk_device = '/dev/rbd/%s/%s' % (POOL_NAME, rbd_img)
        ceph.create_pool(service=SERVICE_NAME,
                         name=POOL_NAME,
                         replicas=int(config('ceph-osd-replication-count')))
        ceph.ensure_ceph_storage(service=SERVICE_NAME,
                                 pool=POOL_NAME,
                                 rbd_img=rbd_img,
                                 sizemb=sizemb,
                                 fstype='ext4',
                                 mount_point=RABBIT_DIR,
                                 blk_device=blk_device,
                                 system_services=['rabbitmq-server'])
        subprocess.check_call(
            ['chown', '-R',
             '%s:%s' % (RABBIT_USER, RABBIT_GROUP), RABBIT_DIR])
    else:
        log('This is not the peer leader. Not configuring RBD.')
        log('Stopping rabbitmq-server.')
        service_stop('rabbitmq-server')

    # If 'ha' relation has been made before the 'ceph' relation
    # it is important to make sure the ha-relation data is being
    # sent.
    if is_relation_made('ha'):
        log('*ha* relation exists. Triggering ha_joined()')
        ha_joined()
    else:
        log('*ha* relation does not exist.')
    log('Finish Ceph Relation Changed')
def ceph_changed():
    log('Start Ceph Relation Changed')
    auth = relation_get('auth')
    key = relation_get('key')
    use_syslog = str(config('use-syslog')).lower()
    if None in [auth, key]:
        log('Missing key or auth in relation')
        sys.exit(0)

    ceph.configure(service=SERVICE_NAME, key=key, auth=auth,
                   use_syslog=use_syslog)

    if is_elected_leader('res_rabbitmq_vip'):
        rbd_img = config('rbd-name')
        rbd_size = config('rbd-size')
        sizemb = int(rbd_size.split('G')[0]) * 1024
        blk_device = '/dev/rbd/%s/%s' % (POOL_NAME, rbd_img)
        ceph.create_pool(service=SERVICE_NAME, name=POOL_NAME,
                         replicas=int(config('ceph-osd-replication-count')))
        ceph.ensure_ceph_storage(service=SERVICE_NAME, pool=POOL_NAME,
                                 rbd_img=rbd_img, sizemb=sizemb,
                                 fstype='ext4', mount_point=RABBIT_DIR,
                                 blk_device=blk_device,
                                 system_services=['rabbitmq-server'])
        subprocess.check_call(['chown', '-R', '%s:%s' %
                               (RABBIT_USER, RABBIT_GROUP), RABBIT_DIR])
    else:
        log('This is not the peer leader. Not configuring RBD.')
        log('Stopping rabbitmq-server.')
        service_stop('rabbitmq-server')

    # If 'ha' relation has been made before the 'ceph' relation
    # it is important to make sure the ha-relation data is being
    # sent.
    if is_relation_made('ha'):
        log('*ha* relation exists. Triggering ha_joined()')
        ha_joined()
    else:
        log('*ha* relation does not exist.')
    log('Finish Ceph Relation Changed')