def test_unix_ping(self): with PodmanClient(base_url=f"unix://{self.socket_file}") as client: self.assertTrue(client.ping()) with PodmanClient( base_url=f"http+unix://{self.socket_file}") as client: self.assertTrue(client.ping())
def test_ssh_ping(self): with PodmanClient( base_url= f"http+ssh://{getpass.getuser()}@localhost:22{self.socket_file}" ) as client: self.assertTrue(client.ping()) with PodmanClient( base_url= f"ssh://{getpass.getuser()}@localhost:22{self.socket_file}" ) as client: self.assertTrue(client.ping())
def setUp(self): super().setUp() self.client = PodmanClient(base_url=self.socket_uri) self.addCleanup(self.client.close) with suppress(NotFound): self.client.networks.get("integration_test").remove(force=True)
def setUp(self) -> None: super().setUp() self.client = PodmanClient(base_url=tests.BASE_SOCK) def mocked_open(self, *args, **kwargs): return PodmanClientTestCase.opener(self, *args, **kwargs) self.mocked_open = mocked_open
def test_tcp_ping(self): podman = utils.PodmanLauncher( "tcp:localhost:8889", podman_path=base.IntegrationTest.podman, log_level=self.log_level, ) try: podman.start(check_socket=False) time.sleep(0.5) with PodmanClient(base_url=f"tcp:localhost:8889") as client: self.assertTrue(client.ping()) with PodmanClient(base_url=f"http://localhost:8889") as client: self.assertTrue(client.ping()) finally: podman.stop()
def setUp(self): super().setUp() self.client = PodmanClient(base_url=self.socket_uri) self.addCleanup(self.client.close) self.alpine_image = self.client.images.pull("quay.io/libpod/alpine", tag="latest")
def test_swarm(self): with PodmanClient(base_url=tests.BASE_SOCK) as client: with self.assertRaises(NotImplementedError): # concrete property _ = client.swarm with self.assertRaises(NotImplementedError): # aliased property _ = client.nodes
def _podman_connect(self, podman_uri: str): logging.debug("Connecting to Podman API") try: client = PodmanClient(base_url=podman_uri, timeout=60) client.info() # info() will try to connect to the API except APIError as e: raise PoolManagerError(f"Could not connect to Podman API: {e}") self._podman_client = client
def setUp(self): super().setUp() self.client = PodmanClient(base_url=self.socket_uri) self.addCleanup(self.client.close) self.alpine_image = self.client.images.pull("quay.io/libpod/alpine", tag="latest") # TODO should this use podman binary instead? for container in self.client.containers.list(): container.remove(force=True)
def __init__(self, socket="/var/run/podman/podman.sock"): """Initialize the Directord pod connection class. Sets up the pod api object. :param socket: Socket path to connect to. :type socket: String """ self.pod = PodmanClient(base_url="unix://{socket}".format( socket=socket)) self.api = self.pod.api
def test_contextmanager(self, mock): body = { "host": { "arch": "amd65", "os": "linux", } } mock.get(tests.BASE_URL + "/libpod/info", json=body) with PodmanClient(base_url="http+unix://localhost:9999") as client: actual = client.info() self.assertDictEqual(actual, body)
def test_connect(self): with mock.patch.multiple(Path, open=self.mocked_open, exists=MagicMock(return_value=True)): with PodmanClient(connection="testing") as client: self.assertEqual( client.api.base_url.geturl(), "http+ssh://qe@localhost:2222/run/podman/podman.sock", ) # Build path to support tests running as root or a user expected = Path(xdg.BaseDirectory.xdg_config_home ) / "containers" / "containers.conf" PodmanClientTestCase.opener.assert_called_with(expected)
def test_connect_default(self): with mock.patch.multiple(Path, open=self.mocked_open, exists=MagicMock(return_value=True)): with PodmanClient() as client: expected = "http+unix://" + urllib.parse.quote_plus( str( Path(xdg.BaseDirectory.get_runtime_dir(strict=False)) / "podman" / "podman.sock")) self.assertEqual(client.api.base_url.geturl(), expected) # Build path to support tests running as root or a user expected = Path(xdg.BaseDirectory.xdg_config_home ) / "containers" / "containers.conf" PodmanClientTestCase.opener.assert_called_with(expected)
def test_contextmanager(self, mock): body = { "host": { "arch": "amd65", "os": "linux", } } adapter = mock.get(tests.LIBPOD_URL + "/info", json=body) with PodmanClient(base_url=tests.BASE_SOCK) as client: actual = client.info() self.assertDictEqual(actual, body) self.assertIn("User-Agent", mock.last_request.headers) self.assertIn("PodmanPy/", mock.last_request.headers["User-Agent"], mock.last_request.headers)
def setUp(self) -> None: super().setUp() self.client = PodmanClient(base_url="http+unix://localhost:9999")
def setUp(self) -> None: super().setUp() self.client = PodmanClient(base_url=tests.BASE_SOCK)
def test_connect_404(self): with mock.patch.multiple(Path, open=self.mocked_open, exists=MagicMock(return_value=True)): with self.assertRaises(KeyError): _ = PodmanClient(connection="not defined")
def setUp(self): super().setUp() self.client = PodmanClient(base_url=self.socket_uri) self.addCleanup(self.client.close)
def podman(): runtime_dir = os.getenv("XDG_RUNTIME_DIR") uri = f"unix://{runtime_dir}/podman/podman.sock" with PodmanClient(base_url=uri) as client: yield client