We have to pass ssh_client object to tobiko/podman/_shell.py/discover_podman_socket
otherwise that methid has no way to get the actual socket url:
In [27]: import six
...:
...: import tobiko
...: from tobiko.tripleo import overcloud
...: from tobiko.shell import sh
...:
...:
In [28]: ssh_client = overcloud.overcloud_ssh_client('controller-0')
In [30]: cmd = "systemctl list-sockets | grep podman | awk '{print $1}'"
...:
In [31]: result = sh.execute(cmd, stdin=False, stdout=True, stderr=True,expect_exit_status=None)
...:
...:
In [32]: result
Out[32]: <tobiko.shell.sh._execute.ShellExecuteResult at 0x7f3a232f2b70>
In [33]: result.stdout
Out[33]: '0 sockets listed.\nPass --all to see loaded but inactive sockets, too.\n'
In [35]: ssh_client = overcloud.overcloud_ssh_client('controller-1')
...:
...:
In [36]: output = sh.execute("systemctl list-sockets | grep podman | awk '{print $1}'" ,ssh_client=ssh_cli
...: ent).stdout
In [37]: output
Out[37]: '/run/podman/io.podman\n'
import six
if six.PY3:
from podman import client as podman_client
from podman.libs import containers
from tobiko import podman
from tobiko.openstack import topology
six.PY3
ssh_client = None
for node in topology.list_openstack_nodes(group='controller'):
ssh_client = node.ssh_client
client = podman.get_podman_client(
ssh_client=ssh_client).connect()
from tobiko.podman import _exception
from tobiko.podman import _shell
from tobiko.shell import ssh
import podman
Now we get this error:
~/tobiko/test/lib/python3.6/site-packages/podman/client.py in factory(cls, uri, interface, *args, **kwargs)
55 local_path = urlparse(uri).path
56 if local_path == '':
---> 57 raise ValueError('path is required for uri,'
58 ' expected format "unix://path_to_socket"')
59
this is because :
uri=_shell.discover_podman_socket(ssh_client=ssh_client)
uri = ssh.get_port_forward_url(ssh_client=ssh_client, url=uri)
uri
Out[18]: 'tcp://127.0.0.1:38005'
the Base client checks for 'path' in : urlparse(uri2)
Out[27]: ParseResult(scheme='tcp', netloc='localhost:38005', path='', params='', query='', fragment='')
and throws an error because uri is a net link, not file.
even If I use socat to create a file link :
[stack@undercloud-0 ~]$ socat PIPE:/tmp/podman_tunnel TCP:127.0.0.1:38005
It still gives me an error becsause of permissions :
uri_via_socat='unix:/tmp/podman_tunnel'
In [34]: client = podman.Client(uri=uri_via_socat)
...:
~/tobiko/test/lib/python3.6/site-packages/varlink/client.py in open_unix()
510 s = socket.socket(socket.AF_UNIX)
511 s.setblocking(True)
--> 512 s.connect(address)
513 return s
514
ConnectionRefusedError: [Errno 111] Connection refused
This just works :
import podman
podman_client = podman.Client(uri='unix:/tmp/podman.sock', remote_uri='ssh://heat-admin@controller-0/run/podman/io.podman',identity_file='~/.ssh/id_rsa')
list(map(print, podman_client.images.list()))
[...]
{'id': 'c076fddbbcb3a1b7aa8765a51bb315938a9964849c5a09753b4f3596cddb7b87',
suggestion:
not to go through loops to make podman client use the netcat tunnel
and let it use it's native podman clients' ssh tunnel instead , thus reducing code vulnerability
podman.Client(uri='unix:/tmp/podman.sock', remote_uri='ssh://{}@{}/run/podman/io.podman'.format(ssh_client.connect_parameters['username'],ssh_client.host),identity_file='~/.ssh/id_rsa')
this works :
In [78]: list(map(print, podman_client.images.list()))
debug1: Connection to port -2 forwarding to /run/podman/io.podman port -2 requested.
debug1: channel 1: new [direct-streamlocal@openssh.com]
{'id': 'c076fddbbcb3a1b7aa8765a51bb315938a9964849c5a09753b4f3596cddb7b87',
lastly :
fix the list containers test in :
tobiko/tests/functional/podman/test_client.py
this will always return true , if the for loop
comes up with an empty list then there will nothing to fail this test on,
so we have to verify we get an actual container list first...
Change-Id: If069a640f0fc5251e5879cb2fd65115e299337f3