podman client add podman access via varlink commands
also fix the podman tests Change-Id: I28fa83ec7ebdac4fa89318363f27df295d76fb4d
This commit is contained in:
parent
2045ba38fb
commit
2a329a619c
|
@ -23,6 +23,7 @@ import tobiko
|
|||
from tobiko.podman import _exception
|
||||
from tobiko.podman import _shell
|
||||
from tobiko.shell import ssh
|
||||
from tobiko.shell import sh
|
||||
|
||||
|
||||
def get_podman_client(ssh_client=None):
|
||||
|
@ -74,6 +75,30 @@ class PodmanClientFixture(tobiko.SharedFixture):
|
|||
return ssh_client
|
||||
|
||||
def setup_client(self):
|
||||
# setup podman access via varlink
|
||||
podman_client_setup_cmds = [
|
||||
"sudo groupadd -f podman",
|
||||
"sudo usermod -a -G podman heat-admin",
|
||||
"sudo chmod o+w /etc/tmpfiles.d",
|
||||
"sudo echo 'd /run/podman 0750 root heat-admin' > "
|
||||
"/etc/tmpfiles.d/podman.conf",
|
||||
"sudo cp /lib/systemd/system/io.podman.socket /etc/systemd/system/"
|
||||
"io.podman.socket",
|
||||
"sudo crudini --set /etc/systemd/system/io.podman.socket Socket "
|
||||
"SocketMode 0660",
|
||||
"sudo crudini --set /etc/systemd/system/io.podman.socket Socket"
|
||||
" SocketGroup podman",
|
||||
"sudo systemctl daemon-reload",
|
||||
"sudo systemd-tmpfiles --create",
|
||||
"sudo systemctl enable --now io.podman.socket",
|
||||
"sudo chown -R root: /run/podman",
|
||||
"sudo chmod g+rw /run/podman/io.podman",
|
||||
"sudo systemctl start io.podman.socket"
|
||||
]
|
||||
|
||||
for cmd in podman_client_setup_cmds:
|
||||
sh.execute(cmd, ssh_client=self.ssh_client)
|
||||
|
||||
client = self.client
|
||||
if client is None:
|
||||
self.client = client = self.create_client()
|
||||
|
@ -81,11 +106,14 @@ class PodmanClientFixture(tobiko.SharedFixture):
|
|||
|
||||
def create_client(self):
|
||||
podman_remote_socket = self.discover_podman_socket()
|
||||
podman_remote_socket_uri = 'unix:/tmp/podman.sock'
|
||||
|
||||
remote_uri = 'ssh://{username}@{host}{socket}'.format(
|
||||
username=self.ssh_client.connect_parameters['username'],
|
||||
host=self.ssh_client.host,
|
||||
host=self.ssh_client.connect_parameters["hostname"],
|
||||
socket=podman_remote_socket)
|
||||
client = podman.Client(uri=podman_remote_socket,
|
||||
|
||||
client = podman.Client(uri=podman_remote_socket_uri,
|
||||
remote_uri=remote_uri,
|
||||
identity_file='~/.ssh/id_rsa')
|
||||
client.system.ping()
|
||||
|
|
|
@ -15,8 +15,9 @@
|
|||
# under the License.
|
||||
from __future__ import absolute_import
|
||||
|
||||
import testtools
|
||||
import types
|
||||
|
||||
import testtools
|
||||
import six
|
||||
|
||||
# We need to ignore this code under py2
|
||||
|
@ -30,8 +31,6 @@ import six
|
|||
# and it will raise related exceptions too.
|
||||
# For all these reasons we can't run podman tests under a python 2 environment
|
||||
if six.PY3:
|
||||
from podman import client as podman_client
|
||||
from podman.libs import containers
|
||||
|
||||
from tobiko import podman
|
||||
from tobiko.openstack import topology
|
||||
|
@ -58,16 +57,10 @@ if six.PY3:
|
|||
def test_connect_podman_client(self):
|
||||
client = podman.get_podman_client(
|
||||
ssh_client=self.ssh_client).connect()
|
||||
podman_clients_valid_types = (
|
||||
podman_client.LocalClient,
|
||||
podman_client.RemoteClient
|
||||
)
|
||||
self.assertIsInstance(client, podman_clients_valid_types)
|
||||
client.ping()
|
||||
self.assertTrue(client.system.ping())
|
||||
|
||||
def test_list_podman_containers(self):
|
||||
podman_containers_list = podman.list_podman_containers(
|
||||
ssh_client=self.ssh_client)
|
||||
self.assertTrue(podman_containers_list)
|
||||
for container in podman_containers_list:
|
||||
self.assertIsInstance(container, containers.Container)
|
||||
client = podman.get_podman_client(
|
||||
ssh_client=self.ssh_client).connect()
|
||||
self.assertIsInstance(client.containers.list(),
|
||||
types.GeneratorType)
|
||||
|
|
Loading…
Reference in New Issue