From fba7aa10c8487116075d56c8dedeebefc40b74eb Mon Sep 17 00:00:00 2001 From: Florence Blanc-Renaud Date: Mon, 16 Jun 2025 18:15:22 +0200 Subject: [PATCH] ipa-idrange-fix: check that IPA server is installed If ipa-idrange-fix is called on a system where the server is not configured, it crashes with a Traceback when trying to access api.env.basedn. Check that IPA server is configured before processing further ipatests: add test launching ipa-idrange-fix on unconfigured server Fixes: https://pagure.io/freeipa/issue/9809 Signed-off-by: Florence Blanc-Renaud Reviewed-By: Rob Crittenden Reviewed-By: David Hanina --- ipaserver/install/ipa_idrange_fix.py | 3 +++ .../test_integration/test_cli_ipa_not_configured.py | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/ipaserver/install/ipa_idrange_fix.py b/ipaserver/install/ipa_idrange_fix.py index c6c67ae9330e2d0184efc09d09a84216ef0772a6..cd21ed4281d37b013537174fb4ab9e773382990e 100644 --- a/ipaserver/install/ipa_idrange_fix.py +++ b/ipaserver/install/ipa_idrange_fix.py @@ -10,6 +10,7 @@ from ipalib import api, errors from ipapython.admintool import AdminTool from ipapython.dn import DN from ipapython import ipautil +from ipaserver.install.installutils import check_server_configuration from typing import List, Tuple logger = logging.getLogger(__name__) @@ -169,6 +170,8 @@ for confirmation", super().validate_options(needs_root) def run(self): + check_server_configuration() + api.bootstrap(in_server=True) api.finalize() diff --git a/ipatests/test_integration/test_cli_ipa_not_configured.py b/ipatests/test_integration/test_cli_ipa_not_configured.py index 1bf36d8ee6e9d1e6019786f3b62d79dbce22655e..7c5601247d7d3c98cf6513eecc333de6aa59d704 100644 --- a/ipatests/test_integration/test_cli_ipa_not_configured.py +++ b/ipatests/test_integration/test_cli_ipa_not_configured.py @@ -22,3 +22,13 @@ class TestIPANotConfigured(IntegrationTest): assert (exp_str in cmd.stderr_text and cmd.returncode == SERVER_NOT_CONFIGURED and unexp_str not in cmd.stderr_text) + + def test_ipa_idrange_fix(self): + """ + Test for https://pagure.io/freeipa/issue/9809 + Launch ipa-idrange-fix command when the server is not configured. + """ + exp_str = "IPA is not configured" + cmd = self.master.run_command(["ipa-idrange-fix"], raiseonerr=False) + assert (exp_str in cmd.stderr_text + and cmd.returncode == SERVER_NOT_CONFIGURED) -- 2.50.0