Пример #1
0
def prepare_filestore(device, journal, secrets, id_=None, fsid=None):
    """
    :param device: The name of the logical volume to work with
    :param journal: similar to device but can also be a regular/plain disk
    :param secrets: A dict with the secrets needed to create the osd (e.g. cephx)
    :param id_: The OSD id
    :param fsid: The OSD fsid, also known as the OSD UUID
    """
    cephx_secret = secrets.get('cephx_secret', prepare_utils.create_key())
    json_secrets = json.dumps(secrets)

    # allow re-using an existing fsid, in case prepare failed
    fsid = fsid or system.generate_uuid()
    # allow re-using an id, in case a prepare failed
    osd_id = id_ or prepare_utils.create_id(fsid, json_secrets)
    # create the directory
    prepare_utils.create_osd_path(osd_id)
    # format the device
    prepare_utils.format_device(device)
    # mount the data device
    prepare_utils.mount_osd(device, osd_id)
    # symlink the journal
    prepare_utils.link_journal(journal, osd_id)
    # get the latest monmap
    prepare_utils.get_monmap(osd_id)
    # prepare the osd filesystem
    prepare_utils.osd_mkfs_filestore(osd_id, fsid)
    # write the OSD keyring if it doesn't exist already
    prepare_utils.write_keyring(osd_id, cephx_secret)
Пример #2
0
def prepare_filestore(device, journal, secrets, id_=None, fsid=None):
    """
    :param device: The name of the logical volume to work with
    :param journal: similar to device but can also be a regular/plain disk
    :param secrets: A dict with the secrets needed to create the osd (e.g. cephx)
    :param id_: The OSD id
    :param fsid: The OSD fsid, also known as the OSD UUID
    """
    cephx_secret = secrets.get('cephx_secret', prepare_utils.create_key())
    json_secrets = json.dumps(secrets)

    # allow re-using an existing fsid, in case prepare failed
    fsid = fsid or system.generate_uuid()
    # allow re-using an id, in case a prepare failed
    osd_id = id_ or prepare_utils.create_id(fsid, json_secrets)
    # create the directory
    prepare_utils.create_osd_path(osd_id)
    # format the device
    prepare_utils.format_device(device)
    # mount the data device
    prepare_utils.mount_osd(device, osd_id)
    # symlink the journal
    prepare_utils.link_journal(journal, osd_id)
    # get the latest monmap
    prepare_utils.get_monmap(osd_id)
    # prepare the osd filesystem
    prepare_utils.osd_mkfs_filestore(osd_id, fsid)
    # write the OSD keyring if it doesn't exist already
    prepare_utils.write_keyring(osd_id, cephx_secret)
Пример #3
0
 def test_default_options(self, conf_ceph_stub, fake_run):
     conf_ceph_stub(dedent("""[global]
     fsid = 1234lkjh1234"""))
     conf.cluster = 'ceph'
     prepare.format_device('/dev/sda1')
     expected = [
         'mkfs', '-t', 'xfs',
         '-f', '-i', 'size=2048',  # default flags
         '/dev/sda1']
     assert expected == fake_run.calls[0]['args'][0]
Пример #4
0
 def test_multiple_options_are_used(self, conf_ceph_stub, fake_run):
     conf_ceph_stub(
         dedent("""[global]
     fsid = 1234lkjh1234
     [osd]
     osd mkfs options xfs = -f -i size=1024"""))
     conf.cluster = 'ceph'
     prepare.format_device('/dev/sda1')
     expected = ['mkfs', '-t', 'xfs', '-f', '-i', 'size=1024', '/dev/sda1']
     assert expected == fake_run.calls[0]['args'][0]
Пример #5
0
 def test_default_options(self, conf_ceph_stub, fake_run):
     conf_ceph_stub(dedent("""[global]
     fsid = 1234lkjh1234"""))
     conf.cluster = 'ceph'
     prepare.format_device('/dev/sda1')
     expected = [
         'mkfs', '-t', 'xfs',
         '-f', '-i', 'size=2048',  # default flags
         '/dev/sda1']
     assert expected == fake_run.calls[0]['args'][0]
Пример #6
0
 def test_multiple_options_will_get_the_force_flag(self, conf_ceph_stub, fake_run):
     conf_ceph_stub(dedent("""[global]
     fsid = 1234lkjh1234
     [osd]
     osd mkfs options xfs = -i size=1024"""))
     conf.cluster = 'ceph'
     prepare.format_device('/dev/sda1')
     expected = [
         'mkfs', '-t', 'xfs',
         '-f', '-i', 'size=1024',
         '/dev/sda1']
     assert expected == fake_run.calls[0]['args'][0]
Пример #7
0
 def test_underscore_options_are_used(self, conf_ceph_stub, fake_run):
     conf_ceph_stub(dedent("""[global]
     fsid = 1234lkjh1234
     [osd]
     osd_mkfs_options_xfs = -i size=128"""))
     conf.cluster = 'ceph'
     prepare.format_device('/dev/sda1')
     expected = [
         'mkfs', '-t', 'xfs',
         '-f', '-i', 'size=128',
         '/dev/sda1']
     assert expected == fake_run.calls[0]['args'][0]
