def test_main_destroy(self): data = tempfile.mkdtemp() main.setup_statedir(data) OSD_UUID = '4fbd7e29-9d25-41b8-afd0-062c0ceff05d' MPATH_OSD_UUID = '4fbd7e29-8ae0-4982-bf9d-5a8d867af560' part_uuid = '0ce28a16-6d5d-11e5-aec3-fa163e5c167b' journal_uuid = "7ad5e65a-0ca5-40e4-a896-62a74ca61c55" mount_5566 = '/var/lib/ceph/osd/ceph-5566/' fake_devices_normal = [{'path': '/dev/sdY', 'partitions': [{ 'dmcrypt': {}, 'type': 'osd', 'ptype': OSD_UUID, 'path': '/dev/sdY1', 'whoami': '5566', 'mount': mount_5566, 'uuid': part_uuid, 'journal_uuid': journal_uuid}]}, {'path': '/dev/sdX', 'partitions': [{ 'dmcrypt': {}, 'type': 'osd', 'ptype': MPATH_OSD_UUID, 'path': '/dev/sdX1', 'whoami': '7788', 'mount': '/var/lib/ceph/osd/ceph-7788/', 'uuid': part_uuid, 'journal_uuid': journal_uuid}]}] def list_devices_return(): return fake_devices_normal # # input device is not the device partition # args = main.parse_args(['destroy', '--cluster', 'ceph', '/dev/sdX']) with patch.multiple( main, is_partition=lambda path: False, ): self.assertRaises(Exception, main.main_destroy, args) # # skip the redundent devices and not found by dev # args = main.parse_args(['destroy', '--cluster', 'ceph', '/dev/sdZ1']) with patch.multiple( main, is_partition=lambda path: True, list_devices=list_devices_return, ): self.assertRaises(Exception, main.main_destroy, args) # # skip the redundent devices and not found by osd-id # args = main.parse_args(['destroy', '--cluster', 'ceph', '--destroy-by-id', '1234']) with patch.multiple( main, is_partition=lambda path: True, list_devices=list_devices_return, ): self.assertRaises(Exception, main.main_destroy, args) # # skip the redundent devices and found by dev # args = main.parse_args(['destroy', '--cluster', 'ceph', '/dev/sdY1', '--zap']) with patch.multiple( main, is_partition=lambda path: True, list_devices=list_devices_return, get_partition_base=lambda dev_path: '/dev/sdY', _check_osd_status=lambda cluster, osd_id: 0, _remove_from_crush_map=lambda cluster, osd_id: True, _delete_osd_auth_key=lambda cluster, osd_id: True, _deallocate_osd_id=lambda cluster, osd_id: True, zap=lambda dev: True ): main.main_destroy(args) # # skip the redundent devices and found by osd-id # with active status and MPATH_OSD # args = main.parse_args(['destroy', '--cluster', 'ceph', '--destroy-by-id', '7788']) with patch.multiple( main, is_partition=lambda path: True, list_devices=list_devices_return, get_partition_base_mpath=lambda dev_path: '/dev/sdX', _check_osd_status=lambda cluster, osd_id: 1, ): self.assertRaises(Exception, main.main_destroy, args) shutil.rmtree(data)
def test_main_destroy(self): data = tempfile.mkdtemp() main.setup_statedir(data) OSD_UUID = '4fbd7e29-9d25-41b8-afd0-062c0ceff05d' MPATH_OSD_UUID = '4fbd7e29-8ae0-4982-bf9d-5a8d867af560' part_uuid = '0ce28a16-6d5d-11e5-aec3-fa163e5c167b' journal_uuid = "7ad5e65a-0ca5-40e4-a896-62a74ca61c55" mount_5566 = '/var/lib/ceph/osd/ceph-5566/' fake_devices_normal = [{ 'path': '/dev/sdY', 'partitions': [{ 'dmcrypt': {}, 'type': 'osd', 'ptype': OSD_UUID, 'path': '/dev/sdY1', 'whoami': '5566', 'mount': mount_5566, 'uuid': part_uuid, 'journal_uuid': journal_uuid }] }, { 'path': '/dev/sdX', 'partitions': [{ 'dmcrypt': {}, 'type': 'osd', 'ptype': MPATH_OSD_UUID, 'path': '/dev/sdX1', 'whoami': '7788', 'mount': '/var/lib/ceph/osd/ceph-7788/', 'uuid': part_uuid, 'journal_uuid': journal_uuid }] }] def list_devices_return(): return fake_devices_normal # # input device is not the device partition # args = main.parse_args(['destroy', '--cluster', 'ceph', '/dev/sdX']) with patch.multiple( main, is_partition=lambda path: False, ): self.assertRaises(Exception, main.main_destroy, args) # # skip the redundent devices and not found by dev # args = main.parse_args(['destroy', '--cluster', 'ceph', '/dev/sdZ1']) with patch.multiple( main, is_partition=lambda path: True, list_devices=list_devices_return, ): self.assertRaises(Exception, main.main_destroy, args) # # skip the redundent devices and not found by osd-id # args = main.parse_args( ['destroy', '--cluster', 'ceph', '--destroy-by-id', '1234']) with patch.multiple( main, is_partition=lambda path: True, list_devices=list_devices_return, ): self.assertRaises(Exception, main.main_destroy, args) # # skip the redundent devices and found by dev # args = main.parse_args( ['destroy', '--cluster', 'ceph', '/dev/sdY1', '--zap']) with patch.multiple( main, is_partition=lambda path: True, list_devices=list_devices_return, get_partition_base=lambda dev_path: '/dev/sdY', _check_osd_status=lambda cluster, osd_id: 0, _remove_from_crush_map=lambda cluster, osd_id: True, _delete_osd_auth_key=lambda cluster, osd_id: True, _deallocate_osd_id=lambda cluster, osd_id: True, zap=lambda dev: True): main.main_destroy(args) # # skip the redundent devices and found by osd-id # with active status and MPATH_OSD # args = main.parse_args( ['destroy', '--cluster', 'ceph', '--destroy-by-id', '7788']) with patch.multiple( main, is_partition=lambda path: True, list_devices=list_devices_return, get_partition_base_mpath=lambda dev_path: '/dev/sdX', _check_osd_status=lambda cluster, osd_id: 1, ): self.assertRaises(Exception, main.main_destroy, args) shutil.rmtree(data)