def test_loop_creation_no_truncate(self, path_exists, create_loopback, loopbacks): """It does not create a new sparse image for loopback if one exists""" loopbacks.return_value = {} path_exists.return_value = True with patch('subprocess.check_call') as check_call: loopback.ensure_loopback_device('/tmp/foo.img', '15G') self.assertFalse(check_call.called)
def test_ensure_loopback_creation(self, path_exists, create_loopback, loopbacks): """It creates a new sparse image for loopback if one does not exists""" loopbacks.return_value = {} path_exists.return_value = False create_loopback.return_value = '/dev/loop0' with patch(STORAGE_LINUX_LOOPBACK + '.check_call') as check_call: loopback.ensure_loopback_device('/tmp/foo.img', '15G') check_call.assert_called_with(['truncate', '--size', '15G', '/tmp/foo.img'])
def test_loopback_create_already_exists(self, loopbacks, check_call, create): """It finds existing loopback device for requested file""" loopbacks.return_value = {'/dev/loop1': '/tmp/bar.img'} res = loopback.ensure_loopback_device('/tmp/bar.img', '5G') self.assertEquals(res, '/dev/loop1') self.assertFalse(create.called) self.assertFalse(check_call.called)