Skip to content

Commit 6e0cddf

Browse files
committed
Move actual setup to a separate task
Move code to a separate task, so a subsequent commit can hook it up to a progress-reporting spoke. Besides plain code move, it uses a TaskQueue to collect tasks first, and then call them all.
1 parent 20b17ad commit 6e0cddf

File tree

2 files changed

+157
-80
lines changed

2 files changed

+157
-80
lines changed

initial_setup/__init__.py

Lines changed: 9 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,14 @@
1111

1212
from initial_setup.product import eula_available
1313
from initial_setup import initial_setup_log
14+
from initial_setup.task import InitialSetupTask
1415

15-
from pyanaconda.core.dbus import DBus
1616
from pyanaconda.core.util import get_os_release_value
1717
from pyanaconda.localization import setup_locale_environment, setup_locale
18-
from pyanaconda.core.constants import FIRSTBOOT_ENVIRON, SETUP_ON_BOOT_RECONFIG, \
19-
SETUP_ON_BOOT_DEFAULT
18+
from pyanaconda.core.constants import FIRSTBOOT_ENVIRON, SETUP_ON_BOOT_RECONFIG
2019
from pyanaconda.flags import flags
2120
from pyanaconda.core.startup.dbus_launcher import AnacondaDBusLauncher
22-
from pyanaconda.modules.common.task import sync_run_task
23-
from pyanaconda.modules.common.constants.services import BOSS, LOCALIZATION, TIMEZONE, USERS, \
21+
from pyanaconda.modules.common.constants.services import BOSS, LOCALIZATION, USERS, \
2422
SERVICES, NETWORK
2523
from pyanaconda.modules.common.structures.kickstart import KickstartReport
2624

@@ -282,81 +280,12 @@ def _apply(self):
282280
# Do not execute sections that were part of the original
283281
# anaconda kickstart file (== have .seen flag set)
284282

285-
log.info("applying changes")
286-
287-
services_proxy = SERVICES.get_proxy()
288-
reconfig_mode = services_proxy.SetupOnBoot == SETUP_ON_BOOT_RECONFIG
289-
290-
# data.selinux
291-
# data.firewall
292-
293-
# Configure the timezone.
294-
timezone_proxy = TIMEZONE.get_proxy()
295-
for task_path in timezone_proxy.InstallWithTasks():
296-
task_proxy = TIMEZONE.get_proxy(task_path)
297-
sync_run_task(task_proxy)
298-
299-
# Configure the localization.
300-
localization_proxy = LOCALIZATION.get_proxy()
301-
for task_path in localization_proxy.InstallWithTasks():
302-
task_proxy = LOCALIZATION.get_proxy(task_path)
303-
sync_run_task(task_proxy)
304-
305-
# Configure persistent hostname
306-
network_proxy = NETWORK.get_proxy()
307-
network_task = network_proxy.ConfigureHostnameWithTask(True)
308-
task_proxy = NETWORK.get_proxy(network_task)
309-
sync_run_task(task_proxy)
310-
# Set current hostname
311-
network_proxy.SetCurrentHostname(network_proxy.Hostname)
312-
313-
# Configure groups, users & root account
314-
#
315-
# NOTE: We only configure groups, users & root account if the respective
316-
# kickstart commands are *not* seen in the input kickstart.
317-
# This basically means that we will configure only what was
318-
# set in the Initial Setup UI and will not attempt to configure
319-
# anything that looks like it was configured previously in
320-
# the Anaconda UI or installation kickstart.
321-
users_proxy = USERS.get_proxy()
322-
323-
if self._groups_already_configured and not reconfig_mode:
324-
log.debug("skipping user group configuration - already configured")
325-
elif users_proxy.Groups: # only run of there are some groups to create
326-
groups_task = users_proxy.ConfigureGroupsWithTask()
327-
task_proxy = USERS.get_proxy(groups_task)
328-
log.debug("configuring user groups via %s task", task_proxy.Name)
329-
sync_run_task(task_proxy)
330-
331-
if self._users_already_configured and not reconfig_mode:
332-
log.debug("skipping user configuration - already configured")
333-
elif users_proxy.Users: # only run if there are some users to create
334-
users_task = users_proxy.ConfigureUsersWithTask()
335-
task_proxy = USERS.get_proxy(users_task)
336-
log.debug("configuring users via %s task", task_proxy.Name)
337-
sync_run_task(task_proxy)
338-
339-
if self._root_password_already_configured and not reconfig_mode:
340-
log.debug("skipping root password configuration - already configured")
341-
else:
342-
root_task = users_proxy.SetRootPasswordWithTask()
343-
task_proxy = USERS.get_proxy(root_task)
344-
log.debug("configuring root password via %s task", task_proxy.Name)
345-
sync_run_task(task_proxy)
346-
347-
# Configure all addons
348-
log.info("executing addons")
349-
boss_proxy = BOSS.get_proxy()
350-
for service_name, object_path in boss_proxy.CollectInstallSystemTasks():
351-
task_proxy = DBus.get_proxy(service_name, object_path)
352-
sync_run_task(task_proxy)
353-
354-
if self.external_reconfig:
355-
# prevent the reconfig flag from being written out
356-
# to kickstart if neither /etc/reconfigSys or /.unconfigured
357-
# are present
358-
services_proxy = SERVICES.get_proxy()
359-
services_proxy.SetupOnBoot = SETUP_ON_BOOT_DEFAULT
283+
task = InitialSetupTask(
284+
groups_already_configured=self._groups_already_configured,
285+
users_already_configured=self._users_already_configured,
286+
root_password_already_configured=self._root_password_already_configured,
287+
)
288+
task.start()
360289

