# Path: tests/whitebox/integration/_keyutils.py
# class RandomKeyTmpFile:
#     """
#     Generate a random passphrase and put it in a temporary file.
#     """
# 
#     # pylint: disable=consider-using-with
#     def __init__(self, key_bytes=32):
#         """
#         Initializer
# 
#         :param int key_bytes: the desired length of the key in bytes
#         """
#         self._tmpfile = NamedTemporaryFile("wb")
#         with open("/dev/urandom", "rb") as random:
#             random_bytes = random.read(key_bytes)
#             self._tmpfile.write(random_bytes)
#             self._tmpfile.flush()
# 
#     def tmpfile_name(self):
#         """
#         Get the name of the temporary file.
#         """
#         return self._tmpfile.name
# 
#     def close(self):
#         """
#         Close and delete the temporary file.
#         """
#         self._tmpfile.close()
# 
#     def __enter__(self):
#         """
#         For use with the "with" keyword.
# 
#         :return str: the path of the file with the random key
#         """
#         return self._tmpfile.name
# 
#     def __exit__(self, exc_type, exc_value, traceback):
#         try:
#             self._tmpfile.close()
#         except Exception as error:
#             if exc_value is None:
#                 raise error
# 
#             raise error from exc_value


from stratis_cli import StratisCliErrorCodes
from stratis_cli._errors import StratisCliEngineError, StratisCliNoChangeError
from .._keyutils import RandomKeyTmpFile
from .._misc import RUNNER, TEST_RUNNER, SimTestCase, device_name_list
        RUNNER(command_line)
        command_line = self._MENU + [
            "tpm2",
            self._POOLNAME,
        ]
        self.check_error(StratisCliNoChangeError, command_line, _ERROR)

    def test_bind_when_bound_2(self):
        """
        Binding when encrypted already should raise a no change error.
        """
        command_line = self._MENU + [
            "keyring",
            self._POOLNAME,
            self._KEY_DESC,
        ]
        self.check_error(StratisCliNoChangeError, command_line, _ERROR)


class BindTestCase3(SimTestCase):
    """
    Test binding when pool is encrypted.
    """

    _MENU = ["--propagate", "pool", "bind"]
    _POOLNAME = "poolname"
    _KEY_DESC = "keydesc"

    def setUp(self):
        super().setUp()

# Path: tests/whitebox/integration/_keyutils.py
# class RandomKeyTmpFile:
#     """
#     Generate a random passphrase and put it in a temporary file.
#     """
# 
#     # pylint: disable=consider-using-with
#     def __init__(self, key_bytes=32):
#         """
#         Initializer
# 
#         :param int key_bytes: the desired length of the key in bytes
#         """
#         self._tmpfile = NamedTemporaryFile("wb")
#         with open("/dev/urandom", "rb") as random:
#             random_bytes = random.read(key_bytes)
#             self._tmpfile.write(random_bytes)
#             self._tmpfile.flush()
# 
#     def tmpfile_name(self):
#         """
#         Get the name of the temporary file.
#         """
#         return self._tmpfile.name
# 
#     def close(self):
#         """
#         Close and delete the temporary file.
#         """
#         self._tmpfile.close()
# 
#     def __enter__(self):
#         """
#         For use with the "with" keyword.
# 
#         :return str: the path of the file with the random key
#         """
#         return self._tmpfile.name
# 
#     def __exit__(self, exc_type, exc_value, traceback):
#         try:
#             self._tmpfile.close()
#         except Exception as error:
#             if exc_value is None:
#                 raise error
# 
#             raise error from exc_value


# Path: tests/whitebox/integration/pool/test_bind.py
from stratis_cli import StratisCliErrorCodes
from stratis_cli._errors import StratisCliEngineError, StratisCliNoChangeError
from .._keyutils import RandomKeyTmpFile
from .._misc import RUNNER, TEST_RUNNER, SimTestCase, device_name_list

        RUNNER(command_line)
        command_line = self._MENU + [
            "tpm2",
            self._POOLNAME,
        ]
        self.check_error(StratisCliNoChangeError, command_line, _ERROR)

    def test_bind_when_bound_2(self):
        """
        Binding when encrypted already should raise a no change error.
        """
        command_line = self._MENU + [
            "keyring",
            self._POOLNAME,
            self._KEY_DESC,
        ]
        self.check_error(StratisCliNoChangeError, command_line, _ERROR)


class BindTestCase3(SimTestCase):
    """
    Test binding when pool is encrypted.
    """

    _MENU = ["--propagate", "pool", "bind"]
    _POOLNAME = "poolname"
    _KEY_DESC = "keydesc"

    def setUp(self):
        super().setUp()

        with RandomKeyTmpFile() as fname: