Re-execute podman client setup commands in case user has changed

In some cases, the user that connects to the overcloud nodes running
podman containers may change during a CI job execution (e.g. in some
upgrade jobs). When Tobiko is executed before that change, it prepares
the podman.socket service to allow connections using the old user; then,
when Tobiko is executed with the new username, the podman.socket does
not allow connections.
With this patch, Tobiko checks whether the podman.socket service is
configured with the proper username and, if not, changes its
configuration and restarts it.

Change-Id: I8466c86c886c983734133a7b4d8435073e309a59
This commit is contained in:
Eduardo Olivares 2023-08-07 15:56:09 +02:00
parent 10e18bb48f
commit 483dcf22f0

View File

@ -100,9 +100,11 @@ class PodmanClientFixture(tobiko.SharedFixture):
podman_socket_file = '/run/podman/io.podman'
username = self.ssh_client.get_connect_parameters()['username']
podman_client_check_status_cmds = (
"sudo test -f /var/podman_client_access_setup && "
f"sudo grep {username} /etc/tmpfiles.d/podman.conf")
podman_client_setup_cmds = \
f"""sudo test -f /var/podman_client_access_setup || \
(sudo groupadd -f podman && \
f"""sudo groupadd -f podman && \
sudo usermod -a -G podman {username} && \
sudo chmod -R o=wxr /etc/tmpfiles.d && \
sudo echo 'd /run/podman 0770 root {username}' > \
@ -121,10 +123,20 @@ class PodmanClientFixture(tobiko.SharedFixture):
sudo chmod g+rw {podman_socket_file} && \
sudo chmod 777 {podman_socket_file} && \
sudo setenforce 0 && \
sudo systemctl start {podman_service} && \
sudo touch /var/podman_client_access_setup)"""
sudo systemctl restart {podman_service} && \
sudo touch /var/podman_client_access_setup"""
sh.execute(podman_client_setup_cmds, ssh_client=self.ssh_client)
# check whether client setup was already executed or not
status_result = sh.execute(podman_client_check_status_cmds,
ssh_client=self.ssh_client,
expect_exit_status=None)
if status_result.exit_status != 0:
LOG.debug('executing podman client setup script for user %s',
username)
sh.execute(podman_client_setup_cmds, ssh_client=self.ssh_client)
else:
LOG.debug('podman client setup was already completed for user %s',
username)
client = self.client
if client is None: