From e37b3d8cf1d1a87dea32914067f4aac3e74b6a91 Mon Sep 17 00:00:00 2001 From: Alexander Bokovoy Date: May 08 2020 06:35:01 +0000 Subject: Azure Pipelines: Override services known to not work in containers Chrony daemon tries to use adjtimex() which doesn't work in the container we run in Docker environment on Azure Pipelines. nis-domainname also tries to modify kernel-specific parameter that doesn't really work in runc-based containers. Use systemd container detection to avoid starting these services in the containers. Signed-off-by: Alexander Bokovoy Reviewed-By: Christian Heimes --- diff --git a/ipatests/azure/scripts/setup_containers.py b/ipatests/azure/scripts/setup_containers.py index fd42519..dbf2ea6 100644 --- a/ipatests/azure/scripts/setup_containers.py +++ b/ipatests/azure/scripts/setup_containers.py @@ -176,6 +176,30 @@ class Container: ] self.execute_all(cmd) + def ignore_service_in_container(self, service): + """ + Amend systemd service configuration to be ignored in a container + """ + service_dir = os.path.join( + "/etc/systemd/system", "{}.service.d".format(service)) + override_file = os.path.join(service_dir, "ipa-override.conf") + cmds = [ + "/bin/bash", "-c", + (f"mkdir -p {service_dir};" + f"echo '[Unit]' > {override_file};" + f"echo 'ConditionVirtualization=!container' >> {override_file}") + ] + self.execute_all(args=cmds) + + def setup_container_overrides(self): + """ + Set services known to not work in containers to be ignored + """ + for service in ('chronyd', 'nis-domainname'): + self.ignore_service_in_container(service) + + self.execute_all(args=["systemctl", "daemon-reload"]) + class Controller(Container): """ @@ -266,6 +290,13 @@ class Controller(Container): with open(os.path.join(IPA_TESTS_ENV_DIR, IPA_TEST_CONFIG), 'w') as f: f.write(template.render(config)) + def setup_container_overrides(self): + """ + Override services known to not work in containers + """ + for container in self.containers: + container.setup_container_overrides() + controller = Controller() master = Container(role='master') @@ -280,6 +311,7 @@ controller.setup_ssh() controller.setup_hosts() controller.setup_hostname() controller.setup_resolvconf() +controller.setup_container_overrides() config = { 'dns_forwarder': IPA_DNS_FORWARDER, diff --git a/ipatests/test_integration/test_sudo.py b/ipatests/test_integration/test_sudo.py index 4d76737..a113df0 100644 --- a/ipatests/test_integration/test_sudo.py +++ b/ipatests/test_integration/test_sudo.py @@ -155,6 +155,9 @@ class TestSudo(IntegrationTest): @pytest.mark.skip_if_platform( "debian", reason="NISDOMAIN has not been set on Debian" ) + @pytest.mark.skip_if_container( + "any", reason="NISDOMAIN cannot be set in containerized environment" + ) def test_nisdomainname(self): result = self.client.run_command('nisdomainname') assert self.client.domain.name in result.stdout_text