Пример #8
0
def prepare_filestore(device, journal, secrets, tags, osd_id, fsid):
    """
    :param device: The name of the logical volume to work with
    :param journal: similar to device but can also be a regular/plain disk
    :param secrets: A dict with the secrets needed to create the osd (e.g. cephx)
    :param id_: The OSD id
    :param fsid: The OSD fsid, also known as the OSD UUID
    """
    cephx_secret = secrets.get('cephx_secret', prepare_utils.create_key())

    # encryption-only operations
    if secrets.get('dmcrypt_key'):
        # format and open ('decrypt' devices) and re-assign the device and journal
        # variables so that the rest of the process can use the mapper paths
        key = secrets['dmcrypt_key']
        device = prepare_dmcrypt(key, device, 'data', tags)
        journal = prepare_dmcrypt(key, journal, 'journal', tags)

    # vdo detection
    is_vdo = api.is_vdo(device)
    # create the directory
    prepare_utils.create_osd_path(osd_id)
    # format the device
    prepare_utils.format_device(device)
    # mount the data device
    prepare_utils.mount_osd(device, osd_id, is_vdo=is_vdo)
    # symlink the journal
    prepare_utils.link_journal(journal, osd_id)
    # get the latest monmap
    prepare_utils.get_monmap(osd_id)
    # prepare the osd filesystem
    prepare_utils.osd_mkfs_filestore(osd_id, fsid, cephx_secret)
    # write the OSD keyring if it doesn't exist already
    prepare_utils.write_keyring(osd_id, cephx_secret)
    if secrets.get('dmcrypt_key'):
        # if the device is going to get activated right away, this can be done
        # here, otherwise it will be recreated
        encryption_utils.write_lockbox_keyring(
            osd_id,
            fsid,
            tags['ceph.cephx_lockbox_secret']
        )
Пример #9
0
def prepare_filestore(device, journal, secrets, tags, osd_id, fsid):
    """
    :param device: The name of the logical volume to work with
    :param journal: similar to device but can also be a regular/plain disk
    :param secrets: A dict with the secrets needed to create the osd (e.g. cephx)
    :param id_: The OSD id
    :param fsid: The OSD fsid, also known as the OSD UUID
    """
    cephx_secret = secrets.get('cephx_secret', prepare_utils.create_key())

    # encryption-only operations
    if secrets.get('dmcrypt_key'):
        # format and open ('decrypt' devices) and re-assign the device and journal
        # variables so that the rest of the process can use the mapper paths
        key = secrets['dmcrypt_key']
        device = prepare_dmcrypt(key, device, 'data', tags)
        journal = prepare_dmcrypt(key, journal, 'journal', tags)

    # vdo detection
    is_vdo = api.is_vdo(device)
    # create the directory
    prepare_utils.create_osd_path(osd_id)
    # format the device
    prepare_utils.format_device(device)
    # mount the data device
    prepare_utils.mount_osd(device, osd_id, is_vdo=is_vdo)
    # symlink the journal
    prepare_utils.link_journal(journal, osd_id)
    # get the latest monmap
    prepare_utils.get_monmap(osd_id)
    # prepare the osd filesystem
    prepare_utils.osd_mkfs_filestore(osd_id, fsid, cephx_secret)
    # write the OSD keyring if it doesn't exist already
    prepare_utils.write_keyring(osd_id, cephx_secret)
    if secrets.get('dmcrypt_key'):
        # if the device is going to get activated right away, this can be done
        # here, otherwise it will be recreated
        encryption_utils.write_lockbox_keyring(
            osd_id,
            fsid,
            tags['ceph.cephx_lockbox_secret']
        )
Пример #10
0
 def test_extra_flags_are_added(self, fake_run, conf_ceph):
     conf_ceph(get_list=lambda *a, **kw: ['--why-yes'])
     prepare.format_device('/dev/sxx')
     flags = fake_run.calls[0]['args'][0]
     assert '--why-yes' in flags
Пример #11
0
 def test_device_is_always_appended(self, fake_run, conf_ceph):
     conf_ceph(get_list=lambda *a, **kw: [])
     prepare.format_device('/dev/sxx')
     flags = fake_run.calls[0]['args'][0]
     assert flags[-1] == '/dev/sxx'
Пример #12
0
 def test_include_force(self, fake_run, monkeypatch):
     monkeypatch.setattr(conf, 'ceph', Factory(get_list=lambda *a, **kw: []))
     prepare.format_device('/dev/sxx')
     flags = fake_run.calls[0]['args'][0]
     assert '-f' in flags
Пример #13
0
 def test_extra_flags_are_added(self, fake_run, conf_ceph):
     conf_ceph(get_list=lambda *a, **kw: ['--why-yes'])
     prepare.format_device('/dev/sxx')
     flags = fake_run.calls[0]['args'][0]
     assert '--why-yes' in flags
Пример #14
0
 def test_device_is_always_appended(self, fake_run, conf_ceph):
     conf_ceph(get_list=lambda *a, **kw: [])
     prepare.format_device('/dev/sxx')
     flags = fake_run.calls[0]['args'][0]
     assert flags[-1] == '/dev/sxx'
Пример #15
0
 def test_include_force(self, fake_run, monkeypatch):
     monkeypatch.setattr(conf, 'ceph',
                         Factory(get_list=lambda *a, **kw: []))
     prepare.format_device('/dev/sxx')
     flags = fake_run.calls[0]['args'][0]
     assert '-f' in flags