From b8ebce7b185f4c934be693a1fbefe5fd2f279e38 Mon Sep 17 00:00:00 2001 From: Michal Polovka Date: May 06 2021 14:51:18 +0000 Subject: ipatests: test_installation: add install test scenarios test_hostname_parameter: Test for issue 2692 ipa-server-install ignores --hostname: check whether hostname provided in `--hostname` parameter is being taken into account and set as new hostname without prompting for it again test_ad_subpackage_dependency: Test for issue 4011 ipa-server-install crashes when AD subpackage is not installed: test if ipa-server installation succeeds without `freeipa-ipa-server-trust-ad` installed test_backup_of_cs_cfg_should_be_created: Test for issue 4166 Backup CS.cfg before modifying it: test if ipa-server installer backs up CS.cfg before modifying it test_installer_wizard_should_prompt_for_DNS: Test for issue 2575 [RFE] Installer wizard should prompt for DNS: test if installer is asking for DNS setup details if not provided as parameter Related: https://pagure.io/freeipa/issue/2692 Related: https://pagure.io/freeipa/issue/4011 Related: https://pagure.io/freeipa/issue/4166 Related: https://pagure.io/freeipa/issue/2575 Signed-off-by: Michal Polovka Reviewed-By: Michal Polovka Reviewed-By: Sergey Orlov Reviewed-By: Rob Crittenden --- diff --git a/ipatests/test_integration/test_installation.py b/ipatests/test_integration/test_installation.py index 2743438..02bcd6f 100644 --- a/ipatests/test_integration/test_installation.py +++ b/ipatests/test_integration/test_installation.py @@ -58,6 +58,17 @@ def server_install_setup(func): return wrapped +@pytest.fixture +def server_cleanup(request): + """ + Fixture to uninstall ipa server before and after the test + """ + host = request.cls.master + tasks.uninstall_master(host) + yield + tasks.uninstall_master(host) + + class InstallTestBase1(IntegrationTest): num_replicas = 3 @@ -662,7 +673,6 @@ def get_pki_tomcatd_pid(host): break return(pid) - def get_ipa_services_pids(host): ipa_services_name = [ "krb5kdc", "kadmin", "named", "httpd", "ipa-custodia", @@ -1119,6 +1129,113 @@ class TestInstallMaster(IntegrationTest): expected_stdout=f'href="https://{self.master.hostname}/' ) + def test_hostname_parameter(self, server_cleanup): + """ + Test that --hostname parameter is respected in interactive mode. + + https://pagure.io/freeipa/issue/2692 + """ + original_hostname = self.master.hostname + new_hostname = 'new.' + original_hostname + # New hostname is added into /etc/hosts as the installer + # is looking for it for resolution. Without it, an installation + # fails with `Unable to resolve host name, check /etc/hosts or DNS + # name resolution`. + hosts = self.master.get_file_contents(paths.HOSTS, encoding='utf-8') + new_hosts = hosts.replace(original_hostname, new_hostname) + self.master.put_file_contents(paths.HOSTS, new_hosts) + try: + cmd = ['ipa-server-install', '--hostname', new_hostname] + with self.master.spawn_expect(cmd) as e: + e.expect_exact('Do you want to configure integrated ' + 'DNS (BIND)? [no]: ') + e.sendline('no') + e.expect_exact('Please confirm the domain name [{}]: '.format( + original_hostname # DN is computed from new hostname + )) + e.sendline(self.master.domain.name) + e.expect_exact('Please provide a realm name [{}]: '.format( + self.master.domain.realm + )) + e.sendline(self.master.domain.realm) + e.expect_exact('Directory Manager password: ') + e.sendline(self.master.config.dirman_password) + e.expect_exact('Password (confirm): ') + e.sendline(self.master.config.dirman_password) + e.expect_exact('IPA admin password: ') + e.sendline(self.master.config.admin_password) + e.expect_exact('Password (confirm): ') + e.sendline(self.master.config.admin_password) + e.expect_exact('Do you want to configure chrony with ' + 'NTP server or pool address? [no]: ') + e.sendline('no') + e.expect_exact('Continue to configure the system ' + 'with these values? [no]: ') + e.sendline('yes') + e.expect_exit(ignore_remaining_output=True, timeout=720) + hostname = self.master.run_command([ + 'hostname', '-f']).stdout_text.strip() + assert hostname == new_hostname + finally: + # no need to restore the hostname as the installer + # does it during uninstallation + self.master.put_file_contents(paths.HOSTS, hosts) + + def test_ad_subpackage_dependency(self, server_cleanup): + """ + Test if the installer is not dependant on trust-ad package and + succeeds even when AD subpackage is not installed + + https://pagure.io/freeipa/issue/4011 + """ + if osinfo.id == 'fedora': + package_name = 'freeipa-server-trust-ad' + else: + package_name = 'ipa-server-trust-ad' + reinstall = False + if tasks.is_package_installed(self.master, package_name): + tasks.uninstall_packages(self.master, [package_name]) + reinstall = True + try: + tasks.install_master(self.master) + finally: + if reinstall: + tasks.install_packages(self.master, [package_name]) + + def test_backup_of_cs_cfg_is_created(self, server_cleanup): + """ + Test that the installer backs up CS.cfg configuration before it's + being modified. + + https://pagure.io/freeipa/issue/4166 + """ + bcp_location = paths.CA_CS_CFG_PATH + '.ipabkp' + original_cfg_content = None + if self.master.transport.file_exists(paths.CA_CS_CFG_PATH): + original_cfg_content = self.master.get_file_contents( + paths.CA_CS_CFG_PATH, encoding='utf-8') + + time_before_install = int(self.master.run_command( + ['date', '+%s']).stdout_text.strip()) + tasks.install_master(self.master) + ipaserver_install_log = self.master.get_file_contents( + paths.IPASERVER_INSTALL_LOG, encoding='utf-8') + assert 'backing up CS.cfg' in ipaserver_install_log + assert self.master.transport.file_exists(bcp_location) + + cfg_mod_time = int(self.master.run_command( + ['stat', '-c', '%Y', paths.CA_CS_CFG_PATH]).stdout_text.strip()) + bcp_mod_time = int(self.master.run_command( + ['stat', '-c', '%Y', bcp_location]).stdout_text.strip()) + + # check if the backup file was modified/created during the installation + # and before the original file was modified + assert time_before_install <= bcp_mod_time <= cfg_mod_time + bcp_cfg_content = self.master.get_file_contents( + paths.CA_CS_CFG_PATH + '.ipabkp', encoding='utf-8') + if original_cfg_content is not None: + assert original_cfg_content == bcp_cfg_content + class TestInstallMasterKRA(IntegrationTest): @@ -1216,6 +1333,60 @@ class TestInstallMasterDNS(IntegrationTest): def test_install_kra(self): tasks.install_kra(self.master, first_instance=True) + def test_installer_wizard_prompts_for_DNS(self, server_cleanup): + """ + Installer wizard should prompt for DNS even if --setup-dns is not + provided as an argument. + + https://pagure.io/freeipa/issue/2575 + """ + cmd = ['ipa-server-install'] + with self.master.spawn_expect(cmd) as e: + e.expect_exact('Do you want to configure integrated ' + 'DNS (BIND)? [no]: ') + e.sendline('yes') + e.expect_exact('Server host name [{}]: '.format( + self.master.hostname)) + e.sendline(self.master.hostname) + e.expect_exact('Please confirm the domain name [{}]: '.format( + self.master.domain.name)) + e.sendline(self.master.domain.name) + e.expect_exact('Please provide a realm name [{}]: '.format( + self.master.domain.realm + )) + e.sendline(self.master.domain.realm) + + e.expect_exact('Directory Manager password: ') + e.sendline(self.master.config.dirman_password) + e.expect_exact('Password (confirm): ') + e.sendline(self.master.config.dirman_password) + + e.expect_exact('IPA admin password: ') + e.sendline(self.master.config.admin_password) + e.expect_exact('Password (confirm): ') + e.sendline(self.master.config.admin_password) + + e.expect_exact( + 'Do you want to configure DNS forwarders? [yes]: ') + e.sendline('no') # irrelevant for this test + e.expect_exact('Do you want to search for missing reverse ' + 'zones? [yes]: ') + e.sendline('no') # irrelevant for this test + e.expect_exact('Do you want to configure chrony with NTP ' + 'server or pool address? [no]: ') + e.sendline('no') # irrelevant for this test + e.expect_exact('Continue to configure the system with these ' + 'values? [no]: ') + e.sendline('yes') + e.expect_exit(ignore_remaining_output=True, timeout=720) + + tasks.kinit_admin(self.master) + result = self.master.run_command( + ['ipa', 'dnszone-show', self.master.domain.name] + ).stdout_text + + assert 'Active zone: TRUE' in result + class TestInstallMasterDNSRepeatedly(IntegrationTest): """ Test that a repeated installation of the primary with DNS enabled