361290
# Write the kickstart data to file
362291
log.info("writing the Initial Setup kickstart file %s", OUTPUT_KICKSTART_PATH)

initial_setup/task.py

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
import logging
2+
3+
from pyanaconda.core.constants import SETUP_ON_BOOT_RECONFIG, SETUP_ON_BOOT_DEFAULT
4+
from pyanaconda.core.dbus import DBus
5+
from pyanaconda.installation_tasks import TaskQueue, DBusTask
6+
from pyanaconda.modules.common.constants.services import SERVICES, TIMEZONE, LOCALIZATION, NETWORK, USERS, BOSS
7+
from pyanaconda.modules.common.task import Task, sync_run_task
8+
from pyanaconda.core.i18n import _
9+
10+
log = logging.getLogger("initial-setup")
11+
12+
13+
class InitialSetupTask(Task):
14+
def __init__(self,
15+
groups_already_configured=False,
16+
users_already_configured=False,
17+
root_password_already_configured=False):
18+
super().__init__()
19+
self._total_steps = 0
20+
self._groups_already_configured = groups_already_configured
21+
self._users_already_configured = users_already_configured
22+
self._root_password_already_configured = root_password_already_configured
23+
24+
@property
25+
def name(self):
26+
"""Name of the task"""
27+
return "Run the initial setup queue."
28+
29+
@property
30+
def steps(self):
31+
"""Total number of steps."""
32+
return self._total_steps
33+
34+
def _queue_started_cb(self, task):
35+
"""The installation queue was started."""
36+
self.report_progress(task.status_message)
37+
38+
def _task_completed_cb(self, task):
39+
"""The installation task was completed."""
40+
self.report_progress("", step_size=1)
41+
42+
def _task_started_cb(self, task):
43+
"""The installation task was completed."""
44+
self.report_progress(task.name)
45+
46+
def _progress_report_cb(self, step, message):
47+
"""Handle a progress report of a task."""
48+
self.report_progress(message)
49+
50+
def run(self):
51+
"""Run the task."""
52+
log.info("applying changes")
53+
54+
queue = TaskQueue("Initial Setup")
55+
56+
# connect progress reporting
57+
queue.queue_started.connect(self._queue_started_cb)
58+
queue.task_completed.connect(self._task_completed_cb)
59+
queue.task_started.connect(self._task_started_cb)
60+
61+
services_proxy = SERVICES.get_proxy()
62+
reconfig_mode = services_proxy.SetupOnBoot == SETUP_ON_BOOT_RECONFIG
63+
64+
# data.selinux
65+
# data.firewall
66+
67+
# Configure the timezone.
68+
timezone_proxy = TIMEZONE.get_proxy()
69+
for task_path in timezone_proxy.InstallWithTasks():
70+
task_proxy = TIMEZONE.get_proxy(task_path)
71+
queue.append(DBusTask(task_proxy))
72+
73+
# Configure the localization.
74+
localization_proxy = LOCALIZATION.get_proxy()
75+
for task_path in localization_proxy.InstallWithTasks():
76+
task_proxy = LOCALIZATION.get_proxy(task_path)
77+
queue.append(DBusTask(task_proxy))
78+
79+
# Configure persistent hostname
80+
network_proxy = NETWORK.get_proxy()
81+
network_task = network_proxy.ConfigureHostnameWithTask(True)
82+
task_proxy = NETWORK.get_proxy(network_task)
83+
queue.append(DBusTask(task_proxy))
84+
# Set current hostname
85+
network_proxy.SetCurrentHostname(network_proxy.Hostname)
86+
87+
# Configure groups, users & root account
88+
#
89+
# NOTE: We only configure groups, users & root account if the respective
90+
# kickstart commands are *not* seen in the input kickstart.
91+
# This basically means that we will configure only what was
92+
# set in the Initial Setup UI and will not attempt to configure
93+
# anything that looks like it was configured previously in
94+
# the Anaconda UI or installation kickstart.
95+
users_proxy = USERS.get_proxy()
96+
97+
if self._groups_already_configured and not reconfig_mode:
98+
log.debug("skipping user group configuration - already configured")
99+
elif users_proxy.Groups: # only run of there are some groups to create
100+
groups_task = users_proxy.ConfigureGroupsWithTask()
101+
task_proxy = USERS.get_proxy(groups_task)
102+
log.debug("configuring user groups via %s task", task_proxy.Name)
103+
queue.append(DBusTask(task_proxy))
104+
105+
if self._users_already_configured and not reconfig_mode:
106+
log.debug("skipping user configuration - already configured")
107+
elif users_proxy.Users: # only run if there are some users to create
108+
users_task = users_proxy.ConfigureUsersWithTask()
109+
task_proxy = USERS.get_proxy(users_task)
110+
log.debug("configuring users via %s task", task_proxy.Name)
111+
queue.append(DBusTask(task_proxy))
112+
113+
if self._root_password_already_configured and not reconfig_mode:
114+
log.debug("skipping root password configuration - already configured")
115+
else:
116+
root_task = users_proxy.SetRootPasswordWithTask()
117+
task_proxy = USERS.get_proxy(root_task)
118+
log.debug("configuring root password via %s task", task_proxy.Name)
119+
queue.append(DBusTask(task_proxy))
120+
121+
# Configure all addons
122+
log.info("executing addons")
123+
boss_proxy = BOSS.get_proxy()
124+
for service_name, object_path in boss_proxy.CollectInstallSystemTasks():
125+
task_proxy = DBus.get_proxy(service_name, object_path)
126+
queue.append(DBusTask(task_proxy))
127+
128+
for item in queue.nested_items:
129+
if isinstance(item, DBusTask):
130+
item._progress_cb = self._progress_report_cb
131+
132+
self._total_steps = queue.task_count
133+
134+
# log contents of the main task queue
135+
log.info(queue.summary)
136+
137+
# start the task queue
138+
queue.start()
139+
140+
# done
141+
self.report_progress(_("Complete!"), step_number=self.steps)
142+
143+
if self.external_reconfig:
144+
# prevent the reconfig flag from being written out
145+
# to kickstart if neither /etc/reconfigSys or /.unconfigured
146+
# are present
147+
services_proxy = SERVICES.get_proxy()
148+
services_proxy.SetupOnBoot = SETUP_ON_BOOT_DEFAULT

0 commit comments

Comments
 (0)