def test_list_dev_osd(self): dev = "Xda" mount_path = '/mount/path' fs_type = 'ext4' cluster = 'ceph' uuid_map = {} def more_osd_info(path, uuid_map, desc): desc['cluster'] = cluster # # mounted therefore active # with patch.multiple( main, is_mounted=lambda dev: mount_path, get_dev_fs=lambda dev: fs_type, more_osd_info=more_osd_info ): desc = {} main.list_dev_osd(dev, uuid_map, desc) assert {'cluster': 'ceph', 'fs_type': 'ext4', 'mount': '/mount/path', 'state': 'active'} == desc # # not mounted and cannot mount: unprepared # mount_path = None with patch.multiple( main, is_mounted=lambda dev: mount_path, get_dev_fs=lambda dev: fs_type, mount=fail_to_mount, more_osd_info=more_osd_info ): desc = {} main.list_dev_osd(dev, uuid_map, desc) assert {'fs_type': 'ext4', 'mount': mount_path, 'state': 'unprepared'} == desc # # not mounted and magic found: prepared # def get_oneliner(path, what): if what == 'magic': return main.CEPH_OSD_ONDISK_MAGIC else: raise Exception('unknown ' + what) with patch.multiple( main, is_mounted=lambda dev: mount_path, get_dev_fs=lambda dev: fs_type, mount=DEFAULT, unmount=DEFAULT, get_oneliner=get_oneliner, more_osd_info=more_osd_info ): desc = {} main.list_dev_osd(dev, uuid_map, desc) assert {'cluster': 'ceph', 'fs_type': 'ext4', 'mount': mount_path, 'magic': main.CEPH_OSD_ONDISK_MAGIC, 'state': 'prepared'} == desc
def test_list_dev_osd(self): dev = "Xda" mount_path = '/mount/path' fs_type = 'ext4' cluster = 'ceph' uuid_map = {} def more_osd_info(path, uuid_map, desc): desc['cluster'] = cluster # # mounted therefore active # with patch.multiple(main, is_mounted=lambda dev: mount_path, get_dev_fs=lambda dev: fs_type, more_osd_info=more_osd_info): desc = {} main.list_dev_osd(dev, uuid_map, desc) assert { 'cluster': 'ceph', 'fs_type': 'ext4', 'mount': '/mount/path', 'state': 'active' } == desc # # not mounted and cannot mount: unprepared # mount_path = None with patch.multiple(main, is_mounted=lambda dev: mount_path, get_dev_fs=lambda dev: fs_type, mount=fail_to_mount, more_osd_info=more_osd_info): desc = {} main.list_dev_osd(dev, uuid_map, desc) assert { 'fs_type': 'ext4', 'mount': mount_path, 'state': 'unprepared' } == desc # # not mounted and magic found: prepared # def get_oneliner(path, what): if what == 'magic': return main.CEPH_OSD_ONDISK_MAGIC else: raise Exception('unknown ' + what) with patch.multiple(main, is_mounted=lambda dev: mount_path, get_dev_fs=lambda dev: fs_type, mount=DEFAULT, unmount=DEFAULT, get_oneliner=get_oneliner, more_osd_info=more_osd_info): desc = {} main.list_dev_osd(dev, uuid_map, desc) assert { 'cluster': 'ceph', 'fs_type': 'ext4', 'mount': mount_path, 'magic': main.CEPH_OSD_ONDISK_MAGIC, 'state': 'prepared' } == desc