Merge "Fixes for podman client (client tunnel discovery, client creation and tests)"
This commit is contained in:
commit
20e53b4762
@ -80,10 +80,14 @@ class PodmanClientFixture(tobiko.SharedFixture):
|
|||||||
return client
|
return client
|
||||||
|
|
||||||
def create_client(self):
|
def create_client(self):
|
||||||
uri = self.discover_podman_socket()
|
podman_remote_socket = self.discover_podman_socket()
|
||||||
if self.ssh_client:
|
remote_uri = 'ssh://{username}@{host}{socket}'.format(
|
||||||
uri = ssh.get_port_forward_url(ssh_client=self.ssh_client, url=uri)
|
username=self.ssh_client.connect_parameters['username'],
|
||||||
client = podman.Client(uri=uri)
|
host=self.ssh_client.host,
|
||||||
|
socket=podman_remote_socket)
|
||||||
|
client = podman.Client(uri=podman_remote_socket,
|
||||||
|
remote_uri=remote_uri,
|
||||||
|
identity_file='~/.ssh/id_rsa')
|
||||||
client.system.ping()
|
client.system.ping()
|
||||||
return client
|
return client
|
||||||
|
|
||||||
|
@ -19,10 +19,11 @@ from tobiko.podman import _exception
|
|||||||
from tobiko.shell import sh
|
from tobiko.shell import sh
|
||||||
|
|
||||||
|
|
||||||
def discover_podman_socket(**execute_params):
|
def discover_podman_socket(ssh_client=None, **execute_params):
|
||||||
cmd = "systemctl list-sockets | grep podman | awk '{print $1}'"
|
cmd = "systemctl list-sockets | grep podman | awk '{print $1}'"
|
||||||
result = sh.execute(cmd, stdin=False, stdout=True, stderr=True,
|
result = sh.execute(cmd, stdin=False, stdout=True, stderr=True,
|
||||||
expect_exit_status=None, **execute_params)
|
expect_exit_status=None, ssh_client=ssh_client,
|
||||||
|
**execute_params)
|
||||||
if result.exit_status or not result.stdout:
|
if result.exit_status or not result.stdout:
|
||||||
raise _exception.PodmanSocketNotFoundError(details=result.stderr)
|
raise _exception.PodmanSocketNotFoundError(details=result.stderr)
|
||||||
try:
|
try:
|
||||||
|
@ -66,6 +66,8 @@ if six.PY3:
|
|||||||
client.ping()
|
client.ping()
|
||||||
|
|
||||||
def test_list_podman_containers(self):
|
def test_list_podman_containers(self):
|
||||||
for container in podman.list_podman_containers(
|
podman_containers_list = podman.list_podman_containers(
|
||||||
ssh_client=self.ssh_client):
|
ssh_client=self.ssh_client)
|
||||||
|
self.assertTrue(podman_containers_list)
|
||||||
|
for container in podman_containers_list:
|
||||||
self.assertIsInstance(container, containers.Container)
|
self.assertIsInstance(container, containers.Container)
|
||||||
|
@ -1,50 +0,0 @@
|
|||||||
# Copyright 2018 Red Hat
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
||||||
# not use this file except in compliance with the License. You may obtain
|
|
||||||
# a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
# License for the specific language governing permissions and limitations
|
|
||||||
# under the License.
|
|
||||||
from __future__ import absolute_import
|
|
||||||
|
|
||||||
import mock
|
|
||||||
import six
|
|
||||||
|
|
||||||
# We need to ignore this code under py2
|
|
||||||
# it's not compatible and parser will failed even if we use
|
|
||||||
# the `unittest.skipIf` decorator, because during the test discovery
|
|
||||||
# stestr and unittest will load this test
|
|
||||||
# module before running it and it will load podman
|
|
||||||
# too which isn't compatible in version leather than python 3
|
|
||||||
# Also the varlink mock module isn't compatible with py27, is using
|
|
||||||
# annotations syntaxe to generate varlink interface for the mocked service
|
|
||||||
# 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 tobiko import podman
|
|
||||||
from tobiko.tests import unit
|
|
||||||
|
|
||||||
from varlink import mock as varlink_mock
|
|
||||||
|
|
||||||
class TestPodmanClient(unit.TobikoUnitTest):
|
|
||||||
|
|
||||||
@varlink_mock.mockedservice(
|
|
||||||
fake_service=unit.mocked_service.ServicePod,
|
|
||||||
fake_types=unit.mocked_service.types,
|
|
||||||
name='io.podman',
|
|
||||||
address='unix:@podmantests'
|
|
||||||
)
|
|
||||||
@mock.patch(
|
|
||||||
'tobiko.podman._client.PodmanClientFixture.discover_podman_socket'
|
|
||||||
)
|
|
||||||
def test_init(self, mocked_discover_podman_socket):
|
|
||||||
mocked_discover_podman_socket.return_value = 'unix:@podmantests'
|
|
||||||
client = podman.get_podman_client().connect()
|
|
||||||
pods = client.pods.get('135d71b9495f')
|
|
||||||
self.assertEqual(pods["numberofcontainers"], "2")
|
|
Loading…
x
Reference in New Issue
Block a user