def get_ready_by_name(name):
return [x[name]['ready'] for x in PTYPE.values()]
+ @staticmethod
+ def is_regular_space(ptype):
+ return Ptype.is_what_space('regular', ptype)
+
+ @staticmethod
+ def is_mpath_space(ptype):
+ return Ptype.is_what_space('mpath', ptype)
+
+ @staticmethod
+ def is_plain_space(ptype):
+ return Ptype.is_what_space('plain', ptype)
+
+ @staticmethod
+ def is_luks_space(ptype):
+ return Ptype.is_what_space('luks', ptype)
+
+ @staticmethod
+ def is_what_space(what, ptype):
+ for name in Space.NAMES:
+ if ptype == PTYPE[what][name]['ready']:
+ return True
+ return False
+
+ @staticmethod
+ def space_ptype_to_name(ptype):
+ for what in PTYPE.values():
+ for name in Space.NAMES:
+ if ptype == what[name]['ready']:
+ return name
+ raise ValueError('ptype ' + ptype + ' not found')
+
+ @staticmethod
+ def is_dmcrypt_space(ptype):
+ for name in Space.NAMES:
+ if Ptype.is_dmcrypt(ptype, name):
+ return True
+ return False
+
@staticmethod
def is_dmcrypt(ptype, name):
for what in ('plain', 'luks'):
self.data.prepare(self.block)
+class Space(object):
+
+ NAMES = ('block', 'journal')
+
+
class PrepareSpace(object):
NONE = 0
if desc['ceph_fsid']:
desc['cluster'] = find_cluster_by_uuid(desc['ceph_fsid'])
desc['whoami'] = get_oneliner(path, 'whoami')
- desc['journal_uuid'] = get_oneliner(path, 'journal_uuid')
- if desc['journal_uuid']:
- desc['journal_uuid'] = desc['journal_uuid'].lower()
- if desc['journal_uuid'] in uuid_map:
- desc['journal_dev'] = uuid_map[desc['journal_uuid']]
+ for name in Space.NAMES:
+ uuid = get_oneliner(path, name + '_uuid')
+ if uuid:
+ desc[name + '_uuid'] = uuid.lower()
+ if desc[name + '_uuid'] in uuid_map:
+ desc[name + '_dev'] = uuid_map[desc[name + '_uuid']]
def list_dev_osd(dev, uuid_map, desc):
desc.append('unknown cluster ' + dev['ceph_fsid'])
if dev.get('whoami'):
desc.append('osd.%s' % dev['whoami'])
- if dev.get('journal_dev'):
- desc.append('journal %s' % dev['journal_dev'])
+ for name in Space.NAMES:
+ if dev.get(name + '_dev'):
+ desc.append(name + ' %s' % dev[name + '_dev'])
return desc
else:
desc = ['ceph data (dmcrypt %s)' % dmcrypt['type'],
'holders: ' + ','.join(dmcrypt['holders'])]
- elif dev['ptype'] == PTYPE['regular']['journal']['ready']:
- desc.append('ceph journal')
- if dev.get('journal_for'):
- desc.append('for %s' % dev['journal_for'])
- elif Ptype.is_dmcrypt(dev['ptype'], 'journal'):
+ elif Ptype.is_regular_space(dev['ptype']):
+ name = Ptype.space_ptype_to_name(dev['ptype'])
+ desc.append('ceph ' + name)
+ if dev.get(name + '_for'):
+ desc.append('for %s' % dev[name + '_for'])
+ elif Ptype.is_dmcrypt_space(dev['ptype']):
+ name = Ptype.space_ptype_to_name(dev['ptype'])
dmcrypt = dev['dmcrypt']
if dmcrypt['holders'] and len(dmcrypt['holders']) == 1:
holder = get_dev_path(dmcrypt['holders'][0])
- desc = ['ceph journal (dmcrypt %s %s)' % (dmcrypt['type'], holder)]
+ desc = ['ceph ' + name + ' (dmcrypt %s %s)' %
+ (dmcrypt['type'], holder)]
else:
- desc = ['ceph journal (dmcrypt %s)' % dmcrypt['type']]
- if dev.get('journal_for'):
- desc.append('for %s' % dev['journal_for'])
+ desc = ['ceph ' + name + ' (dmcrypt %s)' % dmcrypt['type']]
+ if dev.get(name + '_for'):
+ desc.append('for %s' % dev[name + '_for'])
else:
desc.append(dev['type'])
if dev.get('fs_type'):
return "\n".join(lines)
-def list_dev(dev, uuid_map, journal_map):
+def list_dev(dev, uuid_map, space_map):
info = {
'path': dev,
'dmcrypt': {},
info['dmcrypt']['type'] = 'LUKS'
if len(holders) == 1:
list_dev_osd(get_dev_path(holders[0]), uuid_map, info)
- elif ptype in (PTYPE['regular']['journal']['ready'],
- PTYPE['mpath']['journal']['ready']):
- info['type'] = 'journal'
- if ptype == PTYPE['mpath']['journal']['ready']:
+ elif Ptype.is_regular_space(ptype) or Ptype.is_mpath_space(ptype):
+ name = Ptype.space_ptype_to_name(ptype)
+ info['type'] = name
+ if ptype == PTYPE['mpath'][name]['ready']:
info['multipath'] = True
- if info.get('uuid') in journal_map:
- info['journal_for'] = journal_map[info['uuid']]
- elif ptype == PTYPE['plain']['journal']['ready']:
+ if info.get('uuid') in space_map:
+ info[name + '_for'] = space_map[info['uuid']]
+ elif Ptype.is_plain_space(ptype):
+ name = Ptype.space_ptype_to_name(ptype)
holders = is_held(dev)
- info['type'] = 'journal'
+ info['type'] = name
info['dmcrypt']['type'] = 'plain'
info['dmcrypt']['holders'] = holders
- if info.get('uuid') in journal_map:
- info['journal_for'] = journal_map[info['uuid']]
- elif ptype == PTYPE['luks']['journal']['ready']:
+ if info.get('uuid') in space_map:
+ info[name + '_for'] = space_map[info['uuid']]
+ elif Ptype.is_luks_space(ptype):
+ name = Ptype.space_ptype_to_name(ptype)
holders = is_held(dev)
- info['type'] = 'journal'
+ info['type'] = name
info['dmcrypt']['type'] = 'LUKS'
info['dmcrypt']['holders'] = holders
- if info.get('uuid') in journal_map:
- info['journal_for'] = journal_map[info['uuid']]
+ if info.get('uuid') in space_map:
+ info[name + '_for'] = space_map[info['uuid']]
else:
path = is_mounted(dev)
fs_type = get_dev_fs(dev)
partmap = list_all_partitions()
uuid_map = {}
- journal_map = {}
+ space_map = {}
for base, parts in sorted(partmap.iteritems()):
for p in parts:
dev = get_dev_path(p)
tpath = mount(dev=dev_to_mount,
fstype=fs_type, options='')
try:
- journal_uuid = get_oneliner(tpath, 'journal_uuid')
- if journal_uuid:
- journal_map[journal_uuid.lower()] = dev
+ for name in Space.NAMES:
+ space_uuid = get_oneliner(tpath,
+ name + '_uuid')
+ if space_uuid:
+ space_map[space_uuid.lower()] = dev
finally:
unmount(tpath)
except MountError:
pass
LOG.debug("main_list: " + str(partmap) + ", uuid_map = " +
- str(uuid_map) + ", journal_map = " + str(journal_map))
+ str(uuid_map) + ", space_map = " + str(space_map))
devices = []
for base, parts in sorted(partmap.iteritems()):
for p in sorted(parts):
partitions.append(list_dev(get_dev_path(p),
uuid_map,
- journal_map))
+ space_map))
disk['partitions'] = partitions
devices.append(disk)
else:
- device = list_dev(get_dev_path(base), uuid_map, journal_map)
+ device = list_dev(get_dev_path(base), uuid_map, space_map)
device['path'] = get_dev_path(base)
devices.append(device)
LOG.debug("list_devices: " + str(devices))
}]}]
assert expect == main.list_devices()
- def test_list_dmcrypt(self):
+ def test_list_default(self):
self.list(main.PTYPE['plain']['osd']['ready'],
main.PTYPE['plain']['journal']['ready'])
self.list(main.PTYPE['luks']['osd']['ready'],
main.PTYPE['luks']['journal']['ready'])
-
- def test_list_normal(self):
self.list(main.PTYPE['regular']['osd']['ready'],
main.PTYPE['regular']['journal']['ready'])
- def list(self, data_ptype, journal_ptype):
+ def test_list_bluestore(self):
+ self.list(main.PTYPE['plain']['osd']['ready'],
+ main.PTYPE['plain']['block']['ready'])
+ self.list(main.PTYPE['luks']['osd']['ready'],
+ main.PTYPE['luks']['block']['ready'])
+ self.list(main.PTYPE['regular']['osd']['ready'],
+ main.PTYPE['regular']['block']['ready'])
+
+ def list(self, data_ptype, space_ptype):
#
# a single disk has a data partition and a journal
# partition and the osd is active
#
+ name = main.Ptype.space_ptype_to_name(space_ptype)
data_uuid = "56244cf5-83ef-4984-888a-2d8b8e0e04b2"
disk = "Xda"
data = "Xda1"
data_holder = "dm-0"
- journal = "Xda2"
- journal_holder = "dm-0"
+ space = "Xda2"
+ space_holder = "dm-0"
mount_path = '/mount/path'
fs_type = 'ext4'
- journal_uuid = "7ad5e65a-0ca5-40e4-a896-62a74ca61c55"
+ space_uuid = "7ad5e65a-0ca5-40e4-a896-62a74ca61c55"
ceph_fsid = "60a2ef70-d99b-4b9b-a83c-8a86e5e60091"
osd_id = '1234'
def get_oneliner(path, what):
- if what == 'journal_uuid':
- return journal_uuid
+ if '_uuid' in what:
+ if what == name + '_uuid':
+ return space_uuid
+ else:
+ return None
elif what == 'ceph_fsid':
return ceph_fsid
elif what == 'whoami':
def get_partition_uuid(dev):
if dev == '/dev/' + data:
return data_uuid
- elif dev == '/dev/' + journal:
- return journal_uuid
+ elif dev == '/dev/' + space:
+ return space_uuid
else:
raise Exception('unknown ' + dev)
if (dev == '/dev/' + data or
dev == '/dev/' + data_holder):
return data_ptype
- elif (dev == '/dev/' + journal or
- dev == '/dev/' + journal_holder):
- return journal_ptype
+ elif (dev == '/dev/' + space or
+ dev == '/dev/' + space_holder):
+ return space_ptype
else:
raise Exception('unknown ' + dev)
cluster = 'ceph'
else:
raise Exception('unknown ' + data_ptype)
- if journal_ptype == main.PTYPE['regular']['journal']['ready']:
- journal_dmcrypt = {}
- elif journal_ptype == main.PTYPE['plain']['journal']['ready']:
- journal_dmcrypt = {
+ if space_ptype == main.PTYPE['regular'][name]['ready']:
+ space_dmcrypt = {}
+ elif space_ptype == main.PTYPE['plain'][name]['ready']:
+ space_dmcrypt = {
'type': 'plain',
- 'holders': [journal_holder],
+ 'holders': [space_holder],
}
- elif journal_ptype == main.PTYPE['luks']['journal']['ready']:
- journal_dmcrypt = {
+ elif space_ptype == main.PTYPE['luks'][name]['ready']:
+ space_dmcrypt = {
'type': 'LUKS',
- 'holders': [journal_holder],
+ 'holders': [space_holder],
}
else:
- raise Exception('unknown ' + journal_ptype)
+ raise Exception('unknown ' + space_ptype)
if data_dmcrypt:
def is_held(dev):
if dev == '/dev/' + data:
return [data_holder]
- elif dev == '/dev/' + journal:
- return [journal_holder]
+ elif dev == '/dev/' + space:
+ return [space_holder]
else:
raise Exception('unknown ' + dev)
else:
with patch.multiple(
main,
- list_all_partitions=lambda: {disk: [data, journal]},
+ list_all_partitions=lambda: {disk: [data, space]},
get_dev_fs=lambda dev: fs_type,
is_mounted=lambda dev: mount_path,
get_partition_uuid=get_partition_uuid,
'dmcrypt': data_dmcrypt,
'fs_type': fs_type,
'is_partition': True,
- 'journal_dev': '/dev/' + journal,
- 'journal_uuid': journal_uuid,
+ name + '_dev': '/dev/' + space,
+ name + '_uuid': space_uuid,
'mount': mount_path,
'path': '/dev/' + data,
'ptype': data_ptype,
'whoami': osd_id,
'uuid': data_uuid,
}, {
- 'dmcrypt': journal_dmcrypt,
+ 'dmcrypt': space_dmcrypt,
'is_partition': True,
- 'journal_for': '/dev/' + data,
- 'path': '/dev/' + journal,
- 'ptype': journal_ptype,
- 'type': 'journal',
- 'uuid': journal_uuid,
+ name + '_for': '/dev/' + data,
+ 'path': '/dev/' + space,
+ 'ptype': space_ptype,
+ 'type': name,
+ 'uuid': space_uuid,
}]}]
assert expect == main.list_devices()