def test_export_blocks(self): self._add_import_commands() self._add_export_commands() exported_zfs_device = ZfsDevice(self.zpool_name, True) self.assertEqual(exported_zfs_device.__enter__().available, True) self.assertEqual(self.lock._RLock__count, 1) # Now this thread should block. thread = ExceptionThrowingThread(target=self.export, args=(), use_threads=True) thread.start() time.sleep(0.1) self.assertEqual(self.thread_running, True) time.sleep(0.1) self.assertEqual(self.thread_running, True) exported_zfs_device.__exit__(0, 0, 0) time.sleep(0.1) self.assertEqual(self.thread_running, False) self.assertEqual(self.lock._RLock__count, 0) thread.join()
def test_no_import_silient(self): exported_zfs_device = ZfsDevice(self.zpool_name, False) self.assertEqual(exported_zfs_device.available, True) self.assertEqual(exported_zfs_device.__enter__().available, True) exported_zfs_device.__exit__(0, 0, 0) self.assertRanAllCommandsInOrder()
def test_import_writable(self): self._add_import_commands() self._add_export_commands() exported_zfs_device = ZfsDevice(self.zpool_name, True) self.assertEqual(exported_zfs_device.__enter__().available, True) exported_zfs_device.__exit__(0, 0, 0) self.assertRanAllCommandsInOrder()
def test_error_in_list(self): self.add_commands( CommandCaptureCommand(('zpool', 'list', '-H', '-o', 'name'), rc=1)) exported_zfs_device = ZfsDevice(self.zpool_name, True) try: self.assertEqual(exported_zfs_device.__enter__(), True) except BaseShell.CommandExecutionError: pass self.assertEqual(self.lock._RLock__count, 0)
def test_simple_lock_no_import(self): self._add_import_commands(self.zpool_name) exported_zfs_device = ZfsDevice(self.zpool_name, True) self.assertEqual(exported_zfs_device.__enter__().available, True) self.assertEqual(self.lock._RLock__count, 1) exported_zfs_device.__exit__(0, 0, 0) self.assertEqual(self.lock._RLock__count, 0) self.assertRanAllCommandsInOrder()
def test_error_in_export(self): self._add_import_commands() self.add_commands( CommandCaptureCommand(('zpool', 'export', self.zpool_name), rc=1)) exported_zfs_device = ZfsDevice(self.zpool_name, True) self.assertEqual(exported_zfs_device.__enter__().available, True) self.assertEqual(self.lock._RLock__count, 1) try: exported_zfs_device.__exit__(0, 0, 0) except BaseShell.CommandExecutionError: pass self.assertEqual(self.lock._RLock__count, 0) self.assertRanAllCommandsInOrder()
def test_busy_export(self): self._add_import_commands() self.add_commands( CommandCaptureCommand( ('zpool', 'export', self.zpool_name), rc=1, stderr="cannot export '%s': pool is busy" % self.zpool_name, executions_remaining=1)) self._add_export_commands() mock.patch( 'chroma_agent.chroma_common.blockdevices.blockdevice_zfs.time.sleep' ).start() exported_zfs_device = ZfsDevice(self.zpool_name, True) self.assertEqual(exported_zfs_device.__enter__().available, True) exported_zfs_device.__exit__(0, 0, 0) self.assertRanAllCommandsInOrder()
def test_error_in_import(self): self.add_commands( CommandCaptureCommand(('zpool', 'list', '-H', '-o', 'name'), stdout='Boris'), CommandCaptureCommand( ('zpool', 'import', '-f', '-N', '-o', 'readonly=on', '-o', 'cachefile=none', self.zpool_name), rc=1)) exported_zfs_device = ZfsDevice(self.zpool_name, True) self.assertEqual(exported_zfs_device.__enter__().available, False) self.assertEqual(self.lock._RLock__count, 1) exported_zfs_device.__exit__(0, 0, 0) self.assertEqual(self.lock._RLock__count, 0) self.assertRanAllCommandsInOrder()
def test_very_busy_export(self): self._add_import_commands() self.add_commands( CommandCaptureCommand( ('zpool', 'export', self.zpool_name), rc=1, stderr="cannot export '%s': pool is busy" % self.zpool_name)) self._add_export_commands() mock.patch( 'chroma_agent.chroma_common.blockdevices.blockdevice_zfs.time.sleep' ).start() exported_zfs_device = ZfsDevice(self.zpool_name, True) self.assertEqual(exported_zfs_device.__enter__().available, True) try: exported_zfs_device.__exit__(0, 0, 0) except BaseShell.CommandExecutionError: pass