# Path: os_brick/encryptors/cryptsetup.py
# LOG = logging.getLogger(__name__)
# class CryptsetupEncryptor(base.VolumeEncryptor):
#     def __init__(self, root_helper,
#                  connection_info,
#                  keymgr,
#                  execute=None,
#                  *args, **kwargs):
#     def _is_crypt_device_available(self, dev_name):
#     def _get_passphrase(self, key):
#     def _open_volume(self, passphrase, **kwargs):
#     def attach_volume(self, context, **kwargs):
#     def _close_volume(self, **kwargs):
#     def detach_volume(self, **kwargs):
# 
# Path: os_brick/exception.py
# LOG = logging.getLogger(__name__)
# class BrickException(Exception):
# class NotFound(BrickException):
# class Invalid(BrickException):
# class InvalidParameterValue(Invalid):
# class NoFibreChannelHostsFound(BrickException):
# class NoFibreChannelVolumeDeviceFound(BrickException):
# class VolumeNotDeactivated(BrickException):
# class VolumeDeviceNotFound(BrickException):
# class VolumePathsNotFound(BrickException):
# class VolumePathNotRemoved(BrickException):
# class ProtocolNotSupported(BrickException):
# class TargetPortalNotFound(BrickException):
# class TargetPortalsNotFound(TargetPortalNotFound):
# class FailedISCSITargetPortalLogin(BrickException):
# class BlockDeviceReadOnly(BrickException):
# class VolumeGroupNotFound(BrickException):
# class VolumeGroupCreationFailed(BrickException):
# class CommandExecutionFailed(BrickException):
# class VolumeDriverException(BrickException):
# class InvalidIOHandleObject(BrickException):
# class VolumeEncryptionNotSupported(Invalid):
# class VolumeLocalCacheNotSupported(Invalid):
# class InvalidConnectorProtocol(ValueError):
# class ExceptionChainer(BrickException):
# class ExecutionTimeout(putils.ProcessExecutionError):
#     def __init__(self, message=None, **kwargs):
#     def __init__(self, *args, **kwargs):
#     def __repr__(self):
#     def __nonzero__(self) -> bool:
#     def add_exception(self, exc_type, exc_val, exc_tb) -> None:
#     def context(self,
#                 catch_exception: bool,
#                 msg: str = '',
#                 *msg_args: Iterable):
#     def __enter__(self):
#     def __exit__(self, exc_type, exc_val, exc_tb):
# 
# Path: os_brick/tests/encryptors/test_base.py
# class VolumeEncryptorTestCase(base.TestCase):
# class BaseEncryptorTestCase(VolumeEncryptorTestCase):
#     def _create(self):
#     def setUp(self):
#     def _test_get_encryptor(self, provider, expected_provider_class):
#     def test_get_encryptors(self):
#     def test_get_error_encryptors(self):
#     def test_error_log(self, log):
#     def test_get_missing_out_of_tree_encryptor_log(self, log):
#     def test_get_direct_encryptor_log(self, log):


import binascii
import copy
from unittest import mock
from castellan.common.objects import symmetric_key as key
from castellan.tests.unit.key_manager import fake
from os_brick.encryptors import cryptsetup
from os_brick import exception
from os_brick.tests.encryptors import test_base
                      root_helper=self.root_helper,
                      run_as_root=True, check_exit_code=True),
        ])

    @mock.patch('os_brick.executor.Executor._execute')
    def test__close_volume(self, mock_execute):
        self.encryptor.detach_volume()

        mock_execute.assert_has_calls([
            mock.call('cryptsetup', 'remove', self.dev_name,
                      root_helper=self.root_helper,
                      run_as_root=True, check_exit_code=[0, 4]),
        ])

    @mock.patch('os_brick.executor.Executor._execute')
    def test_detach_volume(self, mock_execute):
        self.encryptor.detach_volume()

        mock_execute.assert_has_calls([
            mock.call('cryptsetup', 'remove', self.dev_name,
                      root_helper=self.root_helper,
                      run_as_root=True, check_exit_code=[0, 4]),
        ])

    def test_init_volume_encryption_not_supported(self):
        # Tests that creating a CryptsetupEncryptor fails if there is no
        # device_path key.
        type = 'unencryptable'
        data = dict(volume_id='a194699b-aa07-4433-a945-a5d23802043e')
        connection_info = dict(driver_volume_type=type, data=data)

