Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New root password spoke #44

Merged
merged 3 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion anabot/conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def is_liveimg_install():
if os.path.exists('/run/install/ks.cfg'):
with open('/run/install/ks.cfg', 'r') as ks:
for line in ks.readlines():
if re.search("\s*liveimg.*\s+--url", line):
if re.search(r"\s*liveimg.*\s+--url", line):
return True
return False

15 changes: 13 additions & 2 deletions anabot/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import sys

try: # python3
from configparser import RawConfigParser
Expand All @@ -20,20 +21,30 @@
'profile_name': None,
}

# From python3.12 RawConfigParser doesn't have readfp method, we need to use read_file
def use_read_file():
return sys.version_info >= (3, 12)

def init_config(profile_name):
global _profile_name
global _config

ini_path = os.path.join(profiles_path, profile_name + '.ini')
_config = RawConfigParser(allow_no_value=True)
defaults = open(defauls_path, 'r')
_config.readfp(defaults)
if use_read_file():
_config.read_file(defaults)
else:
_config.readfp(defaults)
try:
local_conf_path = os.environ.get(
'ANABOT_CONF', os.path.join(os.getcwd(), 'anabot.ini')
)
with open(local_conf_path) as local_conf:
_config.readfp(local_conf)
if use_read_file():
_config.read_file(local_conf)
else:
_config.readfp(local_conf)
except OSError:
# couldn't find or read 'anabot.ini'
pass
Expand Down
10 changes: 10 additions & 0 deletions anabot/preprocessor/installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
from .defaults import delete_element
from anabot.variables import get_variable
from anabot.conditions import has_feature_hub_config
from anabot.conditions import is_anaconda_version_ge, is_distro, is_distro_version_ge

def has_new_root_psswd_spoke():
return is_anaconda_version_ge('35.22.1')

@replace("/installation")
def replace_installation(element):
Expand Down Expand Up @@ -75,6 +79,8 @@ def replace_hub(element, default_for=None):
element.addChild(new)
if len(element.xpathEval("./root_password")) == 0 and has_feature_hub_config():
new = load_snippet("/installation/hub/root_password", default_for, tag_name="_default_for")
if has_new_root_psswd_spoke():
new = load_snippet("/installation/hub/new_root_password", default_for, tag_name="_default_for")
element.addChild(new)
if len(element.xpathEval('./begin_installation')) == 0:
new = load_snippet("/installation/hub/begin_installation", default_for, tag_name="_default_for")
Expand All @@ -92,9 +98,13 @@ def replace_hub_rootpw(element):
except IndexError:
# no password specified, just use full preset
new = load_snippet("/installation/hub/root_password", element)
if has_new_root_psswd_spoke():
new = load_snippet("/installation/hub/new_root_password", element)
element.replaceNode(new)
return
new = load_snippet("/installation/hub/root", element)
if has_new_root_psswd_spoke():
new = load_snippet("/installation/hub/new_root", element)
element.replaceNode(new)
new.xpathEval("./password")[0].setProp("value", password)
new.xpathEval("./confirm_password")[0].setProp("value", password)
Expand Down
7 changes: 7 additions & 0 deletions anabot/preprocessor/snippets/installation/hub/new_root.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<root_password>
<root_account value="enable"/>
<password value="from /@password" />
<confirm_password value="from /@password" />
<done policy="may_fail" />
<done policy="may_fail" />
</root_password>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<root_password>
<root_account value="enable"/>
<password value="fo0m4nchU1" />
<confirm_password value="fo0m4nchU1" />
<done />
</root_password>
28 changes: 26 additions & 2 deletions anabot/runtime/installation/configuration/root_password.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
import logging
logger = logging.getLogger('anabot')

from anabot.conditions import is_distro_version
from anabot.conditions import is_distro_version, is_anaconda_version_ge
from anabot.runtime.decorators import handle_action, handle_check, check_action_result
from anabot.runtime.default import default_handler, action_result
from anabot.runtime.functions import get_attr, getnode, getparent, getsibling, clear_text, handle_checkbox, \
check_checkbox
from anabot.runtime.errors import TimeoutError, NonexistentError
from anabot.runtime.translate import tr, gtk_tr
from anabot.runtime.hooks import run_posthooks
from anabot.runtime.actionresult import NotFoundResult as NotFound
from anabot.runtime.actionresult import NotFoundResult as NotFound, ActionResultPass
from anabot.runtime.asserts import assertPasswordTextInputEquals as aptie
from anabot.runtime.installation.common import done_handler

