def test_main_deactivate(self, mock_open): data = tempfile.mkdtemp() main.setup_statedir(data) DMCRYPT_LUKS_OSD_UUID = '4fbd7e29-9d25-41b8-afd0-35865ceff05d' part_uuid = '0ce28a16-6d5d-11e5-aec3-fa163e5c167b' disk = 'sdX' # # Can not find match device by osd-id # args = main.parse_args(['deactivate', '--cluster', 'ceph', '--deactivate-by-id', '5566']) fake_device = [{'path': '/dev/' + disk, 'partitions': [{ 'path': '/dev/sdX1', 'whoami': '-1', }]}] with patch.multiple( main, list_devices=lambda: fake_device, ): self.assertRaises(Exception, main.main_deactivate, args) # # find match device by osd-id, status: OSD_STATUS_IN_DOWN # with --mark-out option # args = main.parse_args(['deactivate', '--cluster', 'ceph', '--deactivate-by-id', '5566', '--mark-out']) fake_device = [{'path': '/dev/' + disk, 'partitions': [{ 'ptype': DMCRYPT_LUKS_OSD_UUID, 'path': '/dev/sdX1', 'whoami': '5566', 'mount': '/var/lib/ceph/osd/ceph-5566/', 'uuid': part_uuid, }]}] with patch.multiple( main, list_devices=lambda: fake_device, _check_osd_status=lambda cluster, osd_id: 2, _mark_osd_out=lambda cluster, osd_id: True ): main.main_deactivate(args) # # find match device by device partition, status: OSD_STATUS_IN_DOWN # args = main.parse_args(['deactivate', '--cluster', 'ceph', '/dev/sdX1']) fake_device = [{'path': '/dev/' + disk, 'partitions': [{ 'ptype': DMCRYPT_LUKS_OSD_UUID, 'path': '/dev/sdX1', 'whoami': '5566', 'mount': '/var/lib/ceph/osd/ceph-5566/', 'uuid': part_uuid, }]}] with patch.multiple( main, list_devices=lambda: fake_device, _check_osd_status=lambda cluster, osd_id: 0, ): main.main_deactivate(args) # # find match device by device partition, status: OSD_STATUS_IN_UP # with --mark-out option # args = main.parse_args(['deactivate', '--cluster', 'ceph', '/dev/sdX1', '--mark-out']) fake_device = [{'path': '/dev/' + disk, 'partitions': [{ 'ptype': DMCRYPT_LUKS_OSD_UUID, 'path': '/dev/sdX1', 'whoami': '5566', 'mount': '/var/lib/ceph/osd/ceph-5566/', 'uuid': part_uuid, }]}] # mock the file open. file_opened = io.StringIO() file_opened.write(u'deactive') mock_open.return_value = file_opened with patch.multiple( main, mock_open, list_devices=lambda: fake_device, _check_osd_status=lambda cluster, osd_id: 3, _mark_osd_out=lambda cluster, osd_id: True, stop_daemon=lambda cluster, osd_id: True, _remove_osd_directory_files=lambda path, cluster: True, path_set_context=lambda path: True, unmount=lambda path: True, dmcrypt_unmap=lambda part_uuid: True, ): main.main_deactivate(args) # # find match device by osd-id, status: OSD_STATUS_OUT_UP # args = main.parse_args(['deactivate', '--cluster', 'ceph', '--deactivate-by-id', '5566']) fake_device = [{'path': '/dev/' + disk, 'partitions': [{ 'ptype': DMCRYPT_LUKS_OSD_UUID, 'path': '/dev/sdX1', 'whoami': '5566', 'mount': '/var/lib/ceph/osd/ceph-5566/', 'uuid': part_uuid, }]}] # mock the file open. file_opened = io.StringIO() file_opened.write(u'deactive') mock_open.return_value = file_opened with patch.multiple( main, mock_open, list_devices=lambda: fake_device, _check_osd_status=lambda cluster, osd_id: 1, _mark_osd_out=lambda cluster, osd_id: True, stop_daemon=lambda cluster, osd_id: True, _remove_osd_directory_files=lambda path, cluster: True, path_set_context=lambda path: True, unmount=lambda path: True, dmcrypt_unmap=lambda part_uuid: True, ): main.main_deactivate(args) shutil.rmtree(data)
def test_main_deactivate(self, mock_open): data = tempfile.mkdtemp() main.setup_statedir(data) DMCRYPT_LUKS_OSD_UUID = '4fbd7e29-9d25-41b8-afd0-35865ceff05d' part_uuid = '0ce28a16-6d5d-11e5-aec3-fa163e5c167b' disk = 'sdX' # # Can not find match device by osd-id # args = main.parse_args( ['deactivate', '--cluster', 'ceph', '--deactivate-by-id', '5566']) fake_device = [{ 'path': '/dev/' + disk, 'partitions': [{ 'path': '/dev/sdX1', 'whoami': '-1', }] }] with patch.multiple( main, list_devices=lambda: fake_device, ): self.assertRaises(Exception, main.main_deactivate, args) # # find match device by osd-id, status: OSD_STATUS_IN_DOWN # with --mark-out option # args = main.parse_args([ 'deactivate', '--cluster', 'ceph', '--deactivate-by-id', '5566', '--mark-out' ]) fake_device = [{ 'path': '/dev/' + disk, 'partitions': [{ 'ptype': DMCRYPT_LUKS_OSD_UUID, 'path': '/dev/sdX1', 'whoami': '5566', 'mount': '/var/lib/ceph/osd/ceph-5566/', 'uuid': part_uuid, }] }] with patch.multiple(main, list_devices=lambda: fake_device, _check_osd_status=lambda cluster, osd_id: 2, _mark_osd_out=lambda cluster, osd_id: True): main.main_deactivate(args) # # find match device by device partition, status: OSD_STATUS_IN_DOWN # args = main.parse_args( ['deactivate', '--cluster', 'ceph', '/dev/sdX1']) fake_device = [{ 'path': '/dev/' + disk, 'partitions': [{ 'ptype': DMCRYPT_LUKS_OSD_UUID, 'path': '/dev/sdX1', 'whoami': '5566', 'mount': '/var/lib/ceph/osd/ceph-5566/', 'uuid': part_uuid, }] }] with patch.multiple( main, list_devices=lambda: fake_device, _check_osd_status=lambda cluster, osd_id: 0, ): main.main_deactivate(args) # # find match device by device partition, status: OSD_STATUS_IN_UP # with --mark-out option # args = main.parse_args( ['deactivate', '--cluster', 'ceph', '/dev/sdX1', '--mark-out']) fake_device = [{ 'path': '/dev/' + disk, 'partitions': [{ 'ptype': DMCRYPT_LUKS_OSD_UUID, 'path': '/dev/sdX1', 'whoami': '5566', 'mount': '/var/lib/ceph/osd/ceph-5566/', 'uuid': part_uuid, }] }] # mock the file open. file_opened = io.StringIO() file_opened.write(u'deactive') mock_open.return_value = file_opened with patch.multiple( main, mock_open, list_devices=lambda: fake_device, _check_osd_status=lambda cluster, osd_id: 3, _mark_osd_out=lambda cluster, osd_id: True, stop_daemon=lambda cluster, osd_id: True, _remove_osd_directory_files=lambda path, cluster: True, path_set_context=lambda path: True, unmount=lambda path: True, dmcrypt_unmap=lambda part_uuid: True, ): main.main_deactivate(args) # # find match device by osd-id, status: OSD_STATUS_OUT_UP # args = main.parse_args( ['deactivate', '--cluster', 'ceph', '--deactivate-by-id', '5566']) fake_device = [{ 'path': '/dev/' + disk, 'partitions': [{ 'ptype': DMCRYPT_LUKS_OSD_UUID, 'path': '/dev/sdX1', 'whoami': '5566', 'mount': '/var/lib/ceph/osd/ceph-5566/', 'uuid': part_uuid, }] }] # mock the file open. file_opened = io.StringIO() file_opened.write(u'deactive') mock_open.return_value = file_opened with patch.multiple( main, mock_open, list_devices=lambda: fake_device, _check_osd_status=lambda cluster, osd_id: 1, _mark_osd_out=lambda cluster, osd_id: True, stop_daemon=lambda cluster, osd_id: True, _remove_osd_directory_files=lambda path, cluster: True, path_set_context=lambda path: True, unmount=lambda path: True, dmcrypt_unmap=lambda part_uuid: True, ): main.main_deactivate(args) shutil.rmtree(data)