def GetStorage(): """Return the module to handle this file system on this machine. Returns: APFSStorage or CoreStorage object. """ fstype = GetFilesystemType() if fstype == 'apfs': return apfs.APFSStorage() elif fstype == 'hfs': return corestorage.CoreStorage() return corestorage.CoreStorage() # default to core storage
def testGetVolumeSize(self, get_plist_from_exec_mock): mock_uuid = str(uuid.uuid4()) pl = plistlib.readPlistFromString(CORE_STORAGE_PLIST_LV_INFO) get_plist_from_exec_mock.return_value = pl cs = corestorage.CoreStorage() self.assertEqual('55.00 GiB', cs.GetVolumeSize(mock_uuid))
def testGetRecoveryPartition(self, get_plist_from_exec_mock): pl = plistlib.readPlistFromString(DISKUTIL_LIST_PLIST) get_plist_from_exec_mock.return_value = pl cs = corestorage.CoreStorage() self.assertEqual(cs.GetRecoveryPartition(), '/dev/disk0s3') get_plist_from_exec_mock.assert_called_once()
def testGetCoreStorageStateFailed(self, get_plist_from_exec_mock): pl = plistlib.readPlistFromString(CORE_STORAGE_PLIST_LIST_ENABLED) pl2 = plistlib.readPlistFromString(CORE_STORAGE_PLIST_LVF_INFO_ENABLED) pl3 = plistlib.readPlistFromString(CORE_STORAGE_PLIST_LV_INFO) pl3['CoreStorageLogicalVolumeConversionState'] = 'Failed' get_plist_from_exec_mock.side_effect = [pl, pl2, pl3] cs = corestorage.CoreStorage() self.assertEqual(cs.GetState(), corestorage.State.FAILED)
def testGetCoreStorageStateEnabled(self, get_plist_from_exec_mock): pl = plistlib.readPlistFromString(CORE_STORAGE_PLIST_LIST_ENABLED) pl2 = plistlib.readPlistFromString(CORE_STORAGE_PLIST_LVF_INFO_ENABLED) pl3 = plistlib.readPlistFromString(CORE_STORAGE_PLIST_LV_INFO) get_plist_from_exec_mock.side_effect = [pl, pl2, pl3] cs = corestorage.CoreStorage() self.assertEqual(cs.GetState(), corestorage.State.ENABLED)
def testGetCoreStorageStateNone(self, get_plist_from_exec_mock): pl = plistlib.readPlistFromString(CORE_STORAGE_PLIST_LIST_EMPTY) get_plist_from_exec_mock.return_value = pl cs = corestorage.CoreStorage() self.assertEqual(cs.GetState(), corestorage.State.NONE) get_plist_from_exec_mock.assert_called_once_with( ['/usr/sbin/diskutil', 'corestorage', 'list', '-plist'])
def testUnlockVolumeAlreadyUnlockedMavericks(self, exec_mock): mock_uuid = str(uuid.uuid4()) mock_passphrase = str(uuid.uuid4()) exec_mock.return_value = ( 1, '', 'Error beginning CoreStorage Logical Volume unlock: ' 'The target Core Storage volume is not locked (-69748)') cs = corestorage.CoreStorage() cs.UnlockVolume(mock_uuid, mock_passphrase)
def testUnlockVolumeOk(self, exec_mock): mock_uuid = str(uuid.uuid4()) mock_passphrase = str(uuid.uuid4()) cs = corestorage.CoreStorage() cs.UnlockVolume(mock_uuid, mock_passphrase) exec_mock.assert_called_once_with( (DISKUTIL, 'corestorage', 'unlockVolume', mock_uuid, '-stdinpassphrase'), stdin=mock_passphrase)
def testRevertVolumeCantRevert(self, unlock_volume_mock, exec_mock): mock_uuid = str(uuid.uuid4()) mock_passphrase = str(uuid.uuid4()) cs = corestorage.CoreStorage() self.assertRaises(storage.CouldNotRevertError, cs.RevertVolume, mock_uuid, mock_passphrase) exec_mock.assert_called_once_with( (DISKUTIL, 'corestorage', 'revert', mock_uuid, '-stdinpassphrase'), stdin=mock_passphrase) unlock_volume_mock.assert_called_once_with(mock_uuid, mock_passphrase)
def testUnlockVolumeCantUnlock(self, exec_mock): mock_uuid = str(uuid.uuid4()) mock_passphrase = str(uuid.uuid4()) cs = corestorage.CoreStorage() self.assertRaises(storage.CouldNotUnlockError, cs.UnlockVolume, mock_uuid, mock_passphrase) exec_mock.assert_called_once_with( (DISKUTIL, 'corestorage', 'unlockVolume', mock_uuid, '-stdinpassphrase'), stdin=mock_passphrase)
def testIsBootVolumeEncryptedWhenNoLVFInfo(self, get_plist_from_exec_mock): lvf_uuid = 'bad uuid' get_plist_from_exec_mock.side_effect = [ {'MemberOfCoreStorageLogicalVolumeFamily': lvf_uuid}, util.ExecError] cs = corestorage.CoreStorage() self.assertEqual(False, cs.IsBootVolumeEncrypted()) get_plist_from_exec_mock.assert_has_calls([ mock.call(('/usr/sbin/diskutil', 'cs', 'info', '-plist', '/')), mock.call(('/usr/sbin/diskutil', 'cs', 'info', '-plist', lvf_uuid))])
def testUnlockVolumeAlreadyUnlockedYosemite(self, exec_mock): mock_uuid = str(uuid.uuid4()) mock_passphrase = str(uuid.uuid4()) exec_mock.return_value = ( 1, '', '%s is already unlocked and is attached as disk1' % mock_uuid) cs = corestorage.CoreStorage() cs.UnlockVolume(mock_uuid, mock_passphrase) exec_mock.assert_called_once_with( (DISKUTIL, 'corestorage', 'unlockVolume', mock_uuid, '-stdinpassphrase'), stdin=mock_passphrase)
def testIsBootVolumeEncryptedWhenEncrypted(self, get_plist_from_exec_mock): lvf_uuid = 'bad uuid' get_plist_from_exec_mock.side_effect = [ {'MemberOfCoreStorageLogicalVolumeFamily': lvf_uuid}, {'CoreStorageLogicalVolumeFamilyEncryptionType': 'AES-XTS'}, ] cs = corestorage.CoreStorage() self.assertEqual(True, cs.IsBootVolumeEncrypted()) get_plist_from_exec_mock.assert_has_calls([ mock.call(('/usr/sbin/diskutil', 'cs', 'info', '-plist', '/')), mock.call(('/usr/sbin/diskutil', 'cs', 'info', '-plist', lvf_uuid))])
def testGetCoreStorageStateEncrypted(self, get_plist_from_exec_mock): pl = plistlib.readPlistFromString(CORE_STORAGE_PLIST_LIST_ENABLED) pl2 = plistlib.readPlistFromString(CORE_STORAGE_PLIST_LVF_INFO_ENCRYPTED) pl3 = plistlib.readPlistFromString(CORE_STORAGE_PLIST_LV_INFO) get_plist_from_exec_mock.side_effect = [pl, pl2, pl3] cs = corestorage.CoreStorage() self.assertEqual(cs.GetState(), corestorage.State.ENCRYPTED) get_plist_from_exec_mock.assert_has_calls([ mock.call(['/usr/sbin/diskutil', 'corestorage', 'list', '-plist']), mock.call([ '/usr/sbin/diskutil', 'corestorage', 'info', '-plist', 'F550F600-D0C3-40C2-AE18-BBEB5197283F']), mock.call([ '/usr/sbin/diskutil', 'corestorage', 'info', '-plist', 'F93A24E9-C8DB-4E83-8EB0-FDEC3C029B9D'])])
def testGetRecoveryPartitionWhenDiskutilFail(self, _): cs = corestorage.CoreStorage() self.assertEqual(cs.GetRecoveryPartition(), None)
def testIsBootVolumeEncryptedWhenNotCoreStorage(self, _): cs = corestorage.CoreStorage() self.assertEqual(False, cs.IsBootVolumeEncrypted())