Skip to content

Commit

Permalink
Copy /var/lib/gnome-initial-setup/state to installed system
Browse files Browse the repository at this point in the history
In order to avoid duplicate screens in gnome-initial-setup we need
to let the gnome-initial-setup on the installed system know what
the user did during the live boot.

This commit copies the relevant state file over.
  • Loading branch information
halfline authored and VladimirSlavik committed Sep 4, 2023
1 parent 42e7b19 commit 980bde4
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 9 deletions.
28 changes: 27 additions & 1 deletion pyanaconda/modules/payloads/payload/live_image/installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
import os
import stat
import requests
import shutil
import blivet.util

from pyanaconda.anaconda_loggers import get_module_logger
from pyanaconda.core.constants import NETWORK_CONNECTION_TIMEOUT
from pyanaconda.core.i18n import _
from pyanaconda.core.util import execWithRedirect, requests_session
from pyanaconda.core.path import join_paths
from pyanaconda.core.path import join_paths, make_directories
from pyanaconda.core.string import lower_ascii
from pyanaconda.modules.common.structures.live_image import LiveImageConfigurationData
from pyanaconda.modules.common.task import Task
Expand Down Expand Up @@ -478,3 +479,28 @@ def run(self):

log.debug("Removing the downloaded image at %s.", self._download_path)
os.unlink(self._download_path)


class CopyTransientGnomeInitialSetupStateTask(Task):
"""Task to copy transient gnome-initial-setup configuration from live system to installed system"""

def __init__(self, sysroot):
"""Create a new task."""
super().__init__()
self._sysroot = sysroot
self._paths = ['/var/lib/gnome-initial-setup/state']

@property
def name(self):
"""Name of the task."""
return "Transfer transient gnome-initial-setup live system configuration to installed system"""

def run(self):
"""Run the task."""
for path in self._paths:
destination_path = join_paths(self._sysroot, path.lstrip('/'))
destination_dir = os.path.dirname(destination_path)
make_directories(destination_dir)
log.debug("Copying %s to %s", path, destination_path)
if os.path.exists(path):
shutil.copy2(path, destination_path)
17 changes: 13 additions & 4 deletions pyanaconda/modules/payloads/payload/live_os/live_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
from pyanaconda.core.configuration.anaconda import conf
from pyanaconda.modules.common.errors.payload import IncompatibleSourceError
from pyanaconda.modules.payloads.constants import SourceType, PayloadType
from pyanaconda.modules.payloads.payload.live_image.installation import InstallFromImageTask
from pyanaconda.modules.payloads.payload.live_image.installation import InstallFromImageTask, \
CopyTransientGnomeInitialSetupStateTask
from pyanaconda.modules.payloads.payload.live_os.utils import get_kernel_version_list
from pyanaconda.modules.payloads.payload.payload_base import PayloadBase
from pyanaconda.modules.payloads.payload.live_os.live_os_interface import LiveOSInterface
Expand Down Expand Up @@ -62,20 +63,28 @@ def install_with_tasks(self):
"""Install the payload with tasks."""
image_source = self._get_source(SourceType.LIVE_OS_IMAGE)

tasks = []

if not image_source:
log.debug("No Live OS image is available.")
return []

task = InstallFromImageTask(
install_task = InstallFromImageTask(
sysroot=conf.target.system_root,
mount_point=image_source.mount_point
)

task.succeeded_signal.connect(
install_task.succeeded_signal.connect(
lambda: self._update_kernel_version_list(image_source)
)

return [task]
tasks += [install_task]

tasks += [CopyTransientGnomeInitialSetupStateTask(
sysroot=conf.target.system_root,
)]

return tasks

def _update_kernel_version_list(self, image_source):
"""Update the kernel versions list."""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (C) 2019 Red Hat, Inc.
# Copyright (C) 2023 Red Hat, Inc.
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions of
Expand All @@ -22,12 +22,13 @@
import unittest

from pyanaconda.core.constants import SOURCE_TYPE_LIVE_OS_IMAGE, PAYLOAD_TYPE_LIVE_OS
from pyanaconda.core.path import join_paths, touch
from pyanaconda.core.path import join_paths, make_directories, touch
from pyanaconda.modules.common.errors.payload import IncompatibleSourceError
from pyanaconda.modules.payloads.constants import SourceType, SourceState
from pyanaconda.modules.payloads.payload.live_os.live_os import LiveOSModule
from pyanaconda.modules.payloads.payload.live_os.live_os_interface import LiveOSInterface
from pyanaconda.modules.payloads.payload.live_image.installation import InstallFromImageTask
from pyanaconda.modules.payloads.payload.live_image.installation import InstallFromImageTask, \
CopyTransientGnomeInitialSetupStateTask

from tests.unit_tests.pyanaconda_tests import patch_dbus_publish_object
from tests.unit_tests.pyanaconda_tests.modules.payloads.payload.module_payload_shared import \
Expand Down Expand Up @@ -106,8 +107,9 @@ def test_install_with_task(self):
self.module.set_sources([source])

tasks = self.module.install_with_tasks()
assert len(tasks) == 1
assert len(tasks) == 2
assert isinstance(tasks[0], InstallFromImageTask)
assert isinstance(tasks[1], CopyTransientGnomeInitialSetupStateTask)

def test_install_with_task_no_source(self):
"""Test Live OS install with tasks with no source fail."""
Expand All @@ -116,3 +118,40 @@ def test_install_with_task_no_source(self):
def test_post_install_with_tasks(self):
"""Test Live OS post installation configuration task."""
assert self.module.post_install_with_tasks() == []


class LiveOSModuleTasksTestCase(unittest.TestCase):
"""Test the Live OS payload module tasks."""

def test_transient_gis_task_present(self):
"""Test copying GIS transient files when present"""
with tempfile.TemporaryDirectory() as oldroot, tempfile.TemporaryDirectory() as newroot:
task = CopyTransientGnomeInitialSetupStateTask(newroot)

mocked_path = join_paths(oldroot, task._paths[0])
make_directories(os.path.dirname(mocked_path))
with open(mocked_path, "w") as f:
f.write("some data to copy over")
assert os.path.isfile(mocked_path)
task._paths = [mocked_path] # HACK: overwrite the files to copy

task.run()

result_path = join_paths(newroot, mocked_path)
assert os.path.isfile(result_path)
with open(result_path, "r") as f:
assert f.readlines() == ["some data to copy over"]

def test_transient_gis_task_missing(self):
"""Test copying GIS transient files when missing"""
with tempfile.TemporaryDirectory() as oldroot, tempfile.TemporaryDirectory() as newroot:
task = CopyTransientGnomeInitialSetupStateTask(newroot)
mocked_path = join_paths(oldroot, task._paths[0])
assert not os.path.exists(mocked_path)
task._paths = [mocked_path] # HACK: overwrite the files to copy

task.run()
# must not fail with missing paths

result_path = join_paths(newroot, mocked_path)
assert not os.path.exists(result_path)

0 comments on commit 980bde4

Please sign in to comment.