# Path: os_brick/encryptors/cryptsetup.py
# LOG = logging.getLogger(__name__)
# class CryptsetupEncryptor(base.VolumeEncryptor):
#     def __init__(self, root_helper,
#                  connection_info,
#                  keymgr,
#                  execute=None,
#                  *args, **kwargs):
#     def _is_crypt_device_available(self, dev_name):
#     def _get_passphrase(self, key):
#     def _open_volume(self, passphrase, **kwargs):
#     def attach_volume(self, context, **kwargs):
#     def _close_volume(self, **kwargs):
#     def detach_volume(self, **kwargs):
# 
# Path: os_brick/exception.py
# LOG = logging.getLogger(__name__)
# class BrickException(Exception):
# class NotFound(BrickException):
# class Invalid(BrickException):
# class InvalidParameterValue(Invalid):
# class NoFibreChannelHostsFound(BrickException):
# class NoFibreChannelVolumeDeviceFound(BrickException):
# class VolumeNotDeactivated(BrickException):
# class VolumeDeviceNotFound(BrickException):
# class VolumePathsNotFound(BrickException):
# class VolumePathNotRemoved(BrickException):
# class ProtocolNotSupported(BrickException):
# class TargetPortalNotFound(BrickException):
# class TargetPortalsNotFound(TargetPortalNotFound):
# class FailedISCSITargetPortalLogin(BrickException):
# class BlockDeviceReadOnly(BrickException):
# class VolumeGroupNotFound(BrickException):
# class VolumeGroupCreationFailed(BrickException):
# class CommandExecutionFailed(BrickException):
# class VolumeDriverException(BrickException):
# class InvalidIOHandleObject(BrickException):
# class VolumeEncryptionNotSupported(Invalid):
# class VolumeLocalCacheNotSupported(Invalid):
# class InvalidConnectorProtocol(ValueError):
# class ExceptionChainer(BrickException):
# class ExecutionTimeout(putils.ProcessExecutionError):
#     def __init__(self, message=None, **kwargs):
#     def __init__(self, *args, **kwargs):
#     def __repr__(self):
#     def __nonzero__(self) -> bool:
#     def add_exception(self, exc_type, exc_val, exc_tb) -> None:
#     def context(self,
#                 catch_exception: bool,
#                 msg: str = '',
#                 *msg_args: Iterable):
#     def __enter__(self):
#     def __exit__(self, exc_type, exc_val, exc_tb):
# 
# Path: os_brick/tests/encryptors/test_base.py
# class VolumeEncryptorTestCase(base.TestCase):
# class BaseEncryptorTestCase(VolumeEncryptorTestCase):
#     def _create(self):
#     def setUp(self):
#     def _test_get_encryptor(self, provider, expected_provider_class):
#     def test_get_encryptors(self):
#     def test_get_error_encryptors(self):
#     def test_error_log(self, log):
#     def test_get_missing_out_of_tree_encryptor_log(self, log):
#     def test_get_direct_encryptor_log(self, log):


# Path: os_brick/tests/encryptors/test_cryptsetup.py
import binascii
import copy
from unittest import mock
from castellan.common.objects import symmetric_key as key
from castellan.tests.unit.key_manager import fake
from os_brick.encryptors import cryptsetup
from os_brick import exception
from os_brick.tests.encryptors import test_base

                      root_helper=self.root_helper,
                      run_as_root=True, check_exit_code=True),
        ])

    @mock.patch('os_brick.executor.Executor._execute')
    def test__close_volume(self, mock_execute):
        self.encryptor.detach_volume()

        mock_execute.assert_has_calls([
            mock.call('cryptsetup', 'remove', self.dev_name,
                      root_helper=self.root_helper,
                      run_as_root=True, check_exit_code=[0, 4]),
        ])

    @mock.patch('os_brick.executor.Executor._execute')
    def test_detach_volume(self, mock_execute):
        self.encryptor.detach_volume()

        mock_execute.assert_has_calls([
            mock.call('cryptsetup', 'remove', self.dev_name,
                      root_helper=self.root_helper,
                      run_as_root=True, check_exit_code=[0, 4]),
        ])

    def test_init_volume_encryption_not_supported(self):
        # Tests that creating a CryptsetupEncryptor fails if there is no
        # device_path key.
        type = 'unencryptable'
        data = dict(volume_id='a194699b-aa07-4433-a945-a5d23802043e')
        connection_info = dict(driver_volume_type=type, data=data)

        exc = self.assertRaises(exception.VolumeEncryptionNotSupported,