'If we hit an error during a `_create_domain` call to `libvirt+lxc`
we need to ensure the guest FS is unmounted from the host so that any
future `lvremove` calls will work.'

@mock.patch('nova.virt.disk.api.teardown_container')
@mock.patch('nova.virt.libvirt.driver.LibvirtDriver.get_info')
@mock.patch('nova.virt.disk.api.setup_container')
@mock.patch('oslo_utils.fileutils.ensure_tree')
@mock.patch.object(fake_libvirt_utils, 'get_instance_path')
def test_unmount_fs_if_error_during_lxc_create_domain(self, mock_get_inst_path, mock_ensure_tree, mock_setup_container, mock_get_info, mock_teardown):

    self.flags(virt_type='lxc', group='libvirt')
    drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
    mock_instance = mock.MagicMock()
    mock_get_inst_path.return_value = '/tmp/'
    mock_image_backend = mock.MagicMock()
    drvr.image_backend = mock_image_backend
    mock_image = mock.MagicMock()
    mock_image.path = '/tmp/test.img'
    drvr.image_backend.by_name.return_value = mock_image
    mock_setup_container.return_value = '/dev/nbd0'
    mock_get_info.side_effect = exception.InstanceNotFound(instance_id='foo')
    drvr._conn.defineXML = mock.Mock()
    drvr._conn.defineXML.side_effect = ValueError('somethingbad')
    with test.nested(mock.patch.object(drvr, '_is_booted_from_volume', return_value=False), mock.patch.object(drvr, 'plug_vifs'), mock.patch.object(drvr, 'firewall_driver'), mock.patch.object(drvr, 'cleanup')):
        self.assertRaises(ValueError, drvr._create_domain_and_network, self.context, 'xml', mock_instance, None)
        mock_teardown.assert_called_with(container_dir='/tmp/rootfs')