Expand Down Expand Up @@ -38,10 +38,16 @@ def check_rootpw_error(parent_node):
except NonexistentError:
return True

def has_new_root_psswd_spoke():
return is_anaconda_version_ge('35.22.1')

SPOKE_SELECTOR="_Root Password"
if is_distro_version('rhel', 7):
SPOKE_SELECTOR="_ROOT PASSWORD"

if has_new_root_psswd_spoke():
SPOKE_SELECTOR="_Root Account"

@handle_act_hub('')
@handle_act('')
def root_password_handler(element, app_node, local_node):
Expand Down Expand Up @@ -158,3 +164,21 @@ def allow_root_ssh_login_with_password_check(element, app_node, local_node):
tr("Allow root SSH login with password",
context="GUI|Root Password|Allow root SSH login with password"))
return check_checkbox(checkbox, element, "Lock root account")

def get_root_account_radio_button(element, local_node):
value = get_attr(element, "value")
if value == "enable":
radio_button = getnode(local_node, "radio button", tr("_Enable root account", context="GUI|Password"))
else:
radio_button = getnode(local_node, "radio button", tr("_Disable root account", context="GUI|Password"))
return radio_button

@handle_act_hub('/root_account')
def root_account_handler(element, app_node, local_node):
radio_button = get_root_account_radio_button(element, local_node)
radio_button.click()

@handle_chck_hub('/root_account')
def root_account_check(element, app_node, local_node):
radio_button = get_root_account_radio_button(element, local_node)
return radio_button.checked
10 changes: 5 additions & 5 deletions anabot/runtime/installation/hub/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from fnmatch import fnmatchcase
from time import sleep

from anabot.conditions import is_distro_version_ge
from anabot.conditions import is_distro_version_ge, is_distro_version_lt, is_distro_version
from anabot.variables import get_variable
from anabot.runtime.decorators import handle_action, handle_check, check_action_result
from anabot.runtime.default import default_handler, action_result
Expand All @@ -31,12 +31,12 @@ def _wait_for_depsolve(initial=True):
waitline = ".*DEBUG yum.verbose.YumBase: Depsolve time:.*"

# Temporary change to also support Fedora 34.
if is_distro_version_ge('rhel', 8) or is_distro_version_ge('fedora', 34):
if ((is_distro_version_ge('rhel', 8) and is_distro_version_lt('rhel', 10))
or is_distro_version('fedora', 34)):
waitline = '.* INF packaging: checking dependencies: success'

if is_distro_version_ge('fedora', 35):
filename = '/tmp/anaconda.log'
waitline = '.*software_selection: The selection has been checked.*'
if is_distro_version_ge('rhel', 10) or is_distro_version_ge('fedora', 35):
waitline = '.*The software selection has been resolved.*'

if wait_for_line(filename, waitline, 600):
reporter.log_info("Depsolving finished, nothing should block anaconda main thread now (GTK/ATK) now")
Expand Down
5 changes: 5 additions & 0 deletions anabot/runtime/installation/hub/partitioning/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ def additional_space_manipulate2(element, app_node, local_node, dry_run):
"I would like to _make additional space available.",
context="GUI|Storage",
)
if is_distro_version_ge('rhel', 10) or is_distro_version_ge('fedora', 35):
checkbox_text = tr(
"Free up space by re_moving or shrinking existing partitions",
context="GUI|Storage",
)
additional_checkbox = getnode_scroll(local_node, "check box", checkbox_text)
if not dry_run:
if (action == "enable") != additional_checkbox.checked:
Expand Down
9 changes: 9 additions & 0 deletions doc/recipe_elements/root_password.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ Equivalent to `/installation/hub/root_password/done`_.
==================================================
Equivalent to `/installation/hub/root_password/password`_.

/installation/hub/root_password/root_account
========================================
Enable or disable the *Root account*. It was introduced in RHEL 10 and the new workflow demands the root account to be
enabled first before setting the root password.

Attributes:

* ``value`` - ``enable`` or ``disable`` (any other value will be considered as ``disable``)

/installation/hub/root_password/allow_root_ssh_login_with_password
==================================================================
*Allow root SSH login with password* check box.
Expand Down
Loading
Loading